Skip to main content
Malaa.1
Associate II
December 15, 2019
Question

What is wrong with my registers` definition in this code?

  • December 15, 2019
  • 3 replies
  • 1176 views

Hello , I`m newbie to STM32 processors , i was working on AVR .....

It has been 3 days since i was trying to find out what is wrong with my registers` definition .. in this photo i defined RCC_APB2ENR and i did try to set a specific bit , but the result is that the bit is not set .. can anyone help me with that?

0690X00000Buco5QAB.png

This topic has been closed for replies.

3 replies

Piranha
Principal III
December 15, 2019

It should work. Debugger problems?

Another question. Register definitions are probably the only useful "code" from ST. Why you are redefining those?

Malaa.1
Malaa.1Author
Associate II
December 15, 2019

Well it is not working and i flashed the code onto the controller and the led connected to a specific GPIOD Pin didn`t turn on ...

and i am redefining these again to get my hand used to it

berendi
Principal
December 15, 2019

Welcome to pointer arithmetic in C. And operators precedence.

Casting a value to another type is an unary operator, it has higher precedence as binary operators like addition. So 0x40023800 is converted to a pointer to uint32_t first, and 0x44 gets added to this pointer. By the rules of C pointer arithmetic, you'll get 0x40023800 + 0x44*sizeof(uint32_t).

To fix it, just ensure that the offset gets added to the base first by the rules of integer arithmetic, and cast to pointer afterwards.

((volatile uint32_t *)(0x40023800 + 0x44))

Malaa.1
Malaa.1Author
Associate II
December 15, 2019

Thank youuuuuu <3 , I had a doubt about that .... thank youuu again <3