cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072 USB CDC example NAKs everything

I'm still trying to get the USB CDC example to work on my STM32F072 disco board. I dug out my ancient Ellisys USB tracker and I can see enumeration looks good. When I hook up to Teraterm all I get is NAKs though. What should that be telling me?

 

9 REPLIES 9

From USB 2.0 8.4.5 Handshake Packets:

NAK indicates that a function was unable to accept data from the host (OUT) or that a function has no
data to transmit to the host (IN).

In other words, your microcontroller on given endpoint did not prepare data, which the host could pick up.

JW

Indeed, but as the example has negligible documentation, the question is why is the firmware not ready? I'm hoping someone here understands the example. A breakpoint on USBD_CDC_DataIn() never gets hit.

I don't use Cube neither do I use the device-only USB. However, it's a peripheral as any other, and it's governed by registers, however weird they may be. At one point, you tell through some library function "I want to send this data", and that should result in the library writing those data into the USB data buffer, and some control information into some USB register(s). That should be not impossible to observe in debugger.

After all the enumeration is usually the basic obstacle and you've already handled that. Now it's "only" the bulk data.

JW

 

Pavel A.
Evangelist III

Enumeration also involves IN requests to read the descriptors, though on a different endpoint. Since it works, your hardware is likely good. But that you don't get breakpoints where expected can mean that the endpoints for CDC data are not set up correctly, or the endpoint descriptors have errors. I've done a CDC device on 'F072 few years ago, based on the ST example. IIRC that was not too hard. The toolchain was Keil, though. Check the descriptors and configuration of endpoints. After enumeration do you see also the usual requests from the host for line settings, baudrate, etc.?

 

 

gbm
Lead III

What example? How do you send and receive data in your code?

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

This is a follow on from my related question at https://community.st.com/t5/stm32-mcus-embedded-software/help-deciphering-the-stm32f072-usb-cdc-example/td-p/631500

The example is from https://github.com/STMicroelectronics/STM32CubeF0/tree/master/Projects/STM32072B_EVAL/Applications/USB_Device/CDC_Standalone and my hardware is the STM32F072 disco board

I think I'm just going to give up because I've finally made some progress with the rival Silabs Giant Gecko example.

The example doesn't look reasonable to me.

 

Somewhere in device init code CDC_Itf_ReceivePacket() should be called (it wasn't in older versions of ST USB - check this in the version you use). Without it , the CDC will not be able to receive anything. Then CDC_Itf_ReceivePacket() must be called after the received data is processed. (update: just noticed that it probably is the case here).

Maybe the problem here is that not all the necessary interrupts are enabled (DMA, UART).

I would recommend to start without UART, just with simple CDC echo - quite easy to do with CubeIDE/CubeMX.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

@gbm,

> The example doesn't look reasonable to me.

Are you talking about the official Cube example Oliver linked to above?

JW

At first, I didn't notice it's official because of strange naming, different from the one used in CubeMX-generated examples. ;) Then I realized it's not as bad as it looks at the first sight. ;)

I am currently in the process of switching all my projects from heavily-modified ST USB device stack with added composite device support (it was before compdev was somehow included by ST) to my own one, written from scratch, with 3x smaller memory footprint and much simpler structure and operation.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice