Author Topic: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types  (Read 1779 times)

0 Members and 1 Guest are viewing this topic.

Offline martysTopic starter

  • Regular Contributor
  • *
  • Posts: 129
  • Country: us
There's a shortage of new parts, can I repurpose 18Fxx39 (18F2539/18F4539 types)to make them PIC18F45x types simply by using a bulk chip erase?

The 18Fxx39 chips are preprogrammed by Microchip with a kernel for induction motor drive which is useless to me.


I can do a bulk erase, but can I completely erase this custom code kernel and then get to use the  18F45x resulting chip in current projects. 

Is this possible?
« Last Edit: January 11, 2022, 10:29:54 am by martys »
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14447
  • Country: fr
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #1 on: January 08, 2022, 06:43:30 pm »
Judging from the datasheet, the "motor control kernel" is not in the main code Flash, which is still available to the user.
Quote
The PIC18F2539 and PIC18F4539 each have a total of
24 Kbytes, or 12K of single word instructions of FLASH
memory,  from  addresses  0000h  to  5FFFh.  The  next
8 Kbytes beyond this space (from 6000h to 7FFFh) are
reserved  for  the  Motor  Control  kernel;  accessing
locations in this range will return random information.

So I'm pretty sure you can ignore this feature and use the parts as you would any other PIC MCU.
No whether they'd be a direct replacement for PIC18F45x, without any code modification, I do no know. You'll need to read the datasheet.
 
The following users thanked this post: martys

Offline martysTopic starter

  • Regular Contributor
  • *
  • Posts: 129
  • Country: us
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #2 on: January 08, 2022, 07:01:23 pm »
What datasheet?  I've already read carefully the 18Fxx39 and it does mention this chip is otherwise compatible with 18F45x types, but there is no mention that it can be resurrected to become a 18F45X. The 18Fxx39 datasheet does mention that WDT is always hardware turned on, and the CONFIG bits that affect operation for motor control and protected code areas are not to be changed.1373951-0
« Last Edit: January 08, 2022, 07:06:53 pm by martys »
 

Offline wraper

  • Supporter
  • ****
  • Posts: 16849
  • Country: lv
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #3 on: January 08, 2022, 07:05:07 pm »
The first thing you should decide if differences between the chips have any meaning for you. If those differences are not used by your code/hardware, then you can just use them as drop-in replacements.
 
The following users thanked this post: martys

Offline martysTopic starter

  • Regular Contributor
  • *
  • Posts: 129
  • Country: us
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #4 on: January 08, 2022, 07:10:00 pm »
I have just posted the datasheet differences above as an attachment.

Of course, the difference I am concerned with is whether some ghost induction motor kernel code will always be asserted, even after a bulk erase(Like a read-only PROM). The induction kernel is, of course, read and write protected by CONFIG settings.

Otherwise, the xx39 is a fairly powerful MCU with a lot of older but useful features that make this chip an attractive MCU.

I can buy from a guy at a local HamFest, more than a dozen ea. and new, of both 28-pin and 40-pin xx39 varieties for a nickle a piece.
« Last Edit: January 08, 2022, 07:26:49 pm by martys »
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8264
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #5 on: January 08, 2022, 11:39:28 pm »
Preprogrammed variants may be ones that have failed tests of other peripherals/configurations not used by the preprogrammed code, so that is one thing to watch out for.
 
The following users thanked this post: martys

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5896
  • Country: es
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #6 on: January 09, 2022, 01:57:13 pm »
Checking the datasheet, it seems the kernel is disabled by default (You need to call ProMPT_Init in your program).
Otherwise, all peripherals and memory should be available to the user.
So if you wipe them, it'll still identify as a 2839, but you could use it pretty much like you want.
« Last Edit: January 09, 2022, 01:58:47 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: martys

Offline martysTopic starter

  • Regular Contributor
  • *
  • Posts: 129
  • Country: us
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #7 on: January 09, 2022, 02:40:04 pm »
Many Thanks DavidAlfa, of course this is the answer I hoped to get.

As I understand this, I can just tell my compiler and chip programmer that the chip is really a 18F25x.

That means I can just take a virgin PIC18F2539 and just treat it as it is really a 18F252 and bulk erase, compile and burn hex code into it, always specifying the chip is a 18F252?
« Last Edit: January 09, 2022, 02:45:46 pm by martys »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5896
  • Country: es
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #8 on: January 09, 2022, 04:11:47 pm »
Might work or not, but the programmer will definitely fail if you do so because it'll check the device id.
You cannot change the Pic model by erasing it.
Why do that? Just specify the correct chip.
Using timer1, spi, io ports will be the same.
The code changes will be minimal between them.
You can try loading a 252x hex file and program it, but you must match the Pic model in the programmer settings.
Compare memory mapping anc config words in both datasheets. If the same, it's likely to work.
« Last Edit: January 09, 2022, 04:14:21 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: martys

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12855
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types
« Reply #9 on: January 09, 2022, 04:59:44 pm »
It looks like the motor control kernel is hardware locked code protected as the reserved bits in CONFIG5L, CONFIG6L, & CONFIG7L, are tagged as "Note 1: Unimplemented, but reserved; maintain this bit set", which would normally be unprotected, so even if you hack a programmer device database to erase outside the user program memory and alias the device ID, you wont get a usable normal  PIC18F45x, unless your application expects the top page of FLASH to be fully protected.

