CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

[PIC24HJ256GP210] Device ID becomes corrupted
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
canadidan



Joined: 13 Feb 2019
Posts: 24

View user's profile Send private message

PostPosted: Tue Feb 19, 2019 3:50 pm     Reply with quote

@dexta64

The ground pins are all connected with a ground-plane:



Yes, it is a switched regulator. Do you believe a lower ESR cap than the sub-1Ω Samsung is required?

I don't understand your meaning RE: hard disk PCB design.

The programming routine looks like this, and takes a standard CCS-generated HEX file as input:

Code:

      data_length = atoi_b16 (&FILE_LINE[1]);         
      CPU_Flash_Address = make32(FLASH_HIGH_ADDR,FLASH_LOW_ADDR);
      CPU_Flash_Address /= 2;

      for (i = 9, data_index=0; i < line_len-3; i += 2)
          CPU_Flash_Data[data_index++]=atoi_b16(&FILE_LINE[i]);

      write_program_memory(CPU_Flash_Address, CPU_Flash_Data, data_length);
      read_program_memory(CPU_Flash_Address, verify_buffer, data_length);

      for(i=0;i<data_length;i++){
          if(verify_buffer[i]!=CPU_Flash_Data[i]) line_error=true;
      }


Is it correct to say that this would be row programming, not word programming? It writes an entire HEX file line per transaction.

Testing Update

* Original code, older IC (1519DQ8): corruption after 12 cycles
* Skip erase routine: no corruption after 97 cycles, aborted testing
* Add 20us delay after checking WR: no corruption after 324 cycles

I received a bunch of alternate VCaps, and will try those if the firmware route doesn't yield a smoking gun.
dexta64



Joined: 19 Feb 2019
Posts: 11

View user's profile Send private message

PostPosted: Wed Feb 20, 2019 1:56 pm     Reply with quote

PIC24HJXXXGPX06 / X08 / X10 Family Silicon Errata and Data Sheet Clarification. Page 15.

"32. Module: Device ID Register On a few devices, the content of the Device ID register can change from the factory programmed default value immediately after RTSP or ICSP™ Flash programming.
As a result, development tools will not recognize these devices and will generate an error message indicating that the device ID and the device part
number do not match. Additionally, some peripherals will be reconfigured and will not function as described in the device data sheet"

Have you considered this place?

I don't understand what your program code is doing, but I think you're trying to program the processor.
There is a situation where you have deleted an address that will not be deleted from the processor. I think the processor had an id number and other internal connection settings. "Silicon Errata" says it.
0xFF0000-0xFFFFFE Are you trying to write something in this program range? see datasheet on page 27. Here says the device ID.

You need to make sure that you have correctly emptied the program area of ​​the processor. The processor will work inconsistently even though there is one bit stuck in the previous program.

Have you changed the compiler version? It cannot be guaranteed that the compiler does the right job.
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Wed Feb 20, 2019 2:44 pm     Reply with quote

Ouch.

Immediate comment. If it is in the errata, then there will be a fix or
work-around in this.

Checking, interesting it says 'on a few devices'. So not universal.

However it does give an alternative programming sequence.
Pretty horrible. You must use row programming, not word programming,
and reload all data latches ending in a specific bit pattern. Yetch.
Can be written fairly easily. You might want to talk to CCS and see if they
can add this to the internal programming code on this chip.
canadidan



Joined: 13 Feb 2019
Posts: 24

View user's profile Send private message

PostPosted: Wed Feb 20, 2019 4:38 pm     Reply with quote

@dexta64

Errata

Yes, I did consider that. That's why I asked you, "Is it correct to say that this would be row programming, not word programming?"

What is the code doing

The code is writing to the internal flash (programming the processor, RTSP). My program only exists in this range:

Code:
#EXPORT (FILE="output.hex", HEX,RANGE=0x000000:0x026BFF)


When I run the erase, I only erase from 0x400 to BIOS_ADDR (0x43FF before the last address):

Code:

/* Determine BIOS size. Reserve 16384 bytes for the BIOS*/
#define BIOS_SIZE        0x3FFF
#define KEYS_SEGM_SIZE   0x400
#define TOTAL_BIOS_SIZE  BIOS_SIZE+KEYS_SEGM_SIZE

