hi,
earlier i was working on PIC controller, now i am shifting to ARM and i am having stm32f401re NUCLEO64 evaluation board.
development tool chain i am using is Keil arm mdk , keil version 5. i found some notes for blinking the led on board and i followed the step.
the led is blinking attached on PA5, below is the code,
/* use delay loop, 1 sec on 1 sec off * default 16 MHz clock * LD2 connects to PA5 */ #include "stm32f4xx.h" void delayMs(int n); int main(void) { RCC->AHB1ENR |= 1; /* enable GPIOA clock */ GPIOA->MODER &= ~0x00000C00; /* clear pin mode */ GPIOA->MODER |= 0x00000400; /* set pin to output mode */ while(1) { GPIOA->BSRR = 0x00000020; /* turn on LED */ delayMs(500); GPIOA->BSRR = 0x00200000; /* turn off LED */ delayMs(500); } } /* 16 MHz SYSCLK */ void delayMs(int n) { int i; for (; n > 0; n--) for (i = 0; i < 3195; i++) ; }
now when i want to change the pin PC10 on PORTC. the register i changed is
RCC->AHB1ENR |= 0x04; /* enable GPIOA clock */
GPIOC->MODER |= 0x00200000; /* set pin to output mode */
GPIOC->BSRR = 0x00000400; /* turn on LED */below is the edited code and i am getting nothing. this is the first attempt on stm32 controller. please help me out.
/* use delay loop, 1 sec on 1 sec off * default 16 MHz clock * LD2 connects to PC10 */ #include "stm32f4xx.h" void delayMs(int n); int main(void) { RCC->AHB1ENR |= 0x04; /* enable GPIOA clock */ //GPIOA->MODER &= ~0x00000C00; /* clear pin mode */ GPIOC->MODER |= 0x00200000; /* set pin to output mode */ while(1) { GPIOC->BSRR = 0x00000400; /* turn on LED */ delayMs(500); GPIOC->BSRR = 0x04000000; /* turn off LED */ delayMs(500); } } /* 16 MHz SYSCLK */ void delayMs(int n) { int i; for (; n > 0; n--) for (i = 0; i < 3195; i++) ; }
I think he did, just didn't change the comment to reflect it. The first example sets GPIOA clock (1 << 0), the second GPIOC (1 << 2), ie 4
The STM32 parts do want you to dwell a few cycles after enabling the peripheral clocks, before talking to them.
Correct you are. And that is why you should never read or write comments in code.
After actually reading the manual (I was trying to avoid that), it seems that we are setting the pin to AF mode instead of Output.
GPIOC->MODER |= 0x00200000; /* set pin to output mode */ /* This is actually Alternate function mode*/
GPIOC->MODER |= 0x00100000; /* No comment needed */
yes, now i got this.
this was first the code in ARM. there is software https://www.st.com/en/development-tools/stm32cubemx.html where we get direct access to function. project by simply clicking the pin and some setting. i tried for blinking and push button and its working.
thank you all.