cancel
Showing results for 
Search instead for 
Did you mean: 

How to access OTG_FS_DEVICE registers?

ATamb.2
Associate II

I am using Nucleo-STM32F767 board. I want to access usb device registers and do register level programming for my project.

3 REPLIES 3

Then perhaps read the Reference Manual, and data available for the Synopsys IP used.

A​ll the source for the library is available for review and analysis.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ABlac.3
Associate

To access the USB device registers on the Nucleo-STM32F767 board, you will need to follow these steps:

  1. Enable the USB device peripheral clock: The first step is to enable the clock for the USB device peripheral. This can be done by setting the appropriate bits in the RCC_AHB1ENR register.
  2. rust
RCC->AHB1ENR |= RCC_AHB1ENR_OTGFSULPIEN | RCC_AHB1ENR_OTGFSEN;
 

Here, the OTGFSEN and OTGFSULPIEN bits are set to enable the USB device and ULPI clock, respectively.

Configure the USB device: The next step is to configure the USB device by setting the appropriate values in the OTG_FS_GUSBCFG and OTG_FS_DCFG registers. This includes setting the USB speed, endpoint configuration, and other parameters. Refer to the STM32F767 Reference Manual for details on how to configure these registers.

Access the USB device registers: Once the USB device is configured, you can access its registers by using pointers to the corresponding memory-mapped addresses. For example, to access the OTG_FS_GINTSTS register, you can use the following code:

volatile uint32_t *pGINTSTS = (uint32_t*)(USB_OTG_FS_PERIPH_BASE + USB_OTG_GINTSTS_OFFSET);
 
uint32_t gintsts = *pGINTSTS;

Here, USB_OTG_FS_PERIPH_BASE is the base address of the USB device peripheral and USB_OTG_GINTSTS_OFFSET is the offset of the OTG_FS_GINTSTS register relative to the base address. The volatile keyword is used to ensure that the compiler does not optimize away the read operation.

Perform register level programming: You can perform register level programming by setting and clearing bits in the USB device registers. For example, to enable an interrupt for a specific USB device endpoint, you can set the corresponding bit in the OTG_FS_DAINTMSK register.

volatile uint32_t *pDAINTMSK = (uint32_t*)(USB_OTG_FS_PERIPH_BASE + USB_OTG_DAINTMSK_OFFSET);
*pDAINTMSK |= (1 << endpoint_num);

Here, endpoint_num is the number of the endpoint for which the interrupt is being enabled.

Note that register level programming can be complex and error-prone. Be sure to refer to the STM32F767 Reference Manual for detailed information on the USB device registers and their usage. It is also recommended to use the STM32CubeMX tool to generate code for configuring the USB device and to use the HAL (Hardware Abstraction Layer) or LL (Low-Level) drivers provided by STMicroelectronics to access the USB device registers.

I am willing to bet that this is a ChatGPT-generated text.

JW