Hi,
I am trying to interface an external flash memory (for generic data storage) with the BLE peripheral software in CC2642R1. In the callback mode, the SPI seems to be fine when I set it up during initialization, but the Flash driver needs both blocking and nonblocking modes depending on the scenario. Hence I was trying to switch back and forth, but then it does not call the callback function after the first nonblocking transfer (determined from the Slave Select pin). Following are the relevant code snippets:
SPI_Handle spiHandle0; SPI_Params SPI_customParams; static void SimplePeripheral_init(void) { ... GPIO_init(); SPI_init(); SPI_Params_init(&SPI_customParams); SPI_customParams.bitRate = 8000000; spiHandle0 = SPI_open(CONFIG_SPI_0, &SPI_customParams); external_flash_init(...); } static void SimplePeripheral_processAppMsg(spEvt_t *pMsg) { ... switch (pMsg->event) { case SP_SPI0_EVT: spi_xfer_done = true; SPI_MEM_enable_blocking(); ... break; ... } ... } void SimplePeripheral_SPI_CB(SPI_Handle spi, SPI_Transaction *tran) { GPIO_write(GPIO_SPI_SS_MEM, 1); SimplePeripheral_enqueueMsg(SP_SPI0_EVT, NULL); } void SPI_MEM_enable_blocking() { SPI_close(spiHandle0); SPI_customParams.transferCallbackFxn = NULL; SPI_customParams.transferMode = SPI_MODE_BLOCKING; spiHandle0 = SPI_open(CONFIG_SPI_0, &SPI_customParams); } void SPI_MEM_disable_blocking() { SPI_close(spiHandle0); SPI_customParams.transferCallbackFxn = SimplePeripheral_SPI_CB; SPI_customParams.transferMode = SPI_MODE_CALLBACK; spiHandle0 = SPI_open(CONFIG_SPI_0, &SPI_customParams); } bool spi_nand_transfer(uint8_t const * p_tx_buffer, uint32_t tx_buffer_length, uint8_t * p_rx_buffer, uint32_t rx_buffer_length, bool block) { bool retCode; if (!block) SPI_MEM_disable_blocking(); SPI_Transaction MEMspiRW; MEMspiRW.count = rx_buffer_length ? rx_buffer_length : tx_buffer_length; MEMspiRW.txBuf = (void *)p_tx_buffer; MEMspiRW.rxBuf = (void *)p_rx_buffer; spi_xfer_done = false; GPIO_write(GPIO_SPI_SS_MEM, 0); retCode = SPI_transfer(spiHandle0, &MEMspiRW); if (block) { GPIO_write(GPIO_SPI_SS_MEM, 1); spi_xfer_done = true; } return retCode; }