flashing firmware through CAN (LPC11C24)

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

flashing firmware through CAN (LPC11C24)

2,766 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Wed Jun 17 11:03:26 MST 2015
Hello everybody,

I decided I want to try and flash my microcontrollers through CAN using the built-in bootloader while avoiding to use flashmagic.

My setup consists in a LPCXpresso LPC11C24 board connected to a computer through CAN (with a USB2CAN from 8devices).
The firmware on the board simply uses IAP 57 (Reinvoke ISP) and sets GPIO0_3 low to enter the bootloader.
Then, CANOpen messages are sent from the PC to the board using a python script. The file to be transferred is the .bin from a blink test, with size optimization and debugging disabled. Here are the messages:

'cansend can0 67D#40.18.10.02.00.00.00.00.'    ask for ID
'cansend can0 67D#2B.00.50.00.5A.5A.00.00.'   unlock
'cansend can0 67D#23.15.50.00.00.10.00.10.'    set RAM addr: 0x10001000
'cansend can0 67D#21.50.1F.01.00.00.00.00.'    segmented transfer
[...]
'cansend can0 67D#2B.20.50.00.02.02.00.00.'   prepare sector 2
'cansend can0 67D#2B.30.50.00.02.02.00.00.'   erase sector 2
'cansend can0 67D#2B.40.50.01.02.02.00.00.'   check sector 2
'cansend can0 67D#2B.20.50.00.02.02.00.00.'   prepare again

'cansend can0 67D#23.50.50.01.00.20.00.00.'   set destination addr: 0x00002000
'cansend can0 67D#23.50.50.02.00.10.00.10.'   set source addr: 0x10001000
'cansend can0 67D#2B.50.50.03.00.10.00.00.'  set number of bytes

'cansend can0 67D#23.70.50.01.00.20.00.00.'   set new entry point
'cansend can0 67D#2F.51.1F.01.01.00.00.00.'  go

I verified that each message receives its corresponding acknowledgment, including all the chunks of data. I also saw that the new firmware gets successfully uploaded to the device flash. Nevertheless, the new firmware doesn't seem to run, and after the upload the processor gets stuck in the bootloader section ( 0x1FFF 0xxx ) and newer CAN messages get ignored (as expected). Dumping the firmware into sector 0 would be ideal but it seems not to be possible (the "erase" request yields an error code). Changing the location/size of the flash in the blink project settings didn't help either.

I searched through the forum and this is all I could put together with all the suggestions found. Is there something I'm missing? :)
Labels (1)
0 Kudos
Reply
8 Replies

2,237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Thu Jun 18 13:34:20 MST 2015
Indeed, but somehow something appears into the flash memory sector right after ISP mode is entered. Is it just some debugger quirk?  :O
0 Kudos
Reply

2,237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Jun 18 07:26:42 MST 2015

Quote: miccio
... the interrupts vectors are still virtually mapped onto the flash. Amirite?



No  :D

Bootloaders are located in ROM to provide ISP functions like 'Erase sector(s)' and 'Copy RAM to flash'...

If you didn't protect the flash (CRP) that's usually working without problems...
0 Kudos
Reply

2,237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Thu Jun 18 06:48:00 MST 2015

Quote:
You are new to this stuff, aren't you?


I've been working with ARMs for a few months only, yup. But it seems quite fun so far :)

Regarding the custom bootloader, I can already see how time consuming it would be to implement one.
Besides my goal is to program virgin chips from CAN, so that still wouldn't have been a viable solution.

Anyways, seems like I can upload the firmware to sector 0 now!
The issue was caused by a mix of bad configurations in the target firmware project setup.
I was showed as not erased by LPCXpresso because although SYSMEMREMAP is set to 0 (boot loader mode) during ISP, the interrupts vectors are still virtually mapped onto the flash. Amirite?
0 Kudos
Reply

2,237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Jun 18 00:36:41 MST 2015

Quote: miccio
that doesn't sound like a bad idea :)



:D  You are new to this stuff, aren't you?

There's an old AN describing an UART bootloader...

http://www.lpcware.com/content/nxpfile/an10995-lpc1100-secondary-bootloader-software-v13

Since LPC11Cxx is an old M0, there's no Vector table offset available and you have to redirect interrupts  :((

And 32k is not a lot of flash anyway...

If you really want to spend a lot of time to write a CAN bootloader, it would be a good idea to use a modern LPC15xx (M3)  :)

However, before trying to write you own bootloader it's necessary to understand vector table, boot mechanism an CANOpen.

So I would strongly recommend to get the ROM bootloader running first...








0 Kudos
Reply

2,237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Wed Jun 17 13:50:08 MST 2015

Quote:
If you don't erase sector 0, you need to write your own bootloader


that doesn't sound like a bad idea, but I wouldn't know where to start to implement one. Any useful link? :)

Using LPCXpresso memory debugger I could see that some chunks of sector 0 changed (marked with red outline) after the IAP entry. However, I don't know what's using them.
0 Kudos
Reply

2,237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Jun 17 13:26:31 MST 2015

Quote: miccio
...but I can't erase the first sector using the CANOpen commands.



The usual way use the ROM CAN-bootloader is to erase / flash the new bin-file via CANOpen. Including sector 0  :O

I'm not sure why you can't erase the first sector (CRP?)...

If you don't erase sector 0, you need to write your own bootloader  :~
0 Kudos
Reply

2,237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Wed Jun 17 13:14:13 MST 2015
Hi and thanks for the help.
I forgot to mention I'm developing with LPCXpresso latest version (7.8) and I generate my .bin file using the information in this link http://bikealive.nl/creating-a-hex-file.html therefore it should already have the correct checksum.
Is there a way I could verify the correctness of the CAN transfer or the copy process through the builtin bootloader?

About the second point, I was wondering if there is a way to overwrite the vector table so i could put my firmware from 0x000 0000, as I normally would with the debugger. According to this thread (from which I took most of my inspiration) it should actually be possible, but I can't erase the first sector using the CANOpen commands.
0 Kudos
Reply

2,237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Jun 17 11:56:01 MST 2015

Quote: miccio
Is there something I'm missing? :)



First of all, check your bin-file  :O

Then rethink your GO usage:


Quote:
26.6.8 Go (C_CAN ISP)
Write the start address into [0x5070, 0]. Then trigger the “start application” command by writing the value 0x1 to [0x1F51, 1].



I'm not sure what you are trying to do and how you generate your bin, but usually the first sector is starting with the vector table  :O

So word 0 is the initial SP value and word 1 is the Reset vector...
0 Kudos
Reply