<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to use flash manager?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71054/how-to-use-flash-manager</link><description>Guys, In a Mesh project, when setting up flash manager: 
 
 How do you get the right value of flash_manager_config_t.p_area ? 
 And where and how is it configured? 
 
 Thanks...</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 01 Feb 2021 10:44:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71054/how-to-use-flash-manager" /><item><title>RE: How to use flash manager?</title><link>https://devzone.nordicsemi.com/thread/292183?ContentTypeID=1</link><pubDate>Mon, 01 Feb 2021 10:44:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c887517-1487-48e8-8e68-8b4ffa9f8884</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;An example that uses the flash manager would be e.g. the Mesh_SDK_5.0.0\examples\light_switch\server&lt;/p&gt;
&lt;p&gt;But I guess you already knew that, and that this is not what you are looking for.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Perhaps you can tell me what you intend to do. Do you intend to store some custom data, and hence you want an own instance of the flash manager? Or do you encounter some issues with the flash manager being used to store the Mesh network data?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="BlueMike"]The demo code from one of the posts here on devzone looks like as if p_area is an input parameter (and hence needs to be provided). [/quote]
&lt;p&gt;&amp;nbsp;Well, it is both.&lt;/p&gt;
&lt;p&gt;Every instance of the flash manager is set up from a start address (p_area) and a size&amp;nbsp;page_count.&lt;/p&gt;
&lt;p&gt;The function&amp;nbsp;mesh_config_backend_file_create() in mesh_config_flashman_glue.c is a good example on how to set this up:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t mesh_config_backend_file_create(mesh_config_backend_file_t * p_file)
{
    uint8_t page_count;
    flash_manager_page_t * p_area;
#if !(BACKWARD_COMPATIBLE_PERSISTENCE)
    page_count = CEIL_DIV(p_file-&amp;gt;size, FLASH_MANAGER_DATA_PER_PAGE);
#else
    legacy_flash_config_get(p_file, &amp;amp;page_count, &amp;amp;p_area);
    if (p_area == NULL)
#endif
    {
        m_allocated_page_count += page_count;
        p_area = (flash_manager_page_t *)(flash_area_end_get() - (m_allocated_page_count * PAGE_SIZE));
    }
    flash_manager_t * p_manager = &amp;amp;p_file-&amp;gt;glue_data.flash_manager;
    const flash_manager_config_t config =
    {
        .write_complete_cb = write_complete_cb,
        .invalidate_complete_cb = invalidate_complete_cb,
        .remove_complete_cb = remove_complete_cb,
        .min_available_space = p_file-&amp;gt;size,
        .p_area = p_area,
        .page_count = page_count
    };

    __LOG(LOG_SRC_FM, LOG_LEVEL_DBG3, &amp;quot;Mesh config area: 0x%08x file_id: 0x%04x\n&amp;quot;,
          config.p_area, p_file-&amp;gt;file_id);
    return flash_manager_add(p_manager, &amp;amp;config);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="BlueMike"]&lt;p&gt;If yes: Is it safe to use the same value that other instances use? I.e. just copy the line:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;p_area = (flash_manager_page_t *)(flash_area_end_get() - (m_allocated_page_count * PAGE_SIZE));&lt;/code&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&amp;nbsp;Yes. If you intend to use the same flash manager instance (you can do that). If you want to use a separate instance with it&amp;#39;s own area, you need to customise this a bit. As you may notice, the area used for the flash manager is the end of the flash. If a bootloader is used, then the flash manager is placed right before the bootloader.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s assume you want to create your own instance with it&amp;#39;s own flash area, then the flash manager instance that is used for the network area is already considering whether a bootloader is present or not. You can either use the p_area and adjust it, or the implementation that it uses.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;p_custom_area = p_area - CUSTOM_FLASH_MANAGER_PAGE_COUNT;
or:
p_area = (flash_manager_page_t *)(flash_area_end_get() - (m_allocated_page_count * PAGE_SIZE)) - CUSTOM_FLASH_MANAGER_PAGE_COUNT;

