Hi,
I'm trying to make a solution for our product where our customers can update the firmware.
We use a M16C/65 and have a RS485 connection.
My question:
Is it possible to create some code to be placed en ROM2 that is executed when the MCU starts (bootloader). This code need to decide if the user has entered bootmode or if the products need to start normal.
If so how do I get it to start in ROM2 ?
Please advice.
Regards
Anders
Hi,
you have to add in ASCII the values "Userboot" at address 13FF0h to 13FF7h.
For debug purposes, it is better to use this function with an "entry pin" (otherwise, your MCU cannot be reprogrammed in standard mode and you cannot correct error into your boot code)...
For more information, you can check the hardware manual (section 30.7). Hi, Tiziano
Doesn’t this require that the pins P50 and P55 CNVSS is set for boot mode ?? I would like NOT to have a hardware solution where I need to change these pins at reset. Therefore I would like to use CPU rewrite mode EW0. But still be able to have my code for this CPU rewrite placed in ROM2. Is this possible ??
Hi,
P50 and P55 pin don't need to be set in boot mode.
You can choose if you want to use a pin (or not) to start code into ROM2 instead of standard bootloader Renesas.
After checking memory (if "UserBoot" is found) and pin status (if an entry pin is configured), the MCU jumps to program ROM2.
In program ROM2 you can do what you want, included an EW0 Flash programming (be careful: in EW0 you have to transfer Flash erase and flash write routines to RAM).
WARNING: if "UserBoot" is written into first byte of ROM2 memory, Renesas bootloader will not start and every setting of CNVSS pin will not have effects! (you'll not able to reprogram the microcontroller through standard serial I/O mode). So, I suggest you to use an entry pin, at least while you are debugging your code!
Regards,
Tiziano
Sorry all these questions just need to make sure I got this right.
If I apply this "UserBoot" string and the port setting then the program will start execution at ROM2 (10000h) if the port is set, and if this port I select is not set it would start execution of the normal ROM1 ? (c0000h)
And finally how do I tell the HEW compiler generate code to be placed in ROM2
Thank you very much for your help...
No problem,
It is correct: with "UserBoot" string (and pin settings) MCU will start from Program ROM2 (10000h).
Otherwise, if MCU is not in Boot mode (CNVSS pin), MCU will start from address pointed by reset vector (0xFFFFC).
To tell compiler how to place code, it depends on the compiler/project type you are using.
With Renesas compiler / assembly source code, you have to modify sect30.inc file;
With Renesas compiler / C source code, you have to modify section location in Build->Renesas M16C Standard-> Link, category section order.
(I think you can find some documentation into compiler manual, or in some other post; search for "sections" keyword!)
BR
Tiziano
Thanks a lot...
I think I'm getting closer now. I made a new project (Bootloader) So far I got it to place the code correct at 0x10000 but it always starts this code.
Is it posibile to combine this with my application project so that I can test this issue with entering bootloader before I start writing the code that programs the flash ??
Did you add a new program section to your bootloader software manually to your project and placed this at 0x10000, or did you just move the default section from the "standard" address to 0x10000?
In your real application you could have a bootloader source file boot.c with this contents:
#include "sfr65.h"
typedef struct {
unsigned char UserBoot[8];
unsigned short Port;
unsigned char Pin;
unsigned char Level;
}_UserBootCode;
#pragma SECTION rom user_boot_code
_far const _UserBootCode BootCode={'U','s','e','r','B','o','o','t', 0x3E5, 0x00, 0x00}; // P30 on "L"
#pragma SECTION program user_boot
unsigned short Boot_count;
void UserBoot(void)
{
pd4 = 0x0F;
p4 = 0x05;
while (1)
{
for (Boot_count=0; Boot_count<0x400; Boot_count++);
p4--;
}
}
Then you only have to add the section user_boot at address 0x10000 and user_boot_code_FE and user_boot_code_FO at address 0x13FF0, and that's it.
You add in sect30.inc:
.section user_boot,CODE
.org 010000h
.section user_boot_code_FE,ROMDATA
.org 013FF0h
.section user_boot_code_FO,ROMDATA
at a place where it fits the the sequence of increasing addresses, may be after the rom_NO definition.
Now I got the project up runnig. And when I debug it using the E8a I can see that the code from the UserBoot function is placed at 0x10000 and the location 13FF0 -> Contains "UserBoot" and the port setting.
(The port is set up to P4.1 and active low)
I can't get it to enter the UserBoot function if I activates the switch so the port 4.1 is low and reset. Is it posibile to debug this using the E8a emulator ??
Just to make sure, I don't need to make any changes to the pins CNVSS,EPM ,CE right ?? (CNVSS is tied low with a 100K ohm resistor) ??
You need to enter flash programming mode the same way as if you use the standard bootloader. This standard boot loader checks for code UserBoot and the port settings and reads the port level. If it is UserBoot but the port settings don't fit it jumps to the reset vector value, with UserBoot and correct port settings it jumps to 0x10000.
So you still need EPM="L", CE="H" and CNVss="H".
And you cannot debug User Boot with E8a. E8a uses standard boot mode for firmware download. If you load your user boot software to M16C, E8a cannot use the standard boot mode for firmware download any more. I think it will then crash.
Hmm that was not how I understod the previous answers from tannoni. Well could a solution be to have the reset vector to point at the 0x10000 (ROM2) and then let this code decide if it needs to start the bootloader or continue to the application start ??
This way I can still keep my bootloader code in ROM2 ??
Thank you very much for your help....
This should work.
Now I have changed the hardware so it enters the ROM2 when a button is activated during reset. (So I don't waste the BLOCK0 64kb Flash)
But how do I initialise the chip when I use the UserBoot ? (I have a file in my application project called bootloader) Do I have to do some section initialisetion?? Stack pointer setup ect ???
©2003–2009 Renesas Technology Corp. All rights reserved. Using Our Website | Privacy
Contact us