Question
STM32L051 GPIO errata
Posted on July 25, 2015 at 15:25
Hello,
I'm having trouble getting the GPIOs work in STM32L051. According to the errata sheet I'm supposed to wait some time after allowing the clock for the peripherials so I did so. However, I still can't measure a logical 1 on PA1. The board doesn't have JTAG on it which makes debugging hard. Any ideas?typedef struct{ volatile unsigned int Moder; // ...} GPIO_Typedef;typedef struct{ volatile unsigned int IOP; volatile unsigned int AHB; volatile unsigned int APB2; volatile unsigned int APB1;} RCCEN_Typedef;// Define GPIOs#define GPIOA_BASE_ADDRESS 0x50000000#define GPIOB_BASE_ADDRESS 0x50000400#define GPIOA ( ( GPIO_Typedef * ) GPIOA_BASE_ADDRESS )#define GPIOB ( ( GPIO_Typedef * ) GPIOB_BASE_ADDRESS )// Define periphery RCC enable#define RCCEN_BASE_ADDRESS 0x4002102C#define RCCEN ( ( RCCEN_Typedef * ) RCCEN_BASE_ADDRESS )int main()
{
char pin = 1;
char mode = 1;
RCCEN->IOP |= 1; // Enable GPIOA clock
Delay(300); // Wait (errata sheet)
// Pin config
GPIOA->Moder &= ~(3 << (pin * 2));
GPIOA->Moder |= (mode << (pin * 2));
// Set pin
GPIOA->BSRR = 1 << pin;
while(1);
return 0;
}
