|
![]() MCU User Forum
![]() Bootloader for c8051F120
|
| next newest topic | next oldest topic |
| Author | Topic: Bootloader for c8051F120 |
|
MGear New Member |
Hi, I am writing a bootloader using uvision2 for c8051F120. The purpose is to update my application code(hex.) through hyper terminal. My objective is to
2) Is there a way that I can select the address to place the codes (different memory bank)? Thank you for any advice! IP: Logged |
|
Scotty Member |
Hi MGear, I had referred to some guides, AN112 and AN201. I intend to place the bootloader and the hexfile receiver codes in one of my file(UART communication) so that I do not need to redefine some of the communication functions. My objective is to Erase the application codes in the hyper terminal and then load the new application codes (hex file) How should I separate the bootloader codes and the application codes in the memory bank? Also, placing the bootloader in a dedicated bank or even memory location isn't enough. Use the forum search here, there are quite some threads regarding bootloaders in general and especially for the F120. I think a good bootloader should at least implement a failsafe mechanism, meaning if anything goes wrong while downloading/programming (received errorneous bytes or power-fail, etc.) the bootloader should restart. Therefore, the bootloader must be able to check if there are any communication errors. And, if possible, the bootloader should also be able to check the integrity of the current flash content (which isn't easy to check if flash memory is used for data storage). Regards, Scotty IP: Logged |
|
MGear New Member |
Hi Scotty, My apology for the late reply. Thank you for the advice! *Okay, but think of changes you make to the UART part will affect both the bootloader and the application. I had separated the bootloader code from my application. Also, I had tested the bootloader. Regarding the flow of the program, Appreciate your inputs! MGear IP: Logged |
|
Scotty Member |
Hi MGear, I intend to place the bootloader code in the common area(Memory Bank) and the application code in Memory Bank 2. Regarding the flow of the program, the erase function must be in the application code. Therefore, the memory address pointer must be set at memory bank 2. Regards, Scotty IP: Logged |
|
MGear New Member |
Hi Scotty, Regarding the flow of the program, the erase function must be in the application code. Therefore, the memory address pointer must be set at memory bank 2. Thank you! I will work on it. I hope to seek for your inputs if there are any problems. Best Regards, IP: Logged |
|
Scotty Member |
Hi MGear, Bascially, the bootloader code will erase and load new codes. This clarify my doubts whether to place the erase codes in the application or the BL code. I will work on it. Regards, Scotty IP: Logged |
|
erikm Member |
the application code in Memory Bank 2. WHY, if the app fit in a bank you do not need banking. Erik IP: Logged |
|
MGear New Member |
Hi Erik, the application code in Memory Bank 2. Do you meant I should place my application in the common memory bank (same as the Bootloader code)? Thank you! Best Regards, IP: Logged |
|
Scotty Member |
Hi MGear, I had consider the increase of the memory space of my application codes in future. I am open for other alternatives. There are still other things which have to be taken into account, again, the forum search should be used. One thing regarding the behaviour of the BL: Especially the informing mechanism and the possibility to call BL functions from application need special considerations regarding variable handling etc. Regards, Scotty IP: Logged |
|
MGear New Member |
Hi Scotty, One thing regarding the behaviour of the BL: Thanks for the guide on BL "triggering". // boot_main.c// SDCC bootloader snippet// I had use RSTSRC as a software reset to trigger the bootloader from my application code. As sugguested from you, I placed all my codes in bank 0 - BL(common memory 0x0000-7FFF) and application(Bank 0 0x8000-0xFFFF) to optimize my approach. The flow of my program should be, 2)In the BL code, it will check for the logic for the software reset pin. If it is active , it will prompt the user, erase the application codes, download the hex files and jump back to the application program, else it will just jump back to the main flow of the application code(at address 8000H) . However, I had tested out my program. The program does not seem to be running as there is no output. Thank you! MGear [This message has been edited by MGear (edited July 29, 2010).] IP: Logged |
|
MGear New Member |
Hi Scotty, My apology for the BL format, Regards, IP: Logged |
|
Scotty Member |
Hi MGear, I had use RSTSRC as a software reset to trigger the bootloader from my application code. As sugguested from you, I placed all my codes in bank 0 - BL(common memory 0x0000-7FFF) and application(Bank 0 0x8000-0xFFFF) to optimize my approach. The user will select an option from the UART from the application code. This will set a software reset pin high and trigger the bootloader code. In the BL code, it will check for the logic for the software reset pin. If it is active , it will prompt the user, erase the application codes, download the hex files and jump back to the application program, else it will just jump back to the main flow of the application code(at address 8000H) . However, I had tested out my program. The program does not seem to be running as there is no output. The code you used is for a F34x device, which is different to F120. If you only copied the code and expected it will run smoothly... sorry, no way I suggest you do a EDIT on your post above, put your current code into it and then we will see... This should give a readable output for the code. Regards, Scotty IP: Logged |
|
MGear New Member |
Hi Scotty, Thank you for your reply! Erm... memory space from 0x8000-0xFFFF could be any memory bank, so I assume it's a typo and you mean "bank 1 0x8000-0xFFFF I am referring to Bank 0 from 0x8000-0xFFFF. Not sure if I understood you correctly: You mean you use a port pin to enable the bootloader, but MCU software controls the pin? However, this also has to be discussed with experienced bootloader forum members. If I'm right Erik Malund has written some bootloader and also many other members. I'm sure they will give additional hints. Thanks! Appreciate all your inputs! The code you used is for a F34x device, which is different to F120. If you only copied the code and expected it will run smoothly... sorry, no way boot.c #define APPLICATION_ENTRY 0x8000 Thanks for your help! Rdgs, [This message has been edited by MGear (edited July 29, 2010).] IP: Logged |
|
vanmierlo Member |
I am referring to Bank 0 from 0x8000-0xFFFF. Then you are overwriting your bootloader! Scotty wrote: - place the code between < pre > and < /pre > (without spaces) MGear wrote: < pre >#define APPLICATION_ENTRY 0x8000 Now what do you think "without spaces" means? And how come your code looks so awful? Ok, I'll spell it out: Put the code between <pre> and </pre> to keep the formatting. That is no space after < and no space before >. And while you're at it, also replace ALL tabs in the code with spaces. Open your code in your favourite editor and choose convert all tabs to spaces from the menu. Then copy and paste the code in the forum. [This message has been edited by vanmierlo (edited July 22, 2010).] IP: Logged |
|
MGear New Member |
Hi vanmierlo, I am referring to Bank 0 from 0x8000-0xFFFF. What do you mean by overwriting? I had placed my BL code in 0x0000-0x7FFF and the application code in 0x8000-0xFFFF. Now what do you think "without spaces" means? And how come your code looks so awful? Ok, I'll spell it out: Put the code between andto keep the formatting. That is no space after < and no space before >. May I know what is the difference using and? Thanks for the guide! Rdgs, IP: Logged |
|
Scotty Member |
Hi MGear, What do you mean by overwriting? I had placed my BL code in 0x0000-0x7FFF and the application code in 0x8000-0xFFFF. You wrote: May I know what is the difference using... Regards, Scotty IP: Logged |
|
MGear New Member |
Hi vanmierlo, I am referring to Bank 0 from 0x8000-0xFFFF. What do you mean by overwriting? I had placed my BL code in 0x0000-0x7FFF and the application code in 0x8000-0xFFFF. Now what do you think "without spaces" means? And how come your code looks so awful? Ok, I'll spell it out: Put the code between andto keep the formatting. That is no space after < and no space before >. May I know what is the difference using and? Thanks for the guide! Rdgs, IP: Logged |
|
vanmierlo Member |
The difference between <pre> and </pre> is that the first starts a preformatted piece of text and the second ends it. But if you write < pre > (that is with extra spaces) then the forum software does not treat it as an HTML tag and shows it unmodified and does not keep formatting in the following text. As Scotty explained the flash memory consists of 4 banks of 32kB. Since bank 0 is always accessable at 0-7FFF your bootloader is located in bank 0. If you also map bank 0 at 8000-FFFF and start writing to it you effectively overwrite your bootloader code. IP: Logged |
|
erikm Member |
your bootloader is located in bank 0. If you also map bank 0 at 8000-FFFF and start writing to it you effectively overwrite your bootloader code. UNLESS you insert proper linker controls to make the 'app' code start after the bootloader. Erik IP: Logged |
|
MGear New Member |
Hi Scotty, I placed all my codes in bank 0 - BL(common memory 0x0000-7FFF) and application(Bank 0 0x8000-0xFFFF) to optimize my approach. Bascially, I can only enable either Bank 0 (0x0000-7FFF) or Bank 0(0x8000-0xFFFF) but not both. Actually, I had referred to AN130 on Configuring a Code Banked Project Thanks! IP: Logged |
|
erikm Member |
There is a SIMPLE linker command that will start linking your app (of course 'noiv' will be required) starting at any address above your bootloader. I have NEVER, till now, heard about fiddling around with banks to separate boot and app. Erik IP: Logged |
|
vanmierlo Member |
Bascially, I can only enable either Bank 0 (0x0000-7FFF) or Bank 0(0x8000-0xFFFF) but not both. Actually, it is impossible to disable bank 0 at 0x0000-0x7FFF. It is always enabled. At 0x8000-0xFFFF you can enable only one of bank 0, 1, 2 or 3. But I get the feeling you don't have a clue what we are saying or what you are doing. Forget about the banks and leave them as they come out of reset. I bet you do not need them. Think of the mcu as having just 64k of flash. Then find out how you can link your app at another starting address. IP: Logged |
|
MGear New Member |
Hi vanmierlo, Actually, it is impossible to disable bank 0 at 0x0000-0x7FFF. It is always enabled. At 0x8000-0xFFFF you can enable only one of bank 0, 1, 2 or 3. But I get the feeling you don't have a clue what we are saying or what you are doing. Yes, I am a little confuse with the enabling of the which bank 0 to 3 for my application code. Since, I can enable one bank from 0 to 3 at (0x8000-0xFFFF). I should be able to use the memory space from bank 0(0x0000 to 0xFFFF) for my all program codes. Forget about the banks and leave them as they come out of reset. I bet you do not need them. Think of the mcu as having just 64k of flash. Then find out how you can link your app at another starting address. Yes. I agree. I believe that should be my starting point. I had edited my current codes format from my previous posting. Thank you for your time! Best Regards, IP: Logged |
|
erikm Member |
Vanmierlo said: "Forget about the banks" I said: There is a SIMPLE linker command that will start linking your app (of course 'noiv' will be required) starting at any address above your bootloader. You seem to have a fixation about banks. I know dozens of seasoned '51 developers that have NEVER used banking ('banks'). The banking is, for all practical purposes, an obsolete technique many have said, and I agree, "if you need banking, you have chosen the wrong processor". FORGET THAT THERE IS SOMETHING CALLED BANKS and get going with your development. Erik IP: Logged |
|
vanmierlo Member |
MGear (do you have a real name?), Since you agreed to forget about the banks I will not elaborate more one them because it will only clutter your view. I suggest to divide the memory into two pieces: the lower piece for the bootloader and the higher piece for the app. E.g. BL:0x0000-0x3FFF APP:0x4000-0xFFFF When linking the bootloader restrict the code memory size (0x4000) so it will not accidentally overflow into application space. Assuming you use Keil I cannot help you here because I'm unfamiliar with that. When linking the app make sure it starts at the offset (0x4000) and is also restricted in memory size (0xC000). Erik says you should use "noiv" but I'm sure you'll need more. Look in the manual for your compiler/linker. Thanks for reformatting the code. IP: Logged |
|
erikm Member |
Erik says you should use "noiv" but I'm sure you'll need more. 'noiv' keeps the compiler from linking interrupt vectors, which would overwrite the bootloader. also you need the standard ISR switch in the bootloader Erik IP: Logged |
All times are CT (US) | next newest topic | next oldest topic |
![]() |
|
Have you seen our MCU Knowledge Base?