From c8e4a56f00de05d13804798d323c8dfa85fdc01b Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sun, 14 Feb 2021 13:23:03 -0800 Subject: [PATCH] [target][pico] switch the uart config to target driven Uses the target/debugconfig.h file pattern laid down before, which is a bit long in the tooth but for the moment still helps us separate target from platform. --- platform/rp20xx/debug.c | 10 ++++++---- platform/rp20xx/init.c | 21 ++++++++++++++------- target/pico/include/target/debugconfig.h | 13 ++++++++++++- target/pico/target.c | 2 +- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/platform/rp20xx/debug.c b/platform/rp20xx/debug.c index 8f19574f..6600a1fe 100644 --- a/platform/rp20xx/debug.c +++ b/platform/rp20xx/debug.c @@ -6,20 +6,22 @@ #include +#include + #include #include void platform_dputc(char c) { if (c == '\n') - uart_putc(uart0, '\r'); - uart_putc(uart0, c); + uart_putc(DEBUG_UART, '\r'); + uart_putc(DEBUG_UART, c); } int platform_dgetc(char *c, bool wait) { - if (!wait && !uart_is_readable(uart0)) + if (!wait && !uart_is_readable(DEBUG_UART)) return -1; - *c = uart_getc(uart0); + *c = uart_getc(DEBUG_UART); return 0; } diff --git a/platform/rp20xx/init.c b/platform/rp20xx/init.c index 3e8437c8..e4b21101 100644 --- a/platform/rp20xx/init.c +++ b/platform/rp20xx/init.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -15,16 +16,22 @@ extern void* vectab; void platform_early_init(void) { + // initialize the clock tree. + // gets clock values from defines in SDK at + // external/platform/pico/rp2040/hardware_regs/include/hardware/platform_defs.h clocks_init(); + // start the systick timer + arm_cm_systick_init(125000000); + + // unreset everything unreset_block_wait(RESETS_RESET_BITS); - uart_init(uart0, 1000000); - gpio_set_function(0, GPIO_FUNC_UART); - gpio_set_function(1, GPIO_FUNC_UART); - uart_puts(uart0, "Hello World!\n"); - - arm_cm_systick_init(133000000); + // target defines drive how we configure the debug uart + uart_init(DEBUG_UART, 115200); + gpio_set_function(DEBUG_UART_GPIOA, GPIO_FUNC_UART); + gpio_set_function(DEBUG_UART_GPIOB, GPIO_FUNC_UART); + uart_puts(DEBUG_UART, "Hello World!\n"); } void platform_init(void) { @@ -32,5 +39,5 @@ void platform_init(void) { bool running_on_fpga(void) { - return false; + return false; } diff --git a/target/pico/include/target/debugconfig.h b/target/pico/include/target/debugconfig.h index a21c5dbf..4a33fd46 100644 --- a/target/pico/include/target/debugconfig.h +++ b/target/pico/include/target/debugconfig.h @@ -1,3 +1,14 @@ +// 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 + #pragma once -#define DEBUG_UART 0 +#include + +// define how this target will map the debug uart to hardware and pins +#define DEBUG_UART uart0 +#define DEBUG_UART_GPIOA 0 +#define DEBUG_UART_GPIOB 1 diff --git a/target/pico/target.c b/target/pico/target.c index c4fe6b16..93009a09 100644 --- a/target/pico/target.c +++ b/target/pico/target.c @@ -5,9 +5,9 @@ // https://opensource.org/licenses/MIT #include +#include #include - void target_early_init(void) { }