Skip to content

Commit 776c9b0

Browse files
authored
Merge pull request #2432 from tannewt/fix_nrf_uart
Fix nRF UART reset
2 parents fc5f776 + f6ec1ea commit 776c9b0

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

ports/nrf/common-hal/busio/I2C.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void i2c_reset(void) {
6363
if (never_reset[i]) {
6464
continue;
6565
}
66-
nrf_twim_disable(twim_peripherals[i].twim.p_twim);
66+
nrfx_twim_uninit(&twim_peripherals[i].twim);
6767
twim_peripherals[i].in_use = false;
6868
}
6969
}
@@ -150,13 +150,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
150150
// About to init. If we fail after this point, common_hal_busio_i2c_deinit() will set in_use to false.
151151
self->twim_peripheral->in_use = true;
152152
nrfx_err_t err = nrfx_twim_init(&self->twim_peripheral->twim, &config, NULL, NULL);
153-
154-
// A soft reset doesn't uninit the driver so we might end up with a invalid state
155-
if (err == NRFX_ERROR_INVALID_STATE) {
156-
nrfx_twim_uninit(&self->twim_peripheral->twim);
157-
err = nrfx_twim_init(&self->twim_peripheral->twim, &config, NULL, NULL);
158-
}
159-
160153
if (err != NRFX_SUCCESS) {
161154
common_hal_busio_i2c_deinit(self);
162155
mp_raise_OSError(MP_EIO);

ports/nrf/common-hal/busio/SPI.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void spi_reset(void) {
6868
if (never_reset[i]) {
6969
continue;
7070
}
71-
nrf_spim_disable(spim_peripherals[i].spim.p_reg);
71+
nrfx_spim_uninit(&spim_peripherals[i].spim);
7272
}
7373
}
7474

@@ -160,13 +160,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
160160
}
161161

162162
nrfx_err_t err = nrfx_spim_init(&self->spim_peripheral->spim, &config, NULL, NULL);
163-
164-
// A soft reset doesn't uninit the driver so we might end up with a invalid state
165-
if (err == NRFX_ERROR_INVALID_STATE) {
166-
nrfx_spim_uninit(&self->spim_peripheral->spim);
167-
err = nrfx_spim_init(&self->spim_peripheral->spim, &config, NULL, NULL);
168-
}
169-
170163
if (err != NRFX_SUCCESS) {
171164
common_hal_busio_spi_deinit(self);
172165
mp_raise_OSError(MP_EIO);

ports/nrf/common-hal/busio/UART.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void uart_callback_irq (const nrfx_uarte_event_t * event, void * context)
124124

125125
void uart_reset(void) {
126126
for (size_t i = 0 ; i < MP_ARRAY_SIZE(nrfx_uartes); i++) {
127-
nrf_uarte_disable(nrfx_uartes[i].p_reg);
127+
nrfx_uarte_uninit(&nrfx_uartes[i]);
128128
}
129129
}
130130

@@ -171,7 +171,6 @@ void common_hal_busio_uart_construct (busio_uart_obj_t *self,
171171
}
172172
};
173173

174-
nrfx_uarte_uninit(self->uarte);
175174
_VERIFY_ERR(nrfx_uarte_init(self->uarte, &config, uart_callback_irq));
176175

177176
// Init buffer for rx

ports/nrf/common-hal/neopixel_write/__init__.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,17 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
130130
if (pattern_size <= sizeof(one_pixel)) {
131131
pixels_pattern = (uint16_t *) one_pixel;
132132
} else {
133-
pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false);
133+
uint8_t sd_en = 0;
134+
(void) sd_softdevice_is_enabled(&sd_en);
135+
if (sd_en) {
136+
// If the soft device is enabled then we must use PWM to
137+
// transmit. This takes a bunch of memory to do so raise an
138+
// exception if we can't.
139+
pixels_pattern = (uint16_t *) m_malloc(pattern_size, false);
140+
} else {
141+
pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false);
142+
}
143+
134144
pattern_on_heap = true;
135145
}
136146
}

0 commit comments

Comments
 (0)