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

System crash when both use softdevie and spi

Dear all,

My chip is nrf52832, and sdk version is SDK12.1.0_0d232a. And tried to use ble service and spi master function.

I create a timer to send spi command every 4 ms.

void spi_master_init(void) {

nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin           = SPI_SS_PIN;
spi_config.miso_pin         = SPI_MISO_PIN;
spi_config.mosi_pin         = SPI_MOSI_PIN;
spi_config.sck_pin          = SPI_SCK_PIN;
spi_config.frequency        = NRF_DRV_SPI_FREQ_8M;
spi_config.irq_priority     = 6;

APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));

}

static void spi_send_handler(void * p_context) {

if(spi_xfer_done) {

    memset(spi_rx_buf, 0, spi_length);

    nrf_drv_spi_transfer(&spi, data_tmp, spi_length, spi_rx_buf, spi_length);

    spi_xfer_done = false;

}

}

void spi_event_handler(nrf_drv_spi_evt_t const * p_event) {

if (spi_rx_buf[0] != 0)

{
	/*
	command and request data
	*/
}

spi_xfer_done = true;

}

int main(void) { bool erase_bonds;

APP_ERROR_CHECK( NRF_LOG_INIT(NULL));

timers_init();

nrf_delay_ms(3000);

buttons_leds_init(&erase_bonds);

if (erase_bonds)
{
    NRF_LOG_INFO("Bonds erased!\r\n");
}

ble_stack_init();

peer_manager_init(erase_bonds);

db_discovery_init();

spi_master_init();

hrs_c_init();

application_timers_start();

gap_params_init();
conn_params_init();
services_init();
advertising_init();

adv_scan_start();

for (;;)
{
    if (NRF_LOG_PROCESS() == false)
    {
        // Wait for BLE events.
        power_manage();
    }
}

}

After some times, the system will crash.

If I request long data or send command faster. The number of occurrences will increased. It look like the spi handler was Interrupted by softdevice.

And I try to use high priority or low frequence, it still not use.

It will stopped at hardfault.

Any suggestions or pointers are very much appreciated.

Thanks!!!!

Parents
  • Hi Kristin,

    I don't know how to see the hardfault originates from. I set break point at HardFault_Handler, i don't see any other message. Is there any example or method?

    I have tried debug, and it occurred at a strange place.

    I called a function in timer, i can see the debug print in timer. But i don't see the debug print in called function.

    the code as follow:

    In timer:

    {

    NRF_LOG_INFO("Send spi data\r\n");

    send_spi_command(type, command, data, 128);

    NRF_LOG_INFO("Send spi data\r\n");

    }

    static uint8_t send_spi_command(uint8_t type, uint8_t command, uint8_t* data, uint8_t length) { NRF_LOG_INFO("Command : %d(%d)\r\n", command, spi_send_buf);

    memset(data_tmp[spi_send_buf - 1], 0xFF, 256);
    
    data_tmp[spi_send_buf - 1][0] = spi_send_buf;
    
    data_tmp[spi_send_buf - 1][1] = type;
    
    data_tmp[spi_send_buf - 1][2] = command;
    
    if (data != NULL) {
    
        memcpy(&data_tmp[spi_send_buf - 1][3], data, length);
    
    }
    
    spi_send_counter++;
    
    return 0;
    

    }

    static void spi_schedule_handler(void * p_context)

    {

    if(spi_send_counter && spi_xfer_done) {
    
        memset(spi_rx_buf, 0, spi_length);
    
        nrf_drv_spi_transfer(&spi, data_tmp[spi_send_buf_count - 1], spi_length, spi_rx_buf, spi_length);
    
        spi_xfer_done = false;
    
        spi_send_counter--;
    
        goto end;
    }
    

    }

    I call the function (send_spi_command) to send data, and i print message before and after the command. It only print the first message.

    And it did't print NRF_LOG_INFO("Command : %d(%d)\r\n", command, spi_send_buf);

    Thanks!!!

Reply
  • Hi Kristin,

    I don't know how to see the hardfault originates from. I set break point at HardFault_Handler, i don't see any other message. Is there any example or method?

    I have tried debug, and it occurred at a strange place.

    I called a function in timer, i can see the debug print in timer. But i don't see the debug print in called function.

    the code as follow:

    In timer:

    {

    NRF_LOG_INFO("Send spi data\r\n");

    send_spi_command(type, command, data, 128);

    NRF_LOG_INFO("Send spi data\r\n");

    }

    static uint8_t send_spi_command(uint8_t type, uint8_t command, uint8_t* data, uint8_t length) { NRF_LOG_INFO("Command : %d(%d)\r\n", command, spi_send_buf);

    memset(data_tmp[spi_send_buf - 1], 0xFF, 256);
    
    data_tmp[spi_send_buf - 1][0] = spi_send_buf;
    
    data_tmp[spi_send_buf - 1][1] = type;
    
    data_tmp[spi_send_buf - 1][2] = command;
    
    if (data != NULL) {
    
        memcpy(&data_tmp[spi_send_buf - 1][3], data, length);
    
    }
    
    spi_send_counter++;
    
    return 0;
    

    }

    static void spi_schedule_handler(void * p_context)

    {

    if(spi_send_counter && spi_xfer_done) {
    
        memset(spi_rx_buf, 0, spi_length);
    
        nrf_drv_spi_transfer(&spi, data_tmp[spi_send_buf_count - 1], spi_length, spi_rx_buf, spi_length);
    
        spi_xfer_done = false;
    
        spi_send_counter--;
    
        goto end;
    }
    

    }

    I call the function (send_spi_command) to send data, and i print message before and after the command. It only print the first message.

    And it did't print NRF_LOG_INFO("Command : %d(%d)\r\n", command, spi_send_buf);

    Thanks!!!

Children
No Data
Related