From 91cdcea9004fcb0b3dbbc830774f5300d0280487 Mon Sep 17 00:00:00 2001 From: ANDREW LI-Nordic Date: Wed, 21 Dec 2022 09:11:27 +0800 Subject: [PATCH] [bsp][nrf5340]add 5340 define for 1000000 baud rate;change RTC driver for 5340 (#6754) * add nrf5340 bsp,add uarte and gpio drv for 5340 * [bsp][nrf5340]add 5340 define for 1000000 baud rate;change RTC driver for 5340 Co-authored-by: andrew li --- .github/workflows/action.yml | 1 + bsp/nrf5x/libraries/drivers/drv_rtc.c | 39 ++++++++++++++++++++++++- bsp/nrf5x/libraries/drivers/drv_uarte.c | 10 +++++-- bsp/nrf5x/nrf5340/README.md | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 765eef2760..edca728b63 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -107,6 +107,7 @@ jobs: - {RTT_BSP: "nrf5x/nrf52832", RTT_TOOL_CHAIN: "sourcery-arm"} - {RTT_BSP: "nrf5x/nrf52833", RTT_TOOL_CHAIN: "sourcery-arm"} - {RTT_BSP: "nrf5x/nrf52840", RTT_TOOL_CHAIN: "sourcery-arm"} + - {RTT_BSP: "nrf5x/nrf5340", RTT_TOOL_CHAIN: "sourcery-arm"} - {RTT_BSP: "qemu-vexpress-a9", RTT_TOOL_CHAIN: "sourcery-arm"} - {RTT_BSP: "sam7x", RTT_TOOL_CHAIN: "sourcery-arm"} - {RTT_BSP: "stm32/stm32f072-st-nucleo", RTT_TOOL_CHAIN: "sourcery-arm"} diff --git a/bsp/nrf5x/libraries/drivers/drv_rtc.c b/bsp/nrf5x/libraries/drivers/drv_rtc.c index 23af3a4892..a06bb934b9 100644 --- a/bsp/nrf5x/libraries/drivers/drv_rtc.c +++ b/bsp/nrf5x/libraries/drivers/drv_rtc.c @@ -112,6 +112,39 @@ const static struct rt_device_ops rtc_ops = }; #endif +#if defined(SOC_NRF5340) +static rt_err_t rt_hw_rtc_register_5340(rt_device_t device, const char *name, rt_uint32_t flag) +{ + struct tm time_new = ONCHIP_RTC_TIME_DEFAULT; + + RT_ASSERT(device != RT_NULL); + + init_time = timegm(&time_new); + if (rt_rtc_config(device) != RT_EOK) + { + return -RT_ERROR; + } +#ifdef RT_USING_DEVICE_OPS + device->ops = &rtc_ops; +#else + device->init = RT_NULL; + device->open = RT_NULL; + device->close = RT_NULL; + device->read = RT_NULL; + device->write = RT_NULL; + device->control = rt_rtc_control; +#endif + device->type = RT_Device_Class_RTC; + device->rx_indicate = RT_NULL; + device->tx_complete = RT_NULL; + device->user_data = RT_NULL; + + /* register a character device */ + rt_device_register(device, name, flag); + + return RT_EOK; +} +#else static rt_err_t rt_hw_rtc_register(rt_device_t device, const char *name, rt_uint32_t flag) { struct tm time_new = ONCHIP_RTC_TIME_DEFAULT; @@ -143,11 +176,15 @@ static rt_err_t rt_hw_rtc_register(rt_device_t device, const char *name, rt_uint return RT_EOK; } - +#endif int rt_hw_rtc_init(void) { rt_err_t result; +#if defined(SOC_NRF5340) + result = rt_hw_rtc_register_5340(&rtc, "rtc", RT_DEVICE_FLAG_RDWR); +#else result = rt_hw_rtc_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR); +#endif if (result != RT_EOK) { LOG_E("rtc register err code: %d", result); diff --git a/bsp/nrf5x/libraries/drivers/drv_uarte.c b/bsp/nrf5x/libraries/drivers/drv_uarte.c index 637d75e7f0..1139b69de8 100644 --- a/bsp/nrf5x/libraries/drivers/drv_uarte.c +++ b/bsp/nrf5x/libraries/drivers/drv_uarte.c @@ -155,9 +155,11 @@ static rt_err_t _uart_cfg(struct rt_serial_device *serial, struct serial_configu case BAUD_RATE_921600: config.baudrate = NRF_UARTE_BAUDRATE_921600; break; - case 1000000: +#if defined(SOC_NRF5340) + case 1000000: config.baudrate = NRF_UARTE_BAUDRATE_1000000; - break; + break; +#endif /* SOC_NRF5340*/ case BAUD_RATE_2000000: case BAUD_RATE_3000000: return -RT_EINVAL; @@ -286,7 +288,9 @@ int rt_hw_uart_init(void) #ifdef BSP_USING_UART0 m_serial_0.config = config; - m_serial_0.config.baud_rate = 1000000; +#if defined(SOC_NRF5340) + m_serial_0.config.baud_rate = 1000000; +#endif /* SOC_NRF5340*/ m_serial_0.ops = &_uart_ops; m_uarte0_cb.serial = &m_serial_0; rt_hw_serial_register(&m_serial_0, "uart0", \ diff --git a/bsp/nrf5x/nrf5340/README.md b/bsp/nrf5x/nrf5340/README.md index cb695deaf5..bdb6f9e811 100644 --- a/bsp/nrf5x/nrf5340/README.md +++ b/bsp/nrf5x/nrf5340/README.md @@ -31,7 +31,7 @@ | **片上外设** | **支持情况** | **备注** | | :----------- | :----------: | :--------------------: | | GPIO | 支持 | GPION | -| UART | 支持 | UART0 | +| UART | 支持 | UART0 请暂时使用1000000波特率| | PWM | 支持 | 支持 | | SPI | 支持 | 支持 | | QSPI | 支持 | 支持开发板上QSPI FLASH |