Skip to content

Commit 42fcbcd

Browse files
committed
add a heartbeat task
1 parent 614b04d commit 42fcbcd

File tree

7 files changed

+69
-2
lines changed

7 files changed

+69
-2
lines changed

stm32-modules/flex-stacker/firmware/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_STM32G4_freertos(${TARGET_MODULE_NAME})
77
add_STM32G4_usb(${TARGET_MODULE_NAME})
88

99
set(SYSTEM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/system")
10+
set(UI_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ui")
1011
set(COMMS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/host_comms_task")
1112
set(MOTOR_CONTROL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/motor_control")
1213
set(COMMON_MCU_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../common/STM32G491")
@@ -17,6 +18,7 @@ set(GDBINIT_PATH "${CMAKE_CURRENT_BINARY_DIR}/../../common/STM32G491/gdbinit")
1718
set(${TARGET_MODULE_NAME}_FW_LINTABLE_SRCS
1819
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
1920
${SYSTEM_DIR}/freertos_idle_timer_task.cpp
21+
${UI_DIR}/freertos_ui_task.cpp
2022
${MOTOR_CONTROL_DIR}/freertos_motor_task.cpp
2123
${MOTOR_CONTROL_DIR}/freertos_motor_driver_task.cpp
2224
${MOTOR_CONTROL_DIR}/motor_driver_policy.cpp
@@ -27,6 +29,8 @@ set(${TARGET_MODULE_NAME}_FW_NONLINTABLE_SRCS
2729
${SYSTEM_DIR}/stm32g4xx_hal_msp.c
2830
${SYSTEM_DIR}/stm32g4xx_it.c
2931
${SYSTEM_DIR}/system_stm32g4xx.c
32+
${SYSTEM_DIR}/hal_tick.c
33+
${UI_DIR}/ui_hardware.c
3034
${COMMS_DIR}/usbd_conf.c
3135
${COMMS_DIR}/usbd_desc.c
3236
${COMMS_DIR}/usb_hardware.c

stm32-modules/flex-stacker/firmware/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ using EntryPoint = std::function<void(tasks::FirmwareTasks::QueueAggregator *)>;
1111
static auto motor_driver_task_entry = EntryPoint(motor_driver_task::run);
1212
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
1313
static auto motor_task_entry = EntryPoint(motor_control_task::run);
14-
14+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
15+
static auto ui_task_entry = EntryPoint(ui_control_task::run);
1516
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
1617
static auto aggregator = tasks::FirmwareTasks::QueueAggregator();
1718

@@ -23,13 +24,18 @@ static auto driver_task =
2324
static auto motor_task =
2425
ot_utils::freertos_task::FreeRTOSTask<tasks::MOTOR_STACK_SIZE, EntryPoint>(
2526
motor_task_entry);
26-
27+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
28+
static auto ui_task =
29+
ot_utils::freertos_task::FreeRTOSTask<tasks::UI_STACK_SIZE, EntryPoint>(
30+
ui_task_entry);
2731
auto main() -> int {
2832
HardwareInit();
33+
2934
driver_task.start(tasks::MOTOR_DRIVER_TASK_PRIORITY, "Motor Driver",
3035
&aggregator);
3136
motor_task.start(tasks::MOTOR_TASK_PRIORITY, "Motor", &aggregator);
3237

38+
ui_task.start(tasks::UI_TASK_PRIORITY, "UI", &aggregator);
3339
vTaskStartScheduler();
3440
return 0;
3541
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "firmware/freertos_tasks.hpp"
2+
3+
#include "firmware/ui_hardware.h"
4+
5+
namespace ui_control_task {
6+
7+
auto run(tasks::FirmwareTasks::QueueAggregator* aggregator) -> void {
8+
while (true) {
9+
ui_hardware_set_heartbeat_led(true);
10+
vTaskDelay(500);
11+
ui_hardware_set_heartbeat_led(false);
12+
vTaskDelay(500);
13+
}
14+
}
15+
16+
}; // namespace ui_control_task
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "main.h"
2+
3+
#include <stdbool.h>
4+
5+
#include "stm32g4xx_hal.h"
6+
7+
8+
#define nSTATUS_LED_Pin GPIO_PIN_10
9+
#define nSTATUS_LED_GPIO_Port GPIOC
10+
11+
void ui_hardware_set_heartbeat_led(bool setting) {
12+
//NOLINTNEXTLINE(performance-no-int-to-ptr)
13+
HAL_GPIO_WritePin(nSTATUS_LED_GPIO_Port, nSTATUS_LED_Pin,
14+
setting ? GPIO_PIN_SET : GPIO_PIN_RESET);
15+
}

stm32-modules/include/flex-stacker/firmware/firmware_tasks.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ constexpr uint8_t MOTOR_TASK_PRIORITY = 1;
2424
constexpr size_t MOTOR_DRIVER_STACK_SIZE = 256;
2525
constexpr uint8_t MOTOR_DRIVER_TASK_PRIORITY = 1;
2626

27+
constexpr size_t UI_STACK_SIZE = 256;
28+
constexpr uint8_t UI_TASK_PRIORITY = 1;
29+
2730
}; // namespace tasks

stm32-modules/include/flex-stacker/firmware/freertos_tasks.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ namespace motor_control_task {
1818
auto run(tasks::FirmwareTasks::QueueAggregator* aggregator) -> void;
1919

2020
} // namespace motor_control_task
21+
22+
namespace ui_control_task {
23+
24+
// Actual function that runs in the task
25+
auto run(tasks::FirmwareTasks::QueueAggregator* aggregator) -> void;
26+
} // namespace ui_control_task
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef UI_HARDWARE_H__
2+
#define UI_HARDWARE_H__
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif // __cplusplus
6+
7+
#include <stdbool.h>
8+
9+
/**
10+
* @brief Enter the bootloader. This function never returns.
11+
*/
12+
void ui_hardware_set_heartbeat_led(bool setting);
13+
14+
#ifdef __cplusplus
15+
} // extern "C"
16+
#endif // __cplusplus
17+
#endif // _UI_HARDWARE_H__

0 commit comments

Comments
 (0)