diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index ab02e12197..51179e2abb 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -1,19 +1,21 @@ -# Select the board to build for: if not given on the command line, -# then default to feather52832. -BOARD ?= feather52832 -ifeq ($(wildcard boards/$(BOARD)/.),) -$(error Invalid BOARD specified) +# Select the board to build for. +ifeq ($(BOARD),) + $(info You must provide a BOARD parameter with 'BOARD=') + $(info Possible values are:) + $(info $(sort $(subst /.,,$(subst boards/,,$(wildcard boards/*/.))))) + $(error BOARD not defined) +else + ifeq ($(wildcard boards/$(BOARD)/.),) + $(error Invalid BOARD specified) + endif endif # If SoftDevice is selected, try to use that one. # Default to SD132 (exact version can be set with SOFTDEV_VERSION) -SD ?= s132 SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]') -# TODO: Verify that it is a valid target. - -# If the build directory is not given, make it reflect the board name -BUILD ?= $(if $(SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD)) +# If the build directory with SD +BUILD = $(if $(SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD)) include ../../py/mkenv.mk include boards/$(BOARD)/mpconfigboard.mk diff --git a/ports/nrf/background.c b/ports/nrf/background.c index fc8128ca8f..094da5d9c7 100644 --- a/ports/nrf/background.c +++ b/ports/nrf/background.c @@ -36,19 +36,11 @@ #include "tusb.h" -/*------------------------------------------------------------------*/ -/* MACRO TYPEDEF CONSTANT ENUM - *------------------------------------------------------------------*/ - -/*------------------------------------------------------------------*/ -/* VARIABLE DECLARATION - *------------------------------------------------------------------*/ - -/*------------------------------------------------------------------*/ -/* FUNCTION DECLARATION - *------------------------------------------------------------------*/ void run_background_tasks(void) { + +#ifdef NRF52840_XXAA tusb_task(); tud_cdc_flush(); +#endif } diff --git a/ports/nrf/boards/feather52832/mpconfigboard.mk b/ports/nrf/boards/feather52832/mpconfigboard.mk index dd7dd06ce8..cd991a7663 100644 --- a/ports/nrf/boards/feather52832/mpconfigboard.mk +++ b/ports/nrf/boards/feather52832/mpconfigboard.mk @@ -1,6 +1,7 @@ MCU_SERIES = m4 MCU_VARIANT = nrf52 MCU_SUB_VARIANT = nrf52 +SD ?= s132 SOFTDEV_VERSION ?= 2.0.1 LD_FILE = boards/feather52832/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld diff --git a/ports/nrf/boards/feather52840/mpconfigboard.mk b/ports/nrf/boards/feather52840/mpconfigboard.mk index 52c0f59404..598f73631c 100644 --- a/ports/nrf/boards/feather52840/mpconfigboard.mk +++ b/ports/nrf/boards/feather52840/mpconfigboard.mk @@ -1,6 +1,7 @@ MCU_SERIES = m4 MCU_VARIANT = nrf52 MCU_SUB_VARIANT = nrf52840 +SD ?= s140 SOFTDEV_VERSION ?= 6.0.0 BOOT_SETTING_ADDR = 0xFF000 diff --git a/ports/nrf/boards/pca10040/mpconfigboard.mk b/ports/nrf/boards/pca10040/mpconfigboard.mk index 036969299d..79aa853494 100644 --- a/ports/nrf/boards/pca10040/mpconfigboard.mk +++ b/ports/nrf/boards/pca10040/mpconfigboard.mk @@ -1,6 +1,7 @@ MCU_SERIES = m4 MCU_VARIANT = nrf52 MCU_SUB_VARIANT = nrf52 +SD ?= s132 SOFTDEV_VERSION ?= 5.0.0 ifeq ($(SD),) diff --git a/ports/nrf/boards/pca10056/board.c b/ports/nrf/boards/pca10056/board.c index 52bc5c92cc..cee269ee6f 100644 --- a/ports/nrf/boards/pca10056/board.c +++ b/ports/nrf/boards/pca10056/board.c @@ -36,10 +36,12 @@ void board_init(void) { - // Init USB + // Clock NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk); NRF_CLOCK->TASKS_LFCLKSTART = 1UL; + // Init USB + #ifdef SOFTDEVICE_PRESENT // TODO support Softdevice config #else diff --git a/ports/nrf/boards/pca10056/mpconfigboard.h b/ports/nrf/boards/pca10056/mpconfigboard.h index 2be1156d07..8ddff6c394 100644 --- a/ports/nrf/boards/pca10056/mpconfigboard.h +++ b/ports/nrf/boards/pca10056/mpconfigboard.h @@ -28,7 +28,7 @@ #define MICROPY_HW_BOARD_NAME "PCA10056" #define MICROPY_HW_MCU_NAME "NRF52840" -#define MICROPY_PY_SYS_PLATFORM "nrf52840-PDK" +#define MICROPY_PY_SYS_PLATFORM "nrf52840-DK" #define MICROPY_HW_HAS_LED (1) #define MICROPY_HW_HAS_SWITCH (0) @@ -77,3 +77,8 @@ #define PORT_HEAP_SIZE (128*1024) #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 + + +// Temp (could be removed) 0: usb cdc (default), 1 : hwuart (jlink) +#define CFG_HWUART_FOR_SERIAL 0 + diff --git a/ports/nrf/boards/pca10056/mpconfigboard.mk b/ports/nrf/boards/pca10056/mpconfigboard.mk index 52c0f59404..598f73631c 100644 --- a/ports/nrf/boards/pca10056/mpconfigboard.mk +++ b/ports/nrf/boards/pca10056/mpconfigboard.mk @@ -1,6 +1,7 @@ MCU_SERIES = m4 MCU_VARIANT = nrf52 MCU_SUB_VARIANT = nrf52840 +SD ?= s140 SOFTDEV_VERSION ?= 6.0.0 BOOT_SETTING_ADDR = 0xFF000 diff --git a/ports/nrf/internal_flash.c b/ports/nrf/internal_flash.c index 56377c9734..35e0ae8b75 100644 --- a/ports/nrf/internal_flash.c +++ b/ports/nrf/internal_flash.c @@ -74,7 +74,6 @@ void internal_flash_init(void) { port_pin_set_config(MICROPY_HW_LED_MSC, &pin_conf); port_pin_set_output_level(MICROPY_HW_LED_MSC, false); #endif -// flash_init(&internal_flash_desc, NVMCTRL); } uint32_t internal_flash_get_block_size(void) { diff --git a/ports/nrf/internal_flash.h b/ports/nrf/internal_flash.h index e83b39d573..3811815e29 100644 --- a/ports/nrf/internal_flash.h +++ b/ports/nrf/internal_flash.h @@ -33,17 +33,17 @@ #define FLASH_ROOT_POINTERS -#define FLASH_PAGE_SIZE 0x1000 -#define CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define FLASH_PAGE_SIZE 0x1000 +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 -#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms -#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2) +#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms +#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2) -void internal_flash_init(void); -uint32_t internal_flash_get_block_size(void); -uint32_t internal_flash_get_block_count(void); -void internal_flash_irq_handler(void); -void internal_flash_flush(void); +void internal_flash_init(void); +uint32_t internal_flash_get_block_size(void); +uint32_t internal_flash_get_block_count(void); +void internal_flash_irq_handler(void); +void internal_flash_flush(void); // these return 0 on success, non-zero on error mp_uint_t internal_flash_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks); diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index e13554d7b5..85e2867553 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -32,13 +32,20 @@ #include "py/mperrno.h" #include "hal_uart.h" -#ifndef NRF52840_XXAA +#if !defined( NRF52840_XXAA) || ( defined(CFG_HWUART_FOR_SERIAL) && CFG_HWUART_FOR_SERIAL == 1 ) #define UART_INSTANCE UART_BASE(0) #if (MICROPY_PY_BLE_NUS == 0) int mp_hal_stdin_rx_chr(void) { for (;;) { + #ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP + #endif + // if (reload_requested) { + // return CHAR_CTRL_D; + // } + if ( hal_uart_available(UART_INSTANCE) ) { uint8_t ch; hal_uart_char_read(UART_INSTANCE, &ch); @@ -99,6 +106,7 @@ int mp_hal_stdin_rx_chr(void) { // if (reload_requested) { // return CHAR_CTRL_D; // } + if (tud_cdc_available()) { #ifdef MICROPY_HW_LED_RX gpio_toggle_pin_level(MICROPY_HW_LED_RX); @@ -106,6 +114,8 @@ int mp_hal_stdin_rx_chr(void) { return tud_cdc_read_char(); } } + + return 0; } bool mp_hal_stdin_any(void) { @@ -114,20 +124,21 @@ bool mp_hal_stdin_any(void) { void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { -// #ifdef MICROPY_HW_LED_TX -// gpio_toggle_pin_level(MICROPY_HW_LED_TX); -// #endif -// -// #ifdef CIRCUITPY_BOOT_OUTPUT_FILE -// if (boot_output_file != NULL) { -// UINT bytes_written = 0; -// f_write(boot_output_file, str, len, &bytes_written); -// } -// #endif + #ifdef MICROPY_HW_LED_TX + gpio_toggle_pin_level(MICROPY_HW_LED_TX); + #endif + + #ifdef CIRCUITPY_BOOT_OUTPUT_FILE + if (boot_output_file != NULL) { + UINT bytes_written = 0; + f_write(boot_output_file, str, len, &bytes_written); + } + #endif tud_cdc_write(str, len); } +// TODO use stdout_helper.c void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { while (len--) { if (*str == '\n') { @@ -137,9 +148,11 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { } } -#endif - void mp_hal_stdout_tx_str(const char *str) { mp_hal_stdout_tx_strn(str, strlen(str)); } +#endif + + + diff --git a/ports/nrf/supervisor/serial.c b/ports/nrf/supervisor/serial.c index 080f77644a..e6c43b58aa 100644 --- a/ports/nrf/supervisor/serial.c +++ b/ports/nrf/supervisor/serial.c @@ -36,7 +36,7 @@ #include "ble_uart.h" #endif -#ifndef NRF52840_XXAA +#if !defined( NRF52840_XXAA) || ( defined(CFG_HWUART_FOR_SERIAL) && CFG_HWUART_FOR_SERIAL == 1 ) void serial_init(void) { @@ -91,7 +91,7 @@ void serial_write(const char* text) { #include "tusb.h" void serial_init(void) { - // usb should be initialized in board_init() + // usb is already initialized in board_init() }