Bare metal programming under mbed

04 Dec 2016

Hello everyone,

Sorry for the newbie question, but I have been trying to fix my issue for a little bit and can't find a solution.

Despite having all these neat librairies I usually enjoy writting my own by manipulating the registers. After some digging in the STM32 librairies, I found this one stm32446x.h which includes all the macro that I would need. For now my code is dead simple.

  1. include "stm32f446xx.h" RCC.RCC_AHB1ENR |= (1 << 4); int main() {}

When I try to access these macros I get the following error (I used a different compiler than the online one after it not working) :

stm32f446xx.h:1145:43: error: expected ')' before '*' token

I have tried all the variation of the include possible, but it still give me the error. I even try to include the file with its full path, but nothing does it.

Thank you in advance for any help you can give me.

05 Dec 2016

I'm at about the same point as you but with a different STM32 variant - so I'm no authority!

Based on the tiny bit I have been able to work out, I think you want something like:

 RCC->AHB1ENR |= (1 << 4);
// or perhaps, to avoid a hard-coded value:
 RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN; 

However, you appear to have that statement outside of your main function, or any other function, which will also cause trouble. If you use the code tag when posting here it will stop the formatting of your program from getting destroyed and make it easier to see exactly what you have done (look under "Editing tips" for how to do that).

06 Dec 2016

Hey Andy,

Thank you for your answer! I put the bit of code in my main function and it compiled just fine. Where I still have a bit of trouble understanding why can't I declare it as a global variable though? Maybe that is a question for an other forum.

In any case I will be able to make some headway now that I can compile the code. :)

P.s. this was my original code

#include "stm32f446xx.h" 
RCC.RCC_AHB1ENR |= (1 << 4); 
int main() {}
23 Nov 2017

Sorry for the late reply but I just tripped over your post. You can't put this: RCC.RCC_AHB1ENR |= (1 << 4); outside of main() because it isn't a global variable, it is a sequence of operations which depend on the current state of the register. A global variable (with an initialization) can be done outside of main because the global variable is internal to the *program*, it isn't part of the *machine* that program is running on. Long before the program is loaded, the compiler can assign the initial value to the variable. The statement you provide reads a register, alters part of it, and then writes the register again. You can't do that until run time.