Skip to content

Commit 2bc0868

Browse files
HardyYuRonaldYou
andauthored
Feature/sm/scaffolding (#60)
Co-authored-by: RonaldYou <[email protected]>
1 parent 3c349c2 commit 2bc0868

File tree

6 files changed

+134
-48
lines changed

6 files changed

+134
-48
lines changed

Boardfiles/nucleol552zeq/Core/Inc/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
#define configTICK_RATE_HZ ((TickType_t)1000)
7373
#define configMAX_PRIORITIES ( 56 )
7474
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
75-
#define configTOTAL_HEAP_SIZE ((size_t)8192)
75+
#define configTOTAL_HEAP_SIZE ((size_t)65536)
7676
#define configMAX_TASK_NAME_LEN ( 16 )
7777
#define configUSE_TRACE_FACILITY 1
7878
#define configUSE_16_BIT_TICKS 0

Boardfiles/nucleol552zeq/Core/Src/main.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@
3232
#include "ucpd.h"
3333
#include "usb.h"
3434
#include "gpio.h"
35+
#include "SystemManager.hpp"
3536

3637
/* Private includes ----------------------------------------------------------*/
3738
/* USER CODE BEGIN Includes */
3839
#include "SystemManager.hpp"
3940
#include "drivers_config.hpp"
4041
#include "independent_watchdog.h"
4142

42-
extern "C" {
43-
#include "app_fatfs.h"
44-
#include "log_util.h"
45-
}
4643
/* USER CODE END Includes */
4744

4845
/* Private typedef -----------------------------------------------------------*/
@@ -77,9 +74,9 @@ extern "C" {
7774

7875
/* Private user code ---------------------------------------------------------*/
7976
/* USER CODE BEGIN 0 */
80-
void SMTask(void *pvParameters) {
81-
SystemManager SM;
82-
SM.flyManually();
77+
void SMTask(void * pvParameters){
78+
SystemManager SM;
79+
SM.startSystemManager();
8380
}
8481
/* USER CODE END 0 */
8582

@@ -131,23 +128,12 @@ int main(void)
131128
MX_ICACHE_Init();
132129
MX_TIM3_Init();
133130
MX_SDMMC1_SD_Init();
134-
if (MX_FATFS_Init() != APP_OK) {
135-
Error_Handler();
136-
}
137131
/* USER CODE BEGIN 2 */
138-
logInit();
139-
140-
TaskHandle_t hSM = NULL;
141-
xTaskCreate(SMTask, "SM", 500U, NULL, osPriorityNormal, &hSM);
142132

143133
/* USER CODE END 2 */
144134

145-
/* Init scheduler */
146-
osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */
147-
MX_FREERTOS_Init();
148-
149-
/* Start scheduler */
150-
osKernelStart();
135+
xTaskCreate(SMTask, "SM Task", 1500U, NULL, osPriorityNormal, NULL);
136+
vTaskStartScheduler();
151137
/* We should never get here as control is now taken by the scheduler */
152138
/* Infinite loop */
153139
/* USER CODE BEGIN WHILE */

Boardfiles/nucleol552zeq/Core/Src/usart.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
#include "usart.h"
2222

2323
/* USER CODE BEGIN 0 */
24-
24+
int __io_putchar(int ch)
25+
{
26+
HAL_UART_Transmit(&hlpuart1, (uint8_t *)&ch, 1, 100);
27+
return ch;
28+
}
2529
/* USER CODE END 0 */
2630

2731
UART_HandleTypeDef hlpuart1;
@@ -44,7 +48,7 @@ void MX_LPUART1_UART_Init(void)
4448

4549
/* USER CODE END LPUART1_Init 1 */
4650
hlpuart1.Instance = LPUART1;
47-
hlpuart1.Init.BaudRate = 209700;
51+
hlpuart1.Init.BaudRate = 112500;
4852
hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
4953
hlpuart1.Init.StopBits = UART_STOPBITS_1;
5054
hlpuart1.Init.Parity = UART_PARITY_NONE;

Boardfiles/nucleol552zeq/nucleol552zeq.ioc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ IWDG.IPParameters=Prescaler,Reload
100100
IWDG.Prescaler=IWDG_PRESCALER_8
101101
IWDG.Reload=3999
102102
KeepUserPlacement=false
103-
LPUART1.BaudRate=230400
103+
LPUART1.BaudRate=112500
104104
LPUART1.IPParameters=BaudRate
105105
Mcu.CPN=STM32L552ZET6Q
106106
Mcu.ContextProject=TrustZoneDisabled

SystemManager/Inc/SystemManager.hpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,34 @@
1616
#define SBUS_MAX 100
1717

1818
class SystemManager {
19-
public:
20-
/* Constructors and Destructors */
21-
SystemManager();
22-
~SystemManager();
23-
24-
/* Other managers*/
25-
TelemetryManager *telemetryManager;
26-
27-
/* Class Functions */
28-
void flyManually();
29-
30-
private:
31-
SBUSReceiver* rcController_;
32-
RCControl rcInputs_;
33-
PWMChannel throttleMotorChannel_;
34-
PWMChannel yawMotorChannel_;
35-
PWMChannel rollMotorChannel_;
36-
PWMChannel invertedRollMotorChannel_;
37-
PWMChannel pitchMotorChannel_;
38-
IndependentWatchdog watchdog_;
19+
public:
20+
/* Constructors and Destructors */
21+
SystemManager();
22+
23+
/* Other managers*/
24+
TelemetryManager *telemetryManager;
25+
26+
/* Class Functions */
27+
void startSystemManager();
28+
29+
private:
30+
SBUSReceiver* rcController_;
31+
RCControl rcInputs_;
32+
PWMChannel throttleMotorChannel_;
33+
PWMChannel yawMotorChannel_;
34+
PWMChannel rollMotorChannel_;
35+
PWMChannel invertedRollMotorChannel_;
36+
PWMChannel pitchMotorChannel_;
37+
IndependentWatchdog watchdog_;
38+
39+
static void attitudeManagerTaskWrapper(void *pvParameters);
40+
static void telemetryManagerTaskWrapper(void *pvParameters);
41+
static void pathManagerTaskWrapper(void *pvParameters);
42+
43+
void systemManagerTask();
44+
void attitudeManagerTask();
45+
void telemetryManagerTask();
46+
void pathManagerTask();
3947
};
4048

41-
4249
#endif //ZEROPILOT_3_5_SYSTEMMANAGER_HPP

SystemManager/Src/SystemManager.cpp

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
#include "sbus_defines.h"
1212
#include "sbus_receiver.hpp"
1313
#include "tim.h"
14+
#include "cmsis_os.h"
15+
#include "FreeRTOS.h"
16+
#include <iostream>
1417

18+
extern "C" {
19+
#include "app_fatfs.h"
20+
#include "log_util.h"
21+
}
1522

1623
#define TIMEOUT_CYCLES 250000 // 25k = 1 sec fro testing 10/14/2023 => 250k = 10 sec
1724
#define TIMOUT_MS 10000 // 10 sec
1825

26+
// 0 - AM, 1 - TM, 2 - PM
27+
static TaskHandle_t taskHandles[3];
28+
1929
static uint32_t DisconnectionCount = 0;
2030
float prevthrottle;
2131
float prevyaw;
@@ -60,10 +70,30 @@ SystemManager::SystemManager()
6070
}
6171

6272

63-
SystemManager::~SystemManager() {}
73+
//wrapper functions are needed as FreeRTOS xTaskCreate function does not accept functions that have "this" pointers
74+
void SystemManager::attitudeManagerTaskWrapper(void* pvParameters){
75+
SystemManager *systemManagerInstance = static_cast<SystemManager *>(pvParameters);
76+
systemManagerInstance->attitudeManagerTask();
77+
}
78+
79+
void SystemManager::telemetryManagerTaskWrapper(void* pvParameters){
80+
SystemManager *systemManagerInstance = static_cast<SystemManager *>(pvParameters);
81+
systemManagerInstance->telemetryManagerTask();
82+
}
83+
84+
void SystemManager::pathManagerTaskWrapper(void *pvParameters) {
85+
SystemManager *systemManagerInstance = static_cast<SystemManager *>(pvParameters);
86+
systemManagerInstance->pathManagerTask();
87+
}
88+
89+
void SystemManager::systemManagerTask(){
90+
TickType_t xNextWakeTime = xTaskGetTickCount();
91+
uint16_t frequency = 5;
92+
93+
for(;;){
94+
printf("SM called\r\n");
95+
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // toggle led light for testing
6496

65-
void SystemManager::flyManually() {
66-
for (;;) {
6797
this->rcInputs_ = rcController_->GetRCControl();
6898

6999
// TO-DO: need to implement it using is_Data_New;
@@ -103,5 +133,64 @@ void SystemManager::flyManually() {
103133
this->pitchMotorChannel_.set(SBUS_MAX / 2);
104134
this->invertedRollMotorChannel_.set(SBUS_MAX / 2);
105135
}
136+
137+
vTaskDelayUntil(&xNextWakeTime, 1000 / frequency);
138+
}
139+
}
140+
141+
void SystemManager::attitudeManagerTask(){
142+
TickType_t xNextWakeTime = xTaskGetTickCount();
143+
uint16_t frequency = 5;
144+
145+
for(;;){
146+
//call AM
147+
148+
printf("AM called\r\n");
149+
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_7); // toggle led light for testing
150+
vTaskDelayUntil(&xNextWakeTime, 1000 / frequency);
151+
}
152+
}
153+
154+
void SystemManager::telemetryManagerTask(){
155+
TickType_t xNextWakeTime = xTaskGetTickCount();
156+
uint16_t frequency = 5;
157+
158+
for(;;){
159+
//call TM
160+
161+
printf("TM called\r\n");
162+
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_9); // toggle led light for testing
163+
vTaskDelayUntil(&xNextWakeTime, 1000 / frequency);
164+
}
165+
}
166+
167+
void SystemManager::pathManagerTask(){
168+
TickType_t xNextWakeTime = xTaskGetTickCount();
169+
uint16_t frequency = 5;
170+
171+
for(;;){
172+
//call PM
173+
174+
printf("PM called\r\n");
175+
vTaskDelayUntil(&xNextWakeTime, 1000 / frequency);
176+
}
177+
}
178+
179+
void SystemManager::startSystemManager() {
180+
printf("Initializing Tasks\r\n");
181+
182+
// enabling SD card logging
183+
if (MX_FATFS_Init() != APP_OK) {
184+
Error_Handler();
106185
}
186+
logInit();
187+
188+
//BaseType_t xTaskCreate( TaskFunction_t pvTaskCode, const char * const pcName, configSTACK_DEPTH_TYPE usStackDepth, void * pvParameters, UBaseType_t uxPriority, TaskHandle_t * pxCreatedTask );
189+
// function's name description size of stack to allocate parameters for task priority handler
190+
xTaskCreate(attitudeManagerTaskWrapper, "AM TASK", 800U, this, osPriorityNormal, taskHandles);
191+
xTaskCreate(telemetryManagerTaskWrapper, "TM TASK", 800U, this, osPriorityNormal, taskHandles + 1);
192+
// xTaskCreate(pathManagerTaskWrapper, "PM TASK", 800U, this, osPriorityNormal, taskHandles +2);
193+
194+
systemManagerTask();
195+
107196
}

0 commit comments

Comments
 (0)