|
|
View previous topic :: View next topic |
Author |
Message |
LFern
Joined: 16 Mar 2011 Posts: 19 Location: Melbourne, Australia
|
PIC24FJ32GA002 Program Memory |
Posted: Wed Oct 05, 2011 11:51 pm |
|
|
Hi All,
I have a bootloader (similar to ccs example bootloader) which can download a target application to the program memory over UART.
This bootloader does not changing the address 0, which contains a GOTO to bootloader's main address.
I have noticed that for some reason, ISR region is not updating with correct values.
I cross checked with the record's values against program memory written values. Also I did a printf just before write_program_memory function. All I can see is it does not writing which it should write.
All the other program memory seems okay.
I have a program memory table snap shot here, problem is with addresses: 0x24, 0x2A, 0x50. These values updating to something else, but not for the values in records.
Your comments are highly appreciated.
Code: |
Line Address Opcode Label Disassembly
1 0000 044C00 goto 0x004c00
2 0002 000000 nop
3 0004 FFFFFF nopr
4 0006 FFFFFF nopr
5 0008 FFFFFF nopr
6 000A FFFFFF nopr
7 000C FFFFFF nopr
8 000E FFFFFF nopr
9 0010 FFFFFF nopr
10 0012 FFFFFF nopr
11 0014 FFFFFF nopr
12 0016 FFFFFF nopr
13 0018 FFFFFF nopr
14 001A FFFFFF nopr
15 001C FFFFFF nopr
16 001E FFFFFF nopr
17 0020 FFFFFF nopr
18 0022 FFFFFF nopr
19 0024 000900 nop
20 0026 FFFFFF nopr
21 0028 FFFFFF nopr
22 002A 0009A0 nop
23 002C FFFFFF nopr
24 002E FFFFFF nopr
25 0030 FFFFFF nopr
26 0032 FFFFFF nopr
27 0034 FFFFFF nopr
28 0036 FFFFFF nopr
29 0038 FFFFFF nopr
30 003A FFFFFF nopr
31 003C FFFFFF nopr
32 003E FFFFFF nopr
33 0040 FFFFFF nopr
34 0042 FFFFFF nopr
35 0044 FFFFFF nopr
36 0046 FFFFFF nopr
37 0048 FFFFFF nopr
38 004A FFFFFF nopr
39 004C FFFFFF nopr
40 004E FFFFFF nopr
41 0050 000C20 nop
42 0052 FFFFFF nopr
43 0054 FFFFFF nopr
|
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Oct 06, 2011 1:40 am |
|
|
An obvious assumption is, that the bootloader is designed to keep block 0 of the program flash or that the block has been write protected.
As discussed in previous threads about PIC24 bootloader design, both would be reasonable measures to make a fail-safe bootloader. But of course, interrupts have to be redirected in this case and bootloader must be aware of the interrupts used in the application.
If your bootloader is freely overwriting block 0, there may be a problem with the correct handling of non-continuous flash images in your programming function. |
|
|
LFern
Joined: 16 Mar 2011 Posts: 19 Location: Melbourne, Australia
|
|
Posted: Thu Oct 06, 2011 2:02 am |
|
|
FvM, Thanks for that info.
If I started with bootloader, first time I can download the target application without any problem. in this case, I can see the ISR region is all FF before downloading the target application.
At first time downloading, it keeps location 0 unchanged and do update the required ISR's with correct values.
If I run this second time, it does not update the ISR region with correct values. Instead ISR region is updated with some other values. these incorrect values remain same even if I did the process again and again starting with a empty program memory.
simplify the process:
started with ISR address, 0xFF -> updated to 0xABC -> updating to 0xDDD -> unchanged 0xDDD.
-> indicates a download process.
My really concern is why write_program_memory function writes invalid values at the second time?
If any erase problems are there, why it writing at the very first instance?
Any clues? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Oct 06, 2011 2:09 am |
|
|
It's a question of how code for block 0 is arranged in your *.hex file. If it's continuous, there should be no problem. If you are including hex image data in your project, they may be non-continuous.
As a test, you can load and rewrite the hex file with MPLAB, which makes the hex data continuous. If it's working with the regenerated hex file, than it's a problem of the said kind. |
|
|
LFern
Joined: 16 Mar 2011 Posts: 19 Location: Melbourne, Australia
|
|
Posted: Thu Oct 06, 2011 4:50 am |
|
|
The target hex file is something like:
:04004800A00D000007
:04005400EA0D0000B1
:0400A000740E0000DA
:100400003220EF00C3202000008041001040BA00DD
:100410000160EF0000000600537500006E00000050
........
which first 3 records are for 3 ISR's and it seems it is non-continuous.
According to these 3 records, ISR address values should be DA0, DEA and E74. but when I write this the second time, these values are not correct. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Oct 06, 2011 6:46 am |
|
|
Quote: | which first 3 records are for 3 ISR's and it seems it is non-continuous. |
This kind of non-continuous data will most likely work. The case I was referring to should be more exactly classified as non-monotonic. It can happen, if you have e.g. bootloader *.hex data imported to the project.
I had some problems of this kind, when I implemented a PIC24 bootloader with a previous PCD version. I added a sector buffer to the bootloader flash programming code to handle non-monotonic programming data. There have been also changes to the write_program_memory() function, so I don't know for sure which programming data will be accepted by recent PCD versions. |
|
|
LFern
Joined: 16 Mar 2011 Posts: 19 Location: Melbourne, Australia
|
|
Posted: Thu Oct 06, 2011 1:41 pm |
|
|
I hard coded following in my bootloader. which should update to the second value. but it is not. Now I can feel that write_program_memory function does something funny here.
Code: |
//0x24 is one of the problematic ISR address.
char buff[4];
buff[0] = 0x11;
buff[1] = 0x22;
buff[2] = 0x00;
buff[3] = 0x00;
write_program_memory(0x24, buff, 4);
delay_ms(100);
//read program memory through MPLAB:
//seen values are updated correctly at 0x24.
buff[0] = 0x33;
buff[1] = 0x44;
buff[2] = 0x00;
buff[3] = 0x00;
write_program_memory(0x24, buff, 4);
//read program memory through MPLAB:
//seen values are updated to some thing else.
|
My compiler version is PCD 4.119. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Oct 06, 2011 2:40 pm |
|
|
You need to understand memory write pages.
Read the 'additional notes', under the write_program memory command.
Then realise that the write_program memory command, _will not erase a page, unless you write to the first address in the page_.
So, when you write '11','22','00','00' the first time, the page is empty, and the write is OK. Then on the second write, since there is no erase, the _extra_ bits you specify, get set 'on top' of what you have already written, so you should see (I Think), '33','66','00','00'.....
To write these bytes, you need to read the _entire_ page into a RAM buffer, change the bytes you want, and write the whole page back, which will then trigger an erase, since you then write the first byte.
This is what FvM had to do - "I added a sector buffer to the bootloader flash programming code to handle non-monotonic programming data."
You need to do the same.
This is also why the default bootloader assumes you do not change the boot, and interrupt handler addresses, leaving these fixed as first written.
Best Wishes |
|
|
LFern
Joined: 16 Mar 2011 Posts: 19 Location: Melbourne, Australia
|
|
Posted: Thu Oct 06, 2011 8:31 pm |
|
|
Thanks all, I make it to work!
Added a sector buffer... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|