![]() |
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: ItalyPosts: 313 |
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? Thanks |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9590 |
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: ItalyPosts: 313 |
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 ZealandPosts: 9590 |
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 KingdomPosts: 23 |
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? |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3282 |
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: ItalyPosts: 313 |
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: AustraliaPosts: 689 |
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 KingdomPosts: 4036 |
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 KingdomPosts: 10215 |
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: ThailandPosts: 2209 |
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: ItalyPosts: 313 |
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 KingdomPosts: 2932 |
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: AustraliaPosts: 3282 |
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. Geoff Geoff Graham - http://geoffg.net |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
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: ItalyPosts: 313 |
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: ThailandPosts: 2209 |
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: ItalyPosts: 313 |
Thanks MicroBlocks, very interesting. But I do not want use external hw. Thanks |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10215 |
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 ZealandPosts: 9590 |
...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 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |