From 15eeac5d4bc796f09b70ad7b3b52f8fc2175a344 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 23 Nov 2018 14:22:07 -0800 Subject: [PATCH] A few fixes for nRF52840 feather QSPI and neopixel --- .../feather_nrf52840_express/mpconfigboard.h | 11 +++++++++-- .../feather_nrf52840_express/mpconfigboard.mk | 2 +- ports/nrf/common-hal/microcontroller/Pin.c | 2 -- ports/nrf/common-hal/neopixel_write/__init__.c | 16 ++++++++++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h index c52b69cf4a..bd1cad504b 100644 --- a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h +++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h @@ -35,12 +35,21 @@ #define MICROPY_HW_NEOPIXEL (&pin_P0_16) +#ifdef QSPI_FLASH_FILESYSTEM #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 17) #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 22) #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 23) #define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 21) #define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 19) #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 20) +#endif + +#ifdef SPI_FLASH_FILESYSTEM +#define SPI_FLASH_MOSI_PIN &pin_P0_17 +#define SPI_FLASH_MISO_PIN &pin_P0_22 +#define SPI_FLASH_SCK_PIN &pin_P0_19 +#define SPI_FLASH_CS_PIN &pin_P0_20 +#endif #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 @@ -51,8 +60,6 @@ #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) -#define EXTERNAL_FLASH_QSPI_DUAL (1) - #define BOARD_HAS_CRYSTAL 1 #define DEFAULT_I2C_BUS_SCL (&pin_P0_11) diff --git a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk index 905921a5d8..bc511e1507 100644 --- a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk +++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk @@ -20,6 +20,6 @@ endif NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 -QSPI_FLASH_FILESYSTEM = 1 +SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICE_COUNT = 1 EXTERNAL_FLASH_DEVICES = "GD25Q16C" diff --git a/ports/nrf/common-hal/microcontroller/Pin.c b/ports/nrf/common-hal/microcontroller/Pin.c index 0522bfef3b..02847e1505 100644 --- a/ports/nrf/common-hal/microcontroller/Pin.c +++ b/ports/nrf/common-hal/microcontroller/Pin.c @@ -48,7 +48,6 @@ STATIC uint32_t claimed_pins[GPIO_COUNT]; STATIC uint32_t never_reset_pins[GPIO_COUNT]; void reset_all_pins(void) { - return; for (size_t i = 0; i < GPIO_COUNT; i++) { claimed_pins[i] = never_reset_pins[i]; } @@ -77,7 +76,6 @@ void reset_all_pins(void) { // Mark pin as free and return it to a quiescent state. void reset_pin_number(uint8_t pin_number) { - return; if (pin_number == NO_PIN) { return; } diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c index ef5e8beb17..c4cb194f36 100644 --- a/ports/nrf/common-hal/neopixel_write/__init__.c +++ b/ports/nrf/common-hal/neopixel_write/__init__.c @@ -108,12 +108,21 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout // using DWT uint32_t pattern_size = numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t); uint16_t* pixels_pattern = NULL; + bool pattern_on_heap = false; + + // Use the stack to store 1 pixels worth of PWM data for the status led. uint32_t to ensure alignment. + uint32_t one_pixel[8 * sizeof(uint16_t) + 1]; NRF_PWM_Type* pwm = find_free_pwm(); // only malloc if there is PWM device available if ( pwm != NULL ) { - pixels_pattern = (uint16_t *) m_malloc(pattern_size, false); + if (numBytes == 4) { + pixels_pattern = (uint16_t *) one_pixel; + } else { + pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false); + pattern_on_heap = true; + } } // Use the identified device to choose the implementation @@ -193,7 +202,10 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout nrf_pwm_disable(pwm); nrf_pwm_pins_set(pwm, (uint32_t[]) {0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL} ); - m_free(pixels_pattern); + if (pattern_on_heap) { + m_free(pixels_pattern); + } + } // End of DMA implementation // --------------------------------------------------------------------- else {