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

Bootloader for nRF51422 ?

Hello Everybody,

I need to write a boot loader for nRF51422. Any suggestion for it, reference site ,sample code for quick reference ?

thanks and regards Robin Singh

  • You are free to write any bootloader you'd like. But without softdevice support there is a weak point when upgrading the first flash page of the application space (where the interrupt vectors are). If this flash page write fails (power loss for example) you risk getting in an unrecoverable error. When supported, the softdevice can be configured to forward interrupts to a bootloader residing anywhere in flash.

  • Thanks for the reply Audun. i tried to write the bootloader program , but it seems to be i have problem in jumping to my application program. here is what i tried: step1: i took a example image hex in a header .[start address =0x30000 size 0x2800] const uint8_t hexFileArray2[2007] = { 0x3A, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, .............}; step 2: i write this image in my main program to flash : sd_softdevice_enable(); ..... if (NRF_UICR->CLENR0 == 0xFFFFFFFF) { NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; NRF_UICR->CLENR0 = 0x30000; while (!NRF_NVMC->READY); NRF_NVMC->CONFIG = 0; NVIC_SystemReset(); } then : step 3: write image image_size = 2007; no_of_pages = (image_size / page_size) + 1; erase_no_of_pages(NRF_UICR->CLENR0, no_of_pages);

          data_packet_handle();//its just write the image start from 0x30000
      uint32_t  n_err_code = sd_softdevice_disable();
          APP_ERROR_CHECK(n_err_code);
    

    step 4: interrupts_disable(); step 5: now jump to application my_application_main_t application_main = (my_application_main_t )(0x30000+4); if (application_main != (my_application_main_t) 0xFFFFFFFF) { // Initialize user application's Stack Pointer __set_MSP((__IO uint32_t) 0x30000); application_main();//jump to application. but this does not jump to application program.

    Do i need to change any CPU mode(USER mode , SVC mode or etc ) setting to jump to application's vector table. because my program seems to be coming back to soft device vector table.?

  • Thanks for the reply Audun. i tried to write the bootloader program , but it seems to be i have problem in jumping to my application program. here is what i tried: step1: i took a example image hex in a header .[start address =0x30000 size 0x2800] const uint8_t hexFileArray2[2007] = { 0x3A, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, .............}; step 2: i write this image in my main program to flash : sd_softdevice_enable(); ..... if (NRF_UICR->CLENR0 == 0xFFFFFFFF) { NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; NRF_UICR->CLENR0 = 0x30000; while (!NRF_NVMC->READY); NRF_NVMC->CONFIG = 0; NVIC_SystemReset(); } then : step 3: write image image_size = 2007; no_of_pages = (image_size / page_size) + 1; erase_no_of_pages(NRF_UICR->CLENR0, no_of_pages);

          data_packet_handle();//its just write the image start from 0x30000
      uint32_t  n_err_code = sd_softdevice_disable();
          APP_ERROR_CHECK(n_err_code);
    

    step 4: interrupts_disable(); step 5: now jump to application my_application_main_t application_main = (my_application_main_t )(0x30000+4); if (application_main != (my_application_main_t) 0xFFFFFFFF) { // Initialize user application's Stack Pointer __set_MSP((__IO uint32_t) 0x30000); application_main();//jump to application. but this does not jump to application program.

    Do i need to change any CPU mode(USER mode , SVC mode or etc ) setting to jump to application's vector table. because my program seems to be coming back to soft device vector table.?

  • Hi Robin, the softdevice memory area is write protected. Attempting a write in this area should trigger a HardFault. Since you cannot delete it, all interrupts will come to the softdevice vector table. I'm not exactly sure what you mean when saying that your application always comes back to the softdevice vector table, because this is the normal behavior.

    You should be able to write to the application space in either Handler or Thread mode though.

    I suggest trying to read out the memory you've written using nrfjprog (command line utility accompanying nRFgo Studio). See nrfjprog --help, and look for the --memrd option. This should help verify that your updated image is actually written to flash as you intend.

  • completed some time before by writing a simple loader via UART, following are the step . if some one want to do it: Reference this project : github.com/.../nrf51-uart-bootloader project: github.com/.../nrf51422-bootloader performance: 5kb/sec approx with 115200 baud rate.

Related