cancel
Showing results for 
Search instead for 
Did you mean: 

CAN and USB CDC on stm32f407 discovery

Mku1
Associate III

Hi is it possible to use in the same time can and USB CDC because i need to receive message from can and then transmit over usb to PC?

11 REPLIES 11
Mku1
Associate III

I can transmit over USB message using CDC_Transmit and i can send CAN message but dont get interrupt for receiving CAN message. Interrupt occurs that can message is received only when i dont initialize USB_CDC

Mku1
Associate III

anyone?

JoniS
Senior

Should be possible, or atleast the reference manual did not tell anything else when i fast looked at it.

How did observe that receive can rx interrupt is not called when USB is initialised? Have you looked at the can register values before and after USB init? Have you tried different order of init, ie. If USB is now first, init can first etc.

There are quite alot of ​discussion about the USB cdc within these forums with many mcu's, maybe you can find something related from there.

I myself have custom board with stm32f446 and have no proplems with USB cdc and can simultaneously, thought i haven't really pushed it more than ~40kb/s rate from can to PC.

Mku1
Associate III

I have debugging and put that in interupt when can rx occurs it should toggle led. When i dont call MX_USB_DEVICE_INIT led has toggled when i send from can device message and during debug session i get data and everything what i have sent from another device over CAN. But when i call MX_USB_DEVICE_INIT led doesnt turn on and in debug session breakpoint doest hit in interrupt. I have configured in CUBE_MX usb_FS as device only and CDC class

Mku1
Associate III

I have also tried different order of init and also doest helps. Are you using CAN1_RX0_IRQHandler for getting RX message over CAN or?

Yes, I use interrupts for can receive.

One thing came to my mind, have you inchereased heap and stack size? ​It's quite common that you have to do that when using the STM provided USB middleware driver. I think you can do it via STM32cube before you generate the code.

Mku1
Associate III

I have tried to decrease usb_tx and rx bufffer to 64 and it didnt help. Where in cubeMX and how much to put for a size of heap and stack (stm32f407 DISC1) ?

Atleast double the default value, I can't remember the exact place since I haven't used cubemx for sometime, but I believe it was near the settings where you can select if you want hal or ll driver periephals.​

Mku1
Associate III

I have found and double values for heap and stack but system have the same behavioral . :S