[rp20xx][pico] platform and target for rp20xx and pico board

- just a skeleton to get us started
- cpu feature config and irq names / vectab2 setup done
- pulled in the second stage for pico as a blob for now
- seems to be hard faulting out of systick setup in platform_init()
This commit is contained in:
Brian Swetland
2021-02-05 18:00:28 -08:00
parent 9270460385
commit b142c6bdcd
14 changed files with 316 additions and 0 deletions

31
platform/rp20xx/debug.c Normal file
View File

@@ -0,0 +1,31 @@
// Copyright (c) 2012 Travis Geiselbrecht
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <stdarg.h>
#include <lk/reg.h>
#include <lk/debug.h>
#include <stdio.h>
#include <kernel/thread.h>
#include <platform/debug.h>
#include <arch/ops.h>
#include <dev/uart.h>
#include <target/debugconfig.h>
#include <arch/arm/cm.h>
void platform_dputc(char c) {
if (c == '\n')
uart_putc(DEBUG_UART, '\r');
uart_putc(DEBUG_UART, c);
}
int platform_dgetc(char *c, bool wait) {
int ret = uart_getc(DEBUG_UART, wait);
if (ret == -1)
return -1;
*c = ret;
return 0;
}

6
platform/rp20xx/gpio.c Normal file
View File

@@ -0,0 +1,6 @@
// Copyright (c) 2020 Brian Swetland
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT

View File

View File

@@ -0,0 +1,29 @@
// included by other headers to fill out tables, etc
RP20XX_IRQ(TIMER_IRQ_0,0)
RP20XX_IRQ(TIMER_IRQ_1,1)
RP20XX_IRQ(TIMER_IRQ_2,2)
RP20XX_IRQ(TIMER_IRQ_3,3)
RP20XX_IRQ(PWM_IRQ_WRAP,4)
RP20XX_IRQ(USBCTRL_IRQ,5)
RP20XX_IRQ(XIP_IRQ,6)
RP20XX_IRQ(PIO0_IRQ_0,7)
RP20XX_IRQ(PIO0_IRQ_1,8)
RP20XX_IRQ(PIO1_IRQ_0,9)
RP20XX_IRQ(PIO1_IRQ_1,10)
RP20XX_IRQ(DMA_IRQ_0,11)
RP20XX_IRQ(DMA_IRQ_1,12)
RP20XX_IRQ(IO_IRQ_BANK0,13)
RP20XX_IRQ(IO_IRQ_QSPI,14)
RP20XX_IRQ(SIO_IRQ_PROC0,15)
RP20XX_IRQ(SIO_IRQ_PROC1,16)
RP20XX_IRQ(CLOCKS_IRQ,17)
RP20XX_IRQ(SPI0_IRQ,18)
RP20XX_IRQ(SPI1_IRQ,19)
RP20XX_IRQ(UART0_IRQ,20)
RP20XX_IRQ(UART1_IRQ,21)
RP20XX_IRQ(ADC_IRQ_FIFO,22)
RP20XX_IRQ(I2C0_IRQ,23)
RP20XX_IRQ(I2C1_IRQ,24)
RP20XX_IRQ(RTC_IRQ,25)

View File

@@ -0,0 +1,20 @@
#pragma once
#define __CM0PLUS_REV 0x0001U
#define __NVIC_PRIO_BITS 2
#define __Vendor_SysTickConfig 0
#define __VTOR_PRESENT 1
#define __MPU_PRESENT 1
#define __FPU_PRESENT 0
typedef enum {
Reset_IRQn = -15,
NonMaskableInt_IRQn = -14,
HardFault_IRQn = -13,
SVCall_IRQn = -5,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
#define RP20XX_IRQ(name,num) name##_IRQn = num,
#include <platform/irqinfo.h>
#undef RP20XX_IRQ
} IRQn_Type;

20
platform/rp20xx/init.c Normal file
View File

@@ -0,0 +1,20 @@
// Copyright (c) 2020 Brian Swetland
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <platform.h>
#include <arch/arm/cm.h>
extern void* vectab;
void platform_early_init(void) {
// arch/arm/arm-m/arch.c does this but only for M3 and above...
SCB->VTOR = (uint32_t) &vectab;
arm_cm_systick_init(133000000);
}
void platform_init(void) {
}

36
platform/rp20xx/rules.mk Normal file
View File

