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

fstorage page address ( start_addr ~ end_Addr)

Hi, all!

Sorry, I'm not good at English myself.

My device is nrf52832. Base code is ble_app_uart (sdk 12.0.0, pca10040, s132).

ADD. fs_sys_event_handler

static void sys_evt_dispatch(uint32_t sys_evt)
{
    // Dispatch the system event to the fstorage module, where it will be
    // dispatched to the Flash Data Storage (FDS) module.
    fs_sys_event_handler(sys_evt);

    // Dispatch to the Advertising module last, since it will check if there are any
    // pending flash operations in fstorage. Let fstorage process system events first,
    // so that it can report correctly to the Advertising module.
    ble_advertising_on_sys_evt(sys_evt);
}

ADD. fstorage code

void fstorage_test(void)
{
		static uint32_t data;

		FS_REGISTER_CFG(fs_config_t fs_config) =
		{
            .callback  = fs_evt_handler, // Function for event callbacks.
            .num_pages = NUM_PAGES,      // Number of physical flash pages required.
	        .priority  = 0xFE            // Priority for flash usage.
		};
		
		fs_ret_t ret = fs_init();
	
		if (ret != FS_SUCCESS)
		{		
		    printf("error\r\n");
		}
	
		printf("0x%X ~ 0x%X\r\n", (uint32_t)fs_config.p_start_addr,(uint32_t)fs_config.p_end_addr);
}

I test, changind page number (NUM_PAGES)

My prediction was this.

NUM_PAGES 1 : 0x7E000 ~ 0x7EFFF

NUM_PAGES 2 : 0x7D000 ~ 0x7DFFF

NUM_PAGES 3 : 0x7C000 ~ 0x7CFFF

But... fstorage_test(); result


NUM_PAGES 1 : 0x7E000 ~ 0x7F000

NUM_PAGES 2 : 0x7C000 ~ 0x7E000

NUM_PAGES 3 : 0x7A000 ~ 0x7D000

NUM_PAGES 4 : 0x78000 ~ 0x7C000

NUM_PAGES 5 : 0x76000 ~ 0x7B000

NUM_PAGES 6 : 0x74000 ~ 0x7A000

NUM_PAGES 7 : 0x72000 ~ 0x79000

Is this the right result?

thank yor for read my problem.

Parents
  • FormerMember
    0 FormerMember

    Where is "NUM_PAGES" printed from? Why is there multiple printouts from fstorage_test()?

    Does any other module in the application use fstorage? (Peer manager for example?)

    What happens if you do the printing of start and end address directly from the end of fs_init()?

     

    fs_ret_t fs_init(void)
    {
        uint32_t const   total_users     = FS_SECTION_VARS_COUNT;
        uint32_t         configs_to_init = FS_SECTION_VARS_COUNT;
        uint32_t const * p_current_end   = FS_PAGE_END_ADDR;
    
        if (m_flags & FS_FLAG_INITIALIZED)
        {
            return FS_SUCCESS;
        }
    
        // Each fstorage user has registered one configuration.
        // The total number of users (and thus the total number of configurations) is
        // kept in total_users. Some of these users might have specified their flash
        // boundaries in their configurations. This function sets the flash boundaries
        // for the remaining user configurations without further user interaction.
    
        // First, determine how many user configurations this function has to initialize,
        // out of the total. This number will be kept in configs_to_init.
    
        for (uint32_t i = 0; i < total_users; i++)
        {
            fs_config_t const * const p_config = FS_SECTION_VARS_GET(i);
    
            if ((p_config->p_start_addr != NULL) &&
                (p_config->p_end_addr   != NULL))
            {
                configs_to_init--;
            }
        }
    
        // For each configuration to initialize, assign flash space based on the priority
        // specified. Higher priority means a higher memory address.
    
        for (uint32_t i = 0; i < configs_to_init; i++)
        {
            fs_config_t * p_config_i   = FS_SECTION_VARS_GET(i);
            uint8_t       max_priority = 0;
            uint8_t       max_index    = i;
    
            for (uint32_t j = 0; j < total_users; j++)
            {
                fs_config_t const * const p_config_j = FS_SECTION_VARS_GET(j);
    
                #if 0
                if (p_config_j->priority == p_config_i->priority)
                {
                    // Duplicated priorities are not allowed.
                    return FS_ERR_INVALID_CFG;
                }
                #endif
    
                if ((p_config_j->p_start_addr != NULL) &&
                    (p_config_j->p_end_addr   != NULL))
                {
                    // When calculating the configuration with the next highest priority
                    // skip configurations which were already set during a previous iteration.
                    // This check needs to be here to prevent re-using the configurations
                    // with higher priorities which we used in previous iterations.
                    continue;
                }
    
                if (p_config_j->priority > max_priority)
                {
                    max_priority = p_config_j->priority;
                    max_index    = j;
                }
            }
    
            p_config_i = FS_SECTION_VARS_GET(max_index);
    
            p_config_i->p_end_addr   = p_current_end;
            p_config_i->p_start_addr = p_current_end - (p_config_i->num_pages * FS_PAGE_SIZE_WORDS);
    
            p_current_end = p_config_i->p_start_addr;
            // Print start and end address here.
        }
    
        m_flags |= FS_FLAG_INITIALIZED;
    
        return FS_SUCCESS;
    }
    

