Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:18 07 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PIC32 Serial Number or MMbasic serialized

     Page 1 of 2    
Author Message
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 06:27pm 31 Aug 2016
Copy link to clipboard 
Print this post

Hi to everybody
I need to know if it's possible to retrieve with a PIC32 instruction a CPUID or Serial Number. Or I ask to Geoff if it's possibile reserve about 10byte which is not affected by commands "new" "clear" etc. Then for example after the firwmare programm I can use "setSN" to save 10byte as string and "getSN" to retrieve the byte saved. These features on micromite.
Geoff what do you think?
ThanksEdited by sagt3k 2016-09-02
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 06:49pm 31 Aug 2016
Copy link to clipboard 
Print this post

Hello.

There is the "CPUtype" Cfunction, which will return a number representing the PIC32 processor MMBASIC is running on. Will that do?

It's in the "Embedded C Modules" folder of the MMBASIC download - attached here for ease of reference....

2016-09-01_044855_CPUType.pdf

Does that do what you need?
Smoke makes things work. When the smoke gets out, it stops!
 
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 07:07pm 31 Aug 2016
Copy link to clipboard 
Print this post

Hi Grogster
Thanks for your reply. I know "CPUtype". No I mean to save a string of 10bytes ..."0123456789".
My idea is this: After the firmware program if I digit "getSN" ...micromite will answer "0000000000". After I set with 'setSN "0123456789". This string will be present on flash. If I use new or clear ...this string will be present always on flash and info returned by "getSN" command.
But I think that setSN will be used just once. For resetting this info I need only to refresh again the PIC32.
Thanks
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 07:19pm 31 Aug 2016
Copy link to clipboard 
Print this post

OK, I see what you are trying to do. Could you not simply set that as part of your VAR SAVE and VAR RESTORE?

If you are meaning an area of flash or RAM that is NEVER touched by programming in the HEX file, I don't think this is possible - not in the general area of the memory anyway(that I am aware of).

You could store something like this in the boot-area of the PIC32, and so long as the new MMBASIC HEX did not re-write the boot-area, that would always remain the same, but I am not sure if MMBASIC re-writes the boot-area with the HEX file - it would not surprise me if it did, so the processor knows how to start.....

Might not be possible within the boundaries of the MMBASIC firmware itself - Matherp would know if this is do-able with some kind of Cfunction or sub.

The other option is an external EEPROM, FRAM or just saving that serial number onto an SD card file, which your code can read - these would never change no matter how many times you reflashed the PIC32 firmware. Very basic(no pun intended!) SD card ability is possible even on the 28-pin device, but that would suffice for what you would want. However, EEPROM or FRAM would be even smaller and quicker for something like that IMHO.

I will be watching this thread to see what others come up with.
Smoke makes things work. When the smoke gets out, it stops!
 
skylight
Newbie

Joined: 10/01/2016
Location: United Kingdom
Posts: 23
Posted: 07:57pm 31 Aug 2016
Copy link to clipboard 
Print this post

As Grogster suggested you could use external memory say the spare memory in an RTC thats attached to the pcb to save your s/n and retrieve it when retrieving the time at the start of your program?Edited by skylight 2016-09-02
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 07:59pm 31 Aug 2016
Copy link to clipboard 
Print this post

I an wondering how this could be useful? Why is it needed? Especially as Grogs pointed out, you could use VAR SAVE.

Generally I only add "features" to MMBasic if they will be valuable to the majority of users.

Geoff
Geoff Graham - http://geoffg.net
 
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 08:34pm 31 Aug 2016
Copy link to clipboard 
Print this post

Hi Geoff
I need to have the certainty to unique identify of the device. Without using variable, var save, uSD or external I2C flash.
But ...when you prepare the firmware ...can you create a constant and set for example a string as "<<hereSN>>"? Then I can prepare a free tools in windows to rewrite correct info in the firmware. And after to proceed to flash the PIC.
thanks Geoff

 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 09:44pm 31 Aug 2016
Copy link to clipboard 
Print this post

One of the configuration words includes a user id that can be set (pickit3/IPE), but it is probably smaller than you want eg FFFF
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4036
Posted: 09:48pm 31 Aug 2016
Copy link to clipboard 
Print this post

It's logically the same whether Geoff does it or you do.

Nothing to stop you using flash (internal/external) / eeprom /fram / etc.

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10215
Posted: 10:06pm 31 Aug 2016
Copy link to clipboard 
Print this post

As Chronic says DEVCFG3 has a 16-bit user ID

Go into Advanced mode in the MPLABX IPE and look at SQTP. This can create an automatically incrementing or ID that can be set in DEVCFG3. This can be read/written with the pickit3

