STM32F103 USB + FreeRTOS question

Hi group I I’m new in this discussion forum and would like to introduce myself. I’m telecommunications and electronics engineer, graduated in 2012. Since some time ago I have been working with STM32 microcontrollers (F1 and F4) and I have a reasonable knowledge about the use of FreeRTOS. Currently I’m working in a project where I would like to use FreeRTOS and need to use USB peripheral in device mode. In the past I have dealt with the interaction between interrupts and tasks, first using semaphores and now using task notifications. My problem comes when I try to apply a principle similar to the handling of STM32F103 USB interrupts, synchronized to a handler task to deal with the USB protocol. The typical scheme delegates the interrupt handling to a task but in the case of this peripheral the interrupt keeps alive until you explicitly clear the causing bits,which I planed to do in the task. When I try to switch the execution to the handler task, the interrupt fires again and again. I tried to temporarily disable the USB interrupt, switch to the task and enable the interrupt again at the end of the task but it doesn’t work always, I guess because of timeouts in the USB protocol. Did someone faced this issue before? Any suggestions? Thanks in advance and sorry for the long post. Best regards.

It sounds like there is no way out of the interrupt until the source of the interrupt has been cleared. Its a while since I’ve done anything with USB so this might be a daft question - but are you able to gather all the information you need from inside the interrupt handler, clear the interrupt, then process the gathered data in the task?

Hi, thanks for your quick reply. Well, in the case of the USB peripheral you can read the interrupt status register but there is a bit, associated with the completion of transfers that functions like a FIFO, in this case you have to cycle reading until there’s no more pending transfers.

Maybe the best solution is to handle the interrupts as traditional and just delegate to task some part of the processing

All depends on how time critical things are. If you have timing requirements that need to be met then process the data within the interrupt handler. Otherwise just fill a buffer, clear the interrupt and defer the processing to a task.