NUCLEO-L011K4 Low Level Blinky not working
I'm starting to learn about low-level embedded development. My goal is to learn how I can write my own linker scripts and startup code. I also want to learn how to use raw register calls to do something useful. I want to use the NUCLEO-L011K4 board and tried reading through the reference manual to find register addresses and the expected values.
For some reason, my minimal blinky (LED connected to PB13) app doesn't work. It flashes just fine, but the board does nothing after that.
I am pretty sure (keep in mind: Still a newbie), that the registers are the right ones. However, I'm not so sure about the linker script.
Here's my linker script:
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 2K
}
ENTRY(main)
__reset_stack_pointer = ORIGIN(RAM) + LENGTH(RAM);
SECTIONS {
.text : {
LONG(__reset_stack_pointer);
LONG(main | 1);
/* The whole interrupt table is 332 bytes long. Advance to that position. */
. += 332;
*(.text)
*(.rodata*)
. = ALIGN(4);
} > FLASH
}
and here's my main.c:
void main(void)
{
volatile int *RCC_IOPENR = (int *)0X4002102C;
volatile int *GPIOB_MODER = (int *)0X50000400;
volatile int *GPIOB_ODR = (int *)0X50000410;
*RCC_IOPENR |= 0b10; // Enable GPIO Port B
*GPIOB_MODER |= 0b10 << 26; // Set Pin 13 as output
while (1)
{
*GPIOB_ODR ^= 0x0020; // Toggle output Pin
for (int i = 0; i < 1000000; i++)
{
__asm__("nop");
}
}
}
I compile this code with
arm-none-eabi-gcc main.c -T LinkerScript.ld -o blink.elf -mcpu=cortex-m0plus -mthumb -nostdlib -Os
and I flash it to the target using the integrated STLink and this OpenOCD command:
openocd -f interface/stlink.cfg -f target/stm32l0.cfg -c "program blink.elf verify reset exit"
The commands are adapted from this blogpost, which is for the blue pill board and Zig. I adapted the code to C and it worked as expected.
I'm not sure if there are other things required in the linker script or if the size of the NVIC table is a different one for the L011K4. I have not found its size in any documentation.
Please tell me if this is not the right place to ask such questions. This is my first post to the forum and I'm still trying to find my way around.
Thanks!
