circuitpython: SPI + Bluetooth crash nRF52840

Calling the write() method of an SPI object while Bluetooth is active crashes the firmware.

Here is a minimal code that reproduces the issue:

import board
import busio
from ubluepy import Peripheral

p = Peripheral()
p.advertise()

spi = busio.SPI(board.P0_22, MOSI=board.P1_00)
while not spi.try_lock():
    pass
spi.write(bytes([0xff]))

If you comment out the last line (the call to spi.write()), then it doesn’t crash anymore. Tested on the nRF52840 USB Dongle.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (3 by maintainers)

Most upvoted comments

I disabled SPIM3 in nrfx_config.h and the problem seems to have been resolved. I can now run a blue advertise and then mount my SPI SD Card

diff --git a/ports/nrf/nrfx_config.h b/ports/nrf/nrfx_config.h
index f217cb053..a9bee8912 100644
--- a/ports/nrf/nrfx_config.h
+++ b/ports/nrf/nrfx_config.h
@@ -27,9 +27,9 @@
 
 // Enable SPIM2 and SPIM3 (if available)
 #define NRFX_SPIM2_ENABLED 1
-#ifdef NRF52840_XXAA
-    #define NRFX_SPIM3_ENABLED 1
-#endif
+//#ifdef NRF52840_XXAA
+//    #define NRFX_SPIM3_ENABLED 1
+//#endif

This BLE + SPIM crash sounds quite similar to this issue: https://devzone.nordicsemi.com/f/nordic-q-a/33982/sdk-15-software-crash-during-spi-session/130572. I’m inquiring.

Since it does not occur on the nrf52832, It could be related to the s140 SD or something in the nrf52840 code. Both are differences.