I need a professional help… um, with bare metal Pokitto programming from scratch. Cause you know, one day I’d like to make my relaxed one file library without any proprietary code. But I’m a noob. I’ll dump my questions here and if someone knows answers, just randomly drop them here maybe
So I have this:
-
main.c
: Program I’d like to compile that would init the HW and just e.g. draw a pixel on the screen. Once I have the option of outputting stuff, I think I can work it out from there. -
link.ln
: Linker script cause memory needs to be like LPC wants it. - a make script which really just does this:
(project now lives here)
arm-none-eabi-gcc -std=gnu99 -c -Wall -Wextra -fno-builtin -funsigned-char -fdata-sections -MMD -mcpu=cortex-m0plus -mthumb -o main.o main.c
arm-none-eabi-ld -Tlink.ld -o main.elf main.o
arm-none-eabi-objcopy -O binary main.elf main.bin
This works! Well at least the compilation. For reference I have:
- CPU user manual, there are registers described and there’s the memory map so that I know where RAM and flash is n stuff, that’s good
- PokittoLib
- Fmanga’s minimum library
- some stuff I’ve found on the Internet (yes it’s Cortex M3, but still helpful)
- edit: ARMv6 reference seems important too
Question: can I achieve what I want without any assembly? I’d like it to be in just one language: C. Looks like I can.
At the beginning of the memory is mapped the flash, mkay, I suppose the bin will be copied here AS IS, somewhere near the end of this section I am expecting to come over the loader.
I can see there is “main” RAM from 0x10000000
to 0x10008000
… OK… but there is yet ANOTHER RAM at 0x20004000
to 0x20004800
. Now I suppose this is the RAM we use for the stack? And the other one is for global variables etc.? I need to enable the clock for the “other RAM” so that it works?
Question: what bare minimum steps exactly do I need to do to init our HW? My ideas is I am supposed to create the interrupt vector at the beginning of the flash, put the initial SP at the first address and then a pointer to the reset interrupt to my init routine (can it all work with just this one interrupt?), in which I need to do something like copy memory segments and maybe enable clock for RAM etc., enable GPIO and send some bits to init the display and then I can call the main function and write to display?
So now I need to set up this boi: link.ln
. I’ve never done it. Deep buried in Pokittolib there is this proprietary boi:
Hey, it’s pretty complex there, half of the stuff I can’t understand. Will it compute with something very simple like:
MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x40000
RAM (rwx) : ORIGIN = 0x10000000, LENGTH = 0x8000
RAM2 (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0800
}
ENTRY(start)
SECTIONS
{
. = 0x00000000;
.text :
{
*(vectorTable)
*(.text)
}
ROM_START = .;
.rodata :
{
*(.rodata)
}
ROM_END = .;
. = 0x10000000;
RAM_START = .;
.data :
{
*(.data)
}
RAM_END = .;
BSS_START = .;
.bss :
{
*(.bss)
}
BSS_END = .;
}
Then I have my program main.c
. The vector I create like this?
uint32_t *vector[2] __attribute__((section("vectorTable")))=
{
(uint32_t *) 0x20000000, // <-- initial stack pointer value? Should it point to "RAM 2"?
(uint32_t *) start // <-- reset interrupt handler?
};
Can this work? Then I’ll have my main
function and the start
function, in which I init everything and call main. Now in Pokittolib this is a separate assembly file, but in the web example I’ve seen it just in C.
Now I’m seeing they’re setting some bits of LPC_SYSAHBCLKCTRL
to enable clock for various modules. Can I do this in C e.g. like this?
*((uint32_t *) 0x40048080) |= (1 << 1) | (1 << 2) | (1 << 6) | (1 << 16) | (1 << 26);
Then I’ve seen I should fill the .bss segment with 0s and copy the .data segment (initialized vars) to RAM.
Ok this is about as far as I’ve made it so far, I’ll be updating this post if I am making any progress, maybe one day it can help someone or something. Thanks for any help with this xD