cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube USB CDC STM32F4Discovery Working!

abebarker
Associate II
Posted on May 09, 2015 at 20:23

I finally got the STM32Cube generated code for USB CDC on the STM32F4Discovery working. I had three issues that need to be corrected with in the generated code. I'm using STM32CubeMX ver 4.0.0 with STM32Cube V1.0 and library STM32Cube_FW_F4_V1.5.0

1) If then statement in stm32f4xx_hal_pcd.c.

2) Replace usbd_cdc.c with a newer version.

3) Cast first argument to USBD_GetString( as a (uint8_t*).

First issue:

/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/STM32Cube+CDC+-+problems+and+a+possible+bug&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=1680

null
2 REPLIES 2
abebarker
Associate II
Posted on May 09, 2015 at 20:38

I then had to figure out how to use the library to transfer data back and forth through the USB. I finally figured out how to do it.

extern USBD_HandleTypeDef hUsbDeviceFS;
 char MyRxBuff[16];

...

if(hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED){
// Transmit 

 USBD_CDC_SetTxBuffer(&hUsbDeviceFS, ''Hello

'', 7);
 USBD_CDC_TransmitPacket(&hUsbDeviceFS); 
// Receive
 USBD_CDC_SetRxBuffer(&hUsbDeviceFS, MyRxBuff);
 USBD_CDC_ReceivePacket(&hUsbDeviceFS);

 } 

If you transmit data before the USB is connected and configured it will crash! If data is sent to you over the USB before you call the receive functions, it will crash!

Posted on May 12, 2015 at 02:35

STM32F4Discovery, STM32CubeMX, STM32CubeF4, System Workbench. I have the distributed code working, loopback with TeraTerm. I had to add some code to the receive function in usbd_cdc.c.

What I want to know, is how does this code actually receive and send data to and from TeraTerm?

I had been expecting to put some c code inside the infinite while loop in main.c to make everything work and, what? Is HAL_delay being continuously called from somewhere in all the USB code?

Sorry if this question seems too simplistic, but i want to know what keeps everything running, where is the loop? There is no scheduler around as there is no OS.