Hi guy,
I'm using ARM STM32F103RC, Cortex M3.
when I compiler the code with this order:
//GPIO structure used to initialize port
GPIO_InitTypeDef GPIO_InitStructure;
//Enable clock on APB2 pripheral bus where button and LEDs are connected
RCC_APB2PeriphClockCmd(LEDPORTCLK | BUTTONPORTCLK, ENABLE);
is okay,
But I want to enable clock first,
the compiler give the error
main.c(28): error: #268: declaration may not appear after executable statement in block
would you like to explain to me why this happened?
Minh
Hi Minh,
Thanks for your question.
I think you will find that the first statement "GPIO_InitTypeDef GPIO_InitStructure;" is a declaration, not an executable statement. I assume what you are doing is moving that statement to below the next line, in the hope that this will enable the clock before enabling the GPIO. The first line is not initialising anything, it is simply declaring a data structure which will be used later.
As the compiler error tells you, the C language does not allow declarations to follow executable statements in a block. Declarations must all appear at the top of the block. So your code will not compiler because it isn't valid C.
I suggest you look further down for the executable statement which actually initializes the GPIO.
Hope this helps.
Chris
Hi Chris,
Thank you very much for your spending time to point my "hole of knowledge "
I got it.
Thanks,