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

LESC with MITM for Peripheral hardfault running on FreeRTOS Issue

Hello:

I am porting the LESC with MITM security protocol from your "ble_app_multirole_lesc" example inyo a project that runs FreeRTOS. This is on an NRF32540 With s140.

I am implementing MITM identical as in the example - a button determines if we accept or deny the bonding. However I have run into issues where a hardfault is triggered after a button admits/rejects the connection. The hardfault seems to be when FreeRTOS is switching contexts (function xPortPendSVHandler in port.c), and it happens in PendSV. My issue seems to be exactly the one described here (https://devzone.nordicsemi.com/f/nordic-q-a/45268/data-bus-hard-fault-when-handling-secure-connection-bonding) but unfortunately I could not find the solution. I preferred to make a new case rather than reviving a years old one.

Thinking it had to do something with the button interrupt throwing everything into haywire, I modified the import of the example to set a flag in the button interrupt. A thread will check for that flag and execute the bond check code (rather than it happening on an interrupt context). I did the following (other than porting the code from the example to my file):

static void bsp_event_handler(bsp_event_t event)

...

case BSP_EVENT_KEY_0:

    SetBondingAllowed(true); /*Set a flag so "on_num_comp_button_press" is called from
                            a thread later on rather than in the interrupt*/
                            
    break;

case BSP_EVENT_KEY_1:
    SetBondingAllowed(false);
    break;

  • On my thread

void vApplicationIdleHook( void )
{
#if NRF_LOG_ENABLED
        if(flagBondConn)
      {
        flagBondConn = false;
        on_num_comp_button_press(bondResult);
      }
     vTaskResume(m_logger_thread);
#endif
}

My question is, is this correct? I see it currently working, but I am not sure if I am missing another example or patch that has implemented LESC with MITM running on FreeRTOS. We really need Freertos for the complexity of our project! Do you think the SD call to check the bond (sd_ble_gap_auth_key_reply) cannot be called on an FreeRTOS context?

Let me know what you think!

Thanks,

Eduardo

Parents
  • A small question related to this - the MITM example makes whoever connects attempt to bond as soond as the connection starts. However on my port I have to initiate the bonding from the NRF Connect App. I still cannot read/write to characteristics, but I can't figure out why NRF Connect does not attempt bonding from the start on my port. Any tips on this would be appreciated. Thank you!

Reply
  • A small question related to this - the MITM example makes whoever connects attempt to bond as soond as the connection starts. However on my port I have to initiate the bonding from the NRF Connect App. I still cannot read/write to characteristics, but I can't figure out why NRF Connect does not attempt bonding from the start on my port. Any tips on this would be appreciated. Thank you!

Children
No Data
Related