/* Place the BIOS at the end of the CPU Programm Flash */
#define MEMORY_END      (getenv("PROGRAM_MEMORY")-1)
#define BIOS_END         MEMORY_END-KEYS_SEGM_SIZE
#define BIOS_ADDR        BIOS_END-BIOS_SIZE
#define KEYS_ADDR        BIOS_END+1


This code is designed to get the last address (0x2ABFE), then allocate 0x400 + 0x3FFF for the "BIOS" bootloader. Thus the erase procedure stops at 0x267FF.

Emptying Memory

Yes, that is why skipping the erase procedure will not work.

Compiler Version

Good point about the compiler - I am using an older version (4.106). Perhaps I will try to bring the code up to date (which will be a challenge) and see if that resolves anything.



@Ttelmah

Work-Around

Yeah, that work-around will be the next thing to test. I'm using the built-in write_program_memory function, so I need to check the following next:

* Does the new compiler V5 use row vs. word programming?
* Implement my own row-based routine?
* Decide firmware-upgrade is not a feature worth having?

Testing Update

With a 20us delay during erase, the unit survived 325 cycles before I stopped it.

With the original code back on, it survived 97 more.

With the 20us delay during erase on another unit, it failed after 23 cycles...

I am beginning to suspect that the delay is not the correct solution (especially since I never reach the Device ID address).
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Thu Feb 21, 2019 12:34 am     Reply with quote

The point is that even if the compiler is using row programming (would
have to look at the code to see), there has to be this 'reload' of
particular data latches. Unless CCS has implemented this as a fix
for this chip, this won't be being done. The compiler age makes
it very likely that a fix for this won't be there. Your compiler predates
that particular part of the erratum being published....
CCS are pretty good at implementing errata, though this one is so
horrible that it is more complex to fix than most.

You have not actually shown us in your posted bits of code, what
'DATA_LENGTH' is set as?. If this is a row, and the write starts at the
row boundary, then the compiler should generate a row write.
Understand also that if this is the case, the compiler _will_ be erasing the
row before writing. If you are separately erasing (as you seem to show),
this will be wasting chip lives.

I realise you do show 'DATA_LENGTH', as a single line of the Intel hex file.
This is not a row. On this chip the flash row is 192 bytes. You would
have to buffer this much data and write this much at a time to switch
to row operation.
dexta64



Joined: 19 Feb 2019
Posts: 11

View user's profile Send private message

erase procedure.
PostPosted: Thu Feb 21, 2019 7:38 am     Reply with quote

I did a little experiment with your flash erase procedure.
You just seem to be wiping off some of the flash. the procedure begins to delete from 0x800.
first started typing address 0x803 = ff, 0x807 = ff, 0x80b = ff, 0x80f = ff, 0x813 = ff, 0x817 = ff ...

0x800,0x801 and 0x802 nothing is done to these addresses. The procedure does this in i=153. i=153 will exit the procedure.
canadidan



Joined: 13 Feb 2019
Posts: 24

View user's profile Send private message

PostPosted: Thu Feb 21, 2019 10:40 am     Reply with quote

Understood, both of you Smile I didn't write this code, just inherited it, and your help dissecting it is huge.

Data Length Packing

ROW = 192 bytes = 64 instructions
PAGE = 1536 bytes = 512 instructions = 8 ROWS

FLASH_ERASE_SIZE = 1536 bytes = 1 PAGE

Wasteful / Incorrect Erase Routine

@dexta64, you are right - this code doesn't behave as desired.

Code:
for(address_erase=0x00400;address_erase<BIOS_ADDR;address_erase+=(getenv("FLASH_ERASE_SIZE")/2))


Each page is 0x200 addresses - what we want is to start at 0x400 and increment 0x200 each time until it reaches the start of BIOS space. However, it increments 0x200/2 = 0x100 each time, and might increment address_erase prematurely.

I also believe my firmware application component exports wrong:

Code:
#EXPORT (FILE="output.hex", HEX,RANGE=0x000000:0x026BFF)


MEMORY_END - KEYS_SEGM_SIZE - BIOS_SIZE = BIOS_ADDR
0x2ABFE - 0x400 - 0x3FFF = 0x267FF

But the export goes until 0x26BFF which is 0x400 more. I don't understand why it was designed like that.

