Reputation: 1
I ported a USBX using the stm32H5 development board, and then created a task to send data using FreeRtos, but the task runs three times before it successfully sends data once. I tried debugging with STLink, but it didn't find the problem, where should I troubleshoot?
Here is my porting process
First I configured the USB using the STM32CubeMX
Then I added the USBX code and header files
After that I modify the code in usb.c to start the USB controller
I'm using USBX in STANDALONE mode, so run ux_system_tasks_run() in FreeRTOS.
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN defaultTask */
/* Infinite loop */
for(;;)
{
/*==============LED===========================*/
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_SET);
vTaskDelay(500);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET);
vTaskDelay(500);
/* call usbx system fuc*/
ux_system_tasks_run();
}
/* USER CODE END defaultTask */
}
Next I used another task to send data via USB
static void SPILCDTaskFunction( void *pvParameters )
{
char buf[100];
int cnt = 0;
while (1)
{
cnt ++;
sprintf(buf, "LCD Task Test : %d\r\n", cnt);
//Draw_String(0, 0, buf, 0x0000ff00, 0);
/* use usb send data */
int ux_device_cdc_acm_send(uint8_t *datas, uint32_t len, uint32_t timeout);
ux_device_cdc_acm_send((uint8_t *)buf, strlen(buf), 1000);
vTaskDelay(1000);
}
}
I was expecting to receive consecutive numbers per second on the serial port, but I didn't get one for 3 seconds.
[14:07:59.126]收←◆LCD Task Test : 79
[14:08:02.119]收←◆LCD Task Test : 82
[14:08:05.102]收←◆LCD Task Test : 85
[14:08:08.094]收←◆LCD Task Test : 88
[14:08:11.077]收←◆LCD Task Test : 91
[14:08:14.072]收←◆LCD Task Test : 94
[14:08:17.052]收←◆LCD Task Test : 97
[14:08:32.993]收←◆LCD Task Test : 100
I used ST-Link debugging and found that this task is running fine, that is to say the Variable cnt grows continuously, but the ux_device_cdc_acm_send() function is called every three times before the data is successfully sent once
ux_device_cdc_acm_send() function
int ux_device_cdc_acm_send(uint8_t *datas, uint32_t len, uint32_t timeout)
{
if (cdc_acm)
{
if (UX_SUCCESS == ux_device_class_cdc_acm_write_with_callback(cdc_acm, datas, len))
{
}
else
{
return -1;
}
}
else
{
return -1;
}
return 0;
}
I'm using the serial debugging assistant to send data to the board and he's receiving it fine.
I don't know where to look next to troubleshoot the error
Upvotes: 0
Views: 100
Reputation: 1
I found the reason, it turns out that I put an LED task in the default task of RTOS, so the default task has a delay of 1s every time, and the USBX system function ux_system_tasks_run() is also in this task, and it will be affected by the delay, which results in the message not being sent in time
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN defaultTask */
/* Infinite loop */
for(;;)
{
/*==============LED===========================*/
// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_SET);
// vTaskDelay(500);
// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET);
// vTaskDelay(500);
ux_system_tasks_run();
}
/* USER CODE END defaultTask */
}
As shown in the code above, after I commented out the LED and delay related code, I received the desired result
[14:09:56.984]收←◆LCD Task Test : 35
[14:09:57.985]收←◆LCD Task Test : 36
[14:09:58.970]收←◆LCD Task Test : 37
[14:09:59.972]收←◆LCD Task Test : 38
[14:10:00.974]收←◆LCD Task Test : 39
[14:10:01.959]收←◆LCD Task Test : 40
[14:10:02.538]发→◇12343245324534efsadfasdfasdfa□
[14:10:02.960]收←◆LCD Task Test : 41
[14:10:03.961]收←◆LCD Task Test : 42
[14:10:04.947]收←◆LCD Task Test : 43
Upvotes: 0