...
.p_area = p_custom_area,
.page_count = CUSTOM_FLASH_MANAGER_PAGE_COUNT,&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And CUSTOM_FLASH_MANAGER_PAGE_COUNT is the amount of flash pages you want to set aside for your custom flash manager instance.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use flash manager?</title><link>https://devzone.nordicsemi.com/thread/292068?ContentTypeID=1</link><pubDate>Sat, 30 Jan 2021 20:54:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfd59e74-5f12-4230-bc95-d65d4fbe790f</guid><dc:creator>BlueMike</dc:creator><description>&lt;p&gt;Edvin,&lt;/p&gt;
&lt;p&gt;If somehow possible please provide a demo and a few lines of explanation that clarify how to set up flash manager in an application. TBH, flashmanager&amp;#39;s &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.meshsdk.v4.2.0%2Fmd_doc_user_guide_modules_flash_manager.html"&gt;documentation&lt;/a&gt; is &lt;span style="text-decoration:line-through;"&gt;total cr@p&lt;/span&gt; not helpful (&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.meshsdk.v4.2.0%2Fgroup__FLASH__MANAGER.html"&gt;api docs&lt;/a&gt; are a little better, but still insufficient). And looking at any of the examples in the Mesh SDK doesn&amp;#39;t explain much neither. See, I&amp;#39;m really not in the mood of copy&amp;amp;pasting some code I don&amp;#39;t understand...&lt;/p&gt;
&lt;p&gt;So a little example would help a lot!&lt;/p&gt;
&lt;p&gt;Thanks for your help,&lt;br /&gt;Michael.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use flash manager?</title><link>https://devzone.nordicsemi.com/thread/292019?ContentTypeID=1</link><pubDate>Fri, 29 Jan 2021 14:32:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64d7c42b-a153-404c-b4b5-73d49146958e</guid><dc:creator>BlueMike</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/71054/how-to-use-flash-manager/291989#291989"]Is there a particular reason why you need to change this?[/quote]
&lt;p&gt;No, not at all! I&amp;#39;d rather keep the value as it is as long as saving/loading to/from flash works.&lt;/p&gt;
&lt;p&gt;The demo code from one of the posts here on devzone looks like as if p_area is an input parameter (and hence needs to be provided). Your question sounds like p_area is an output parameter that can safely be ignored. I&amp;#39;m a little confused now: Is it necessary to have p_area set before calling flash_manager_add()?&lt;/p&gt;
&lt;p&gt;If yes: Is it safe to use the same value that other instances use? I.e. just copy the line:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;p_area = (flash_manager_page_t *)(flash_area_end_get() - (m_allocated_page_count * PAGE_SIZE));&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Again thanks for the clarification,&lt;br /&gt;Michael.&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use flash manager?</title><link>https://devzone.nordicsemi.com/thread/291989?ContentTypeID=1</link><pubDate>Fri, 29 Jan 2021 12:35:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e88955e-9696-4d53-962d-37f213486db4</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Is there a particular reason why you need to change this? Did you encounter any issues?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The p_area is the address to the start address that should be used by the flash manager. If you look at any of the examples in the Mesh SDK, you can see that in mesh_config_flashman_glue.c -&amp;gt; mesh_config_backend_file_create(), p_area is set to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;p_area = (flash_manager_page_t *)(flash_area_end_get() - (m_allocated_page_count * PAGE_SIZE));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The function flash_area_end_get() (via a lot of functions) points to mp_recovery area, which again is set based on whether or not you have a bootloader programmed, via the BOOTLOADERADDR(), which is a macro that checks the chip&amp;#39;s bootloader address register.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I guess that answers both 1. and 2. Check out&amp;nbsp;&lt;span&gt;mesh_config_backend_file_create(), and the function&amp;nbsp;flash_manager_defrag_init() in flash_manager_defrag.c.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>