From cfd71d90234c5a2ec757f905b969637d0bcab226 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 27 Dec 2019 20:18:07 -0800 Subject: Fix nRF UART reset disable only turns off ENABLE but doesn't set the init tracking that nrfx uses. uninit hangs if ENABLE is off and is called because it waits forever for TX to stop. --- ports/nrf/common-hal/busio/UART.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 0579db414..d79b65ff8 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -124,7 +124,7 @@ static void uart_callback_irq (const nrfx_uarte_event_t * event, void * context) void uart_reset(void) { for (size_t i = 0 ; i < MP_ARRAY_SIZE(nrfx_uartes); i++) { - nrf_uarte_disable(nrfx_uartes[i].p_reg); + nrfx_uarte_uninit(&nrfx_uartes[i]); } } @@ -171,7 +171,6 @@ void common_hal_busio_uart_construct (busio_uart_obj_t *self, } }; - nrfx_uarte_uninit(self->uarte); _VERIFY_ERR(nrfx_uarte_init(self->uarte, &config, uart_callback_irq)); // Init buffer for rx -- cgit v1.2.3 From 6afb8dadbcc91562deb413638e2ef7e17f3305a6 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 3 Jan 2020 15:14:37 -0800 Subject: Change SPI and I2C in the same way. --- ports/nrf/common-hal/busio/I2C.c | 9 +-------- ports/nrf/common-hal/busio/SPI.c | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c index 7a079ff7f..f6f686cdf 100644 --- a/ports/nrf/common-hal/busio/I2C.c +++ b/ports/nrf/common-hal/busio/I2C.c @@ -63,7 +63,7 @@ void i2c_reset(void) { if (never_reset[i]) { continue; } - nrf_twim_disable(twim_peripherals[i].twim.p_twim); + nrfx_twim_uninit(&twim_peripherals[i].twim); twim_peripherals[i].in_use = false; } } @@ -150,13 +150,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t * // About to init. If we fail after this point, common_hal_busio_i2c_deinit() will set in_use to false. self->twim_peripheral->in_use = true; nrfx_err_t err = nrfx_twim_init(&self->twim_peripheral->twim, &config, NULL, NULL); - - // A soft reset doesn't uninit the driver so we might end up with a invalid state - if (err == NRFX_ERROR_INVALID_STATE) { - nrfx_twim_uninit(&self->twim_peripheral->twim); - err = nrfx_twim_init(&self->twim_peripheral->twim, &config, NULL, NULL); - } - if (err != NRFX_SUCCESS) { common_hal_busio_i2c_deinit(self); mp_raise_OSError(MP_EIO); diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index d2977909e..639bbcdd0 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -68,7 +68,7 @@ void spi_reset(void) { if (never_reset[i]) { continue; } - nrf_spim_disable(spim_peripherals[i].spim.p_reg); + nrfx_spim_uninit(&spim_peripherals[i].spim); } } @@ -160,13 +160,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * } nrfx_err_t err = nrfx_spim_init(&self->spim_peripheral->spim, &config, NULL, NULL); - - // A soft reset doesn't uninit the driver so we might end up with a invalid state - if (err == NRFX_ERROR_INVALID_STATE) { - nrfx_spim_uninit(&self->spim_peripheral->spim); - err = nrfx_spim_init(&self->spim_peripheral->spim, &config, NULL, NULL); - } - if (err != NRFX_SUCCESS) { common_hal_busio_spi_deinit(self); mp_raise_OSError(MP_EIO); -- cgit v1.2.3 From f6ec1ea17284ce6874a79db1998df21b81bc4ebd Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 3 Jan 2020 15:15:36 -0800 Subject: Throw an error when we cannot allocate PWM pixel buffer --- ports/nrf/common-hal/neopixel_write/__init__.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c index 3b67778a6..3052e908d 100644 --- a/ports/nrf/common-hal/neopixel_write/__init__.c +++ b/ports/nrf/common-hal/neopixel_write/__init__.c @@ -130,7 +130,17 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout if (pattern_size <= sizeof(one_pixel)) { pixels_pattern = (uint16_t *) one_pixel; } else { - pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false); + uint8_t sd_en = 0; + (void) sd_softdevice_is_enabled(&sd_en); + if (sd_en) { + // If the soft device is enabled then we must use PWM to + // transmit. This takes a bunch of memory to do so raise an + // exception if we can't. + pixels_pattern = (uint16_t *) m_malloc(pattern_size, false); + } else { + pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false); + } + pattern_on_heap = true; } } -- cgit v1.2.3