Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

STM32F4 with FreeRTOS and USB HID

Posted by VladB on April 12, 2013
Hi,

platform: STM32F4 on STM32F4 Discovery Board
toolchain: Sourcery G++ Lite

I'm trying to merge two working projects (USB HID Device and a FreeRTOS based simple project) but i'm having some problems. After a quick debug of the project I found out that it's a problem with the delay function used by USB Module:
void USB_OTG_BSP_uDelay (const uint32_t usec)
{
__IO uint32_t count = 0;
uint32_t utime = (120 * usec / 7);
do
{
if ( ++count > utime )
{
break;
}
}
while (1);
}

After a call to this delay function, the debugger can't return to the previous level and seems to run continuously. When I pause the execution, the debugger seems to be in a function from task.c vTaskSwitchContext( void ) and I can't continue the debugging.

I have to mention that I call the USB init function before the creation of tasks and the start of scheduler.

Thank you.

RE: STM32F4 with FreeRTOS and USB HID

Posted by Dave on April 12, 2013
That delay function is very crude. It does not seem to take into account the clock speed for a start so will presumably only give you microseconds at when the STM32 is running at one particular clock speed. It just a C function though and probably nothing to do with the problem you are seeing.

“I have to mention that I call the USB init function before the creation of tasks and the start of scheduler.”


Are you saying that this error occurs before the scheduler has started? In which case vTaskSwitchContext() should never be running and I would guess that either vTaskSwitchContext() is installed on the wrong interrupt vector, or that your USB driver is using the same vectors as FreeRTOS. FreeRTOS uses the SVC, SysTick and PendSV interrupts, is the driver using any of those?

RE: STM32F4 with FreeRTOS and USB HID

Posted by VladB on April 12, 2013
The delay function comes from an official example. It works very well in the project that not include FreeRTOS. Yes, this error occurs before the scheduler has started. I will check the vectors used by USB driver and the necessity of the code from SysTick_Handler (I think I've already remove it).

I will come back with an answer asap.

Thank you.

RE: STM32F4 with FreeRTOS and USB HID

Posted by VladB on April 12, 2013
The USB driver isn't using the SVC, SysTick and PendSV. I've commented the map of FreeRTOS's handlers to standard names and the problem persist. In this case the call stack looks like:

WWDG_IRQHandler() at 0x801029c
() at 0xfffffff9
USB_OTG_BSP_uDelay() at usb_bsp.c:348 0x8003468
USB_OTG_BSP_mDelay() at usb_bsp.c:365 0x8003498
USB_OTG_CoreInit() at usb_core.c:408 0x8003f70
DCD_Init() at usb_dcd.c:128 0x8005462
USBD_Init() at usbd_core.c:144 0x8006542
USBDeviceInit() at usb_comm.c:44 0x80034be
main() at main.c:71 0x8002df4

When I use the FreeRTOS's handlers the call stack is:
vTaskSwitchContext() at tasks.c:1,836 0x8001e44
PendSV_Handler() at port.c:341 0x800043c


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS