Hello,
I am trying to toggle the Port C Pin 0 using the debugger (No eval board attached) for the device STM32F407 with the following code:
#include "stm32f4xx_hal.h" void delay() { for(int i = 0; i < 100000; i++); } int main (void) { while(1) { GPIOC->MODER = 0x01; GPIOC->BSRR ^= 1; delay(); } }
When stepping thorough the code, the GPIO in peripherals Window does not show any change to the values of MODER and BSSR. Its always 0 and does not work for other ports also. What is wrong?
Make sure the GPIOC clock is enabled, and the port correctly configured.
You don't seem to understand the Bit Set/Reset Register
Use the Output Data Register GPIOC->ODR ^= 1;
Thanks for the reply. Could you show me an example or otherwise suggest some online resource where one can get the basics.
Which "basics" are you talking about?
The stuff you've talked about so far is all ST stuff - so ST's website would be the obvious place to go for support on that stuff!
The Datasheet and User Manual for the chip in question are required reading.
ST also have a youtube channel, and lots of training materials online.
They also do quite a lot of real-world training classes
ok, I have updated the code to:
#include "stm32f4xx_hal.h" void delay() { for(int i = 0; i < 100000; i++); } int main (void) { while(1) { RCC->AHB1ENR |= ((1UL << 3) ); /* Enable GPIOD clock */ GPIOD->MODER &= ~((3UL << 2*12)); /* PD.12 is output */ GPIOD->MODER |= ((1UL << 2*12) ); GPIOD->OTYPER &= ~((1UL << 12) ); /* PD.12 output Push-Pull */ GPIOD->OSPEEDR &= ~((3UL << 2*12) ); /* PD.12 50MHz Fast Speed */ GPIOD->OSPEEDR |= ((2UL << 2*12) ); GPIOD->PUPDR &= ~((3UL << 2*12) ); /* PD.12 is Pull up */ GPIOD->PUPDR |= ((1UL << 2*12) ); //GPIOC->MODER = 0x01; GPIOD->ODR |= 0x1000; delay(); } }
The registers in the GPIO still do not change.
Not sure I understand the necessity to put all that in the loop
#include "stm32f4xx_hal.h" void delay() { volatile int i; for(i = 0; i < 100000; i++); } int main (void) { RCC->AHB1ENR |= ((1UL << 3) ); /* Enable GPIOD clock */ RCC->AHB1ENR; /* make sure write buffers clear */ GPIOD->MODER &= ~((3UL << 2*12)); /* PD.12 is output */ GPIOD->MODER |= ((1UL << 2*12) ); GPIOD->OTYPER &= ~((1UL << 12) ); /* PD.12 output Push-Pull */ GPIOD->OSPEEDR &= ~((3UL << 2*12) ); /* PD.12 50MHz Fast Speed */ GPIOD->OSPEEDR |= ((2UL << 2*12) ); GPIOD->PUPDR &= ~((3UL << 2*12) ); /* PD.12 is Pull up */ GPIOD->PUPDR |= ((1UL << 2*12) ); while(1) { GPIOD->ODR ^= (1 << 12); delay(); } }
thanks for the update. When I go to Peripherals -> System Viewer -> GPIO -> GPIOD, a window opens up which shows all register associated with the port such as MODER, GPIOD and many others. When the the code is executed I expect to see changes in these registers but no matter what is done there is absolutely no change in any of the register values, the value is always 0. Even when the (+) next to ODR is clicked the check box for ODR12 must be checked after running the code GPIOD->ODR ^= (1 << 12); But it is never checked. Any ideas whats happening?
>> .. debugger (No eval board attached) ..
You mean the simulator?
Yes, running simulator from debug options, Debug tab, use simulator.
Use real hardware, See "Simulated Features" in page below to understand why what you're doing doesn't work the way you imagine.
http://www.keil.com/dd/chip/6103.htm