Jonathan
Jonathan

Reputation: 87

STM32 NUCLEO F401RE cannot write to some bits in GPIO BSRR

I recently bought a STM-NUCLEO and I am trying to write to PA0,PA1,PA2,PA3 which are connected to LED's. The LED's connected to PA0 and PA1 light up as expected but PA2 and PA3 don't. I tried it with PA4 and that works too. Here is the code:

int main(void)
{

  /* Configure the System clock to 84 MHz */
  SystemClock_Config();

  RCC->AHB1RSTR |= RCC_AHB1RSTR_GPIOARST; // resetting GPIOA
    RCC->AHB1RSTR = 0; //exiting reset state
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; //enabeling GPIOA clock
    GPIOA->MODER |= GPIO_MODER_MODER0_0;
    GPIOA->MODER |= GPIO_MODER_MODER1_0;
    GPIOA->MODER |= GPIO_MODER_MODER2_0;
    GPIOA->MODER |= GPIO_MODER_MODER3_0;
    //setting the pins
    GPIOA->BSRR |= (1<<0);
    GPIOA->BSRR |= (1<<1);
    GPIOA->BSRR |= (1<<2);
    GPIOA->BSRR |= (1<<3);
  /* Add your application code here*/

  /* Infinite loop */
  while (1)
  { 

  }
}

Upvotes: 0

Views: 1727

Answers (1)

According to the Nucleo schematics, PA2 & PA3 are connected to the internal ST-Link controller, therefore not usable for GPIO without adding and removing some bridges first.

That's your MCU, "SB62, SB63 Default open" means that the connection is not there.

enter image description here

And this is where it's connected to the ST-Link interface.

enter image description here

Upvotes: 3

Related Questions