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

Not Saving in Flash Memory

Hi,
I am saving data in flash memory but when I read after restarting the device it shows FF. 
How can I read from flash after restarting the device? and how can I check that there is already data?
Thanks 

Parents Reply Children
  • Don't call any flash write functions from an interrupt. It is what I have been trying to say the last 13 days.

    When I say "don't call it from an interrupt" this also means that if you put your flash functions in another function, you can't call this function from an interrupt either. 

    In your case "characteristic10()" or whatever it was called contains a flash write. This means that characteristic10() can't be called from an interrupt. Your ble_evt_handler, where your BLE_GAP_EVT_CONNECTED event is generated is an interrupt. You can't call characteristic10() (which contains the flash write) from this interrupt. You must call it from main().

    Workaround:

    volatile write_to_flash = false;
    
    write_to_flash_function()
    {
        write_to_flash();
        wait_for_flash_ready();
    }
    
    characteristic10()
    {   
        //do your characteristic things
        
        //DON'T CALL YOUR FLASH WRITE FUNCTION!
    }
    
    ble_evt_handler()
    {
        ...
        case BLE_GAP_EVT_CONNECTED:
        characteristic10();
    }
    
    main()
    {
        ...
        while(true)
        {
            if (write_to_flash == true)
            {
                write_to_flash = false;
                write_to_flash_function();
            }
            sd_app_evt_wait(); //or whatever wait function you use in your main() loop.
        }
    }

    This is pseudo code, but please study this snippet thoroughly, as I am trying to explain how to move the flash writes to main priority.

Related