2015-07-25 06:25 AM
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;
}
2015-07-25 10:05 AM
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?2015-07-25 10:10 AM
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.2015-07-26 09:56 AM
2015-07-26 12:24 PM
Sorry, don't know what's going on there, the forum doesn't tolerate mobile phone/tablets very well.
2015-07-27 09:52 AM
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?