Author Topic: setting registers bits in KEIL ARM uvision problem!  (Read 555 times)

0 Members and 1 Guest are viewing this topic.

Offline kgavionicsTopic starter

  • Regular Contributor
  • *
  • Posts: 195
  • Country: ca
setting registers bits in KEIL ARM uvision problem!
« on: February 01, 2023, 08:00:58 pm »
Hello guys
I'm using keil uvsion latest version and I came across this problem that is when I try to enable the clock for GPIOD on stm32f407 as following:


Code: [Select]
RCC->AHB1ENR |= (1<<RCC_AHB1ENR_GPIOAEN) | (1<<RCC_AHB1ENR_GPIOBEN) | (1<<RCC_AHB1ENR_GPIODEN);
For some unknown reason, only GPIOD clock doesn't enable ( I get nothing on the GPIOD outputs nor inputs), but if I change the code to:
Code: [Select]
RCC->AHB1ENR |= (1<<RCC_AHB1ENR_GPIOAEN) | (1<<RCC_AHB1ENR_GPIOBEN) | (1<<3);//  it does work! What's going on here, anybody has any idea please?
« Last Edit: February 01, 2023, 09:24:19 pm by kgavionics »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11236
  • Country: us
    • Personal site
Re: Is this a bug in KEIL ARM uvision or what ?
« Reply #1 on: February 01, 2023, 08:17:11 pm »
Those defines are already shifted bits, so the correct expression is
Quote
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIODEN;

Also, bugs in compilers are exceedingly rare. Chances of you running one with a pin toggling code are nil. So, when something does not work as expected, look for issues in your code, not the compiler.
« Last Edit: February 01, 2023, 08:44:31 pm by ataradov »
Alex
 

Offline kgavionicsTopic starter

  • Regular Contributor
  • *
  • Posts: 195
  • Country: ca
Re: Is this a bug in KEIL ARM uvision or what ?
« Reply #2 on: February 01, 2023, 08:31:15 pm »
 My bad😊😊😊 !
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf