• AVR Freaks

Hot!Save configuration in PIC32: NVM or File System?

Page: < 12 Showing page 2 of 2
Author
luca84
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2016/03/24 15:53:47
  • Location: 0
  • Status: offline
Re: Save configuration in PIC32: NVM or File System? 2016/07/11 03:13:37 (permalink)
0
Some of the PICs have unique ids. For others, you can use SQTP programming to implant them.

Thank you NorthGuy, I've seen that but SQTP feature is part of MPLAB X IPE and not MPLAB X so with starter kit boards is not possible to use IPE, because I can't connect to the board. Is it correct?
 
It's not that difficult. You can start from random ids, then let the master sort out the clashes.
It's not possible for now because my connection is one master to multiple slaves on USART + XBEE so when the master asks every slaves can answer in the same time and the packet (33bytes) can be corrupted. The ID number avoids this behaviour because when the master asks only one slave can answer. I don't know if XBEE modules can avoid the collision. I think that develop a collision-detection system in my software layer is too complicated for my project. 
I thought I could program every slave board with the same default ID and develop a configuration page on web server on master board to set a new ID on every slave board and store the new ID in the internal flash. The drawback is that the setting new ID procedure is possible only for one slave at time, but it should works. What do you think about this solution?
 
Thanks
 
 
#21
NorthGuy
Super Member
  • Total Posts : 6228
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: Save configuration in PIC32: NVM or File System? 2016/07/11 07:28:29 (permalink)
0
luca84
Thank you NorthGuy, I've seen that but SQTP feature is part of MPLAB X IPE and not MPLAB X so with starter kit boards is not possible to use IPE, because I can't connect to the board. Is it correct?

 
luca84
I thought I could program every slave board with the same default ID and develop a configuration page on web server on master board to set a new ID on every slave board and store the new ID in the internal flash. The drawback is that the setting new ID procedure is possible only for one slave at time, but it should works. What do you think about this solution?



For prototyping, re-programming with MPLAB X is easier. For production, it might work, but SQTP surely makes better user experience.
 
You can also use purely random IDs. If you use 32-bit IDs, it's only one in 4 billion chance of a clash - that's much less likely than silicon failure. If you use 64-bit IDs, clash is virtually impossible.
 
Another idea is to use jumpers. Dedicate 4 pins on each slave and set them high or low with jumpers. Let the slave read the pins at startup. This gives you 16 different IDs. If that's too many, use 3 pins for 8 IDs. If that's too little, use 5 pins for 32 IDs. User can set jumpers to avoid clashes. That's how garage door openers used to work.
#22
lelsteph
Super Member
  • Total Posts : 405
  • Reward points : 0
  • Joined: 2008/09/17 05:10:00
  • Location: 0
  • Status: offline
Re: Save configuration in PIC32: NVM or File System? 2016/07/11 07:48:54 (permalink)
0
Hello
 
To the initial question in this post, I think I will finally use the Serial EEPROM then it does not get erased when I re-program the chip for example. As mentioned I use a signature to detect when the definition of the structure for my parameters changes.
 
For your ID, you may want to use a Serial EEPROM with MAC address, ex: 25AA02E48 or 25AA02E64. You put one in each modules and then you have a unique ID.
 
Stephane.
#23
luca84
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2016/03/24 15:53:47
  • Location: 0
  • Status: offline
Re: Save configuration in PIC32: NVM or File System? 2016/07/11 08:14:03 (permalink)
0
You can also use purely random IDs. If you use 32-bit IDs, it's only one in 4 billion chance of a clash - that's much less likely than silicon failure. If you use 64-bit IDs, clash is virtually impossible.
It's such a good idea! I have to augment my packet to 36 bytes for a 32-bit ID but the advantage is that every slave has not to store its ID in internal flash. I think there is a little problem if the slave is being switched off and after switched on again, the master has to scan again the network so the user has to start a new scanning procedure from the web page. 
For your ID, you may want to use a Serial EEPROM with MAC address, ex: 25AA02E48 or 25AA02E64. You put one in each modules and then you have a unique ID.
Thank you Stephane but unfortunately my customer doesn't want to create a custom PCB so I have to use only the pic32 usb starter kit2 board and for size problem another connected shield board is not permitted.But I think I will use a Serial EEPROM with the master board to store all configurations.
post edited by luca84 - 2016/07/11 08:21:32
#24
NorthGuy
Super Member
  • Total Posts : 6228
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: Save configuration in PIC32: NVM or File System? 2016/07/11 11:01:35 (permalink)
0
luca84
... my customer doesn't want to create a custom PCB ...



Did you explain to him that this is crazy? :)
 
@OP: An ability to re-program without erasing data is not very important in production. And data may be preserved while re-programming - it only makes re-programming slower.
 
PICs used to have internal EEPROM, which allows re-programming single bytes and also re-programming can be done without stalling CPU. Some of them still do.
 
#25
rudolfpolzer
Starting Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2015/04/29 08:45:09
  • Location: 0
  • Status: offline
Re: Save configuration in PIC32: NVM or File System? 2017/06/28 14:41:54 (permalink)
5 (2)
Here is a code example done with Harmony v2_03b and Configurator 2.0.3.5 running on an Ethernet starter kit II.
I am using the flash memory both with NVM (for settings) and Microchip File System (for static web pages). A bit tricky are the three different NVM block sizes for read, writte and erase. And writing to the begin of the NVM destroys the web content, so I address the last erasable block.

Take the sample app
apps/tcpip/web_server_nvm_mpfs
and with the Configurator, set the number of NVM Driver Clients to 2.


#define NVM_SIZE (DRV_NVM_MEDIA_SIZE * 1024) // NVM size in bytes
#define WAITING_TIME_SETTINGS (2 * 60) // wait a minute , then store changed settings

DRV_HANDLE NvmHandle = 0;
DRV_NVM_COMMAND_HANDLE NvmCommandHandle;
bool SettingsChanged = false;
uin32_t WaitToSaveSettings = 0;

void APP_Tasks (void) {
    uint32_t address, count;
    uint32_t startTick = 0;
     DRV_NVM_COMMAND_STATUS commandStatus;
 
        ...

        case APP_TCPIP_TRANSACT:
        if (NvmHandle == 0) { // when started, read the settings
            NvmHandle = DRV_NVM_Open(DRV_NVM_INDEX_0, DRV_IO_INTENT_READWRITE
                | DRV_IO_INTENT_NONBLOCKING | DRV_IO_INTENT_SHARED);
            if (NvmHandle != DRV_HANDLE_INVALID) {
                // reading is counted in bytes and addressed in bytes
                address = NVM_SIZE - DRV_NVM_PAGE_SIZE;
                count = sizeof(Configuration);
                DRV_NVM_Read(NvmHandle, &NvmCommandHandle, Configuration, address, count);
            }
        }

        // twice a second:
        if(SYS_TMR_TickCountGet() - startTick >= SYS_TMR_TickCounterFrequencyGet()/2ul) {
            startTick = SYS_TMR_TickCountGet();
            LEDstate ^= BSP_LED_STATE_ON;
            BSP_LEDStateSet(APP_LED_1, LEDstate);
                
            // did settings change?
            if (SettingsChanged) WaitToSaveSettings++;
            if (WaitToSaveSettings == WAITING_TIME_SETTINGS) {
                SettingsChanged = false;
                if (NvmHandle == DRV_HANDLE_INVALID) WaitToSaveSettings = 0;
                else {
                    address = NVM_SIZE / DRV_NVM_PAGE_SIZE - 1;
                    count = 1; // 4096 byte blocks for erase
                    DRV_NVM_Erase(NvmHandle, &NvmCommandHandle, address, count);
                    if (NvmCommandHandle == DRV_NVM_COMMAND_HANDLE_INVALID) WaitToSaveSettings = 0;
                    else WaitToSaveSettings++;
                }
            } else if (WaitToSaveSettings == WAITING_TIME_SETTINGS + 1) {
                commandStatus = DRV_NVM_CommandStatus(NvmHandle, NvmCommandHandle);
                if (commandStatus == DRV_NVM_COMMAND_ERROR_UNKNOWN) WaitToSaveSettings = 0;
                else if (commandStatus == DRV_NVM_COMMAND_COMPLETED) {
                    address = (NVM_SIZE - DRV_NVM_PAGE_SIZE) / DRV_NVM_ROW_SIZE;
                    count = 1; // 512 byte blocks for write
                    DRV_NVM_Write(NvmHandle, &NvmCommandHandle, Configuration, address, count);
                    WaitToSaveSettings = 0;
                }
            }
        }
 
        ...
 
        // settings have been changed
        SettingsChanged = true;
        WaitToSaveSettings = 0;
 
post edited by rudolfpolzer - 2017/06/29 00:36:32
#26
glamprecht
Starting Member
  • Total Posts : 11
  • Reward points : 0
  • Joined: 2010/09/27 22:45:46
  • Location: 0
  • Status: offline
Re: Save configuration in PIC32: NVM or File System? 2020/06/29 09:32:15 (permalink)
0
These functions are only available on Harmony 2. There does not seem to be anything for Harmony 3 yet.
 
There is example available:   flash_read_write_pic32mz
 
This does work on the PIC32MX, but the callback function does not work on the http_net TCP/IP project.
 
 
#27
Paul PortSol
Super Member
  • Total Posts : 630
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Save configuration in PIC32: NVM or File System? 2020/06/30 04:06:15 (permalink)
4 (1)
Start a fresh issue since this was H2 and you are using H3
#28
Page: < 12 Showing page 2 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5