AP_HAL_LINUX: Add support for Raspberry Pi 4

The Raspberry Pi 4 uses a new BCM cpu, the BCM2711 with
a peripheral base address of 0xFE000000

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
This commit is contained in:
Patrick José Pereira 2020-01-10 10:53:38 -03:00 committed by Andrew Tridgell
parent d36157f314
commit 6518d6dc4d
4 changed files with 18 additions and 4 deletions

View File

@ -22,6 +22,7 @@
// Raspberry Pi GPIO memory
#define BCM2708_PERI_BASE 0x20000000
#define BCM2709_PERI_BASE 0x3F000000
#define BCM2711_PERI_BASE 0xFE000000
#define GPIO_BASE(address) (address + 0x200000)
// GPIO setup. Always use INP_GPIO(x) before OUT_GPIO(x) or SET_GPIO_ALT(x,y)
@ -44,7 +45,14 @@ GPIO_RPI::GPIO_RPI()
void GPIO_RPI::init()
{
int rpi_version = UtilRPI::from(hal.util)->get_rpi_version();
uint32_t gpio_address = rpi_version == 1 ? GPIO_BASE(BCM2708_PERI_BASE) : GPIO_BASE(BCM2709_PERI_BASE);
uint32_t gpio_address;
if(rpi_version == 1) {
gpio_address = GPIO_BASE(BCM2708_PERI_BASE);
} else if (rpi_version == 2) {
gpio_address = GPIO_BASE(BCM2709_PERI_BASE);
} else {
gpio_address = GPIO_BASE(BCM2711_PERI_BASE);
}
int mem_fd = open("/dev/mem", O_RDWR|O_SYNC|O_CLOEXEC);
if (mem_fd < 0) {

View File

@ -199,6 +199,7 @@ int Util::read_file(const char *path, const char *fmt, ...)
const char *Linux::Util::_hw_names[UTIL_NUM_HARDWARES] = {
[UTIL_HARDWARE_RPI1] = "BCM2708",
[UTIL_HARDWARE_RPI2] = "BCM2709",
[UTIL_HARDWARE_RPI4] = "BCM2711",
[UTIL_HARDWARE_BEBOP] = "Mykonos3 board",
[UTIL_HARDWARE_BEBOP2] = "Milos board",
[UTIL_HARDWARE_DISCO] = "Evinrude board",

View File

@ -16,6 +16,7 @@ namespace Linux {
enum hw_type {
UTIL_HARDWARE_RPI1 = 0,
UTIL_HARDWARE_RPI2,
UTIL_HARDWARE_RPI4,
UTIL_HARDWARE_BEBOP,
UTIL_HARDWARE_BEBOP2,
UTIL_HARDWARE_DISCO,

View File

@ -40,8 +40,9 @@ int UtilRPI::_check_rpi_version()
int ret = sscanf(buffer + 12, "%d", &_rpi_version);
fclose(f);
if (ret != EOF) {
if (_rpi_version > 2) {
if (_rpi_version > 3) {
_rpi_version = 4;
} else if (_rpi_version > 2) {
// Preserving old behavior.
_rpi_version = 2;
} else if (_rpi_version == 0) {
@ -58,7 +59,10 @@ int UtilRPI::_check_rpi_version()
// Attempting old method if the version couldn't be read with the new one.
hw = Util::from(hal.util)->get_hw_arm32();
if (hw == UTIL_HARDWARE_RPI2) {
if (hw == UTIL_HARDWARE_RPI4) {
printf("Raspberry Pi 4 with BCM2711!\n");
_rpi_version = 4;
} else if (hw == UTIL_HARDWARE_RPI2) {
printf("Raspberry Pi 2/3 with BCM2709!\n");
_rpi_version = 2;
} else if (hw == UTIL_HARDWARE_RPI1) {