1
votes

I have created a project using STMCubeMX which includes a usbd driver configured as a virtual com port. I have it working and can receive data via the CDC_Receive_FS callback. My question is how is this callback called. Is it done at interrupt level, or is there some other mechanism. In particular, if I want to copy the data from the callback buffer into a queue which will be read by my main code, do I need some protection for concurrency (e.g. disable interrupts)?

Thanks.

1
is it difficult to place the breakpoint there and sell call stack?0___________
Well I have yet to be able to get the debugger working properly (I am using Eclipse), so yes, at this point it is. I was hoping that someone would know the answer.John Gaby
Start from it. Configure the tools first.0___________
Are using System Workbench from st (which is based on Eclipse)?iamJP
Yes, I am. And I have an ST-LINK V2, but have not been able to get debugging to work so far.John Gaby

1 Answers

3
votes

It is called from an ISR. (Interrupt Service Routine)

Most likely it is called from:

OTG_HS_IRQHandler.  

(with several levels of functions inbetween).

Here is a copy of my stack inside of a breakpoint.

CDC_Receive_HS() at usbd_cdc_if.c:456 0x801c758 
USBD_CDC_DataOut() at usbd_cdc.c:699 0x8031592  
USBD_LL_DataOutStage() at usbd_core.c:331 0x80318aa 
HAL_PCD_DataOutStageCallback() at usbd_conf.c:249 0x801e486 
HAL_PCD_IRQHandler() at stm32f7xx_hal_pcd.c:359 0x802d264   
OTG_HS_IRQHandler() at stm32f7xx_it.c:288 0x801ab74 

You most likely do NOT need to disable other interrupts just to copy this data to another buffer. I believe the buffer it uses should only be used by the usb receive. Copy the data to a separate buffer. The new buffer will need concurrency protection when used outside of this interrupt.

If you are using FreeRTOS, I recommend using the "xQueue" type as a buffer. It is thread safe. You use xQueueSendToBackFromISR inside of interrupts and xQueueSendToBack outside of interrupts.