Content originally posted in LPCWare by mister_T on Sat May 02 02:18:24 MST 2015
Using LPCxpresso 7.6.2 I had to do the following to get the flash_nvol files compiled:
-copy files flash_nvol.c and flash_nvol.h to your project.
-add #include "flash_nvol.h" to the main file of your project
-remove ifdefs that are not for the MCU type you are using from the top of flash_nvol.c file
-change CPU_CLK define to the clock frequency you are using in flash_nvol.c
-add #include "board.h" to flash_nvol.c
-remove defines for TRUE and FALSE from flash_nvol.h
Change this set of code in flash_nvol.c:
// defines a sector record
// members must be byte aligned
// must be 48 bytes in size
typedef __packed struct _Sector_Record
{
UNSIGNED8 Flags1; // flags indicate sector status
UNSIGNED8 Reserved1[15]; // padding
UNSIGNED8 Flags2; // flags indicate sector status
UNSIGNED8 Reserved2[15]; // padding
UNSIGNED8 Flags3; // flags indicate sector status
UNSIGNED8 Reserved3[15]; // padding
} SECTOR_RECORD;
// defines a variable record
// members must be byte aligned
typedef __packed struct _Variable_Record
{
UNSIGNED8 Flags; // flags indicate variable status
UNSIGNED16 Id; // unique variable id
UNSIGNED8 Data[MAX_VARIABLE_SIZE]; // variable data
UNSIGNED8 Checksum; // 2's complement checksum of id and data
} VARIABLE_RECORD;
to this:
// defines a sector record
// members must be byte aligned
// must be 48 bytes in size
typedef struct __attribute__ ((__packed__)) _Sector_Record
{
UNSIGNED8 Flags1; // flags indicate sector status
UNSIGNED8 Reserved1[15]; // padding
UNSIGNED8 Flags2; // flags indicate sector status
UNSIGNED8 Reserved2[15]; // padding
UNSIGNED8 Flags3; // flags indicate sector status
UNSIGNED8 Reserved3[15]; // padding
} SECTOR_RECORD;
// defines a variable record
// members must be byte aligned
typedef struct __attribute__ ((__packed__)) _Variable_Record
{
UNSIGNED8 Flags; // flags indicate variable status
UNSIGNED16 Id; // unique variable id
UNSIGNED8 Data[MAX_VARIABLE_SIZE]; // variable data
UNSIGNED8 Checksum; // 2's complement checksum of id and data
} VARIABLE_RECORD;
Change these lines in flash_nvol.c
// allocate memory for non-volatile memory so it isn't used by the linker
// for something else
static UNSIGNED8 mSectorMemory1[SECTOR_SIZE] __attribute__((at(SECTOR1_STARTADDR)));
static UNSIGNED8 mSectorMemory2[SECTOR_SIZE] __attribute__((at(SECTOR2_STARTADDR)));
To this:
// allocate memory for non-volatile memory so it isn't used by the linker
// for something else
static __attribute__ ((section(".SECTOR1_STARTADDR"))) UNSIGNED8 mSectorMemory1[SECTOR_SIZE];
static __attribute__ ((section(".SECTOR2_STARTADDR"))) UNSIGNED8 mSectorMemory2[SECTOR_SIZE];
Remove defines from flash_nvol.c:
//#define SECTOR1_STARTADDR 0x00002000
//#define SECTOR2_STARTADDR 0x00003000
Check from your MCU manual for flash addresses, I placed mine to the end of the flash (0x6000 and 0x7000) flash sectors. Add these flash addresses to MCU Linker-Miscellaneous- other options- (found by right clicking on your project tree- properties- C/C++ build-settings-
like this (one entry for each line):
--section-start=.SECTOR2_STARTADDR=0x6000
--section-start=.SECTOR2_STARTADDR=0x7000
Thanks to user curtvm for this hint!
On the top of flash_nvol.c, change defines SECTOR1_NUM and SECTOR2_NUM to the numbers of the flash sectors you are using. These can be found from the MCU user manual under flash configuration.
I haven't tested in actual hardware if this works (since my board is still in the pcb shop), but at least it compiles and links without errors.