The only gotcha is that I haven't quickly been able to find out how/if you can read the location in a program. PEEK doesn't work, nor does a simple CFunction
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 10:20pm 31 Aug 2016
Copy link to clipboard 
Print this post

MM.Version is probably stored somewhere known and could be overwritten with a CFunction to contain a uniqueid.

Microblocks. Build with logic.
 
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 11:33pm 31 Aug 2016
Copy link to clipboard 
Print this post

Hi to everybody
The another soluction is that to create a new constant MM.micromiteSN... that geoff initialize to "<<SN null>>".. than before to refresh .hex throught PICkit3 , I can manipolate with a my sw the file .hex and substitute the default string with my string entered by the sw.
I think that will be necessary to recalculate CRC or other on .hex?
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 11:50pm 31 Aug 2016
Copy link to clipboard 
Print this post

There is great value in what sagt3k is trying to do when creating a 'commercial' product to which you need to 'track' units.

It would be a fantastic addition to have MMBasic be able to read these bytes suggested as it would allow software to be written that can allow an end user to phone a 'help line' number with their unique unit ID.

I know many people here would just never use this feature - but for anyone considering a commercial product based on a MM then this feature is invaluable.

Will be interesting to see how this thread develops. . . .

WW
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 12:45am 01 Sep 2016
Copy link to clipboard 
Print this post

In the bootflash area (starting at 0x9FC00000) there is plenty of space where you could store a serial number encoded in the hex file then read it using PEEK().

Bootflash is used for a variety of storage including the interrupt jump table, some MMBasic tables and PIC32 config words. The best way to find a suitable location is to write a simple program using PEEK() to dump the memory and pick a place where the flash is 0xFF as that is unused and unprogrammed. Don't use any address above 0x9FC00500 because that might be used by MMBasic in the future.

GeoffEdited by Geoffg 2016-09-02
Geoff Graham - http://geoffg.net
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 01:10am 01 Sep 2016
Copy link to clipboard 
Print this post

  WhiteWizzard said   There is great value in what sagt3k is trying to do when creating a 'commercial' product to which you need to 'track' units.

It would be a fantastic addition to have MMBasic be able to read these bytes suggested as it would allow software to be written that can allow an end user to phone a 'help line' number with their unique unit ID.

I know many people here would just never use this feature - but for anyone considering a commercial product based on a MM then this feature is invaluable.

Will be interesting to see how this thread develops. . . .

WW

The way i am trying to solve this (as i have exactly his problem) is to add a unique serial number to my USB-Serial-Programmer chip. Often a product that needs to be maintained and updated needs a facility to uniquely identify a product and also have a way to determine the version of its bootloader/firmware etc.
The way i got it working is to have a windows program contact a webservice that checks if new software is available. The first time it uses the standard ID from FLASH which will prompt the user for information. It then validates that and creates a new unique code which is written into the FLASH and from that time on will be used to make sure any future updates will be valid for that particular product(product version).

A more secure way of having a unique id is to add an ID chip on your pcb. This will then have a globally unique 64 bit number that can be used to identify a product.

Microblocks. Build with logic.
 
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 01:50am 01 Sep 2016
Copy link to clipboard 
Print this post

Ok MicroBlocks. I'm ready to develop free sw on windows 32/64 bit. Tell me what I to do.
If you want, you can contact me on private email.
However my need is that to make an internet IoT service. For example I can tell to my service Cloud IOT trought unique ID to set global variables or execute functions or subprogram on server so I can interact many device indipendently at the same time.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 03:37am 01 Sep 2016
Copy link to clipboard 
Print this post

One of the chips you could add is a Crypto/Authentication chip from Atmel.
It just connects to the i2c bus so it is easy to use.
here is the datasheet: ATSHA204A Datasheet
This will guarantee a uniqueID as it has a 72bit identifier uniquely for each chip.
(They are also used on the electric imp!)
It also has a encrypt/decrypt facility if you need to have secure info transfer.

Microblocks. Build with logic.
 
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 04:50am 01 Sep 2016
Copy link to clipboard 
Print this post

Thanks MicroBlocks, very interesting. But I do not want use external hw.
Thanks
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10215
Posted: 05:10am 01 Sep 2016
Copy link to clipboard 
Print this post

Geoff's solution should work well

The SQTP settings in the IPE will write to that area so you won't even need to calculate checksums



 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 05:18am 01 Sep 2016
Copy link to clipboard 
Print this post

...and so the clutch is released in 1st gear on the matherp machine.
Smoke makes things work. When the smoke gets out, it stops!
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025