Could someone point me to the best reference for using code flash greater than 64KB? I am working on a project that uses the SiLabs C8051F121 that has 128KB code flash. I am about 10K away from 64KB so I need to figure out how to use the upper 64KB and at the moment am having mixed results figuring things out. In particular I have two problems that I cannot figure out.
1. I want to place a CRC in my code so that I can determine if there has been any data corruption in the flash. I want to place the CRC at physical address 0x1EFFE (I am setting aside 0x1F000 - 0x1FFFF). I can modify the HEX file and place the CRC at the desired address but I cannot figure out how to get the compiler/linker to do it. I created an A51 that has the following code in it:
CSEG AT 0x1EFFE ;CRC_ADDR DW 0xABCD ;CRC END
Without activating Code Banking this places the CRC at 0xEFFE. If I turn code banking on and specify that this A51 file be placed in Bank #3 then the CRC gets placed at 0x1EFFE and 0xEFFE. Why does that happen? (In uVision under Configure Flash Tools, I select the Target Tab and select Code Banking, Banks = 4 and for Bank Area: Start=0x8000 and End=0xFFFF). However, looking in the HEX file I cannot find the duplicate CRC.
2. The second problem appears related to #1 in that if I specify any files in a Bank other than Common I will get a portion of my code duplicated in both the lower 64KB and the upper 64KB. These duplications are in the HEX file. Again, I do not understand why code is being duplicated.
My understanding is that when code banking is instituted, the common bank 0x0 thru 0x7FFF is always available at this address range and the rest of the code is "paged in" via the code banks using address range 0x8000 thru 0xFFFF but actually reside in physical addresses as shown here:
Bank 1: 0x8000 thru 0xFFFF Bank 2: 0x10000 thru 0x17FFF Bank 3: 0x18000 thru 0x1FFFF (with the range 0x1FC00 thru 0x1FFFF reserved on the SiLabs device)
I am using the LX51 linker and the L51_BANK.A51 file but just do not understand why the above things are occurring. If anyone could provide me an explanation or a pointer to documentation that might better explain this I would appreciate it. I have combed thru the Keil and SiLabs sites and have some App notes and other resources but nothing so far, in my opinion, explains code banking very well so that I can understand the above behaviors.
the SiLabs C8051F121 that has 128KB code flash. at silabs there is an appnote how to do this. using 128k internal is not the "Keil way" but following the appnote oit works
Erik
Before going to Code banking, have you looked at moving Constants out of Code space and into some Flash mapped as XDATA?
I haven't actually done this on an SiLabs part, but looked at it once and thought it should be possible...
Haven't SiLabs jumped onto the Cortext-M3/0 bandwaggon yet...?
not that I know, there is no (obvious) reference to such at their website
I do not understand the reference to the "keil way". Please explain.
The Constants are not the problem. I can take them all out and still get the duplication problem.
The Constants are not the problem. I can take them all out and still get the duplication problem. please reread Andys post. He did not suggest the constants gave you the duplication, he suggested you avoid code banking (which I wholehardedly support)
Erik is right - that wasn't my point.
My suggestion was, indeed, that XCONST might save you the need to do code banking at all.
My mistake. However, my used code space is enough when added to what yet needs to be done that I am certain that I will blow past the 64KB code space boundary. So I don't see that I have a choice but to do banking.
I understand how to set it up but I do not understand what is actually happening. Why are large blocks of code being duplicated in each bank?
As a note to the above, I actually ran into this a couple of months ago and my first thought was as you suggest to see if I could avoid code banking altogether. However, as I said, I do not now see that happening.
From Keil support:
If you leave a module assigned to the <default> bank, the linker will assign it to the common bank.
If you have more than 32k of code in your common bank, it will overflow into the banked area. The linker will place a copy of that "overflow" code in each bank, because it won't do a bank switch before calling that code.
Also, if you look at page 186 of the user's manual for that device (http://www.keil.com/dd/docs/datashts/silabs/c8051f12x.pdf) you'll see that "bank 0" appears at address range 0x0000 to 0x7FFF at all times, AND at address 0x8000 to 0xFFFF when COBANK == 0.
Therefore (for practical purposes) your device has three banks that appear in the upper 32k of CODE space, plus the common bank that appears in the lower 32k.
To minimize the duplication, make sure you assign each source module to a specific bank. The tools will not do that for you.
It all makes sense now.