SVC_Handler and PendSV_Handler

cuixiaoxia632 wrote on Friday, October 21, 2011:

I am working FreeRTOS in CortexM3 platform. As we know, we need define the following code in startup.s to make sure FREERTOS work.
IF FreeRTOS = {TRUE}
                           DCD     vPortSVCHandler              ; FreeRTOS SVC handler                                               
         ELSE
                           DCD     SVC_Handler                               ; SVCall Handler         
         ENDIF
                           DCD     DebugMon_Handler          ; Debug Monitor Handler
                           DCD     0                         ; Reserved
         IF FreeRTOS = {TRUE}
                           DCD     xPortPendSVHandler        ; FreeRTOS PendSV  Handler                                  
         ELSE
                           DCD     PendSV_Handler            ; PendSV Handler
         ENDIF               

But I found that USB otg code will call SVC_Handler and PendSV_Handler when communication with mass storage device.
So, it seems not possible that merge USBOTG function in FreeRTOS environment …

Anyone meet this question ?

rtel wrote on Friday, October 21, 2011:

I don’t know where your USBOTG software came from, not from me that’s for sure.  If it is using such a major core resource such as SVC then I would imagine it comes with instructions on how to integrate it into you code.

FreeRTOS only uses an SVC 0 call.  It uses it once only, to start the scheduler, and then never uses it again.  You therefore have three choices:

1) Move the vector table into RAM, then when the kernel has started, rewrite the SVC handler entry to use the USB OTG code.

2) Have two copies of the vector table, one in flash with the FreeRTOS handler as per normal, and one in RAM with the USB handler.  Then, when the scheduler has started, remap the vector table using the vector base address register.

3) Update the FreeRTOS handler so it checks the SVC call parameter.  Currently it assumes only one thing is using the SVC call, so it does not bother to check it and just assumes it is 0.

Regards.

cuixiaoxia632 wrote on Monday, October 24, 2011:

Richard:

first, thanks for your adivise…the usb otg code from ST… I use ST cortex M3 platform…its OTG code refers to SVC handler. ST guys develop a new file system library to operate USB file operation…I think method3 is ok for me .do you help support it ?
regards

cuixiaoxia632 wrote on Wednesday, October 26, 2011:

Richard:

I checked FreeRTOS code and find that it call " svc 0" to trigger svc handler…so it is possible to get the parameter of svc handler. would you help to get the parameter in svc_handler function … if this, I could dispath them to different svcaller …
thank you

Hello Richard,

I was about to post a question related to the usage of SVC in FreeRTOS, and I found this post from 2011. Now in 2024, is it still valid that FreeRTOS uses SVC 0 call only once to start the first task? I already rewrote the SVC handler entry but I still have this question if in the future I will find some strange behaviour.

Thanks in advance and best regards.

It depends on the port you are using. The original question was about Cortex-M3 port and it still uses only svc 0 - FreeRTOS-Kernel/portable/GCC/ARM_CM3/port.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub. Others ports use more SVC calls. For example, Cortex-M4 MPU port uses a number of SVC calls - FreeRTOS-Kernel/portable/GCC/ARM_CM4_MPU/port.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub.

Thank you for your reply Gaurav!

I forgot to share that detail, I’m actually interested in the Cortex-M7 port (ARM_CM7). At first sight I can only identify one SVC call in the prvPortStartFirstTask function. In this port is this the only time it is ever called?

Thanks again and best regards.

Yes, that is correct - CM7 only uses svc 0 to start the first task.