|
|
View previous topic :: View next topic |
Author |
Message |
Marcs Guest
|
Code corruption |
Posted: Fri Sep 11, 2009 5:28 am |
|
|
I have have a code corruption problem with an PIC18LF4550
The problem was as identified as a block of 64 bytes in program memory being reprogrammed(erased?) to $ff.
Having read numerous posts I thought that blame could be attributed to the code's lack of fuse settings for:
Brown Out Protection
Write Protect
stack overflow reset
power up delay
From my understanding the main issue caused by these mechanisms is that the PC can go to any memory location randomly. For this to have caused the program memory erase problem it would need to have jumped to an erase program memory code segment.
However there is no such segment in the code. The nearest thing is a write to the EEPROM (generated by the CCS compiler being used):
Code: |
1025: void FineWriteEeprom( int8 address, int8 value )
1026: {
1027: write_eeprom( address, value );
0D50 C06D MOVFF 0x6d, 0xfa9
0D54 C06E MOVFF 0x6e, 0xfa8
0D58 9CA6 BCF 0xfa6, 0x6, ACCESS
0D5A 9EA6 BCF 0xfa6, 0x7, ACCESS
0D5C 84A6 BSF 0xfa6, 0x2, ACCESS
0D5E CFF2 MOVFF 0xff2, 0
0D62 9EF2 BCF 0xff2, 0x7, ACCESS
0D64 010F MOVLB 0xf
0D66 0E55 MOVLW 0x55
0D68 6EA7 MOVWF 0xfa7, ACCESS
0D6A 0EAA MOVLW 0xaa
0D6C 6EA7 MOVWF 0xfa7, ACCESS
0D6E 82A6 BSF 0xfa6, 0x1, ACCESS
0D70 B2A6 BTFSC 0xfa6, 0x1, ACCESS
0D72 D7FE BRA 0xd70
0D74 94A6 BCF 0xfa6, 0x2, ACCESS
0D76 5000 MOVF 0, W, ACCESS
0D78 12F2 IORWF 0xff2, F, ACCESS
0D7A 0100 MOVLB 0
0D7C 0C00 RETLW 0
|
This code does not set or modify the EECON1 bit4 (flash row erase) which would be needed to cause a program block erase. This control bit is 0 on POR and is not modified at any point in the code. There is no code to even write to the program memory.
The EECON1 bit7 (flash program memory select bit) is cleared before every write? Which prevents acesses to the program memory
The power supplies are rock solid and have < 20mv pk-pk noise, drop to around 0.2v when off so the device should receive a good POR
External IO lines are protected by 220kohm series resistors
MClr is pulled up with a 47k resistor to the power supply.
Whilst I am happy to put the additional safety measures (mentioned above) into the code as an attempt to try and fix the problem, I would like to understand the mechanism which could have caused this program memory curruption. Are there any other compiler or device issues which could cause this problem?
I have set up a test bench with the PSU cycling on and off every 10 seconds to try and replicate the problem but with no luck as yet. |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 11, 2009 7:10 am |
|
|
First thing, is this on more than one physical chip?. If not, it could simply be a chip fault. I have known chips that 'lose' a block without warning like this....
The first 'hardware' thing you don't mention, is is LVP enabled?. If so, then external hardware events on the LVP pins could cause this problem.
The second is the connection to the MCLR pin. Why 47K?. how long is the connection?. What else is near it?. The normal reason for using 47K, is if you are using ISP, since this is around the lowest resistor the programmers can drive high, without overloading their drives, and is large enough, so that the supply rail doesn't get pulled up significantly when they do. Unless you are using ISP, lower this value, and add a clamp diode, so the pin cannot go above the supply.
If you are not needing to write the memory from inside the code, why not try enabling the write protection fuses. If it still gives the problem, you have proved it is a chip hardware problem. WRTB,WRTC,WRT,CPB.
Best Wishes |
|
|
marcs Guest
|
|
Posted: Fri Sep 11, 2009 7:55 am |
|
|
Ttelmah
Thanks for the speedy reply
In answers to your points:
I have seen this on two separate occasions at random locations in memory.
The LVP is disabled in the fuse settings and I have confirmed this on the actual device using MPLAB
47k was used as it is a common value elsewhere on the board and a value i commonly use to pull up in applications where I am trying to save current wherever I can.
The 47k resistor is located adjacent adjacent to the pin on the pic and routed into a plane to get the power. The track is routed approx 20mm to a header for programming.
I can see no way that this can exceed the power rail, capacitive, emi, etc. As it is just a piece of 20mm track with a pull up at one end inside a metal enclosure.
I take your point about lowering the value and clamping. Belt and braces but it is not really viable at this stage as the products are out in the field.
Assuming some unknown event caused a spike on MClr is it likely that that could cause a block of program memory to be erased?
With regards to setting the protection fuses that will be my immediate action. I am hoping to duplicate the problem first to prove a fix but I am simply not seeing any other devices fail to test the fix against. |
|
|
Marcs Guest
|
|
Posted: Tue Sep 15, 2009 7:43 am |
|
|
Hi Ttelmah
You mention that you have seen devices which lose a block of memory.
In my case reprogramming the device was completely successful and despite power cycling the device I am not able replicate the problem.
Is this in common with your experience of lost memory blocks or was the device then rendered unusable?
cheers
Marc |
|
|
|
|
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
|