I have an application using 4 wire SPI connecting to a 2MB data flash. An application using UART (no BLE) works fine reading and writing to this device. However with BLE enabled, it only works with larger transfers and never generates the completion callback. Initialization and use based on the nrfx_spim.
#define SPI_INSTANCE 2
static const nrfx_spim_t spi = NRFX_SPIM_INSTANCE(SPI_INSTANCE);
static volatile bool spi_xfer_done;
void spim_event_handler(const nrfx_spim_evt_t* evt, void* cntxt)
{
spi_xfer_done = true;
}
uint32_t errc;
nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG;
spi_config.frequency = NRF_SPIM_FREQ_4M,
spi_config.ss_pin = SPI_FLASH_CS_N,
spi_config.miso_pin = SPI_MISO,
spi_config.mosi_pin = SPI_MOSI,
spi_config.sck_pin = SPI_CLK;
spi_xfer_done = false;
errc = nrfx_spim_init(&spi, &spi_config, spim_event_handler, NULL);
...
Then trying to read:
uint8_t rdid[] = {MX25V_RDID};
uint8_t middid[4];
uint32_t rc;
nrfx_spim_xfer_desc_t xf = NRFX_SPIM_XFER_TRX(rdid, 1, middid, 4);
spi_xfer_done = false;
rc = nrfx_spim_xfer(&spi, &xf, 0);
for( rc = 0; !spi_xfer_done && rc < 1000; ++rc ) __WFE();
All the return codes check out as 0. The final loop always times out, yet, the values have been put into middid correctly. I've tried replacing __WFE() with nrf_pwr_mgmt_run(), same result, just a 1, same result. If you printf the result through the SES debug channel you get the completion after the printf.
This all works wonderfully with just the UART and the debug port.
The sdk_config.h has the following. I've tried enabling NRFX_SPIM2_ENABLED but that appears to not make a difference.
sdk_config.h:#define NRFX_SPIM_ENABLED 1
sdk_config.h:#define NRFX_SPIM0_ENABLED 0
sdk_config.h:#define NRFX_SPIM1_ENABLED 0
sdk_config.h:#define NRFX_SPIM2_ENABLED 0
sdk_config.h:#define NRFX_SPIM_MISO_PULL_CFG 1
sdk_config.h:#define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY 6
sdk_config.h:#define NRFX_SPIM_CONFIG_LOG_ENABLED 0
sdk_config.h:#define NRFX_SPIM_CONFIG_LOG_LEVEL 3
sdk_config.h:#define NRFX_SPIM_CONFIG_INFO_COLOR 0
sdk_config.h:#define NRFX_SPIM_CONFIG_DEBUG_COLOR 0
sdk_config.h:#define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 0
Also
#define SPI_ENABLED 1
#define SPI_DEFAULT_CONFIG_IRQ_PRIORITY 6
#define NRF_SPI_DRV_MISO_PULLUP_CFG 1
#define SPI0_ENABLED 0
#define SPI0_USE_EASY_DMA 0
#define SPI1_ENABLED 0
#define SPI1_USE_EASY_DMA 1
#define SPI2_ENABLED 1
#define SPI2_USE_EASY_DMA 1
#define SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 0
#define APP_SDCARD_SPI_INSTANCE 0
#define NRF_SPI_MNGR_ENABLED 0