Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 6 months ago.
Linker error when using pstorage
Hi all,
I'm trying to make use of pstorage API from the Nordic softdevice library in my nrf51822 based project. My project also includes the mbed BLE library. Compilation is fine, but at the end I get linker errors, e.g.: "Undefined symbol pstorage_init"
I've included pstorage.h in the file and #defined NEEDS_PSTORAGE.
Any ideas how to fix this? Thanks.
Question relating to:
1 Answer
9 years, 3 months ago.
When I added the define 'NEED_PSTORAGE 1', I got past the linker error but then received a new compiler error:
Cannot open source input file "nrf.h": No such file or directory
To fix this, I had to add a missing line in "pstorage_platform.h" immediately after the define for PSTORAGE_DATA_END_ADDR...
#define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */
Everything is working now! :)
I spoke too soon!
Yes the program compiles and runs now however pstorage_init() doesn't return NRF_SUCCESS so is failing...
Any ideas why? (Thanks!)
(I should add that I am using the nRF51-DK that has a nRF51422 mcu onboard - similar but not identical hw)
UPDATE
I have got it working now!
The mbed version of storage_platform.h for the nRF51-DK is incorrect.
Ultimately, to get this all working, I had to define/redefine the following:
#define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_MAX_APPLICATIONS - 1) \ * PSTORAGE_FLASH_PAGE_SIZE) /**< Start address for persistent data, configurable according to system requirements. */ #define PSTORAGE_DATA_END_ADDR ((PSTORAGE_FLASH_PAGE_END - 1) * PSTORAGE_FLASH_PAGE_SIZE) /**< End address for persistent data, configurable according to system requirements. */ #define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */
After this, pstorage_init() now works correctly.
posted by 15 Jan 2015
Where is pstorage_init symbol defined? I believe it's probably a function , which is defined somewhere..
posted by Martin Kojtal 28 Oct 2014yes, it's defined in pstorage.cpp which is in the nRF51822 library at the location /nordic/app_common/pstorage.cpp. I expected it to get compiled and linked automatically since other parts of nRF51822 library work OK.
posted by Prashant Vaibhav 28 Oct 2014could there be a missing extern "C" somewhere?
posted by Rohit Grover 28 Oct 2014Thanks for the hints. The pstorage.h (and pstorage_platform.h) files already have extern "C" wrapping, so that was not it. I solved it by adding #define NEED_PSTORAGE 1 directly inside pstorage.cpp, because the entire file is wrapped in #if NEED_PSTORAGE. I couldn't find a way in the mbed online IDE to specify default preprocessor defines, which was probably causing pstorage.cpp not to get compiled at all.
posted by Prashant Vaibhav 29 Oct 2014