AnsweredAssumed Answered

FreeRTOS STM32F4 Question / Problem

Question asked by Hz Lin on Dec 23, 2017
Latest reply on Dec 31, 2017 by KIC8462852 EPIC204278916

I am a beginner in both STM32 and FreeRTOS. I tried writing a FreeRTOS program logging ADC reading through serial port. I have a DMA set-up to save ADC readings in an circular buffer array, and I also have a DMA set up for serial port. Meanwhile, I have another thread running to blink a LED through PWM using timer 12, and another defaultTask doing nothing. The board is STM32F446RE nucleo, and the initial code was generated using STM32Cube.

The part of code with modification is shown below:

 

 

/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{

/* USER CODE BEGIN StartDefaultTask */
/* Infinite loop */
osDelay(5);
for(;;)
{
osDelay(100);
}
/* USER CODE END StartDefaultTask */
}

/* StartTECContrlTask function */
void StartTECContrlTask(void const * argument)
{
/* USER CODE BEGIN StartTECContrlTask */
/* Infinite loop */
static float ratio_tmp=0;
for(;;)
{
ratio_tmp=(1.0+sinf(0.02*xTaskGetTickCount()))/2.0;
TEC_set_valuef(ratio_tmp,ratio_tmp);
osDelay(5);
}
/* USER CODE END StartTECContrlTask */
}

/* StartDataLogTask function */
void StartDataLogTask(void const * argument)
{
/* USER CODE BEGIN StartDataLogTask */
if(HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADC_results, ADC_DATA_N) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* Infinite loop */
for(;;)
{
uint16_t str_size=sprintf(print_buff, "t %5d : %d %d \r\n",xTaskGetTickCount(),uhADC_results[0],uhADC_results[1]);
//uint16_t str_size=strlen(print_buff);
//HAL_UART_Transmit(&huart2,print_buff,strlen(print_buff),1000);
while(HAL_UART_Transmit_DMA(&huart2,print_buff, str_size)!= HAL_OK){
osDelay(2);
}
osDelay(20);
//vTaskList(print_buff);
//HAL_UART_Transmit_DMA(&huart2,print_buff, 200);
//osDelay(30);
}
/* USER CODE END StartDataLogTask */
}

For some reason, the code stops around 10 seconds. I have tried several things:

  1. Increasing the delay amount seems to make it goes away.
  2. Whether the memory is statically or dynamically allocated does not seem to change it.
  3. I have logged the TaskList. Right  before it crashes, the stack watermark will suddenly go very low, and task name got corrupted somehow. (The code I post above have those parts commented because I am currently trying static memory, which does not support vTaskList)
  4. when it crashes, it goes here:

I don't know what is wrong with this arguably simple code. But I am a student really new in this, and would really appreciate any help.

Thanks!

Outcomes