Skip to content

Commit f0012df

Browse files
committed
nrf: neopixel_write: busy poll for one pixel writes
It's probably not the whole story, however, this fixes a crash observed when bulk copying data to an nRF board using `dd`. Basically, the call stack looked like this when resetting into safe mode: #0 reset_into_safe_mode reason=reason@entry=GC_ALLOC_OUTSIDE_VM #1 gc_alloc .. #4 external_flash_write_block .. adafruit#11 usb_background adafruit#12 run_background_tasks adafruit#13 common_hal_neopixel_write .. adafruit#18 start_mp i.e., during early startup, it is not okay yet to call allocation functions like m_malloc_maybe that use the garbage collected heap. However, nRF's neopixel_write (which already includes special handling to avoid heap allocations for the status pixel!) can enter background tasks, which do nearly arbitrary things including heap allocations. We re-use the same test that switches from heap allocation to stack allocation for the pattern buffer.
1 parent c000567 commit f0012df

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
200200

201201
// But we have to wait for the flag to be set.
202202
while ( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {
203-
RUN_BACKGROUND_TASKS;
203+
if (pattern_size > sizeof(one_pixel)) {
204+
RUN_BACKGROUND_TASKS;
205+
}
204206
}
205207

206208
// Before leave we clear the flag for the event.

0 commit comments

Comments
 (0)