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

Store data in flash with NRF52832 and MBED and GCC

Hi,

I'm trying to use an existing NRF51822 mbed codebase on a new NRF52832 product and am having some issues.

First of all, it seems that I can't use mbedlib, but need to update to mbed-os because BLE on NRF52832 isn't implemented for the old libraries. No problem.

I got things building with mbed-os with the rtos disabled using the .mbedignore file. However, my pstorage-based flash data storage isn't working. The callback never gets called.

From reading on forums and digging around in the source it seems that things have been switched internally to fstorage. Again, no problem. I didn't really want to update my code, but no big deal.

However, I can't get the FS_REGISTER_CFG macro to compile. I'm getting an error: "sorry, unimplemented: non-trivial designated initializers not supported".

I tried a number of ways to work around it but none of them have worked so far.

Is there some way to get this working with this toolchain? Or some way to continue to use pstorage? Would I be better off to just ditch mbed entirely?

Thanks!

  • I've gotten pstorage working again by #defining IS_LEGACY_DEVICE_MANAGER_ENABLED to 1 at the top of btle.cpp (the pre-existing code defined it to 1 for S110 and 0 for S130 or S132). So far BTLE seems to be working as well and it doesn't seem to be used in any obviously bad way from a quick search, but I don't know enough about the internal workings to know if this is dangerous. Any thoughts from someone more familiar? Thanks.

  • You need to initialize the FS_REGISTER_CFG as follows:

    FS_REGISTER_CFG(fs_config_t fs_config) =
    {
        .p_start_addr = NULL,
        .p_end_addr   = NULL,
        .callback  = fs_evt_handler, // Function for event callbacks.
        .num_pages = NUM_PAGES,      // Number of physical flash pages required.
        .priority  = 0xFE            // Priority for flash usage.
    };
    

    It will compile cleanly then. Just remember that you need to have the SofDevice enabled (call ble.init()) otherwise the event callback will never be called (and your write_flag will stay set).

  • The error "sorry, unimplemented: non-trivial designated initializers not supported" is normally caused by C++ compilers that require all fields of the struct to be initialized AND in the exact same order they are listed in the struct definition.

  • About C to C++

    Yes that is a world wide problem porting C code to C++

    You can initialize the same way in C++ but not using specific property names and you then have to populate the entire struct.

    It becomes anonymous and you can not clearly see what property will be set. If the underlaying struct is changed you may mix things up.

    FS_REGISTER_CFG(fs_config_t fs_config) =
    {
        NULL,
        NULL,
        fs_evt_handler, // Function for event callbacks.
        NUM_PAGES,      // Number of physical flash pages required.
        0xFE            // Priority for flash usage.
    };

    C++ In the blind. Hopefully you have assigned to all fields and in the right order

    What they expected you to do in C++ was to use classes and implement contructors. And you can do that even in a struct. This is a nice but when objectifying C code it makes room for misstakes when you assign contructor parameters to the struct and there is a lot of typing. In the end when calling the constructor you can not set specific fields by name anyway.

    It expands to nice formal objects but as the code becomes more formal and uses more text space each class should be keept in a separate .h, .cpp file. Somwhere at this point C++ accelerates and classes becomes safely contained and less prone to destruction. Once debuged they can be reused and improved.  

    But now back to quick and dirty..

    A nice shortcut in C++ is you can initiate the struct as empty {}; and then reference and set each field one by one.

    FS_REGISTER_CFG(fs_config_t fs_config) = {};
    fs_config.p_start_addr = NULL;
    fs_config.p_end_addr   = NULL;
    fs_config.callback  = fs_evt_handler; // Function for event callbacks.
    fs_config.num_pages = NUM_PAGES;      // Number of physical flash pages required.
    fs_config.priority  = 0xFE;            // Priority for flash usage.

    Something along that line if you have limited time and can work on clean objectification in a later stage,

Related