I am using 8051F120 having 127KB Program memory, theoretically. I have written 4 *.C files residing in each bank. The length of the code in Bank1 and Bank2 is less than 32KB (observing the list file). But, instead of this, the linker gives an address space overflow for both the banks. Kindly assist.
Dhaval Solanki
Set the option to produce a linker map file, enable everything, do a rebuild (if necessary) and look for the information at the start that begins with something like:
BL51 BANKED LINKER/LOCATER V5.03, INVOKED BY: C:\KEIL\C51\BIN\BL51.EXE BANK1 {.....etc.......}
I think you need to examine details relating to the 'common area'. I suspect the common code might be being placed at the start of each bank.
You mention that the datasheet specifies:
Common Bank Area: 0000H to 8000H Bank1 Area: 8000H to FFFFH Bank2 Area: 8000H to FFFFH Bank3 Area: 8000H to F7FFH
But, there is no specification of the common area in the linker invocation.
For example, my old project (which seems to have similarities to your memory layout) has a linker invocation containing:
BANKAREA (0X8000, 0XFFEF) RAMSIZE (256) DISABLEWARNING (16) CODE (0X0000-0X7FFF) XDATA (0X0000-0XFFFF)
Note the 'code' which I did not see in your linker invocation.
My observations, conclusions and Solution to Address Space Overflow
* * * * * * * C O D E M E M O R Y * * * * * * * CODE 0000H 0003H ABSOLUTE CODE 0003H 0007H UNIT 000AH 0001H *** GAP *** . . . . . . . . . . . . . . . . CODE 97F5H 001FH UNIT CODE 9814H 001EH UNIT CODE 9832H 0012H UNIT CODE 9844H 0010H UNIT CODE 9854H 000BH UNIT CODE 985FH 000AH UNIT CODE 9869H 000AH UNIT CODE 9873H 0007H UNIT CODE 987AH 0007H UNIT end address = starting address of function + length Refer NOTE end address = 987A + 7 = 9981 * * * * * * * C O D E B A N K 1 * * * * * * * 0000H 9881H *** GAP *** Refer NOTE BANK1 9881H 1D5BH UNIT BANK1 B5DCH 1756H UNIT BANK1 CD32H 0D51H UNIT BANK1 DA83H 0623H UNIT BANK1 E0A6H 05DDH UNIT BANK1 E683H 0541H UNIT BANK1 EBC4H 044EH UNIT BANK1 F012H 03D7H UNIT BANK1 F3E9H 03BCH UNIT BANK1 F7A5H 033AH UNIT BANK1 FADFH 0322H UNIT BANK1 FE01H 01B4H UNIT BANK1 FFB5H 004BH UNIT * * * * * * * C O D E B A N K 2 * * * * * * * 0000H 9881H *** GAP *** Refer NOTE BANK2 9881H 03CCH UNIT BANK2 9C4DH 02A7H UNIT BANK2 9EF4H 02A7H UNIT BANK2 A19BH 0205H UNIT BANK2 A3A0H 0175H UNIT BANK2 A515H 00F6H UNIT BANK2 A60BH 00B2H UNIT BANK2 A6BDH 0079H UNIT BANK2 A736H 0053H UNIT * * * * * * * C O D E B A N K 3 * * * * * * * 0000H 9881H *** GAP *** Refer NOTE BANK3 9881H 06ECH UNIT BANK3 9F6DH 0220H UNIT
The following is my conclusion.
NOTE: The starting address of each bank = End address of common bank + 1
When I shifted some piece of the code from common bank into other banks, I found that the starting address of each bank in the M51 file (A part of which i have shown above), changed.
However, a very good solution is change the Code Optimization level to Level10. Go to:
Project -> Tool Chain Integration -> Compiler (Tab) -> Customize -> Optimization -> Level
Select "Level 10: Rearrange Code (Linker Optimization)". Save Project and click on "Rebuild" or press "Ctrl + Shift + F7" keys.
Now write your code in any bank without worrying about linking. The linker will take care of everything. It rearranges the code in each bank and hence will generate the hex file with minimum code size.
OOps! Made a mistake in addition in my previous post.
987A + 7 = 9881
Sorry.
Dear All, If in case you find my observations wrong, or have any other solution, kindly inform me.
Thank you for all the necessary help, guidance and valuable time you provided. Learnt a lot. Hope the observations and conclusions helps other newbies to solve the problems related to 'Code Banking' and 'Address Space Overflow'.
Regards, Dhaval Solanki
Glad to see you've got it going.
Regardless of what anyone else might say about banking, I think what Keil did to provide the mechanism is really pretty smart. Certainly for the application I used it on, the results were perfectly acceptable; in terms of development time, reliablility and end product costs. And, after the initial learning curve in getting it going, the fact that we were using banking was virtually forgotten about.
That said, for any new projects, I would recommend you keep an open mind and consider something different.
Dear, I already highlighted ... Cortex-M3 is used for all the new project development. ... Never the less, I would also, as my personal opinion, always work with latest controllers and technology. .
I am glad that Keil has provided the feature "Optimization: Level 10: Rearrange Code (Linker Optimization) ". I mean they should, to be the best IDE software developers. Respect.
But i still Fail to understand
The starting address of each bank = End address of common bank + 1
This should not happen, ideally.
On the contrary: that must happen. Your believing otherwise indicates you don't really understand how banking works.
The common bank is called a "common bank" because it contains the material that has to be commonly accessible to code in all banks. The only way that can work is if the entire address range of the common bank is reserved and kept available, regardless which other banks are mapped. In a scheme like SiLabs', with a 32KiB+32KiB hardwired bank mapping, the only way the common bank can become bigger than 32 KiB is if all bytes beyond the 32 KiB boundary are copied to all 3 "upper" banks, so they'll be accessible regardless which of the upper banks is currently active.
I think your real problem was that in your original configuration you placed too much stuff into the common bank yourself, causing this spill-over mechanism to be triggered.
Dear Hans-Bernhard Broeker, Thank you for clearing the air. But, in my opinion, there should be a document produced by the chip vendor stating this. A newbie may not understand this, the very first time he is using the IC, or may not have a clear picture unless he faces a problem like me.
Dhaval
But, in my opinion, there should be a document produced by the chip vendor stating this.
Though it might be helpful if the chip vendor produced application notes or other documentation relating to such things, I don't think it is really something that they should be expected to do. Which compiler vendors would they document for? Where would they stop?
The Keil documentation relating to banking is reasonably good and:
http://www.keil.com/support/man/docs/bl51/bl51_codebanking.htm
It just requires the reader to have an appreciation of what it is trying to achieve and what is possible.
But, in my opinion, there should be a document produced by the chip vendor stating this. well, SILabs does
The Keil documentation relating to banking is reasonably good and: but is somewhat invalid for the SILabs (and other?) chips with "internal banking"
go by the SILabs appnote, it is crystal clear
Erik
I'll take your word for it :)