@Ttelmah, you are right - this is wasteful of write cycles (though by design it might only be upgraded twice in its life). If I write page by page then I don't need to duplicate the effort of erasing it all - write_program_memory will do it for me.

Compiler Version

This morning I tried porting to V5.044 but have plenty of build errors to diagnose. Not part of this thread.

For me to do:

* Investigate why firmware exports beyond expected address range
* Pack hex lines to fit a row / page
* Fix/remove erase loop
* Look at updating compiler
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Thu Feb 21, 2019 10:51 am     Reply with quote

The commonest cause of faults, is pointers.
In late V5 compilers CCS implement explicit pointer checking.
So in your program memory write for example, you would probably
have to cast the pointer to be to int8 *. On the older compilers mixed
types were accepted without complaint.
dexta64



Joined: 19 Feb 2019
Posts: 11

View user's profile Send private message

Importance of Datasheet
PostPosted: Thu Feb 21, 2019 11:29 am     Reply with quote

Look at Datasheet's page 62, telling you what to do. http://ww1.microchip.com/downloads/en/devicedoc/70175h.pdf

Sometimes a datasheet may not have enough information. In another datasheet, the process can be explained in more detail. For example, compare your PIC24FJ256GA110 with the datasheet of this processor.

Sometimes it may not help you in a forum just about the pic. Follow the forums of other processors. As a result everyone is dealing with the same problems.
dexta64



Joined: 19 Feb 2019
Posts: 11

View user's profile Send private message

Re: [PIC24HJ256GP210] Device ID becomes corrupted
PostPosted: Fri Feb 22, 2019 12:37 am     Reply with quote

Code:

void BIOS_Erase_CPU_Flash_FMWR_Sector()
{

   for(address_erase=0x00200;address_erase<BIOS_ADDR;address_erase+=(getenv("FLASH_ERASE_SIZE")/2))
   {     
      erase_program_memory(address_erase);
      delay_cycles(4);
      while(bit_test(NVMCON, 15));     
   }
}


This deletes the program area starting from 0x400. But I'm not sure if it will empty the bootloader field.


Last edited by dexta64 on Fri Feb 22, 2019 1:54 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Fri Feb 22, 2019 1:28 am     Reply with quote

You are missing the + to increment address_erase....
canadidan



Joined: 13 Feb 2019
Posts: 24

View user's profile Send private message

PostPosted: Fri Feb 22, 2019 8:15 am     Reply with quote

@dexta64 - actually I don't want it to touch the bootloader - this should be protected (recovery mode).

I'm still reworking this code - basically I want to buffer a whole page then write in one shot. I have enough RAM to do this. The trick is that HEX files aren't always in address sequence...

@Ttelmah - you mean this doesn't work?

Code:
address_erase += (getenv("FLASH_ERASE_SIZE")/2))


I'm planning to skip this erase tool anyway - if I write by page, CCS will erase the page for me.
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Fri Feb 22, 2019 9:49 am     Reply with quote

dexta64 originally posted his version without the + ....
canadidan



Joined: 13 Feb 2019
Posts: 24

View user's profile Send private message

PostPosted: Mon Feb 25, 2019 3:34 pm     Reply with quote

Update

Erase loop does not seem to be the problem

* Commented out the erase loop: Corruption still occurs

* Page-aligned the erase: Corruption still occurs

Code:

void BIOS_Erase_CPU_Flash_FMWR_Sector(){
 unsigned int32 address_erase;
   for(address_erase=0x00400;address_erase<BIOS_ADDR;address_erase+=0x400)
   {
      erase_program_memory(address_erase);
      while(bit_test(NVMCON, 15));
   }
}


Problem must be with programming routine

* Updated compiler to V5.044 (from V4.106): Corruption still occurs

* My first attempts at page-buffering don't work: I will retry with a simpler row-buffering routine

Graveyard

I'm starting to run low on units to test with...



Edit - Quick Confirmation

To make sure I'm doing this right, for a PIC24HJ:

Row = 64 instructions = 128 words = 128 addresses = 64 address pairs

Page = 512 instructions = 1024 words = 1024 addresses = 512 address pairs

Thus each row is 0x80 addresses, and each page is 0x400 addresses, right?
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 25, 2019 3:43 pm     Reply with quote

Glad to know I'm not the only guy who breaks everything around here :P
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
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