diff --git a/platform/rp20xx/debug.c b/platform/rp20xx/debug.c new file mode 100644 index 00000000..987bc21c --- /dev/null +++ b/platform/rp20xx/debug.c @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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; +} + diff --git a/platform/rp20xx/gpio.c b/platform/rp20xx/gpio.c new file mode 100644 index 00000000..df9ad1f1 --- /dev/null +++ b/platform/rp20xx/gpio.c @@ -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 + diff --git a/platform/rp20xx/include/platform/gpio.h b/platform/rp20xx/include/platform/gpio.h new file mode 100644 index 00000000..e69de29b diff --git a/platform/rp20xx/include/platform/irqinfo.h b/platform/rp20xx/include/platform/irqinfo.h new file mode 100644 index 00000000..efc97750 --- /dev/null +++ b/platform/rp20xx/include/platform/irqinfo.h @@ -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) + diff --git a/platform/rp20xx/include/platform/platform_cm.h b/platform/rp20xx/include/platform/platform_cm.h new file mode 100644 index 00000000..46ee48c7 --- /dev/null +++ b/platform/rp20xx/include/platform/platform_cm.h @@ -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 +#undef RP20XX_IRQ +} IRQn_Type; diff --git a/platform/rp20xx/init.c b/platform/rp20xx/init.c new file mode 100644 index 00000000..9a42565f --- /dev/null +++ b/platform/rp20xx/init.c @@ -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 +#include + +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) { +} diff --git a/platform/rp20xx/rules.mk b/platform/rp20xx/rules.mk new file mode 100644 index 00000000..dbb34e6d --- /dev/null +++ b/platform/rp20xx/rules.mk @@ -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 diff --git a/platform/rp20xx/uart.c b/platform/rp20xx/uart.c new file mode 100644 index 00000000..079e4ae3 --- /dev/null +++ b/platform/rp20xx/uart.c @@ -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 +#include + +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) {} + diff --git a/platform/rp20xx/vectab.c b/platform/rp20xx/vectab.c new file mode 100644 index 00000000..bbbac0ae --- /dev/null +++ b/platform/rp20xx/vectab.c @@ -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 +#include +#include + +/* 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 +#undef RP20XX_IRQ + +const void* const __SECTION(".text.boot.vectab2") vectab2[26] = { +#define RP20XX_IRQ(name,num) [name##_IRQn] = name##_IRQHandler, +#include +#undef RP20XX_IRQ +}; + diff --git a/project/pico-test.mk b/project/pico-test.mk new file mode 100644 index 00000000..8b785c2f --- /dev/null +++ b/project/pico-test.mk @@ -0,0 +1,11 @@ +LOCAL_DIR := $(GET_LOCAL_DIR) + +TARGET := pico + +MODULES += \ + app/shell \ + app/stringtests \ + app/tests \ + lib/cksum \ + lib/debugcommands \ + diff --git a/target/pico/boot.stage2.S b/target/pico/boot.stage2.S new file mode 100644 index 00000000..e2b87b66 --- /dev/null +++ b/target/pico/boot.stage2.S @@ -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 diff --git a/target/pico/include/target/debugconfig.h b/target/pico/include/target/debugconfig.h new file mode 100644 index 00000000..a21c5dbf --- /dev/null +++ b/target/pico/include/target/debugconfig.h @@ -0,0 +1,3 @@ +#pragma once + +#define DEBUG_UART 0 diff --git a/target/pico/rules.mk b/target/pico/rules.mk new file mode 100644 index 00000000..50ef923f --- /dev/null +++ b/target/pico/rules.mk @@ -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 diff --git a/target/pico/target.c b/target/pico/target.c new file mode 100644 index 00000000..c4fe6b16 --- /dev/null +++ b/target/pico/target.c @@ -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 +#include + + +void target_early_init(void) { +} + +void target_set_debug_led(unsigned int led, bool on) { +} + +void target_init(void) { +} +