I also expect erasing the extra page wont be easy if even possible - fully protected pages can only be erased by whole device bulk erase, and that's done on-chip and is not going to touch the reserved page.
 
The following users thanked this post: martys

Offline martysTopic starter

  • Regular Contributor
  • *
  • Posts: 129
  • Country: us
Re: Can PIC18F2539 Chips be Bulk Erased to become PIC18F45x types(SOLVED)
« Reply #10 on: January 09, 2022, 06:01:13 pm »
As I understand it now, only 24K of the 32K flash code memory is able to be modified. Code memory block 4 is not erased by even a chip bulk erase (although the xx39 programming spec says that the entire chip can be erased by a bulk erase). I can select the programmer to program the chip as a 18F452, for instance, and it would attempt to bulk erase the entire memory space and I have a programmer that can be told to ignore the device id.

But as before mentioned, the induction motor code is inactive unless invoked by software. In that case, I should be able to use the peripherals (such as Timer1 and PWM1 and PWM2) but the compiler programming my code must not try create code to write to the last 8K of program memory.

In other words, the peripherals used by the induction motor kernel would not be controlled by the kernel and this allows me to use them as I wish?

Would it also be  that by default a compiler would start to load my code at the start of program memory, after the boot block, and not touch the top 8K unless I had code >24K?

Of course, by trial and error I can just write code to  use the reserved peripherals and see if it works.

I have examined the enable bytes used for table writes to select each block of flash for bulk erase for the xx39 and x252 and they match, except the x252 has one more byte to enable bulk erase for the top 8k memory block area of the xx39.

« Last Edit: January 11, 2022, 10:31:54 am by martys »
 

Offline martysTopic starter

  • Regular Contributor
  • *
  • Posts: 129
  • Country: us
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #11 on: January 11, 2022, 10:31:09 am »
Solved

By setting my programmer to type '252(with a '2539 inserted) and first erasing block four(the 8k embedded kernel) I was then able to completely Bulk Erase everything. I then made a test that byte-banged 8-bytes into the top of 8K top block four and verified it was there with a memory dump and all other locations were from boot block to top 8K of Pgm Flash were 0xFF.

I then burned a 113K source file of random assorted clips of my code that did absolute nonsense but showed use of PWM, Timers, etc and when compiled including CONFIGs for '252, showed it  used 98% of 32K pgm Flash and it all verified perfectly and even blinked LEDs. Success!
 
The following users thanked this post: thm_w, edavid

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12855
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #12 on: January 11, 2022, 10:45:56 am »
After you've done that, do the protection bits for the fourth page work as expected for a PIC18F252?
 
The following users thanked this post: martys

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9930
  • Country: nz
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #13 on: January 11, 2022, 11:20:18 am »
and now that the secret is out, they're all sold out in ...3 ... 2... 1...
Greek letter 'Psi' (not Pounds per Square Inch)
 
The following users thanked this post: martys

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14447
  • Country: fr
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #14 on: January 11, 2022, 06:18:02 pm »
and now that the secret is out, they're all sold out in ...3 ... 2... 1...

 ;D
 
The following users thanked this post: martys

Offline martysTopic starter

  • Regular Contributor
  • *
  • Posts: 129
  • Country: us
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #15 on: January 11, 2022, 07:28:04 pm »
I've bought them all, after all, at that price, what did I have to loose?

Ian.M: I've not tried to re-protect block 4, but why should it not work, because everything else seems to work perfectly.

The 18Fxx39 seems to be no more than a 18F252 wearing a mask, and for most of my projects, I am not concerned about protecting code.
 
I realize at this moment, I might have overthought the  problem.

I might only have had to bulk erase the 18Fxx39 with the programmer doing a chip erase while set for a18F252.

I haven't tried this, the programmer might prevent a bulk chip erase operation for the entire xx39, or more likely, just allowing the lower 24K area to be valid flash pgm. space, and the compiler would certainly agree to this limitation.

The 18Fxx39 might only need to be bulk erased to accomplish the name change. The induction motor code might be protected from chip erase by rules of use only, that is, the user is told to only to add code without ever doing a total bulk erase, just erasing/burning  flash blocks other than block four.

« Last Edit: January 11, 2022, 07:59:09 pm by martys »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5896
  • Country: es
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #16 on: January 11, 2022, 09:28:11 pm »
Even if you bulk erase it, it will still identify as a xx39 part.
The programmer has a database defining the flash sizes and config words based on the part ID.
So you'll probably need to keep forcing it as a 252.
The final result is the same, though.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: martys

Offline martysTopic starter

  • Regular Contributor
  • *
  • Posts: 129
  • Country: us
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #17 on: January 11, 2022, 09:50:58 pm »
Thanks DavidAlfa,


Somehow I will have to learn to live with this humiliation.
« Last Edit: January 12, 2022, 12:06:10 am by martys »
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8264
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #18 on: January 12, 2022, 02:26:14 pm »
Even if you bulk erase it, it will still identify as a xx39 part.
The programmer has a database defining the flash sizes and config words based on the part ID.
So you'll probably need to keep forcing it as a 252.
The final result is the same, though.
I would not be surprised if there's a way to change the device ID too... I know that's possible with AVRs and there was some discussion here a while ago about it (undocumented programming commands.)
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5896
  • Country: es
Re: PIC18F2539 Chips Can be Bulk Erased to become PIC18F252 types
« Reply #19 on: January 12, 2022, 05:48:45 pm »
Maybe, but you need these commands...
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf