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

Dual bank DFU with code for external uC

I am using two microcontrollers for my application, one of which is the nRF52. What I would like to do is transfer the firmware for the nRF and external uC as a single bundle using the dual bank update approach. The bootloader should then verify and program the firmware for the nRF and exernal uC in sequence. Is there an example for this, and how could the bootloader distinguish the difference between the two applications when they are transferred as a single bundle?

  • I have done this to use the NRF chip to flash an STM chip, but I use separate bundles. My guess is that you won't need to update both chips every single time, so I would suggest to keep it simple and separate the bundles.

    To distinguish the different firmwares, I first tried using a flag which you first needed to set by writing a code to the DFU Control Point. If the flag was set, the firmware was meant for the STM, if not, for the NRF. Then I had a situation where the flag wasn't set for some reason and "bricked" my device because I accidentally flashed STM firmware onto the NRF, so I decided to change my implementation.

    My final approach was to use different key signatures for NRF and STM DFU packages and to set the flag accordingly.

    I considered a third approach of modifying nrfutil to include a flag to indicate whether the DFU package was meant for the NRF or the STM, but I found the different keys to be an easier implementation.

  • Hi Andy, thanks for your answer. It makes sense. A simple question - can one use the same keys for each firmware update? Are you able to supply a code snippet of the key parts of the bootloader or point me to any publicly available examples?

  • You can use the same key, but then you have to use a different approach to set the flag. You could set it via BLE as I did in the beginning, just to try it out. I don't have a code snippet I can share with you, but I can tell you most if not all of the changes you need to make are in dfu_req_handling.c (I'm on SDK13, not sure if that file exists in all SDKs)

  • In dfu_handle_prevalidate() I do this:

        switch (p_command->signature_type)
        {
            case DFU_SIGNATURE_TYPE_ECDSA_P256_SHA256:
                {
                  ...
                    err_code = nrf_crypto_ecdsa_verify_hash(sig_info_p256, &crypto_key_pk_nrf, &init_packet_hash, &crypto_sig);
                    if (err_code == NRF_SUCCESS)
                    {
                    	m_is_stm_transfer = false;
                    }
                    else
                    {
                    	err_code = nrf_crypto_ecdsa_verify_hash(sig_info_p256, &crypto_key_pk_stm, &init_packet_hash, &crypto_sig);
    
                    	if (err_code == NRF_SUCCESS)
                    	{
    				m_is_stm_transfer = true;
                    	}
                    	else
                    	{
    				return NRF_DFU_RES_CODE_INVALID_OBJECT;
                    	}
                    }
                }
                break;
    ...
        }
    
  • Hi Andy,

    I am working on the same project I would like to flash the stm32 via the nrf52. Is it possible for you to share an example code.Thanks in advance,

    Constantin

Related