Reply
  • FormerMember
    0 FormerMember

    Where is "NUM_PAGES" printed from? Why is there multiple printouts from fstorage_test()?

    Does any other module in the application use fstorage? (Peer manager for example?)

    What happens if you do the printing of start and end address directly from the end of fs_init()?

     

    fs_ret_t fs_init(void)
    {
        uint32_t const   total_users     = FS_SECTION_VARS_COUNT;
        uint32_t         configs_to_init = FS_SECTION_VARS_COUNT;
        uint32_t const * p_current_end   = FS_PAGE_END_ADDR;
    
        if (m_flags & FS_FLAG_INITIALIZED)
        {
            return FS_SUCCESS;
        }
    
        // Each fstorage user has registered one configuration.
        // The total number of users (and thus the total number of configurations) is
        // kept in total_users. Some of these users might have specified their flash
        // boundaries in their configurations. This function sets the flash boundaries
        // for the remaining user configurations without further user interaction.
    
        // First, determine how many user configurations this function has to initialize,
        // out of the total. This number will be kept in configs_to_init.
    
        for (uint32_t i = 0; i < total_users; i++)
        {
            fs_config_t const * const p_config = FS_SECTION_VARS_GET(i);
    
            if ((p_config->p_start_addr != NULL) &&
                (p_config->p_end_addr   != NULL))
            {
                configs_to_init--;
            }
        }
    
        // For each configuration to initialize, assign flash space based on the priority
        // specified. Higher priority means a higher memory address.
    
        for (uint32_t i = 0; i < configs_to_init; i++)
        {
            fs_config_t * p_config_i   = FS_SECTION_VARS_GET(i);
            uint8_t       max_priority = 0;
            uint8_t       max_index    = i;
    
            for (uint32_t j = 0; j < total_users; j++)
            {
                fs_config_t const * const p_config_j = FS_SECTION_VARS_GET(j);
    
                #if 0
                if (p_config_j->priority == p_config_i->priority)
                {
                    // Duplicated priorities are not allowed.
                    return FS_ERR_INVALID_CFG;
                }
                #endif
    
                if ((p_config_j->p_start_addr != NULL) &&
                    (p_config_j->p_end_addr   != NULL))
                {
                    // When calculating the configuration with the next highest priority
                    // skip configurations which were already set during a previous iteration.
                    // This check needs to be here to prevent re-using the configurations
                    // with higher priorities which we used in previous iterations.
                    continue;
                }
    
                if (p_config_j->priority > max_priority)
                {
                    max_priority = p_config_j->priority;
                    max_index    = j;
                }
            }
    
            p_config_i = FS_SECTION_VARS_GET(max_index);
    
            p_config_i->p_end_addr   = p_current_end;
            p_config_i->p_start_addr = p_current_end - (p_config_i->num_pages * FS_PAGE_SIZE_WORDS);
    
            p_current_end = p_config_i->p_start_addr;
            // Print start and end address here.
        }
    
        m_flags |= FS_FLAG_INITIALIZED;
    
        return FS_SUCCESS;
    }
    

Children
No Data
Related