A few days ago, I have tried to write bare medal program but failed. Now I find that the main mistake is that I have mistake the address of GPIO of BC...
A few days ago, I have tried to write bare medal program but failed. Now I find that the main mistake is that I have mistake the address of GPIO of BCM 2835(Raspberry Pi 1 for which the sample code is desined ) and BCM2836(Raspberry Pi 2 which I am using).
Refrence: dwelch67
Firstly, the base address of GPIO is changed.
Address of RPi BCM2835: 0x20000000
Address of RPi BCM2836: 0x3f000000
Let us make it more easier
Create two file BCM2835.h and BCM2836.h to recode the macro define.
BCM2835.h
#define PBASE 0x20000000
BCM2836.h
#define PBASE 0x3f000000
Then in the code which control your used to control the peripheral, like periph.c, add the following code:
#ifdef RPI2
#include "BCM2836.h" //Raspberry Pi 2
#else
#include "BCM2835.h" //Raspberry Pi 1
#endif
//Ther other macro looks like this:
#define ARM_TIMER_CTL (PBASE + 0x0000B408)
At last, we could modify our Makefile to generate two kernel image:
- kernel.img : for Raspberry Pi 1, BCM2835
- Kernel7.img : for Raspberry Pi 2, BCM2836
To do this, you could add -DRpi2 in your compile cmd to add the macro define
$(ARMGNU)-gcc $(COPS) -c periph.c -o periph7.o -DRPI2
And this is why your /boot/ directory has both kernel.img and kernel7.img.
The official has already consider the two situations.