2017-12-23 12:40 PM
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:
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!
#freertos+hal #freertos #stm32cube_fw_f42017-12-23 09:15 PM
How long does it take to get an adc value? [T1]
How long does it take to send the same data by uart? [T2]
2017-12-24 07:36 AM
It takes ~1.2ms to send the 30byte data through uart (I configured baud rate of 256000)
And I have my ADC running in scanning mode. It takes ~0.05ms to finish one round of conversion. I leave it to be always running.
2017-12-30 02:54 PM
I found this post which seems to be related to my issue.
I do observe corruption of the default task when I debug this application, which seems to agree with what the post mentions.
So I increase stack size of all the tasks to 1024 words and now it seems to works fine.
But still I am not understanding this issue. Could someone please explain what is going on? Why is the stack of the default task that becomes relevant? And is this the right way to solve this issue?
Thanks.
2017-12-31 12:18 AM
Not being verse in RTOS, it probably means your task buffers or related local variables or pointets need space in there. The initial question was to make sure the buffer acting as fifo was large enough for the feeding rate from adc and eating rate of serial interface.