cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L051 GPIO errata

bp1112
Associate II
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;

}

5 REPLIES 5
Posted on July 25, 2015 at 19:05

The board doesn't have JTAG on it which makes debugging hard.

You do appear to be approaching everything from the hardest possible angle, hopefully there's some merit to that. The SWD  connection takes two pins. There are include files so you don't have to reinvent everything.

So based on the dearth of information, I'm going to assume you're pushing code in via the system loader, perhaps the USART. Maybe you can use the USART to provide you with progress information, and get that working as a first order of business.

I suspect it isn't getting to your code. Any chance you can experiment on a DISCO board that does have a debugger? What are you doing with the BOOT[0] pin in your design?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 25, 2015 at 19:10

Are you sure the delay function works, or returns?

The delay between enabling the GPIO clocks and talking to the GPIO peripheral is in the order of a few machine cycles, to account for pipelined execution, write buffers, on buses external to the core.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bp1112
Associate II
Posted on July 26, 2015 at 18:56

Posted on July 26, 2015 at 21:24

Sorry, don't know what's going on there, the forum doesn't tolerate mobile phone/tablets very well.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bp1112
Associate II
Posted on July 27, 2015 at 18:52

Oh sorry for the two previous posts.

Thank you for your answer.Yes, I use USART1 to download code on it.As you suggested I tried to transfer progress information via USART1 but it doesn't work from my code (I can't receive characters) so I guess you were right, it isn't getting to my code. The delay fuction must be fine but I think I don't even need to enable the clock for GPIOA and USART1 as I use the boot loader and jump to my programme from that. Is that correct? I think there must be something wrong with my eclipse configuration (I'm not an expert on that) so I'll look into that. What do you think?