@@ -0,0 +1,36 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
MODULE := $(LOCAL_DIR)
# ROMBASE, MEMBASE, and MEMSIZE are required for the linker script
ROMBASE := 0x10000000
MEMBASE := 0x20000000
MEMSIZE := 0x00042000
# can be overridden by target
ARCH := arm
ARM_CPU := cortex-m0plus
GLOBAL_DEFINES += \
MEMSIZE=$(MEMSIZE)
MODULE_SRCS += \
$(LOCAL_DIR)/debug.c \
$(LOCAL_DIR)/gpio.c \
$(LOCAL_DIR)/init.c \
$(LOCAL_DIR)/uart.c \
$(LOCAL_DIR)/vectab.c
# use a two segment memory layout, where all of the read-only sections
# of the binary reside in rom, and the read/write are in memory. The
# ROMBASE, MEMBASE, and MEMSIZE make variables are required to be set
# for the linker script to be generated properly.
#
LINKER_SCRIPT += \
$(BUILDDIR)/system-twosegment.ld
MODULE_DEPS += \
arch/arm/arm-m/systick \
lib/cbuf
include make/module.mk

30
platform/rp20xx/uart.c Normal file
View File

@@ -0,0 +1,30 @@
// Copyright (c) 2020 Brian Swetland
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <lk/reg.h>
#include <lib/cbuf.h>
void uart_init_early(void) {
for (;;) ;
}
void uart_init(void) {
}
int uart_putc(int port, char c) {
return 1;
}
int uart_getc(int port, bool wait) {
return -1;
}
void uart_flush_tx(int port) {}
void uart_flush_rx(int port) {}
void uart_init_port(int port, uint baud) {}

28
platform/rp20xx/vectab.c Normal file
View File

@@ -0,0 +1,28 @@
// Copyright (c) 2020 Brian Swetland
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <lk/debug.h>
#include <lk/compiler.h>
#include <arch/arm/cm.h>
/* un-overridden irq handler */
void rp20xx_dummy_irq(void) {
arm_cm_irq_entry();
panic("unhandled irq\n");
}
/* a list of default handlers that are simply aliases to the dummy handler */
#define RP20XX_IRQ(name,num) \
void name##_IRQHandler(void) __WEAK_ALIAS("rp20xx_dummy_irq");
#include <platform/irqinfo.h>
#undef RP20XX_IRQ
const void* const __SECTION(".text.boot.vectab2") vectab2[26] = {
#define RP20XX_IRQ(name,num) [name##_IRQn] = name##_IRQHandler,
#include <platform/irqinfo.h>
#undef RP20XX_IRQ
};

11
project/pico-test.mk Normal file
View File

@@ -0,0 +1,11 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
TARGET := pico
MODULES += \
app/shell \
app/stringtests \
app/tests \
lib/cksum \
lib/debugcommands \

69
target/pico/boot.stage2.S Normal file
View File

@@ -0,0 +1,69 @@
// This is a hack
// TODO: replace with actual second stage boot source
.section .text.boot.secondstage
.word 0x4b32b500
.word 0x60582021
.word 0x21026898
.word 0x60984388
.word 0x611860d8
.word 0x4b2e6158
.word 0x60992100
.word 0x61592102
.word 0x22f02101
.word 0x492b5099
.word 0x21016019
.word 0x20356099
.word 0xf844f000
.word 0x42902202
.word 0x2106d014
.word 0xf0006619
.word 0x6e19f834
.word 0x66192101
.word 0x66182000
.word 0xf000661a
.word 0x6e19f82c
.word 0x6e196e19
.word 0xf0002005
.word 0x2101f82f
.word 0xd1f94208
.word 0x60992100
.word 0x6019491b
.word 0x60592100
.word 0x481b491a
.word 0x21016001
.word 0x21eb6099
.word 0x21a06619
.word 0xf0006619
.word 0x2100f812
.word 0x49166099
.word 0x60014814
.word 0x60992101
.word 0x2800bc01
.word 0x4700d000
.word 0x49134812
.word 0xc8036008
.word 0x8808f380
.word 0xb5034708
.word 0x20046a99
.word 0xd0fb4201
.word 0x42012001
.word 0xbd03d1f8
.word 0x6618b502
.word 0xf7ff6618
.word 0x6e18fff2
.word 0xbd026e18
.word 0x40020000
.word 0x18000000
.word 0x00070000
.word 0x005f0300
.word 0x00002221
.word 0x180000f4
.word 0xa0002022
.word 0x10000100
.word 0xe000ed08
.word 0x00000000
.word 0x00000000
.word 0x00000000
.word 0x7a4eb274

View File

@@ -0,0 +1,3 @@
#pragma once
#define DEBUG_UART 0

14
target/pico/rules.mk Normal file
View File

@@ -0,0 +1,14 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
MODULE := $(LOCAL_DIR)
PLATFORM := rp20xx
GLOBAL_DEFINES += \
TARGET_HAS_DEBUG_LED=1
MODULE_SRCS += \
$(LOCAL_DIR)/boot.stage2.S \
$(LOCAL_DIR)/target.c
include make/module.mk

19
target/pico/target.c Normal file
View File

@@ -0,0 +1,19 @@
// Copyright (c) 2020 Brian Swetland
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <target.h>
#include <platform/gpio.h>
void target_early_init(void) {
}
void target_set_debug_led(unsigned int led, bool on) {
}
void target_init(void) {
}