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

cant access flash when bootloader is present

i am trying to use flash to store and read data. I am able to do that when there is only softdevice and application. but when there is bootloader code get stuck. softdevice using is s130 2.0.1. i used keil to generate hex . softdevice and bootloader(buttonless) hex are loaded with nrfgo then app is loaded using nrfconnect(dfu). to give command to flash data given by uart(pin 0.1 and p0.2) . ble_flash.c function i am using to access flash.

NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos);

this is line used before erasing the page. i had put two led turn on instructions before and after this line and came to the conclusion that after this line execute code seem stuck somewhere.

cant figure out why?. because without bootloader ,code works.

Parents Reply Children
  • The events may get consumed by the Softdevice Handler before being read in your main loop. You should register a callback for SoC events at the end of ble_stack_init instead.

    /**@brief Function for dispatching a system event to interested modules.
     *
     * @details This function is called from the System event interrupt handler after a system
     *          event has been received.
     *
     * @param[in] sys_evt  System stack event.
     */
    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        //TODO: check sys_evt
    }
    
    /**@brief Function for initializing the BLE stack.
     *
     * @details Initializes the SoftDevice and the BLE event interrupt.
     */
    static void ble_stack_init(void)
    {
        ...
    
        // Register with the SoftDevice handler module for SoC events.
        err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    }
    

  • added this in ble_stack_init

    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);

    then,

    static void sys_evt_dispatch(uint32_t sys_evt)
    {
    if(sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS)
    {
    printf("\r\nerased\r\n");
    }
    else if(sys_evt == NRF_EVT_FLASH_OPERATION_ERROR)
    {
    printf("\r\nerror\r\n");
    }

    }

    when erase execute,

    err_code_ = sd_flash_page_erase(NRF_FICR->CODESIZE - 20);

    i get, 

    err_code = NRF_SUCCESS  and  event of NRF_EVT_FLASH_OPERATION_SUCCESS

    but at   

    err_code = sd_flash_write((uint32_t *)(NRF_FICR->CODESIZE) - 20,data_32_1,2);

    i get,

    err_code = NRF_ERROR_FORBIDDEN and no event in sys_evt_dispatch

    why i get forbidden error while writing and not in erase?

    for source i am using  

    uint32_t const data_32_1[6] = {'@','@','@','@','@','@'};

  • ok ...so in the sd_flash write it was memory address instead of page number.

    err_code = sd_flash_write((uint32_t *)((NRF_FICR->CODESIZE - 20)*NRF_FICR->CODEPAGESIZE),data_32_1,2);

    with this i get , err_code = NRF_SUCCESS and  NRF_EVT_FLASH_OPERATION_SUCCESS in sys_evt_dispatch

    with pointers ..able to read data direclty from address...

  • it works with bootloader also  ...

    i am now doing sd_flash_write while i am connected via NUS service...its  woking now...but do you suggest to do this way?

  • It's ok to use the sd flash API directly. Although I prefer using fstorage/fds modules on top of the SD flash API when I have flash data needs to be updated frequently. 

Related