STM32 register syntax - Page 1
Forum section: electronics / general

author: lawrence11
author_rank: Frequent Contributor
timestamp: February 16, 2020, 03:10:27 pm
content: 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?

author: dave j
author_rank: Regular Contributor
timestamp: February 16, 2020, 05:17:10 pm
content: If you look in the stm32f205xx.h file you'll see that USB_OTG_FS is a pointer defined as:Code:#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:#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:MY_OTG_DEVICE->DIEPMSKI'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.

author: techman-001
author_rank: Frequent Contributor
timestamp: February 16, 2020, 05:55:52 pm
content: Quote from: dave j on February 16, 2020, 05:17:10 pmI 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)

author: dave j
author_rank: Regular Contributor
timestamp: February 16, 2020, 06:55:48 pm
content: Quote from: techman-001 on February 16, 2020, 05:55:52 pmSince DIEPMSK is part of a structure it only needs to be defined once.It would be worth definingOTG_FS_DEVICEandOTG_HS_DEVICEto make it clear which set of registers were being accessed.

author: lawrence11
author_rank: Frequent Contributor
timestamp: February 17, 2020, 02:47:59 am
content: 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?

author: lawrence11
author_rank: Frequent Contributor
timestamp: February 17, 2020, 05:05:25 pm
content: 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.

author: lawrence11
author_rank: Frequent Contributor
timestamp: February 17, 2020, 07:29:29 pm
content: 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.

author: lawrence11
author_rank: Frequent Contributor
timestamp: February 18, 2020, 04:06:42 am
content: So all I manage to make work is the sendreport HIDSo 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...