Showing results for 
Search instead for 
Did you mean: 

Unable to write device address into the DAD field of the DCFG register for USB device on STM32F411VET6U


I am writing a bare-metal USB CDC device stack on the STM32F411 discovery board which has a STM32F411VET6U controller. During enumeration I can see that the DAD field is not responding in the DCFG register. In other words when the stack tries to write the device address as per the host request, the DAD field is not getting populated with the right address. Here is the function I am using to write the address. 

void set_device_address(uint8_t device_address){

USB_DEVICE->DCFG &= ~(0x7F0);

USB_DEVICE->DCFG |= ((uint32_t)device_address << 4) & 0x7F0;

  printm("Im here in address 0x%x\n", USB_DEVICE->DCFG);

Through this code say if I am to set the device address to 87. I left shift it by 4 bits and try to write it in DAD. However I do not get the right value being put in. Ideally before writing the address into the DCFG the value is 0x200003 and after putting in the address of 87 (just an example in this case) I should be getting 0x200183, but I am getting 0x200073 instead in the DCFG register. This value changes for other address change requests by the host but never is the right address written in the DAD field in the DCFG register.

I have tried with both VBUS enabled and disabled but in both cases I see the same problem. Besides filling in the field 0 and 1 in the DSPD of the DCFG, trying to fill in the other fields do not work and junk values get populated in DCFG.

I have attached 2 screenshots of a debug session (before and after address setting in DAD) where I have captured the status of the DCFG register. The device address to be set can be seen in the variable window in the IDE. And in the memory viewer the address location corresponding to the DCFG register can be seen as well. In the screenshots, I have added some console messages for debugging purposes.  

I am attaching the console log messages as well


Have a look at the errata, Wrong software-read OTG_FS_DCFG register values erratum in particular.


Thank you so much for pointing me to the errata sheet.

At least this means the stack I'm writing has some other problem and hence not accepting the address change request from the host👍 so I can start looking into other areas of the stack for the issue.

Much appreciated.