Author Topic: STM32 register syntax  (Read 1692 times)

0 Members and 1 Guest are viewing this topic.

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
STM32 register syntax
« on: February 16, 2020, 03:10:27 pm »
 So in my Book by Carmine Noviello, I can access the GPIO structs easily since they are not divided into sub-peripherals.

How do i access the "sub-peripherals".

The syntax from the book does not work.

In OTG_FS_DEVICE, I wanna give a value to DIEPMSK, how would you do this?
 

Offline dave j

  • Regular Contributor
  • *
  • Posts: 128
  • Country: gb
Re: STM32 register syntax
« Reply #1 on: February 16, 2020, 05:17:10 pm »
If you look in the stm32f205xx.h file you'll see that USB_OTG_FS is a pointer defined as:

Code: [Select]
#define USB_OTG_FS ((USB_OTG_GlobalTypeDef *) USB_OTG_FS_PERIPH_BASE)
This is used to access the global registers starting at 0x50000000 as a USB_OTG_GlobalTypeDef structure.

Although there is a structure defined for accessing the device registers there isn't a pointer already defined so you'll have to do that yourself. Something like:

Code: [Select]
#define MY_OTG_DEVICE ((USB_OTG_DeviceTypeDef *) USB_OTG_FS_PERIPH_BASE+USB_OTG_DEVICE_BASE)
You should then be able to access the register using:

Code: [Select]
MY_OTG_DEVICE->DIEPMSK
I've used the name MY_OTG_DEVICE so it doesn't clash if STM decides to make a definition for it in the future and uses the more obvious name USB_OTG_DEVICE.
I'm not David L Jones. Apparently I actually do have to point this out.
 

Offline techman-001

  • Frequent Contributor
  • **
  • !
  • Posts: 748
  • Country: au
  • Electronics technician for the last 50 years
    • Mecrisp Stellaris Unofficial UserDoc
Re: STM32 register syntax
« Reply #2 on: February 16, 2020, 05:55:52 pm »
If you look in the stm32f205xx.h file you'll see that USB_OTG_FS is a pointer defined as:

Code: [Select]
#define USB_OTG_FS ((USB_OTG_GlobalTypeDef *) USB_OTG_FS_PERIPH_BASE)
This is used to access the global registers starting at 0x50000000 as a USB_OTG_GlobalTypeDef structure.

Although there is a structure defined for accessing the device registers there isn't a pointer already defined so you'll have to do that yourself. Something like:

Code: [Select]
#define MY_OTG_DEVICE ((USB_OTG_DeviceTypeDef *) USB_OTG_FS_PERIPH_BASE+USB_OTG_DEVICE_BASE)
You should then be able to access the register using:

Code: [Select]
MY_OTG_DEVICE->DIEPMSK
I've used the name MY_OTG_DEVICE so it doesn't clash if STM decides to make a definition for it in the future and uses the more obvious name USB_OTG_DEVICE.

I don't use C but as there are two "DIEPMSK" registers in this device, perhaps further categorization may be needed ?

\ OTG_FS_DEVICE_FS_DIEPMSK (read-write)
and
\ OTG_HS_DEVICE_OTG_HS_DIEPMSK (read-write)


 

Offline dave j

  • Regular Contributor
  • *
  • Posts: 128
  • Country: gb
Re: STM32 register syntax
« Reply #3 on: February 16, 2020, 06:55:48 pm »
I don't use C but as there are two "DIEPMSK" registers in this device, perhaps further categorization may be needed ?

\ OTG_FS_DEVICE_FS_DIEPMSK (read-write)
and
\ OTG_HS_DEVICE_OTG_HS_DIEPMSK (read-write)

Since DIEPMSK is part of a structure it only needs to be defined once.

It would be worth defining

OTG_FS_DEVICE
and
OTG_HS_DEVICE

to make it clear which set of registers were being accessed.
I'm not David L Jones. Apparently I actually do have to point this out.
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 register syntax
« Reply #4 on: February 17, 2020, 02:47:59 am »
Ok it compiled. Thanks alot.

So if I get it, it says, take this type of struct (USB_OTG_DeviceTypeDef *  ) , and apply this pattern starting at this address (base + offset) and name it MY_OTG.

Heres my setup, is this good?
« Last Edit: February 17, 2020, 02:54:39 am by lawrence11 »
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 register syntax
« Reply #5 on: February 17, 2020, 05:05:25 pm »
Hey I have a few small questions for you regarding USB.

I'm gonna show you a few images now from the Library and the ST helper files that came with video tutorials. I dont fully understand where I should write my data since theres so many functions.

I wanna make it so that when the "data endpoint ram buffer" to be sent to computer is empty and was acked, generate Interrupt based on this graph here. I seem to have only 1 enpoints, the EP0 and EP1.

So now the default is keyboard, 8 bytes sent. My plan is to write my function and inside the IRQ generated space  that is created by automatically by the checkbox in CubeMX, in the xx_it.c file. But before I reach this, I will have to mess around with the Interrupt hierarchy peripherals.

Any help would be appreciated.
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 register syntax
« Reply #6 on: February 17, 2020, 07:29:29 pm »
I keep seeing in the doc, Non periodic transmit FIFO.

So non periodic basically means what? The enumerations ?

It always refers to endpoint0.

Now I know endpoint0 is special for enumeration, and that ep1 is what I gotta work with.
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 register syntax
« Reply #7 on: February 18, 2020, 04:06:42 am »
So all I manage to make work is the sendreport HID

So now, How should I differentiate this event from HS and FS and externalize that somehow??

This example shows my method, I know this is not very elegant...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf