diff --git a/RTE/CMSIS/RTX_Config.h b/RTE/CMSIS/RTX_Config.h index 4d2f501..44393c0 100644 --- a/RTE/CMSIS/RTX_Config.h +++ b/RTE/CMSIS/RTX_Config.h @@ -64,7 +64,7 @@ // Defines how many ticks a thread will execute before a thread switch. // Default: 5 #ifndef OS_ROBIN_TIMEOUT -#define OS_ROBIN_TIMEOUT 5 +#define OS_ROBIN_TIMEOUT 1 #endif // diff --git a/RTE/_Target_1/RTE_Components.h b/RTE/_Target_1/RTE_Components.h index 58d6eab..5349988 100644 --- a/RTE/_Target_1/RTE_Components.h +++ b/RTE/_Target_1/RTE_Components.h @@ -20,15 +20,9 @@ #define RTE_CMSIS_RTOS2 /* CMSIS-RTOS2 */ #define RTE_CMSIS_RTOS2_RTX5 /* CMSIS-RTOS2 Keil RTX5 */ #define RTE_CMSIS_RTOS2_RTX5_SOURCE /* CMSIS-RTOS2 Keil RTX5 Source */ -/* Keil.ARM Compiler::Compiler:Event Recorder:DAP:1.5.1 */ -#define RTE_Compiler_EventRecorder - #define RTE_Compiler_EventRecorder_DAP -/* Keil.ARM Compiler::Compiler:I/O:STDIN:User:1.2.0 */ -#define RTE_Compiler_IO_STDIN /* Compiler I/O: STDIN */ - #define RTE_Compiler_IO_STDIN_User /* Compiler I/O: STDIN User */ -/* Keil.ARM Compiler::Compiler:I/O:STDOUT:User:1.2.0 */ +/* Keil.ARM Compiler::Compiler:I/O:STDOUT:ITM:1.2.0 */ #define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */ - #define RTE_Compiler_IO_STDOUT_User /* Compiler I/O: STDOUT User */ + #define RTE_Compiler_IO_STDOUT_ITM /* Compiler I/O: STDOUT ITM */ /* Keil::Device:STM32Cube Framework:Classic:1.2.7 */ #define RTE_DEVICE_FRAMEWORK_CLASSIC /* Keil::Device:STM32Cube HAL:CRC:1.2.7 */ diff --git a/lab06-evt.uvprojx b/lab06-evt.uvprojx index b4a7e0a..2ef308e 100644 --- a/lab06-evt.uvprojx +++ b/lab06-evt.uvprojx @@ -313,7 +313,7 @@ 1 - 1 + 3 0 0 1 @@ -446,19 +446,7 @@ - - - - - - - - - - - - - + @@ -543,12 +531,10 @@ - RTE\Compiler\EventRecorderConf.h + RTE\Compiler\EventRecorderConf.h - - - + RTE\Device\STM32F746NGHx\RTE_Device.h diff --git a/main.c b/main.c new file mode 100644 index 0000000..2535e61 --- /dev/null +++ b/main.c @@ -0,0 +1,152 @@ +/*---------------------------------------------------------------------------- + * CMSIS-RTOS 'main' function template + *---------------------------------------------------------------------------*/ + #include "stm32f7xx_hal.h" +#include "RTE_Components.h" +#include CMSIS_device_header +#include "cmsis_os2.h" +#include "string.h" +#include +#include "ext_uart.h" + +#ifdef RTE_Compiler_EventRecorder +#include "EventRecorder.h" +#endif + +#define NBR_COUNTER 4 + +osThreadId_t idTask1, idTask2, idTask3, idTask4, idTask5; +osMutexId_t mutexCounter[NBR_COUNTER]; + + const osThreadAttr_t AttrTask1 = { + .stack_size = 512, // Create the thread stack size + .priority = osPriorityNormal, //Set initial thread priority to high + .name = "Task 1" +}; + const osThreadAttr_t AttrTask2 = { + .stack_size = 512, // Create the thread stack size + .priority = osPriorityNormal, //Set initial thread priority to high + .name = "Task 2" +}; + const osThreadAttr_t AttrTask3 = { + .stack_size = 512, // Create the thread stack size + .priority = osPriorityNormal, //Set initial thread priority to high + .name = "Task 3" +}; + const osThreadAttr_t AttrTask4 = { + .stack_size = 512, // Create the thread stack size + .priority = osPriorityNormal, //Set initial thread priority to high + .name = "Task 4" +}; + + const osThreadAttr_t AttrTask5 = { + .stack_size = 1024, // Create the thread stack size + .priority = osPriorityHigh, //Set initial thread priority to high + .name = "Task 5", +}; + +uint32_t counter[NBR_COUNTER]; + + +/*---------------------------------------------------------------------------- + * Thread Task counter + *---------------------------------------------------------------------------*/ +__NO_RETURN static void taskCounter(void *argument) { + uint8_t idCounter = (uint8_t) *((uint8_t* )argument); + for (;;) { + osMutexAcquire(mutexCounter[idCounter], osWaitForever); + counter[idCounter]++; + osMutexRelease(mutexCounter[idCounter]); + } +} + +/*---------------------------------------------------------------------------- + * Thread Task 5 + *---------------------------------------------------------------------------*/ +__NO_RETURN static void task5(void *argument) { + uint32_t freq = osKernelGetTickFreq(); + uint32_t countTick = freq*5; + for (;;) { + uint32_t sum = 0; + for(uint8_t i = 0; i < NBR_COUNTER; i++) + { + osMutexAcquire(mutexCounter[i], osWaitForever); + sum += counter[i]; + printf("[%d] ", counter[i]); + osMutexRelease(mutexCounter[i]); + } + printf("\r\nSum = %u\r\n", sum); + osDelay(countTick); + } +} + +//------------------------------------------------------------------------------ +// Setup system clock to 216MHz +//------------------------------------------------------------------------------ +void SystemClock_Config (void) { + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct; + + /* Enable HSE Oscillator and activate PLL with HSE as source */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSIState = RCC_HSI_OFF; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 25; + RCC_OscInitStruct.PLL.PLLN = 432; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 9; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + /* Activate the OverDrive to reach the 216 MHz Frequency */ + HAL_PWREx_EnableOverDrive(); + + /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7); +} + +int main (void) { + + uint8_t task1_parameter = 0; + uint8_t task2_parameter = 1; + uint8_t task3_parameter = 2; + uint8_t task4_parameter = 3; + + // System Initialization + SystemCoreClockUpdate(); + SystemClock_Config(); +#ifdef RTE_Compiler_EventRecorder + // Initialize and start Event Recorder +// Ext_UART_Init(9600); + EventRecorderInitialize(EventRecordAll, 1U); +#endif + + osKernelInitialize(); // Initialize CMSIS-RTOS + + idTask1 = osThreadNew(taskCounter, &task1_parameter, &AttrTask1); + idTask2 = osThreadNew(taskCounter, &task2_parameter, &AttrTask2); + idTask3 = osThreadNew(taskCounter, &task3_parameter, &AttrTask3); + idTask4 = osThreadNew(taskCounter, &task4_parameter, &AttrTask4); + idTask5 = osThreadNew(task5, NULL, &AttrTask5); + + //---------------------------------------------------------------------------------------------- + // get names are placed for TraceAlyzer visualisation + //---------------------------------------------------------------------------------------------- + osThreadGetName(idTask1); + osThreadGetName(idTask2); + osThreadGetName(idTask3); + osThreadGetName(idTask4); + osThreadGetName(idTask5); + + + osKernelStart(); + // Start thread execution + for (;;) { + } +}