This Question is Answered (go to answer)

308 Views 14 Replies Last post: Feb 3, 2010 2:25 AM by Anders Nielsen RSS
Anders Nielsen Newbie 17 posts since
Oct 27, 2009
Currently Being Moderated

Jan 27, 2010 2:28 AM

EW0 CPU Rewrite

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

 

Tags: bootloader, cpu, m16c65, rewrite, ew0
tannoni Newbie 4 posts since
May 26, 2008
Currently Being Moderated
1. Jan 27, 2010 3:32 AM in response to: Anders Nielsen
Re: EW0 CPU Rewrite

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

tannoni Newbie 4 posts since
May 26, 2008
Currently Being Moderated
3. Jan 27, 2010 5:00 AM in response to: Anders Nielsen
Re: EW0 CPU Rewrite

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

tannoni Newbie 4 posts since
May 26, 2008
Currently Being Moderated
5. Jan 27, 2010 10:24 AM in response to: Anders Nielsen
Re: EW0 CPU Rewrite

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

FrankL Apprentice 958 posts since
Mar 16, 2009
Currently Being Moderated
7. Jan 28, 2010 12:46 AM in response to: Anders Nielsen
Re: EW0 CPU Rewrite

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.

FrankL Apprentice 958 posts since
Mar 16, 2009
Currently Being Moderated
9. Jan 28, 2010 4:08 AM in response to: Anders Nielsen
Re: EW0 CPU Rewrite

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.

FrankL Apprentice 958 posts since
Mar 16, 2009
Currently Being Moderated
11. Jan 28, 2010 5:37 AM in response to: Anders Nielsen
Re: EW0 CPU Rewrite

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.

FrankL Apprentice 958 posts since
Mar 16, 2009
Currently Being Moderated
13. Jan 28, 2010 6:14 AM in response to: Anders Nielsen
Re: EW0 CPU Rewrite

This should work.

More Like This

  • Retrieving data ...

Bookmarked By (0)