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

SOFTDEVICE_PRESENT macro must be present in a custom usb hid project that could potentially work without softdevice. Should I init and use softdevice?

To the kind attention of Nordic support team,

I 'm working on a custom project so that nRF52840 can operate in two different mutual exclusive running modes. A USB operational mode and a connectivity firmware mode (they are meant to never run at the same time). USB code is based on SDK15.2 USB HID composite example, and it makes no use of Softdevice. Having included connectivity firmware code also in the project I'm working on, emProject file of the project has got a SOFTDEVICE_PRESENT macro. My problem is that macro is still there for the USB operational mode also, I mean a project that can work without Softdevice is compiled with SOFTDEVICE_PRESENT macro. I'd like to know, having a situation where USB code could potentially work without Softdevice and having Softdevice loaded in flash (for connectivity fw purposes), do I have to enable Softdevice explicitly for the project running in USB mode, so that is compiled to work with a Softdevice and having a Softdevice properly initialized? Could you please tell me what is theoretically the best practice for this kind of situations? And what is the documentation I could read? Do I need to properly initialize Softdevice even when running in USB mode? And, should I init Softdevice does code like this suffice:

nrf_sdh_enable_request();
ASSERT(nrf_sdh_is_enabled());

Or is it a different procedure? Am I missing something? Is it safe to use those instructions in a project like USB HID composite example but using SOFTDEVICE_PRESENT macro also and having Softdevice present in flash?I already saw, that ENTER/EXIT CRITICAL regions where not working properly in USB project, maybe because SOFTDEVICE_PRESENT is there and Softdevice loaded in flash, still it has not been properly initialized (I didn't initialize it at all in USB project)

Thank you for your great work and attention.

Best regards

  • Hi

    You shouldn't have to initialize the SoftDevice if you aren't using it. It can still be present on the flash if you need it for another application on your device, so I suggest keeping the SoftDevice, but just "ignoring" it in your USB mode. The USB peripheral should not need the SoftDevice at all. This seems like a non-issue, and I don't think you have to worry about this.

    Best regards,

    Simon

  • Thank you Simon for your kindness, I was worried about code like this, linked to CRITICAL_REGION_ENTER:

    because as you say USB should ignore Softdevice, but in a way some part of code that is common with USB still is compiled in order to use Softdevice, having the SOFTDEVICE_PRESENT macro

    void app_util_critical_region_enter(uint8_t *p_nested)
    {
    #if __CORTEX_M == (0x04U)
    ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
    #endif

    #if defined(SOFTDEVICE_PRESENT)
    /* return value can be safely ignored */
    (void) sd_nvic_critical_region_enter(p_nested);
    #else
    app_util_disable_irq();
    #endif
    }

    Thank you

  • But the application doesn't actually use the SoftDevice, does it? It checks if the SoftDevice is there, and then leaves it be if I'm not mistaken.

    Best regards,

    Simon

Related