Difficulties with non_volatile storage code AN11008

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Difficulties with non_volatile storage code AN11008

1,851 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JSalisbury on Tue Aug 23 08:34:23 MST 2011
Hi,
I am having some difficulties with the code supplied with the AN11008 application note. It would appear that this code was provided for the the Keil tool chain rather than LPCxpresso. I am having 2 particular problems;

1. there seems to be an issue with the use of __packed
the lines
 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

needed __attribute__ and double brackets round __packed

 typedef __attribute__ ((__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;


2. I am getting undefined reference to `NVOL_GetVariable'    and also undefined reference to `NVOL_Init' Yet when I highlight them and then push F3 it does take me through to the source.

Thanks
0 Kudos
Reply
8 Replies

1,762 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szempy on Fri Mar 25 03:34:27 MST 2016
Yes that is my problem that the variable are initialized and the size of the bin file is bigger with this variables and are initialized with 0.
So i want them to not be initialized, so they size of the compiled bin file is smaller.
0 Kudos
Reply

1,762 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mister_T on Sun Mar 06 04:28:33 MST 2016
See the end of the post:
"""
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=.SECTOR1_STARTADDR=0x6000
--section-start=.SECTOR2_STARTADDR=0x7000
""""
This should initialize the variables.
0 Kudos
Reply

1,762 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szempy on Mon Feb 22 02:57:25 MST 2016
Thank you it helped me a lot.
I would have a question.
How can i set that the two variables are not initialized ?
static __attribute__ ((section(".SECTOR1_STARTADDR"))) UNSIGNED8 mSectorMemory1[SECTOR_SIZE];
static __attribute__ ((section(".SECTOR2_STARTADDR"))) UNSIGNED8 mSectorMemory2[SECTOR_SIZE];


When complied the variables are initialized with 0.
I tried to set it to the  .noinit.SECTOR1_STARTADDR but it set it to the address 0x10003808
0 Kudos
Reply

1,762 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gbrus on Fri Jan 22 08:35:33 MST 2016
Hello mister_T,

Thank you for sharing your instruction how to port the flash_nvol library to LPCxpresso. That saved me a lot of time.  :)

I can confirm that the library will work with this modifications. I use it on a LPC1768 with LPCxpresso v8.0.0.
0 Kudos
Reply

1,762 Views
lpcware
NXP Employee
NXP Employee
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.
0 Kudos
Reply

1,762 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Aug 24 11:40:58 MST 2011

Quote: JSalisbury
Hi,
Thanks for the feeback, issue 1. was addressed by the notes you mentioned. Issue 2. was fixed by going into the project properites-> C/C++ general ->paths and symbols -> source locations and adding the required directries.


Sounds like you didn't create the directories containing these files as "source folders", and hence the IDE by default wouldn't build the code included in them.


Quote:

I am also now getting  the errors
../nxp_nonvol/flash_nvol.c:140:1: warning: 'at' attribute directive ignored

The '[FONT=Courier New][SIZE=2]at[/SIZE][/FONT]' attribute is a Keil/RealView specific attribute and has no direct equivalent in GNU. In addition to the linker script FAQs you have been pointed at, take a look at:

http://support.code-red-tech.com/CodeRedWiki/PlacingData

In addition, this might be of interest....

http://stackoverflow.com/questions/4067811/how-to-place-a-variable-at-a-given-address-in-gcc


Quote:

c:/nxp/lpcxpresso_4.0.6_152/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe: region `RamLoc8' overflowed by 1172 bytes

Sounds like you have too much data to fit in the available memory! This is doubly dangerous as it also means that you have no memory for your stack.

At a general level look at the following FAQ (though this is really aimed at too much code to fit in flash)....

http://support.code-red-tech.com/CodeRedWiki/DebugBuildTooBig

And if you have CRP enabled...
http://support.code-red-tech.com/CodeRedWiki/CodeSizeCRP

Regards,
CodeRedSupport
0 Kudos
Reply

1,762 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JSalisbury on Wed Aug 24 03:14:35 MST 2011
Hi,
Thanks for the feeback, issue 1. was addressed by the notes you mentioned. Issue 2. was fixed by going into the project properites-> C/C++ general ->paths and symbols -> source locations and adding the required directries.

I am also now getting  the errors
../nxp_nonvol/flash_nvol.c:140:1: warning: 'at' attribute directive ignored
../nxp_nonvol/flash_nvol.c:141:1: warning: 'at' attribute directive ignored

also

c:/nxp/lpcxpresso_4.0.6_152/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe: flash_test.axf section `.bss' will not fit in region `RamLoc8'
c:/nxp/lpcxpresso_4.0.6_152/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe: region `RamLoc8' overflowed by 1172 bytes

any suggestions?

Thanks



static UNSIGNED8 mSectorMemory1[SECTOR_SIZE] __attribute__((at(SECTOR1_STARTADDR)));
static UNSIGNED8 mSectorMemory2[SECTOR_SIZE] __attribute__((at(SECTOR2_STARTADDR)));
0 Kudos
Reply

1,762 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Aug 23 23:57:35 MST 2011
There are a few notes on porting code to LPCXpresso in the following FAQs:

http://support.code-red-tech.com/CodeRedWiki/PortingCodeOtherToolchains
http://support.code-red-tech.com/CodeRedWiki/PackedStructs

With regards to your undefined references, these are likely to be linker errors informing you that the object files containing these functions are not getting pulled in for the link step. I would suspect that these functions are maybe in a library project and you have not correctly configured your project to pull them in?

http://support.code-red-tech.com/CodeRedWiki/UndefinedReference
http://support.code-red-tech.com/CodeRedWiki/LibraryProjects

Regards,
CodeRedSupport
0 Kudos
Reply