Mysterious strange gpio port behaviour

Hello,

my steup: Keil 5.43, MM32F003TW ARM cortex 0 cpu, compiler v6.23

Newbie with ARM, trying to do some example on GPIO. My ( manufacture demo from Keil) code is toggling 3 bits on PB port and one on PA port, the PA4.

For the PB port resulting outputs it is 50%, as usually, with freq depending only on defined delay time.
Why is the PA behaviour different than PB it must, it should also be 50% but it is not.

The RED curve in scope screenshot above is PA4 output signal, Yellow is PB.
The code:

int main(void)
{
    u32 i;
    LED_Init();
    while(1) {
			
				LED1_TOGGLE();
        LED2_TOGGLE();
        LED3_TOGGLE();
				LED4_TOGGLE();
        i = 50;
        while(i--){
        __asm__("nop");}
						
}
}

LED steup:

void LED_Init(void)
{

    RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN; // port A and B clocking

		//GPIOA->CRL |= GPIO_CRL_CNF4; //port type	
    GPIOA->CRL &= ~((1U << 18) | (1U << 19));
		GPIOA->CRL |= GPIO_CRL_MODE4;
    GPIOA->ODR |= GPIO_ODR_ODR4;

    GPIOB->CRL |= GPIO_CRL_MODE3 | GPIO_CRL_MODE4 | GPIO_CRL_MODE0;
    //GPIOB->ODR |= GPIO_ODR_ODR3 | GPIO_ODR_ODR4 | GPIO_ODR_ODR5;

    GPIOA->BSRR |= GPIO_BSRR_BS4;  	//OFF GPIO_BSRR_BS4; PA4
    GPIOB->BSRR |= GPIO_BSRR_BS3;	 	//PB3
    GPIOB->BSRR |= GPIO_BSRR_BS4; 	//PB4
    GPIOA->BSRR |= GPIO_BSRR_BS4; 	//PA4

}

#ifndef __LED_H
#define __LED_H

#define LED1ON()  GPIOA->BRR |= GPIO_BRR_BR4
#define LED2ON()  GPIOB->BRR |= GPIO_BRR_BR3
#define LED3ON()  GPIOB->BRR |= GPIO_BRR_BR4
#define LED4ON()  GPIOA->BRR |= GPIO_BRR_BR4

#define LED1OFF()  GPIOA->BSRR |= GPIO_BSRR_BS4
#define LED2OFF()  GPIOB->BSRR |= GPIO_BSRR_BS3
#define LED3OFF()  GPIOB->BSRR |= GPIO_BSRR_BS4
#define LED4OFF()  GPIOA->BSRR |= GPIO_BSRR_BS4

#define LED1_TOGGLE()   ((GPIOA->ODR & GPIO_BRR_BR4) ? (GPIOA->BRR |= GPIO_BRR_BR4) : (GPIOA->BSRR |= GPIO_BSRR_BS4))
#define LED2_TOGGLE()   ((GPIOB->ODR & GPIO_BRR_BR3) ? (GPIOB->BRR |= GPIO_BRR_BR3) : (GPIOB->BSRR |= GPIO_BSRR_BS3))
#define LED3_TOGGLE()   ((GPIOB->ODR & GPIO_BRR_BR4) ? (GPIOB->BRR |= GPIO_BRR_BR4) : (GPIOB->BSRR |= GPIO_BSRR_BS4))
#define LED4_TOGGLE()   ((GPIOA->ODR & GPIO_BRR_BR4) ? (GPIOA->BRR |= GPIO_BRR_BR4) : (GPIOA->BSRR |= GPIO_BSRR_BS4))

void LED_Init(void);
#endif

I have to say this is strange, how is that possible? Something new for me was that port must have clock enabled, but it is done.

Whats is going on here?

Parents Reply Children
No data