0

I am trying to use the USB Device library on STM32Cube but when I execute using the debugger or that I try to turn an LED on in CDC_Receive_FS, it never reaches that point.

Here is how I set up everyting:

  • My board is a NUCLEO-F746ZG
  • I enabled USB_OTG_FS in Device_Only mode, activated _VBUS and _SOF. Left everything else by default and USB On The Go FS global interrupt is enabled!
  • I set up USB_DEVICE: Class For FS IP set to Virtual Port Com, left everything by default
  • Main loop left empty
  • CDC_Receive_FS: put breakpoint in it and/or HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
  • I have TIM2 set up for the things I would like to do when it will work

Then I tried to send data to the board, first using Python using serial with a baudrate of 921600 but got nothing. Then using PuTTY with a baudrate of 9600, still nothing...

If anyone has a clue, I have been struggling with it the whole day.
Here is the whole project: https://ecloud.global/s/cjGYqK6z9g58Lm4

Ardakaniz
  • 155
  • 1
  • 7
  • Maybe this belong to electrical engineering? – Ardakaniz Jun 03 '22 at 15:57
  • generally this should work, as I have the same approach and it works. Please do a quick check, disable VBUS sensing and SOF and try again. My USB_OTG_FS Mode and Configuration is: Device_Only, Activate_SOF=Off, Activate_VBUS=Off, Speed=12MBit/s, Low power = Disabled, Link Power Management = Disabled, VBUS sensing = Disabled, Signal start of frame = Disabled. You could use this https://controllerstech.com/send-and-receive-data-to-pc-without-uart-stm32-usb-com/ tutorial for a quick hardware check. If you can get it run with this code, your hardware is ok – Chris_B Jun 04 '22 at 05:49
  • Thanks for your answer, I will be able to test on tuesday. One more thing I managed to try is CDC_Transmit_FS: the function always returned USBD_BUSY. After further investigation, I ended up realising that hUsbDeviceFS.pClassData was NEVER set and still a null ptr after 10s delay right after the init, that is weird – Ardakaniz Jun 05 '22 at 11:32
  • hmm, strange. I looked into one of my test projects, where I tested the procedure from the link in my last comment. You have to include >>#include "usb_device.h"<< and >>#include "usbd_cdc_if.h"<<. You have to call >>MX_USB_DEVICE_Init();<< in the int main(void) {...}, which is normaly done by the code-generation of CubeMX, and you need a RxComplete Callback function. Last but not least you have to edit the usb_cdc_if.c/h as follows in the next comment – Chris_B Jun 06 '22 at 15:52
  • Edit the usb_cdc_if.c/h as follows: // add __weak void CDC_RxCpltCallback(uint8_t* buf, uint32_t bufSz) to usb_cdc_if.h // add empty function __weak void CDC_RxCpltCallback(uint8_t* buf, uint32_t bufSz) to usb_cdc_if.c (User code Section) // edit usb_cdc_if.c, User-Code 6, add CDC_RxCpltCallback(Buf, *Len); to static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) // before return (USBD_OK); that worked well for me and I was able to send bytes via RealTerm and get a message back. – Chris_B Jun 06 '22 at 15:53
  • .... I ended up checking if this was a hardware issue, indeed... There are TWO usb port on the board, one ONLY for power, the other one that can be used for USB. Plugged both in then with the step 3/ of here https://stackoverflow.com/questions/40597612/stm32-usb-vcp-virtual-com-port it worked. Thanks – Ardakaniz Jun 07 '22 at 08:09

0 Answers0