MCU : NordicSemi nRF51822-QFAA (Using custom board)
SDK Version : 7.2
Softdevice : S110 7.1
Using IAR for ARM 7.1
Hi, I was migrating my codes (SDK 6.1 to 7.2).
I used this code to back up some data to flash.
#define BD_BLOCK_SIZE 128
#define BD_BLOCK_COUNT 960
#pragma data_alignment = 4
static uint8_t ram_page[2][BD_BLOCK_SIZE];
/**< Ram pages for data & config to be saved in FLASH. */
static pstorage_handle_t m_base_handle;
/**< Identifier for allocated blocks' base address. */
static void pstorage_callback(pstorage_handle_t *p_handle,
uint8_t op_code, uint32_t result,
uint8_t *p_data,uint32_t data_len)
{ /*do nothing yet*/ }
void backup_init (void) {
pstorage_module_param_t storage_param; /**< pstorage parameter for data recording. */
uint32_t err_code;
storage_param.block_size = BD_BLOCK_SIZE;
storage_param.block_count = BD_BLOCK_COUNT;
storage_param.cb = pstorage_callback;
// Register pstorage module
err_code = pstorage_register(&storage_param, &m_base_handle);
APP_ERROR_CHECK(err_code);
memset(ram_page, 0xFF, 2 * BD_BLOCK_SIZE);
}
I call backup_init at main function after device_manager_init is called.
The device_manager_init functions follows the same content of the HID keyboard example.
When I used SDK 6.1 this backup_init had no problem,
but after I migrated at SDK 7.2, I recieved Invaid parameter error.
When using SDK 6.1, at the pstorage_register function, the block_count was equal to 960.
However, using SDK 7.2, block_count was equal to 0 so I ended up at ther assert handler.
////// edited
To be more specific, my function did set the block_count to 960.
However, after the parameters were passed to the pstorage_register function,
the value becomes zero.
Also, my code calls pstorage_init only once.
////////////////// ////////////////// edited
I founded the difference from each SDKs.
=SDK 6.1, pstorage.c
#define BLOCK_COUNT_CHECK(COUNT, SIZE) \
if (((COUNT) == 0) || ((m_next_page_addr + ((COUNT) *(SIZE)) > PSTORAGE_SWAP_ADDR))) \
{ \
return NRF_ERROR_INVALID_PARAM; \
}
=SDK 7.2, pstorage.c
#define BLOCK_COUNT_CHECK(COUNT, SIZE) \
if (((COUNT) == 0) || \
((m_next_page_addr + ((COUNT) *(SIZE)) > PSTORAGE_SWAP_ADDR)) || \
((((COUNT) * (SIZE)) > PSTORAGE_FLASH_PAGE_SIZE) && (PSTORAGE_FLASH_PAGE_SIZE % (SIZE)))) \
{ \
return NRF_ERROR_INVALID_PARAM; \
}
Additionally, I modified pstorage_platform.h . =SDK 7.2, pstorage_platform.h
#define PSTORAGE_MAX_APPLICATIONS 2 // 1 -> 2
typedef uint32_t pstorage_size_t; /** Size of length and offset fields. */
//Originally typedef uint16_t pstorage_size_t; Since 960 * 128 = 0x0001 E000 is 32 bit.
(Changed my question) So my question is,
After changing uint16_t pstorage_size_t to uint32_t pstorage_size_t,
The parameters passed fine. However, I received error at the new SDK's MACRO.
(Since PSTORAGE_FLASH_PAGE_SIZE % (SIZE) = = 0) (1024 % 128 == 0)
-
Why did the new SDK added this (modulus) condition?
-
Also, is it fine to change the size of pstorage_size_t ?
Always appreciate your help!
-Regards, Mango922