I’m trying to get going on bare metal programming with my rapsberry pi 4b and I’m encountering an issue when trying to run it on 64bits. Whenever I try to write to the GPIO SET0 register, the program completly stops. When I use a similar code in 32 bits, it works just fine with the exact same base addresses and offset.
I tried simulating the kernel using qemu and gdb, and it appears that whenever I reach the line that writes into the GPIO SET0 reg, the action doesn’t go through and the PC gets stuck at a random address. Maybe I’m using the wrong address (I’m currently using 0xFE20_0000) but I’m fairly sure it’s the correct one.
An other source of the issue could be the way I compile the kernel8.img since I am using the aarch64-none-elf toolchain. I then replace the *.img files in the boot section of the SD card with my own kernel8.img and leave the other files (from Raspberry OS).
I wrote another assembly code that I compiled using arm-none-eabi and set the rpi to 32bits and this works but it is very inconsistant. By that I mean that the same code works sometimes and if I try to rerun it, it doesn’t.
This is the code that writes into GPIO_SET0 and whenever it reaches that last line it completly stops working
.section ".text.boot"
.global _start
.equ GPIO_BASE, 0xFE200000
.equ GPIO_SET_21_OUT, 1 << 3
.equ GPIO_SEL2, 0x08
.equ GPIO_SET0, 0x1C
.equ GPIO_21, 1 << 21
_start:
ldr x0, =GPIO_BASE
ldr x1, =GPIO_SET_21_OUT
str x1, [x0, #GPIO_SEL2]
ldr x1, =GPIO_21
ldr x1, [x0, #GPIO_SET0] // this line seems to be the issue
loop:
nop
b loop
Luca Seelbach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3