diff options
| author | guozhanxin <[email protected]> | 2021-01-28 19:59:31 +0800 |
|---|---|---|
| committer | guozhanxin <[email protected]> | 2021-01-28 19:59:59 +0800 |
| commit | 6d36d384c243012918e97eb7e9529b2de4b50357 (patch) | |
| tree | b46f5eec4ccfb1c0e9f9359e978a99078c8c7ae6 /bsp/raspberry-pico/drivers | |
| parent | fdb270c6f4cd6e9cd6335199d13d8a8e6e2a7dfb (diff) | |
add raspberry-pico bsp
Diffstat (limited to 'bsp/raspberry-pico/drivers')
| -rw-r--r-- | bsp/raspberry-pico/drivers/SConscript | 9 | ||||
| -rw-r--r-- | bsp/raspberry-pico/drivers/board.c | 59 | ||||
| -rw-r--r-- | bsp/raspberry-pico/drivers/board.h | 30 | ||||
| -rw-r--r-- | bsp/raspberry-pico/drivers/drv_uart.c | 150 | ||||
| -rw-r--r-- | bsp/raspberry-pico/drivers/drv_uart.h | 19 |
5 files changed, 267 insertions, 0 deletions
diff --git a/bsp/raspberry-pico/drivers/SConscript b/bsp/raspberry-pico/drivers/SConscript new file mode 100644 index 0000000000..9c96da4809 --- /dev/null +++ b/bsp/raspberry-pico/drivers/SConscript @@ -0,0 +1,9 @@ +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') +CPPPATH = [cwd] + +group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/bsp/raspberry-pico/drivers/board.c b/bsp/raspberry-pico/drivers/board.c new file mode 100644 index 0000000000..e4db84bdad --- /dev/null +++ b/bsp/raspberry-pico/drivers/board.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2009-01-05 Bernard first implementation + */ + +#include <rthw.h> +#include <rtthread.h> + +#include <stdio.h> + +#include "board.h" +#include "hardware/structs/systick.h" + +uint8_t heap[1024 * 80]; + +void isr_systick(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + rt_tick_increase(); + + /* leave interrupt */ + rt_interrupt_leave(); +} + +uint32_t systick_config(uint32_t ticks) +{ + if ((ticks - 1UL) > M0PLUS_SYST_RVR_RELOAD_BITS) + { + return (1UL); /* Reload value impossible */ + } + + mpu_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */ + mpu_hw->csr = M0PLUS_SYST_CSR_CLKSOURCE_BITS | + M0PLUS_SYST_CSR_TICKINT_BITS | + M0PLUS_SYST_CSR_ENABLE_BITS; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ +} + +void rt_hw_board_init() +{ + /* Configure the SysTick */ + systick_config(frequency_count_khz(CLOCKS_FC0_SRC_VALUE_ROSC_CLKSRC)*10000/RT_TICK_PER_SECOND); + + rt_system_heap_init(heap, (uint8_t *)heap + sizeof(heap)); + + stdio_init_all(); + rt_hw_uart_init(); + +#ifdef RT_USING_CONSOLE + rt_console_set_device(RT_CONSOLE_DEVICE_NAME); +#endif +} diff --git a/bsp/raspberry-pico/drivers/board.h b/bsp/raspberry-pico/drivers/board.h new file mode 100644 index 0000000000..725ce1e4c2 --- /dev/null +++ b/bsp/raspberry-pico/drivers/board.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2009-09-22 Bernard add board.h to this bsp + */ + +// <<< Use Configuration Wizard in Context Menu >>> +#ifndef __BOARD_H__ +#define __BOARD_H__ + +#include "pico/stdlib.h" +#include "hardware/pll.h" +#include "hardware/clocks.h" +#include "hardware/structs/pll.h" +#include "hardware/structs/clocks.h" + +#define PICO_SRAM_SIZE 256 +#define PICO_SRAM_END (0x20000000 + PICO_SRAM_SIZE * 1024) + +extern int __bss_end; +#define HEAP_BEGIN (&__bss_end) +#define HEAP_END PICO_SRAM_END + +int rt_hw_uart_init(void); + +#endif diff --git a/bsp/raspberry-pico/drivers/drv_uart.c b/bsp/raspberry-pico/drivers/drv_uart.c new file mode 100644 index 0000000000..48599e01f8 --- /dev/null +++ b/bsp/raspberry-pico/drivers/drv_uart.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + +#include <rthw.h> +#include <rtthread.h> +#include <rtdevice.h> +#include "board.h" +#include "drv_uart.h" + +#include "hardware/uart.h" +#include "hardware/irq.h" + +#define UART_ID uart0 +#define BAUD_RATE 115200 +#define DATA_BITS 8 +#define STOP_BITS 1 +#define PARITY UART_PARITY_NONE + +// We are using pins 0 and 1, but see the GPIO function select table in the +// datasheet for information on which other pins can be used. +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + +#define PICO_UART_DEVICE(uart) (struct pico_uart_dev *)(uart) + +static struct pico_uart_dev uart0_dev; + +struct pico_uart_dev +{ + struct rt_serial_device parent; + rt_uint32_t uart_periph; + rt_uint32_t irqno; +}; + +void pico_uart_isr(void) +{ + rt_interrupt_enter(); + /* read interrupt status and clear it */ + if (uart_is_readable(uart0)) /* rx ind */ + { + rt_hw_serial_isr(&uart0_dev.parent, RT_SERIAL_EVENT_RX_IND); + } + + rt_interrupt_leave(); +} + +/* + * UART interface + */ +static rt_err_t pico_uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg) +{ + return RT_EOK; +} + +static rt_err_t pico_uart_control(struct rt_serial_device *serial, int cmd, void *arg) +{ + return RT_EOK; +} + +static int pico_uart_putc(struct rt_serial_device *serial, char c) +{ + uart_putc_raw(uart0, c); + + return 1; +} + +static int pico_uart_getc(struct rt_serial_device *serial) +{ + int ch; + + if (uart_is_readable(uart0)) + { + ch = uart_get_hw(uart0)->dr; + } + else + { + ch =-1; + } + + return ch; +} + +const static struct rt_uart_ops _uart_ops = +{ + pico_uart_configure, + pico_uart_control, + pico_uart_putc, + pico_uart_getc, + RT_NULL, +}; + +/* + * UART Initiation + */ +int rt_hw_uart_init(void) +{ + rt_err_t ret = RT_EOK; + + struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; + + uart_init(UART_ID, 115200); + + // Set the TX and RX pins by using the function select on the GPIO + // Set datasheet for more information on function select + gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART); + gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART); + + // Actually, we want a different speed + // The call will return the actual baud rate selected, which will be as close as + // possible to that requested + uart_set_baudrate(UART_ID, BAUD_RATE); + + // Set UART flow control CTS/RTS, we don't want these, so turn them off + uart_set_hw_flow(UART_ID, false, false); + + // Set our data format + uart_set_format(UART_ID, DATA_BITS, STOP_BITS, PARITY); + + // Turn off FIFO's - we want to do this character by character + uart_set_fifo_enabled(UART_ID, false); + + // Set up a RX interrupt + // We need to set up the handler first + // Select correct interrupt for the UART we are using + int UART_IRQ = UART_ID == uart0 ? UART0_IRQ : UART1_IRQ; + + // And set up and enable the interrupt handlers + irq_set_exclusive_handler(UART_IRQ, pico_uart_isr); + irq_set_enabled(UART_IRQ, true); + + // Now enable the UART to send interrupts - RX only + uart_set_irq_enables(UART_ID, true, false); + + uart0_dev.parent.ops = &_uart_ops; + uart0_dev.parent.config = config; + + ret = rt_hw_serial_register(&uart0_dev.parent, + "uart0", + RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, + &uart0_dev); + + return ret; +} +// INIT_DEVICE_EXPORT(rt_hw_uart_init); diff --git a/bsp/raspberry-pico/drivers/drv_uart.h b/bsp/raspberry-pico/drivers/drv_uart.h new file mode 100644 index 0000000000..73aa036833 --- /dev/null +++ b/bsp/raspberry-pico/drivers/drv_uart.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2009-01-05 Bernard the first version + */ + +#ifndef __USART_H__ +#define __USART_H__ + +#include <rthw.h> +#include <rtthread.h> + +int rt_hw_uart_init(void); + +#endif |
