FreeRTOS config

This commit is contained in:
2026-06-02 15:44:49 +02:00
parent 70ae757c33
commit b0152e2751
50 changed files with 39462 additions and 149 deletions

View File

@@ -1,23 +1,25 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "FreeRTOS.h"
#include "cmsis_os2.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
@@ -25,6 +27,7 @@
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
typedef StaticTask_t osStaticThreadDef_t;
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
@@ -36,7 +39,7 @@
/* demonstration code based on hardware semaphore */
/* This define is present in both CM7/CM4 projects */
/* To comment when developping/debugging on a single core */
#define DUAL_CORE_BOOT_SYNC_SEQUENCE
// #define DUAL_CORE_BOOT_SYNC_SEQUENCE
#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
#ifndef HSEM_ID_0
@@ -55,6 +58,37 @@
TIM_HandleTypeDef htim2;
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for crankTask */
osThreadId_t crankTaskHandle;
uint32_t crankTaskBuffer[ 128 ];
osStaticThreadDef_t crankTaskControlBlock;
const osThreadAttr_t crankTask_attributes = {
.name = "crankTask",
.cb_mem = &crankTaskControlBlock,
.cb_size = sizeof(crankTaskControlBlock),
.stack_mem = &crankTaskBuffer[0],
.stack_size = sizeof(crankTaskBuffer),
.priority = (osPriority_t) osPriorityRealtime7,
};
/* Definitions for camTask */
osThreadId_t camTaskHandle;
uint32_t camTaskBuffer[ 128 ];
osStaticThreadDef_t camTaskControlBlock;
const osThreadAttr_t camTask_attributes = {
.name = "camTask",
.cb_mem = &camTaskControlBlock,
.cb_size = sizeof(camTaskControlBlock),
.stack_mem = &camTaskBuffer[0],
.stack_size = sizeof(camTaskBuffer),
.priority = (osPriority_t) osPriorityRealtime7,
};
/* USER CODE BEGIN PV */
/* USER CODE END PV */
@@ -64,6 +98,10 @@ void SystemClock_Config(void);
static void MPU_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);
void StartDefaultTask(void *argument);
void crankHandler(void *argument);
void camHandler(void *argument);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@@ -96,10 +134,10 @@ int main(void)
#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
/* Wait until CPU2 boots and enters in stop mode or timeout*/
timeout = 0xFFFF;
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));
if ( timeout < 0 )
{
Error_Handler();
while ((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0))
;
if (timeout < 0) {
Error_Handler();
}
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
/* USER CODE END Boot_Mode_Sequence_1 */
@@ -116,21 +154,21 @@ int main(void)
SystemClock_Config();
/* USER CODE BEGIN Boot_Mode_Sequence_2 */
#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by means of
HSEM notification */
/*HW semaphore Clock enable*/
__HAL_RCC_HSEM_CLK_ENABLE();
/*Take HSEM */
HAL_HSEM_FastTake(HSEM_ID_0);
/*Release HSEM in order to notify the CPU2(CM4)*/
HAL_HSEM_Release(HSEM_ID_0,0);
/* wait until CPU2 wakes up from stop mode */
timeout = 0xFFFF;
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));
if ( timeout < 0 )
{
Error_Handler();
}
/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by
means of HSEM notification */
/*HW semaphore Clock enable*/
__HAL_RCC_HSEM_CLK_ENABLE();
/*Take HSEM */
HAL_HSEM_FastTake(HSEM_ID_0);
/*Release HSEM in order to notify the CPU2(CM4)*/
HAL_HSEM_Release(HSEM_ID_0, 0);
/* wait until CPU2 wakes up from stop mode */
timeout = 0xFFFF;
while ((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0))
;
if (timeout < 0) {
Error_Handler();
}
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
/* USER CODE END Boot_Mode_Sequence_2 */
@@ -145,10 +183,51 @@ Error_Handler();
/* USER CODE END 2 */
/* Init scheduler */
osKernelInitialize();
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of crankTask */
crankTaskHandle = osThreadNew(crankHandler, NULL, &crankTask_attributes);
/* creation of camTask */
camTaskHandle = osThreadNew(camHandler, NULL, &camTask_attributes);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */
/* USER CODE END RTOS_EVENTS */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
while (1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
@@ -266,6 +345,10 @@ static void MX_TIM2_Init(void)
{
Error_Handler();
}
if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM2_Init 2 */
/* USER CODE END TIM2_Init 2 */
@@ -307,6 +390,59 @@ static void MX_GPIO_Init(void)
/* USER CODE END 4 */
/* USER CODE BEGIN Header_StartDefaultTask */
/**
* @brief Function implementing the defaultTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for (;;) {
osDelay(1);
}
/* USER CODE END 5 */
}
/* USER CODE BEGIN Header_crankHandler */
/**
* @brief Function implementing the crankTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_crankHandler */
void crankHandler(void *argument)
{
/* USER CODE BEGIN crankHandler */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END crankHandler */
}
/* USER CODE BEGIN Header_camHandler */
/**
* @brief Function implementing the camTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_camHandler */
void camHandler(void *argument)
{
/* USER CODE BEGIN camHandler */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END camHandler */
}
/* MPU Configuration */
void MPU_Config(void)
@@ -345,8 +481,7 @@ void Error_Handler(void)
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
while (1) {
}
/* USER CODE END Error_Handler_Debug */
}
@@ -361,8 +496,9 @@ void Error_Handler(void)
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* User can add his own implementation to report the file name and line
number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file,
line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */