HCS08 firmware update on CAN

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS08 firmware update on CAN

10,736 Views
Simone
Contributor II

Hello everyone!
I'm working on the new DZ60 uC, and what I'm searching is a way to remotely update its firmware.
I've made some research on the net and in the forum, and I've found something interesting about it (AN2140, TN228, TN235; I attached them for your convenience).
From what I know at the moment, it's possible to run a routine in Ram in order to erase or reprogram the flash, but my ideas are still a little confused.
What I have in mind is to update the firmware (i.e. reprogram it in part or entirely), "downloading" the new firmware by CAN.
I have a system composed by many different parts connected on a CAN bus; the goal is to permit the update of any part simply plugging an SD card, containing the firmware files, into the motherboard. The motherboard reads the data on the SD and transfer them to the appropriate target device on the CAN bus. At this point the target should be able to read the data and auto-update its firmware... and that's the crucial point!

-   If I complete the transfer of the new firmware, copy it in ram, and then erase/reprogram the flash I don't need to move in Ram the code to use the Mscan and to manage the interrupts on CAN receive, but I think that probably the entire firmware won't fit into the Ram.
-   If I move in Ram the code to manage Mscan I won't have the last problem since the firmware is received and written 8 bytes at the time, but there is the backside that if for some reason there is a problem on the CAN transmission, the process will stop and my device will be lost.

Do you have any idea or suggestion?

Simone

 

TN235.pdf

AN2140.pdf

TN228.pdf

Message Edited by t.dowe on 2009-09-24 03:06 PM
Labels (1)
30 Replies

1,692 Views
renatocardoso
Contributor I

Hi Simone,

Would be possible you send me by email the source code. For I am programming the exact same thing, the CAN bootloader for DZ60.

My e-mail is: rcardoso@stara.com.br

Thank you

0 Kudos

1,692 Views
kaspergermannol
Contributor I

Hi Simone,

I am very interested in your CAN bootloader. Is it possible that you could email the source code.

Thanks

Kasper

0 Kudos

1,692 Views
shukybronfeld
Contributor I

Hi Simone,

I'm interesting in the bootloader for the CAN can you please post or send me via mail the source code?

Thanks Shuky

shuky@advice4u.co.il

0 Kudos

1,692 Views
Simone
Contributor II
Hi Alban,
 
I post here my source code, please move it in another thread if you think that so it will be more visible.
 
The code is in part developed from Rocco's source; it implements a selectable RS232-CAN bootloader which resides in protected memory. It's all except perfect, especially in the asm part (I'm nothing more than a rookie in assembler); if you have any advice it will be well accepted.
At startup it checks the flash (sum and xor); if it's ok it jump to the normal "_entrypoint" of the application, otherwise it enter the boot mode and waits for incoming messages. The external application has the ability to write, erase and read the flash, plus some other little options (reboot, read firmware ID...). For now I tested it with an external application in VB, and I'm able to reprogram the firmware via both rs232 and CAN.
The .asm file contains the low-low level initial check, and the init to start the essential functions of the micro, including obviously FLASH, SCI and CAN. The clock is given by an external 4MHz oscillator, requested by the tight timing tolerance of CAN controller. I then enabled the protection of last 3K of flash, and redirection of vector table.
The main loop waits for incoming messages in a polling fashion.
 
The .prm file contains the memory allocation for the bootloader: I put it in PROTECTED_ROM section. All the bootloader is in protected rom (0xF400-0xFFB0); please note that I didn't manage to put the .asm code in a relocatable section, so I had to assign it at address 0xF800 by mean of a ORG directive.
An important thing is where you place the "_EntryPoint" of the normal application in the non protected rom. It MUST be always in the same location to allow the bootloader to jump to it. I did this allocating the "_EntryPoint" function in MY_ENTRYPOINT.
Then I added here the code to automatically write the SUM and XOR in the right locations. Finally, note the entry point of the application (bootEntry). This, along with the reset interrupt vector, should point to label "bootEntry" in the asm file.
 
The .c file contains the routine to manage the CAN messages. I wrote them in C because I found it less difficult. Please pay attention to double check your code when you modify the C code; infact the compiler can try to optimize your code calling some low-level library function, which resides in non-protected rom! It result in application crashing when it runs!! To check if the compiler has used the library you have to look in the .map file. An example is visible in the code, where there are the splitted "switch" instructions: I had to split it because if it's all in one it requires a library function (try it to see).
 
If you have questions, or if I wasn't clear enough, feel free to ask!
 
Simone
0 Kudos

1,692 Views
datamstr
Contributor II

Hello Simone,

 

I have never attempted making a bootloader, so I am planning to give your project a try.

Since it has been a few years, do you have any updates or changes?

 

TIA,
David

0 Kudos

1,692 Views
ohanica
Contributor III
Hello Simone,

very nice project! seems to be a very basic working example which is really a nice thing  for newbies to (CAN-)bootloaders, like I am. 
Could you post your complete (CW-)project, so it should be possible to get it working on a DZ60-test-platform and much more easily understand everything, where code is written, how it is organized on the PC and then in  uC-memory.

How do you flash down the s19 file of your main  application via CAN when the bootloader is installed already? What kind of PC-software/hardware do you use for "CAN-flashing"?

many thanks and regards,
Johannes



Message Edited by ohanica on 2007-11-15 04:03 PM
0 Kudos

1,692 Views
Simone
Contributor II
Hello Johannes!
Glad to hear that someone find it interesting. Maybe someone will put it into an application note... :smileytongue:
Here it is the complete sample project (please change it's extension to .rar). It's based on the DZ60 demo board (DEMO9S08DZ60) so it should be simple enough to understand. The program do not really do anything of complex...it just flashes two leds.
 
For testing purposes I have written a Visual Basic program that takes the .s19 and send the appropriate command (via CAN) to the bootloader (it send the "Reset and enter boot mode" command too, while in normal mode). The CAN interface is a PCI based card from Trinamic (CANNes); the vb software is based on drivers made for this card, so it should be useless without it.
 
Now I'm working on the other part of the project, the implementation of a "FAT32 compatible"-"SD Card" reader for the micro that acts as master. In this way I'll be able to put the .s19 file on a SD and download it to the bootloader without a pc.
 
I know it's quite a big problem to send a complete .s19 file if you have no PC to CAN interface; if you have one I can send you my vb program so you can adapt it to your hardware.
 
Bye!
Simone
 
Message Edited by t.dowe on 2009-10-27 12:27 PM
0 Kudos

1,692 Views
ohanica
Contributor III
Hello Simone,

first of all many thanks for posting your coplete project. Seems very interesting and it did help me a lot in understanding and learning about CAN-bootloader from practical point of view. I still have a little issue I don't know how to solve: The project doesn't build, it tells me

Code:
Error   : C5200: non_bank.sgm file not foundStart08.c line 31  Error   : Compile failed

 
This has something to do with the Processor Expert, but I didn't manage to sole this issue up to now.

One more question: where did you get your CANnes Card? How much does it cost (approx.)?

greetx,
Johannes






0 Kudos

1,692 Views
Simone
Contributor II
Hello!
I don't know exactly how much it costs, because it was here since before I started working in my office. I think it should be around 200$. The link is: http://www.trinamic.com/tmc/render.php?sess_pid=216. For testing purpose maybe you will find other interfaces (i.e. CAN-USB) that can be even more useful.
 
For the problem you find, maybe it's for the different version of CW used. For my project I used CodeWarrior 6.0 (in the "about" it tells 5.9.0 - quite confusing). However, I search for the file you are missing; it contains only this lines of code:
Code:
#if defined (__BANKED__)#pragma CODE_SEG __NEAR_SEG NON_BANKED#endif

 Try to create a "non_bank.sgm" file and insert those lines in it. It should work now. Let me know if it ask for some more files.
 
Bye!
Simone
0 Kudos

1,691 Views
ohanica
Contributor III
Hey Simone,

thaks, the project is now compiling/linking. I just put the file named "non_bank.sgm" with your content into the "Sources"-subdirectory of the project.

The only thing missing now is the PC-software and hardware-interface (on PC-side) for which I have to find a solution to try out if things work.

BTW: Is it possible to program a bootloader onto my DZ60 device to try out debugging, and later on remove it again (download another SW without bootloader onto it)?

once again many thanks!

Bye,
Johannes
0 Kudos

1,692 Views
Simone
Contributor II
Absolutely yes; the bootloader is in protected flash, but this only means it can't be erased from the running firmware (from the micro itself). You are free to erase it, simply downloading a new program via BDM.
 
Simone
0 Kudos

1,692 Views
ohanica
Contributor III
Hello Simone,

I'm about to step deeper into your bootloader now. The version you posted, it is configured for firmware downloading via the serial interface AS1, if I understood it correctly. Now if I put the CAN1_Init() into the main routine at the beginning I initialize the CAN also.
I will still have to set my CAN-configuration according to the protocol I'll define (CANIDAC,CANIDMR.. registers).
Do you have a summary of the protocol you use for CAN-messages. What messages do you use? How are data organized in it? How do I start the bootloader-mode via CAN?
Up to now only the leds are blinking as in the main-routine, and I don't know how to enter bootloader mode. CAN-functions are not interrupt based, so where do you poll for new messages on the bus?

many thanks and best regards,
Johannes
0 Kudos

1,692 Views
Simone
Contributor II
Finally I got it!:smileyvery-happy:
The CAN bootloader is a reality.
If someone is interested I can post the source. I still have to reorder it because it's still a mess, but it works.
 
Simone
0 Kudos

1,692 Views
aguo1223
Contributor III


hello simone!

   Could you send the source to me ? My e-mail : aguo1223@126.com   thanks!

kris

0 Kudos

1,692 Views
Alban
Senior Contributor II
Hello Simone,

That would be a great idea !!! :smileyhappy:


Cheers,
Alban.
0 Kudos

1,692 Views
Simone
Contributor II
Ok, I finally managed to have my code working! :smileyvery-happy:
I'm able to write and erase the flash; for now I send a simple byte on SCI adn write it at a fixed location. Now I'll develope the rest of the application. I'm also looking for a way to integrate asm and C; now the bootloader is entirely in assembly, but the rest of my application is in C, so if exist a way to "merge" the two parts it will be very helpful.
 
Thank you all very much for your help!
 
Simone
0 Kudos

1,692 Views
bigmac
Specialist III
Hello Simone,
 
When you create the project, using the new project wizard, you will need to specify that you require both C and assembly within the project.  I would assume that you would use relocatable assembly code, so that the linker can organize the various sections of code.
 
If you need to call assembly routines from within your C code, any parameters passed will need to conform with C parameter passing rules.
 
This assumes that there would be separate .ASM files for the assembly code.  You may also use inline assembly within a .C file.
 
Regards,
Mac
 
0 Kudos

1,692 Views
Simone
Contributor II
Ops...I made a little confusion with 0xFF...but I think that what I did mean is clear nevertheless....


Simone
0 Kudos

1,692 Views
allawtterb
Contributor IV
I don't think it is necessary to run the flash writing from the stack, I believe that in the DZ60 flash can be written from flash.
0 Kudos

1,692 Views
Simone
Contributor II
Firstly, thanks for your reply. The situation is getting clearer to me, but I still have some doubts...
Please tell me if I have well understood:
The bootloader will reside in protected flash, so it will be always available. On startup the bootloader is called, and it checks the control sector bytes; if they are all 0xFF it starts the "main" routine jumping at the right location in non-protected flash, otherwise it waits for CAN messages to download data (maybe sending signals on CAN bus of his state of "please give me my firmware I'm hungry... :smileytongue:). On the reception of the update request on CAN bus the program writes 0xFF to control sector bytes and then reset.

If till now I'm right, I have a few questions: in which way I enter the bootloader routine during normal operation? Can I reset the device with a CAN message?
In order to prevent the "master" sending messages when the "slave" is writing to flash, would it be better to enable a sort of protocol, in which the master send the first message with the update request, then the slave (now in boot mode) asks the download parameters (such as number of sector to write etc...), and subsequently asks for single sector trasfer?

Simone



0 Kudos