This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Toggle Port C Pin

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?

Parents
  • 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.

Reply
  • 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.

Children