This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPIM on 52832, emStudio, SES, SDK 16.0

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

Parents
  • Hello Jed,

    Jed Marti said:
    I won't bother you again.

    We are not bothered, do not worry. The forum exists for you to post questions and issues, this is fine.
    What Awneil pointed out is that by using the insert->code option the readability of your code drastically increases, and thus it will be easier to help you.
    It will also make it more likely that someone in the forum will spot and point out your issue, which could lead to a faster response.

    Now over to your issue.
    You say that you code is working fine when you are not using BLE - could you elaborate what this means? Does it mean that you have excluded the BLE parts and SoftDevice from your project entierly, or does it mean that you have temporarily disabled it?
    Could you also elaborate how it does not work for smaller transfers - does it generate any errors?
    Lastly, just to make sure, when you say UART in your ticket you are actually referencing the SPIM interface, is this correct?

    From the parts that you have shared from your sdk_config it seems to me that you are enabling both the legacy SPI and the nrfx SPIM instances.
    This will cause the legacy driver to overwrite the nrfx spim module - this is a feature to maintain compatability of older projects.
    Instead, you should remove or comment out the SPI_ENABLED, SPI1_*, and SPI2_* defines, and only have the NRFX_SPIM_* enabled.
    For emphesis; it is not enought to leave the old SPI_ENABLED in the sdk_config set to 0 - as long as it is defined then the apply_old_config will overwrite the nrfx module. For clarity in your code I would also make sure that you stick to only using SPIM or SPI in your naming convention, based on which module you are utilizing.

    Looking forward to resolving this issue together,

    Best regards,
    Karl

Reply
  • Hello Jed,

    Jed Marti said:
    I won't bother you again.

    We are not bothered, do not worry. The forum exists for you to post questions and issues, this is fine.
    What Awneil pointed out is that by using the insert->code option the readability of your code drastically increases, and thus it will be easier to help you.
    It will also make it more likely that someone in the forum will spot and point out your issue, which could lead to a faster response.

    Now over to your issue.
    You say that you code is working fine when you are not using BLE - could you elaborate what this means? Does it mean that you have excluded the BLE parts and SoftDevice from your project entierly, or does it mean that you have temporarily disabled it?
    Could you also elaborate how it does not work for smaller transfers - does it generate any errors?
    Lastly, just to make sure, when you say UART in your ticket you are actually referencing the SPIM interface, is this correct?

    From the parts that you have shared from your sdk_config it seems to me that you are enabling both the legacy SPI and the nrfx SPIM instances.
    This will cause the legacy driver to overwrite the nrfx spim module - this is a feature to maintain compatability of older projects.
    Instead, you should remove or comment out the SPI_ENABLED, SPI1_*, and SPI2_* defines, and only have the NRFX_SPIM_* enabled.
    For emphesis; it is not enought to leave the old SPI_ENABLED in the sdk_config set to 0 - as long as it is defined then the apply_old_config will overwrite the nrfx module. For clarity in your code I would also make sure that you stick to only using SPIM or SPI in your naming convention, based on which module you are utilizing.

    Looking forward to resolving this issue together,

    Best regards,
    Karl

Children
No Data
Related