Merge pull request #1000 from arturo182/nrfx_uart
nrf: Rewrite the UART HAL using nRFx
This commit is contained in:
commit
a45659c59a
|
@ -90,7 +90,6 @@ LIBS += -L $(dir $(LIBC_FILE_NAME)) -lc
|
||||||
LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc
|
LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc
|
||||||
|
|
||||||
SRC_HAL = $(addprefix hal/,\
|
SRC_HAL = $(addprefix hal/,\
|
||||||
hal_uart.c \
|
|
||||||
hal_time.c \
|
hal_time.c \
|
||||||
hal_rng.c \
|
hal_rng.c \
|
||||||
)
|
)
|
||||||
|
@ -98,11 +97,11 @@ SRC_HAL = $(addprefix hal/,\
|
||||||
SRC_NRFX = $(addprefix nrfx/,\
|
SRC_NRFX = $(addprefix nrfx/,\
|
||||||
drivers/src/nrfx_spim.c \
|
drivers/src/nrfx_spim.c \
|
||||||
drivers/src/nrfx_twim.c \
|
drivers/src/nrfx_twim.c \
|
||||||
|
drivers/src/nrfx_uart.c \
|
||||||
)
|
)
|
||||||
|
|
||||||
SRC_C += \
|
SRC_C += \
|
||||||
mphalport.c \
|
mphalport.c \
|
||||||
help.c \
|
|
||||||
fatfs_port.c \
|
fatfs_port.c \
|
||||||
fifo.c \
|
fifo.c \
|
||||||
tick.c \
|
tick.c \
|
||||||
|
|
|
@ -25,47 +25,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MICROPY_HW_BOARD_NAME "Bluefruit nRF52 Feather"
|
#define MICROPY_HW_BOARD_NAME "Bluefruit nRF52 Feather"
|
||||||
#define MICROPY_HW_MCU_NAME "NRF52832"
|
#define MICROPY_HW_MCU_NAME "nRF52832"
|
||||||
#define MICROPY_PY_SYS_PLATFORM "nrf52"
|
#define MICROPY_PY_SYS_PLATFORM "nRF52"
|
||||||
|
|
||||||
#define MICROPY_HW_HAS_LED (1)
|
#define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8)
|
||||||
#define MICROPY_HW_HAS_SWITCH (0)
|
#define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6)
|
||||||
#define MICROPY_HW_HAS_FLASH (0)
|
#define MICROPY_HW_UART_HWFC (0)
|
||||||
#define MICROPY_HW_HAS_SDCARD (0)
|
|
||||||
#define MICROPY_HW_HAS_MMA7660 (0)
|
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (0)
|
|
||||||
#define MICROPY_HW_HAS_LCD (0)
|
|
||||||
#define MICROPY_HW_ENABLE_RNG (0)
|
|
||||||
#define MICROPY_HW_ENABLE_RTC (0)
|
|
||||||
#define MICROPY_HW_ENABLE_TIMER (0)
|
|
||||||
#define MICROPY_HW_ENABLE_SERVO (0)
|
|
||||||
#define MICROPY_HW_ENABLE_DAC (0)
|
|
||||||
#define MICROPY_HW_ENABLE_CAN (0)
|
|
||||||
|
|
||||||
#define MICROPY_HW_LED_COUNT (2)
|
#define PORT_HEAP_SIZE (32 * 1024)
|
||||||
#define MICROPY_HW_LED_PULLUP (0)
|
|
||||||
|
|
||||||
#define MICROPY_HW_LED1 (17) // LED1
|
|
||||||
#define MICROPY_HW_LED2 (19) // LED2
|
|
||||||
|
|
||||||
// UART config
|
|
||||||
#define MICROPY_HW_UART1_RX (pin_P0_08)
|
|
||||||
#define MICROPY_HW_UART1_TX (pin_P0_06)
|
|
||||||
#define MICROPY_HW_UART1_HWFC (0)
|
|
||||||
|
|
||||||
// SPI0 config
|
|
||||||
#define MICROPY_HW_SPI0_NAME "SPI0"
|
|
||||||
#define MICROPY_HW_SPI0_SCK (pin_P0_12) // (Arduino D13)
|
|
||||||
#define MICROPY_HW_SPI0_MOSI (pin_P0_13) // (Arduino D11)
|
|
||||||
#define MICROPY_HW_SPI0_MISO (pin_P0_14) // (Arduino D12)
|
|
||||||
|
|
||||||
#define MICROPY_HW_PWM0_NAME "PWM0"
|
|
||||||
#define MICROPY_HW_PWM1_NAME "PWM1"
|
|
||||||
#define MICROPY_HW_PWM2_NAME "PWM2"
|
|
||||||
|
|
||||||
#define HELP_TEXT_BOARD_LED "1,2"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define PORT_HEAP_SIZE (32*1024)
|
|
||||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||||
|
|
|
@ -27,53 +27,12 @@
|
||||||
#define FEATHER52840
|
#define FEATHER52840
|
||||||
|
|
||||||
#define MICROPY_HW_BOARD_NAME "Feather52840"
|
#define MICROPY_HW_BOARD_NAME "Feather52840"
|
||||||
#define MICROPY_HW_MCU_NAME "NRF52840"
|
#define MICROPY_HW_MCU_NAME "nRF52840"
|
||||||
#define MICROPY_PY_SYS_PLATFORM "nrf52840-PDK"
|
#define MICROPY_PY_SYS_PLATFORM "nRF52840-PDK"
|
||||||
|
|
||||||
#define MICROPY_HW_HAS_LED (1)
|
#define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8)
|
||||||
#define MICROPY_HW_HAS_SWITCH (0)
|
#define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6)
|
||||||
#define MICROPY_HW_HAS_FLASH (0)
|
#define MICROPY_HW_UART_HWFC (0)
|
||||||
#define MICROPY_HW_HAS_SDCARD (0)
|
|
||||||
#define MICROPY_HW_HAS_MMA7660 (0)
|
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (0)
|
|
||||||
#define MICROPY_HW_HAS_LCD (0)
|
|
||||||
#define MICROPY_HW_ENABLE_RNG (0)
|
|
||||||
#define MICROPY_HW_ENABLE_RTC (0)
|
|
||||||
#define MICROPY_HW_ENABLE_TIMER (0)
|
|
||||||
#define MICROPY_HW_ENABLE_SERVO (0)
|
|
||||||
#define MICROPY_HW_ENABLE_DAC (0)
|
|
||||||
#define MICROPY_HW_ENABLE_CAN (0)
|
|
||||||
|
|
||||||
#define MICROPY_HW_LED_COUNT (4)
|
#define PORT_HEAP_SIZE (128 * 1024)
|
||||||
#define MICROPY_HW_LED_PULLUP (1)
|
|
||||||
|
|
||||||
#define MICROPY_HW_LED1 (13) // LED1
|
|
||||||
#define MICROPY_HW_LED2 (14) // LED2
|
|
||||||
#define MICROPY_HW_LED3 (15) // LED3
|
|
||||||
#define MICROPY_HW_LED4 (16) // LED4
|
|
||||||
|
|
||||||
// UART config
|
|
||||||
#define MICROPY_HW_UART1_RX (pin_P0_08)
|
|
||||||
#define MICROPY_HW_UART1_TX (pin_P0_06)
|
|
||||||
#define MICROPY_HW_UART1_CTS (pin_P0_07)
|
|
||||||
#define MICROPY_HW_UART1_RTS (pin_P0_05)
|
|
||||||
#define MICROPY_HW_UART1_HWFC (1)
|
|
||||||
|
|
||||||
// SPI0 config
|
|
||||||
#define MICROPY_HW_SPI0_NAME "SPI0"
|
|
||||||
|
|
||||||
#define MICROPY_HW_SPI0_SCK (pin_P1_15)
|
|
||||||
#define MICROPY_HW_SPI0_MOSI (pin_P1_13)
|
|
||||||
#define MICROPY_HW_SPI0_MISO (pin_P1_14)
|
|
||||||
|
|
||||||
#define MICROPY_HW_PWM0_NAME "PWM0"
|
|
||||||
#define MICROPY_HW_PWM1_NAME "PWM1"
|
|
||||||
#define MICROPY_HW_PWM2_NAME "PWM2"
|
|
||||||
#if 0
|
|
||||||
#define MICROPY_HW_PWM3_NAME "PWM3"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HELP_TEXT_BOARD_LED "1,2,3,4"
|
|
||||||
|
|
||||||
#define PORT_HEAP_SIZE (128*1024)
|
|
||||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||||
|
|
|
@ -24,52 +24,13 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PCA10040
|
|
||||||
|
|
||||||
#define MICROPY_HW_BOARD_NAME "PCA10040"
|
#define MICROPY_HW_BOARD_NAME "PCA10040"
|
||||||
#define MICROPY_HW_MCU_NAME "NRF52832"
|
#define MICROPY_HW_MCU_NAME "nRF52832"
|
||||||
#define MICROPY_PY_SYS_PLATFORM "nrf52-DK"
|
#define MICROPY_PY_SYS_PLATFORM "nRF52-DK"
|
||||||
|
|
||||||
#define MICROPY_HW_HAS_LED (1)
|
#define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8)
|
||||||
#define MICROPY_HW_HAS_SWITCH (0)
|
#define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6)
|
||||||
#define MICROPY_HW_HAS_FLASH (0)
|
#define MICROPY_HW_UART_HWFC (0)
|
||||||
#define MICROPY_HW_HAS_SDCARD (0)
|
|
||||||
#define MICROPY_HW_HAS_MMA7660 (0)
|
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (0)
|
|
||||||
#define MICROPY_HW_HAS_LCD (0)
|
|
||||||
#define MICROPY_HW_ENABLE_RNG (0)
|
|
||||||
#define MICROPY_HW_ENABLE_RTC (0)
|
|
||||||
#define MICROPY_HW_ENABLE_TIMER (0)
|
|
||||||
#define MICROPY_HW_ENABLE_SERVO (0)
|
|
||||||
#define MICROPY_HW_ENABLE_DAC (0)
|
|
||||||
#define MICROPY_HW_ENABLE_CAN (0)
|
|
||||||
|
|
||||||
#define MICROPY_HW_LED_COUNT (4)
|
#define PORT_HEAP_SIZE (32 * 1024)
|
||||||
#define MICROPY_HW_LED_PULLUP (1)
|
|
||||||
|
|
||||||
#define MICROPY_HW_LED1 (17) // LED1
|
|
||||||
#define MICROPY_HW_LED2 (18) // LED2
|
|
||||||
#define MICROPY_HW_LED3 (19) // LED3
|
|
||||||
#define MICROPY_HW_LED4 (20) // LED4
|
|
||||||
|
|
||||||
// UART config
|
|
||||||
#define MICROPY_HW_UART1_RX (pin_P0_08)
|
|
||||||
#define MICROPY_HW_UART1_TX (pin_P0_06)
|
|
||||||
#define MICROPY_HW_UART1_CTS (pin_P0_07)
|
|
||||||
#define MICROPY_HW_UART1_RTS (pin_P0_05)
|
|
||||||
#define MICROPY_HW_UART1_HWFC (1)
|
|
||||||
|
|
||||||
// SPI0 config
|
|
||||||
#define MICROPY_HW_SPI0_NAME "SPI0"
|
|
||||||
#define MICROPY_HW_SPI0_SCK (pin_P0_25) // (Arduino D13)
|
|
||||||
#define MICROPY_HW_SPI0_MOSI (pin_P0_23) // (Arduino D11)
|
|
||||||
#define MICROPY_HW_SPI0_MISO (pin_P0_24) // (Arduino D12)
|
|
||||||
|
|
||||||
#define MICROPY_HW_PWM0_NAME "PWM0"
|
|
||||||
#define MICROPY_HW_PWM1_NAME "PWM1"
|
|
||||||
#define MICROPY_HW_PWM2_NAME "PWM2"
|
|
||||||
|
|
||||||
#define HELP_TEXT_BOARD_LED "1,2,3,4"
|
|
||||||
|
|
||||||
#define PORT_HEAP_SIZE (32*1024)
|
|
||||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||||
|
|
|
@ -24,56 +24,13 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PCA10056
|
|
||||||
|
|
||||||
#define MICROPY_HW_BOARD_NAME "PCA10056"
|
#define MICROPY_HW_BOARD_NAME "PCA10056"
|
||||||
#define MICROPY_HW_MCU_NAME "NRF52840"
|
#define MICROPY_HW_MCU_NAME "nRF52840"
|
||||||
#define MICROPY_PY_SYS_PLATFORM "nrf52840-PDK"
|
#define MICROPY_PY_SYS_PLATFORM "nRF52840-PDK"
|
||||||
|
|
||||||
#define MICROPY_HW_HAS_LED (1)
|
#define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8)
|
||||||
#define MICROPY_HW_HAS_SWITCH (0)
|
#define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6)
|
||||||
#define MICROPY_HW_HAS_FLASH (0)
|
#define MICROPY_HW_UART_HWFC (0)
|
||||||
#define MICROPY_HW_HAS_SDCARD (0)
|
|
||||||
#define MICROPY_HW_HAS_MMA7660 (0)
|
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (0)
|
|
||||||
#define MICROPY_HW_HAS_LCD (0)
|
|
||||||
#define MICROPY_HW_ENABLE_RNG (0)
|
|
||||||
#define MICROPY_HW_ENABLE_RTC (0)
|
|
||||||
#define MICROPY_HW_ENABLE_TIMER (0)
|
|
||||||
#define MICROPY_HW_ENABLE_SERVO (0)
|
|
||||||
#define MICROPY_HW_ENABLE_DAC (0)
|
|
||||||
#define MICROPY_HW_ENABLE_CAN (0)
|
|
||||||
|
|
||||||
#define MICROPY_HW_LED_COUNT (4)
|
#define PORT_HEAP_SIZE (128 * 1024)
|
||||||
#define MICROPY_HW_LED_PULLUP (1)
|
|
||||||
|
|
||||||
#define MICROPY_HW_LED1 (13) // LED1
|
|
||||||
#define MICROPY_HW_LED2 (14) // LED2
|
|
||||||
#define MICROPY_HW_LED3 (15) // LED3
|
|
||||||
#define MICROPY_HW_LED4 (16) // LED4
|
|
||||||
|
|
||||||
// UART config
|
|
||||||
#define MICROPY_HW_UART1_RX (pin_P0_08)
|
|
||||||
#define MICROPY_HW_UART1_TX (pin_P0_06)
|
|
||||||
#define MICROPY_HW_UART1_CTS (pin_P0_07)
|
|
||||||
#define MICROPY_HW_UART1_RTS (pin_P0_05)
|
|
||||||
#define MICROPY_HW_UART1_HWFC (1)
|
|
||||||
|
|
||||||
// SPI0 config
|
|
||||||
#define MICROPY_HW_SPI0_NAME "SPI0"
|
|
||||||
|
|
||||||
#define MICROPY_HW_SPI0_SCK (pin_P1_15)
|
|
||||||
#define MICROPY_HW_SPI0_MOSI (pin_P1_13)
|
|
||||||
#define MICROPY_HW_SPI0_MISO (pin_P1_14)
|
|
||||||
|
|
||||||
#define MICROPY_HW_PWM0_NAME "PWM0"
|
|
||||||
#define MICROPY_HW_PWM1_NAME "PWM1"
|
|
||||||
#define MICROPY_HW_PWM2_NAME "PWM2"
|
|
||||||
#if 0
|
|
||||||
#define MICROPY_HW_PWM3_NAME "PWM3"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HELP_TEXT_BOARD_LED "1,2,3,4"
|
|
||||||
|
|
||||||
#define PORT_HEAP_SIZE (128*1024)
|
|
||||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||||
|
|
|
@ -1,181 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of the MicroPython project, http://micropython.org/
|
|
||||||
*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "nrf.h"
|
|
||||||
#include "mphalport.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
#include "fifo.h"
|
|
||||||
|
|
||||||
#include "lib/utils/interrupt_char.h"
|
|
||||||
|
|
||||||
#ifdef HAL_UART_MODULE_ENABLED
|
|
||||||
|
|
||||||
FIFO_DEF(_ff_uart, 128, uint8_t, true, UARTE0_UART0_IRQn);
|
|
||||||
|
|
||||||
uint32_t hal_uart_baudrate_lookup[] = {
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud1200, ///< 1200 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud2400, ///< 2400 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud4800, ///< 4800 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud9600, ///< 9600 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud14400, ///< 14400 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud19200, ///< 19200 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud28800, ///< 28800 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud38400, ///< 38400 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud57600, ///< 57600 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud76800, ///< 76800 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud115200, ///< 115200 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud230400, ///< 230400 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud250000, ///< 250000 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud460800, ///< 460800 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud921600, ///< 921600 baud.
|
|
||||||
UART_BAUDRATE_BAUDRATE_Baud1M, ///< 1000000 baud.
|
|
||||||
};
|
|
||||||
|
|
||||||
hal_uart_error_t hal_uart_char_write(NRF_UART_Type * p_instance, uint8_t ch) {
|
|
||||||
p_instance->ERRORSRC = 0;
|
|
||||||
p_instance->TXD = (uint8_t)ch;
|
|
||||||
while (p_instance->EVENTS_TXDRDY != 1) {
|
|
||||||
// Blocking wait.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear the TX flag.
|
|
||||||
p_instance->EVENTS_TXDRDY = 0;
|
|
||||||
|
|
||||||
return p_instance->ERRORSRC;
|
|
||||||
}
|
|
||||||
|
|
||||||
hal_uart_error_t hal_uart_char_read(NRF_UART_Type * p_instance, uint8_t * ch) {
|
|
||||||
while ( !fifo_read(_ff_uart, ch) ) {
|
|
||||||
// wait for fifo data
|
|
||||||
}
|
|
||||||
|
|
||||||
return HAL_UART_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
hal_uart_error_t hal_uart_buffer_write(NRF_UART_Type * p_instance, uint8_t * p_buffer, uint32_t num_of_bytes, uart_complete_cb cb) {
|
|
||||||
int i = 0;
|
|
||||||
hal_uart_error_t err = 0;
|
|
||||||
uint8_t ch = p_buffer[i++];
|
|
||||||
while (i < num_of_bytes) {
|
|
||||||
err = hal_uart_char_write(p_instance, ch);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
ch = p_buffer[i++];
|
|
||||||
}
|
|
||||||
cb();
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
hal_uart_error_t hal_uart_buffer_read(NRF_UART_Type * p_instance, uint8_t * p_buffer, uint32_t num_of_bytes, uart_complete_cb cb) {
|
|
||||||
int i = 0;
|
|
||||||
hal_uart_error_t err = 0;
|
|
||||||
while (i < num_of_bytes) {
|
|
||||||
hal_uart_error_t err = hal_uart_char_read(p_instance, &p_buffer[i]);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
cb();
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int hal_uart_available(NRF_UART_Type * p_instance)
|
|
||||||
{
|
|
||||||
return fifo_count(_ff_uart);
|
|
||||||
}
|
|
||||||
|
|
||||||
void hal_uart_init(NRF_UART_Type * p_instance, hal_uart_init_t const * p_uart_init) {
|
|
||||||
hal_gpio_cfg_pin(p_uart_init->tx_pin->port, p_uart_init->tx_pin->pin, HAL_GPIO_MODE_OUTPUT, HAL_GPIO_PULL_DISABLED);
|
|
||||||
hal_gpio_cfg_pin(p_uart_init->tx_pin->port, p_uart_init->rx_pin->pin, HAL_GPIO_MODE_INPUT, HAL_GPIO_PULL_DISABLED);
|
|
||||||
|
|
||||||
hal_gpio_pin_clear(p_uart_init->tx_pin->port, p_uart_init->tx_pin->pin);
|
|
||||||
|
|
||||||
p_instance->PSELTXD = p_uart_init->tx_pin->pin;
|
|
||||||
p_instance->PSELRXD = p_uart_init->rx_pin->pin;
|
|
||||||
|
|
||||||
#if NRF52840_XXAA
|
|
||||||
p_instance->PSELTXD |= (p_uart_init->tx_pin->port << UARTE_PSEL_TXD_PORT_Pos);
|
|
||||||
p_instance->PSELRXD |= (p_uart_init->rx_pin->port << UARTE_PSEL_RXD_PORT_Pos);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (p_uart_init->flow_control) {
|
|
||||||
hal_gpio_cfg_pin(p_uart_init->rts_pin->port, p_uart_init->rts_pin->pin, HAL_GPIO_MODE_OUTPUT, HAL_GPIO_PULL_DISABLED);
|
|
||||||
hal_gpio_cfg_pin(p_uart_init->cts_pin->port, p_uart_init->cts_pin->pin, HAL_GPIO_MODE_INPUT, HAL_GPIO_PULL_DISABLED);
|
|
||||||
|
|
||||||
p_instance->PSELCTS = p_uart_init->cts_pin->pin;
|
|
||||||
p_instance->PSELRTS = p_uart_init->rts_pin->pin;
|
|
||||||
|
|
||||||
#if NRF52840_XXAA
|
|
||||||
p_instance->PSELCTS |= (p_uart_init->cts_pin->port << UARTE_PSEL_CTS_PORT_Pos);
|
|
||||||
p_instance->PSELRTS |= (p_uart_init->rts_pin->port << UARTE_PSEL_RTS_PORT_Pos);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
p_instance->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
p_instance->BAUDRATE = (hal_uart_baudrate_lookup[p_uart_init->baud_rate]);
|
|
||||||
p_instance->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
|
|
||||||
p_instance->EVENTS_TXDRDY = 0;
|
|
||||||
p_instance->EVENTS_RXDRDY = 0;
|
|
||||||
p_instance->TASKS_STARTTX = 1;
|
|
||||||
p_instance->TASKS_STARTRX = 1;
|
|
||||||
|
|
||||||
// Adafruit IRQ + fifo
|
|
||||||
fifo_clear(_ff_uart);
|
|
||||||
p_instance->INTENSET = UART_INTENSET_RXDRDY_Msk;
|
|
||||||
NVIC_ClearPendingIRQ(p_uart_init->irq_num);
|
|
||||||
NVIC_SetPriority(p_uart_init->irq_num, p_uart_init->irq_priority);
|
|
||||||
NVIC_EnableIRQ(p_uart_init->irq_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UARTE0_UART0_IRQHandler(void)
|
|
||||||
{
|
|
||||||
NRF_UART_Type * p_instance = NRF_UART0;
|
|
||||||
|
|
||||||
if (p_instance->EVENTS_RXDRDY)
|
|
||||||
{
|
|
||||||
uint8_t ch = (uint8_t) p_instance->RXD;
|
|
||||||
|
|
||||||
// Keyboard interrupt
|
|
||||||
if (mp_interrupt_char != -1 && ch == mp_interrupt_char)
|
|
||||||
{
|
|
||||||
mp_keyboard_interrupt();
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
fifo_write(_ff_uart, &ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
p_instance->EVENTS_RXDRDY = 0x0UL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // HAL_UART_MODULE_ENABLED
|
|
|
@ -1,113 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of the MicroPython project, http://micropython.org/
|
|
||||||
*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef HAL_UART_H__
|
|
||||||
#define HAL_UART_H__
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "nrf.h"
|
|
||||||
|
|
||||||
#define UART_HWCONTROL_NONE ((uint32_t)UARTE_CONFIG_HWFC_Disabled << UARTE_CONFIG_HWFC_Pos)
|
|
||||||
#define UART_HWCONTROL_RTS_CTS ((uint32_t)(UARTE_CONFIG_HWFC_Enabled << UARTE_CONFIG_HWFC_Pos)
|
|
||||||
#define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
|
|
||||||
(((CONTROL) == UART_HWCONTROL_NONE) || \
|
|
||||||
((CONTROL) == UART_HWCONTROL_RTS_CTS))
|
|
||||||
#ifdef HAL_UART_MODULE_ENABLED
|
|
||||||
#define UART_BASE_POINTERS (const uint32_t[]){NRF_UART0_BASE}
|
|
||||||
#define UART_IRQ_VALUES (const uint32_t[]){UARTE0_UART0_IRQn}
|
|
||||||
#else // HAL_UARTE_MODULE_ENABLED
|
|
||||||
#ifdef NRF52832_XXAA
|
|
||||||
#define UART_BASE_POINTERS (const uint32_t[]){NRF_UARTE0_BASE}
|
|
||||||
#define UART_IRQ_VALUES (const uint32_t[]){UARTE0_UART0_IRQn}
|
|
||||||
#elif NRF52840_XXAA
|
|
||||||
#define UART_BASE_POINTERS (const uint32_t[]){NRF_UARTE0_BASE, \
|
|
||||||
NRF_UARTE1_BASE}
|
|
||||||
#define UART_IRQ_VALUES (const uint32_t[]){UARTE0_UART0_IRQn, \
|
|
||||||
UARTE1_IRQn}
|
|
||||||
#endif // HAL_UARTE_MODULE_ENABLED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define UART_BASE(x) ((NRF_UART_Type *)UART_BASE_POINTERS[x])
|
|
||||||
#define UART_IRQ_NUM(x) (UART_IRQ_VALUES[x])
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
HAL_UART_ERROR_NONE = 0x00, /*!< No error */
|
|
||||||
HAL_UART_ERROR_ORE = 0x01, /*!< Overrun error. A start bit is received while the previous data still lies in RXD. (Previous data is lost.) */
|
|
||||||
HAL_UART_ERROR_PE = 0x02, /*!< Parity error. A character with bad parity is received, if HW parity check is enabled. */
|
|
||||||
HAL_UART_ERROR_FE = 0x04, /*!< Frame error. A valid stop bit is not detected on the serial data input after all bits in a character have been received. */
|
|
||||||
HAL_UART_ERROR_BE = 0x08, /*!< Break error. The serial data input is '0' for longer than the length of a data frame. (The data frame length is 10 bits without parity bit, and 11 bits with parity bit.). */
|
|
||||||
} hal_uart_error_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
HAL_UART_BAUD_1K2 = 0, /**< 1200 baud */
|
|
||||||
HAL_UART_BAUD_2K4, /**< 2400 baud */
|
|
||||||
HAL_UART_BAUD_4K8, /**< 4800 baud */
|
|
||||||
HAL_UART_BAUD_9K6, /**< 9600 baud */
|
|
||||||
HAL_UART_BAUD_14K4, /**< 14.4 kbaud */
|
|
||||||
HAL_UART_BAUD_19K2, /**< 19.2 kbaud */
|
|
||||||
HAL_UART_BAUD_28K8, /**< 28.8 kbaud */
|
|
||||||
HAL_UART_BAUD_38K4, /**< 38.4 kbaud */
|
|
||||||
HAL_UART_BAUD_57K6, /**< 57.6 kbaud */
|
|
||||||
HAL_UART_BAUD_76K8, /**< 76.8 kbaud */
|
|
||||||
HAL_UART_BAUD_115K2, /**< 115.2 kbaud */
|
|
||||||
HAL_UART_BAUD_230K4, /**< 230.4 kbaud */
|
|
||||||
HAL_UART_BAUD_250K0, /**< 250.0 kbaud */
|
|
||||||
HAL_UART_BAUD_500K0, /**< 500.0 kbaud */
|
|
||||||
HAL_UART_BAUD_1M0 /**< 1 mbaud */
|
|
||||||
} hal_uart_baudrate_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t id; /* UART instance id */
|
|
||||||
const pin_obj_t * rx_pin; /* RX pin. */
|
|
||||||
const pin_obj_t * tx_pin; /* TX pin. */
|
|
||||||
const pin_obj_t * rts_pin; /* RTS pin, only used if flow control is enabled. */
|
|
||||||
const pin_obj_t * cts_pin; /* CTS pin, only used if flow control is enabled. */
|
|
||||||
bool flow_control; /* Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */
|
|
||||||
bool use_parity; /* Even parity if TRUE, no parity if FALSE. */
|
|
||||||
uint32_t baud_rate; /* Baud rate configuration. */
|
|
||||||
uint32_t irq_priority; /* UARTE IRQ priority. */
|
|
||||||
uint32_t irq_num;
|
|
||||||
} hal_uart_init_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
NRF_UART_Type * p_instance; /* UART registers base address */
|
|
||||||
hal_uart_init_t init; /* UART communication parameters */
|
|
||||||
} UART_HandleTypeDef;
|
|
||||||
|
|
||||||
typedef void (*uart_complete_cb)(void);
|
|
||||||
|
|
||||||
void hal_uart_init(NRF_UART_Type * p_instance, hal_uart_init_t const * p_uart_init);
|
|
||||||
|
|
||||||
hal_uart_error_t hal_uart_char_write(NRF_UART_Type * p_instance, uint8_t ch);
|
|
||||||
|
|
||||||
hal_uart_error_t hal_uart_char_read(NRF_UART_Type * p_instance, uint8_t * ch);
|
|
||||||
int hal_uart_available(NRF_UART_Type * p_instance);
|
|
||||||
|
|
||||||
#endif // HAL_UART_H__
|
|
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of the MicroPython project, http://micropython.org/
|
|
||||||
*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013, 2014 Damien P. George
|
|
||||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "py/builtin.h"
|
|
||||||
|
|
||||||
#if BLUETOOTH_SD
|
|
||||||
#include "help_sd.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char nrf5_help_text[] =
|
|
||||||
"Welcome to MicroPython!\n"
|
|
||||||
"\n"
|
|
||||||
"For online help please visit http://micropython.org/help/.\n"
|
|
||||||
"\n"
|
|
||||||
"Quick overview of commands for the board:\n"
|
|
||||||
#if MICROPY_HW_HAS_LED
|
|
||||||
" pyb.LED(n) -- create an LED object for LED n (n=" HELP_TEXT_BOARD_LED ")\n"
|
|
||||||
"\n"
|
|
||||||
#endif
|
|
||||||
#if BLUETOOTH_SD
|
|
||||||
HELP_TEXT_SD
|
|
||||||
#endif
|
|
||||||
"Control commands:\n"
|
|
||||||
" CTRL-A -- on a blank line, enter raw REPL mode\n"
|
|
||||||
" CTRL-B -- on a blank line, enter normal REPL mode\n"
|
|
||||||
" CTRL-D -- on a blank line, do a soft reset of the board\n"
|
|
||||||
" CTRL-E -- on a blank line, enter paste mode\n"
|
|
||||||
"\n"
|
|
||||||
"For further help on a specific object, type help(obj)\n"
|
|
||||||
;
|
|
|
@ -93,8 +93,8 @@
|
||||||
#define MICROPY_PY_BUILTINS_EXECFILE (0)
|
#define MICROPY_PY_BUILTINS_EXECFILE (0)
|
||||||
#define MICROPY_PY_BUILTINS_COMPILE (1)
|
#define MICROPY_PY_BUILTINS_COMPILE (1)
|
||||||
#define MICROPY_PY_BUILTINS_HELP (1)
|
#define MICROPY_PY_BUILTINS_HELP (1)
|
||||||
#define MICROPY_PY_BUILTINS_HELP_TEXT nrf5_help_text
|
|
||||||
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
|
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
|
||||||
|
#define MICROPY_PY_BUILTINS_HELP_TEXT circuitpython_help_text
|
||||||
#define MICROPY_PY_BUILTINS_INPUT (1)
|
#define MICROPY_PY_BUILTINS_INPUT (1)
|
||||||
#define MICROPY_MODULE_BUILTIN_INIT (1)
|
#define MICROPY_MODULE_BUILTIN_INIT (1)
|
||||||
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
|
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
|
||||||
|
@ -126,14 +126,6 @@
|
||||||
|
|
||||||
#define MICROPY_KBD_EXCEPTION (1)
|
#define MICROPY_KBD_EXCEPTION (1)
|
||||||
|
|
||||||
#ifndef MICROPY_HW_LED_COUNT
|
|
||||||
#define MICROPY_HW_LED_COUNT (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef MICROPY_HW_LED_PULLUP
|
|
||||||
#define MICROPY_HW_LED_PULLUP (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef MICROPY_PY_HW_RNG
|
#ifndef MICROPY_PY_HW_RNG
|
||||||
#define MICROPY_PY_HW_RNG (1)
|
#define MICROPY_PY_HW_RNG (1)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015 Glenn Ruben Bakke
|
* Copyright (c) 2015 Glenn Ruben Bakke
|
||||||
|
* Copyright (c) 2018 Artur Pacholec
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -24,46 +25,47 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "py/mpstate.h"
|
#include "mphalport.h"
|
||||||
#include "py/mphal.h"
|
|
||||||
#include "py/mperrno.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
|
|
||||||
#define UART_INSTANCE UART_BASE(0)
|
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
|
||||||
|
|
||||||
#if (MICROPY_PY_BLE_NUS == 0)
|
#if (MICROPY_PY_BLE_NUS == 0)
|
||||||
int mp_hal_stdin_rx_chr(void) {
|
int mp_hal_stdin_rx_chr(void) {
|
||||||
for (;;) {
|
uint8_t data = 0;
|
||||||
if ( hal_uart_available(UART_INSTANCE) ) {
|
|
||||||
uint8_t ch;
|
|
||||||
hal_uart_char_read(UART_INSTANCE, &ch);
|
|
||||||
return (int) ch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
while (!nrfx_uart_rx_ready(&serial_instance));
|
||||||
|
|
||||||
|
const nrfx_err_t err = nrfx_uart_rx(&serial_instance, &data, sizeof(data));
|
||||||
|
if (err == NRFX_SUCCESS)
|
||||||
|
NRFX_ASSERT(err);
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mp_hal_stdin_any(void) {
|
bool mp_hal_stdin_any(void) {
|
||||||
return hal_uart_available(UART_INSTANCE);
|
return nrfx_uart_rx_ready(&serial_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
||||||
while(len--) {
|
if (len == 0)
|
||||||
hal_uart_char_write(UART_INSTANCE, *str++);
|
return;
|
||||||
}
|
|
||||||
|
const nrfx_err_t err = nrfx_uart_tx(&serial_instance, (uint8_t*)str, len);
|
||||||
|
if (err == NRFX_SUCCESS)
|
||||||
|
NRFX_ASSERT(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
|
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
|
||||||
while(len--){
|
const char cr = '\r';
|
||||||
if (*str == '\n') {
|
|
||||||
hal_uart_char_write(UART_INSTANCE, '\r');
|
while (len--) {
|
||||||
|
if (*str == '\n')
|
||||||
|
mp_hal_stdout_tx_strn(&cr, sizeof(cr));
|
||||||
|
|
||||||
|
mp_hal_stdout_tx_strn(str++, sizeof(char));
|
||||||
}
|
}
|
||||||
hal_uart_char_write(UART_INSTANCE, *str++);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,12 @@
|
||||||
#include "lib/utils/interrupt_char.h"
|
#include "lib/utils/interrupt_char.h"
|
||||||
#include "nrf.h"
|
#include "nrf.h"
|
||||||
#include NRF5_HAL_H
|
#include NRF5_HAL_H
|
||||||
|
#include "nrfx_uart.h"
|
||||||
#include "pin.h"
|
#include "pin.h"
|
||||||
#include "py/mpconfig.h"
|
#include "py/mpconfig.h"
|
||||||
|
|
||||||
|
extern nrfx_uart_t serial_instance;
|
||||||
|
|
||||||
extern volatile uint64_t ticks_ms;
|
extern volatile uint64_t ticks_ms;
|
||||||
|
|
||||||
static inline mp_uint_t mp_hal_ticks_ms(void) {
|
static inline mp_uint_t mp_hal_ticks_ms(void) {
|
||||||
|
|
|
@ -21,4 +21,13 @@
|
||||||
#define NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY NRF_TWIM_FREQ_400K
|
#define NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY NRF_TWIM_FREQ_400K
|
||||||
#define NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT 0
|
#define NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT 0
|
||||||
|
|
||||||
|
// UART
|
||||||
|
#define NRFX_UART_ENABLED 1
|
||||||
|
#define NRFX_UART0_ENABLED 1
|
||||||
|
|
||||||
|
#define NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY 7
|
||||||
|
#define NRFX_UART_DEFAULT_CONFIG_HWFC NRF_UART_HWFC_DISABLED
|
||||||
|
#define NRFX_UART_DEFAULT_CONFIG_PARITY NRF_UART_PARITY_EXCLUDED
|
||||||
|
#define NRFX_UART_DEFAULT_CONFIG_BAUDRATE NRF_UART_BAUDRATE_115200
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,45 +24,45 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "supervisor/serial.h"
|
|
||||||
|
|
||||||
#include "py/obj.h"
|
|
||||||
#include "py/runtime.h"
|
|
||||||
#include "mphalport.h"
|
#include "mphalport.h"
|
||||||
#include "pins.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
|
|
||||||
#if (MICROPY_PY_BLE_NUS)
|
#if MICROPY_PY_BLE_NUS
|
||||||
#include "ble_uart.h"
|
#include "ble_uart.h"
|
||||||
|
#else
|
||||||
|
#include "nrf_gpio.h"
|
||||||
|
#include "pin.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void serial_init(void) {
|
#define INST_NO 0
|
||||||
|
|
||||||
|
nrfx_uart_t serial_instance = NRFX_UART_INSTANCE(INST_NO);
|
||||||
|
|
||||||
|
void serial_init(void) {
|
||||||
#if MICROPY_PY_BLE_NUS
|
#if MICROPY_PY_BLE_NUS
|
||||||
ble_uart_init0();
|
ble_uart_init0();
|
||||||
while (!ble_uart_enabled()) {
|
while (!ble_uart_enabled()) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
hal_uart_init_t param =
|
nrfx_uart_config_t config = NRFX_UART_DEFAULT_CONFIG;
|
||||||
{
|
config.pseltxd = MICROPY_HW_UART_TX;
|
||||||
.id = 0,
|
config.pselrxd = MICROPY_HW_UART_RX;
|
||||||
.rx_pin = &MICROPY_HW_UART1_RX,
|
config.hwfc = MICROPY_HW_UART_HWFC ? NRF_UART_HWFC_ENABLED : NRF_UART_HWFC_DISABLED;
|
||||||
.tx_pin = &MICROPY_HW_UART1_TX,
|
#ifdef MICROPY_HW_UART_CTS
|
||||||
.rts_pin = NULL,
|
config.pselcts = MICROPY_HW_UART_CTS;
|
||||||
.cts_pin = NULL,
|
#endif
|
||||||
.flow_control = MICROPY_HW_UART1_HWFC ? true : false,
|
#ifdef MICROPY_HW_UART_RTS
|
||||||
.use_parity = false,
|
config.pselrts = MICROPY_HW_UART_RTS;
|
||||||
.baud_rate = HAL_UART_BAUD_115K2,
|
#endif
|
||||||
.irq_priority = 6,
|
|
||||||
.irq_num = UARTE0_UART0_IRQn
|
|
||||||
};
|
|
||||||
|
|
||||||
hal_uart_init( UART_BASE(0), ¶m);
|
const nrfx_err_t err = nrfx_uart_init(&serial_instance, &config, NULL);
|
||||||
|
if (err == NRFX_SUCCESS)
|
||||||
|
NRFX_ASSERT(err);
|
||||||
|
|
||||||
|
nrfx_uart_rx_enable(&serial_instance);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool serial_connected(void) {
|
bool serial_connected(void) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,6 @@ bool serial_bytes_available(void) {
|
||||||
return mp_hal_stdin_any();
|
return mp_hal_stdin_any();
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_write(const char* text) {
|
void serial_write(const char *text) {
|
||||||
mp_hal_stdout_tx_str(text);
|
mp_hal_stdout_tx_str(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue