2019-08-10 07:31 PM
I'm using STM32CubeIDE and created a project for the Nucleo-L476RG with FreeRTOS selected. I switched the Timebase Source to TIM6 to allow FreeRTOS to have SysTick. I created 2 tasks and 1 queue (for the default 16x queue size of uint16_t). Here are my tasks (the idea is to have LD2 toggle more and more slowly as time passes):
/* USER CODE BEGIN Header_startBlinkTask */
/**
* @brief Function implementing the blinkTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_startBlinkTask */
void startBlinkTask(void *argument)
{
/* USER CODE BEGIN 5 */
uint16_t msg;
uint16_t delay = 500; // Default delay
osStatus_t status;
/* Infinite loop */
for(;;)
{
// Assign delay based on message in queue
status = osMessageQueueGet(msgQueueHandle, &msg, NULL, 0);
// If message was received, update delay
if ( status == osOK )
{
delay = msg;
}
// Blink with given delay
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
osDelay(delay);
}
// In case we accidentally exit from task loop
osThreadTerminate(NULL);
/* USER CODE END 5 */
}
/* USER CODE BEGIN Header_startUITask */
/**
* @brief Function implementing the uiTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_startUITask */
void startUITask(void *argument)
{
/* USER CODE BEGIN startUITask */
uint16_t desiredDelay = 0;
/* Infinite loop */
for(;;)
{
desiredDelay += 100;
osMessageQueuePut(msgQueueHandle, &desiredDelay, 0, osWaitForever);
osDelay(1000);
}
// In case we accidentally exit from task loop
osThreadTerminate(NULL);
/* USER CODE END startUITask */
}
However, when I run this, the LED blinks once and then hangs. I stepped through the osMessageQueueGet() function and found that when there was a message waiting at the head of the queue, the memory location for the message is oddly cleared within the function.
I was able to track it down to the xTaskGetSchedulerState() function (please see attached screenshots). Before entering xTaskGetSchedulerState() (queue-01.png), you can see that the memory location 0x20000D78 contains my data (decimal 100), which is the head of the queue. As soon as I step into xTaskGetSchedulerState() (queue-02.png), that memory location is mysteriously cleared (set to 0). Queue-03.png shows that this memory location stays cleared after returning from that function.
I am very new to FreeRTOS and just now learning about queues. I figure that I must have something wrong in my code to be causing this. I am working through "Mastering STM32" by Carmine Noviello, but since he uses CMSIS-RTOS v1, I'm trying to update my code to CMSIS-RTOS v2 (with this example: https://www.keil.com/pack/doc/CMSIS/RTOS2/html/group__CMSIS__RTOS__Message.html#gaa515fc8b956f721a8f72b2c505813bfc).
Any help would be appreciated!