Author Topic: Parameters Save Command  (Read 9786 times)

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Parameters Save Command
« on: October 22, 2009, 10:50:19 AM »
Hello,

I notice that the
Save command is not working...
When I did it, the memory dump of parameters was :

00030000:55 55 55 55 ff ff ff ff ff ff ff ff ff ff ff ff    UUUU............
00030010:55 55 55 55 ff ff ff ff ff ff ff ff ff ff ff ff    UUUU............
00030020:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030030:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030040:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030050:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030060:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030070:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030080:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030090:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300a0:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300b0:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300c0:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300d0:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300e0:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300f0:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

I change the code to suppress the line
Code: [Select]
      fnDelPar(SWAP_PARAMETER_BLOCK);                                   // delete old block and validate new one.
then the dump gave me:
00030000:55 55 55 55 ff ff ff ff ff ff ff ff ff ff ff ff    UUUU............
00030010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030020:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030030:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030040:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030050:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030060:18 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030070:00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030080:0c ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030090:1d ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300a0:12 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300b0:e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300c0:1f ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300d0:23 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    #...............
000300e0:c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
000300f0:a8 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

It looks the valid parameter block is deleted ...
Do you have some idea where it comes from ?

Code: [Select]
extern int fnSaveNewPars(int iTemp)
{
#ifdef USE_PARAMETER_BLOCK
   // Network variables
   if (iTemp == SAVE_NEW_PARAMETERS_CHECK_CRITICAL) {                    // we check to see whether network parameters have been changed
       if (((temp_pars->temp_parameters.ucServers & ACTIVE_DHCP) != (parameters->ucServers & ACTIVE_DHCP)) || (uMemcmp((unsigned char *)&temp_pars->temp_network, (unsigned char *)&network_flash, sizeof(NETWORK_PARAMETERS)))) {
           return 1;                                                     // since a network parameter has been change, we warn the user that he/she will have to validate afterwards
       }
   }
    #ifndef USE_PAR_SWAP_BLOCK
   fnDelPar(INVALIDATE_PARAMETER_BLOCK);                                 // delete parameter block before continuing
   iTemp = SAVE_NEW_PARAMETERS;
    #endif
   fnSetPar((unsigned short)(PAR_NETWORK | TEMPORARY_PARAM_SET), (unsigned char *)&temp_pars->temp_network, sizeof(NETWORK_PARAMETERS)); // network parameters

   // device parameters
   fnSetPar((PAR_DEVICE | TEMPORARY_PARAM_SET), (unsigned char *)&temp_pars->temp_parameters, sizeof(PARS));  // copy the new set to the swap buffer (temp)

   if (iTemp != SAVE_NEW_PARAMETERS_VALIDATE) {
   #ifdef ACTIVE_FILE_SYSTEM
//       fnDelPar(SWAP_PARAMETER_BLOCK);                                   // delete old block and validate new one.
   #endif
//     uMemcpy(&network, &temp_pars->temp_network, sizeof(NETWORK_PARAMETERS)); // update working parameter set - we never do this since we always reset after a network change (otherise we can have DHCP difficulties, since DHCP values will be overwritten)
       uMemcpy(parameters, &temp_pars->temp_parameters, sizeof(PARS));
   }
#endif
   return 0;
}

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Parameters Save Command
« Reply #1 on: October 22, 2009, 11:31:01 AM »
Hi Hervé

See full details of the parameter here: http://www.utasker.com/docs/uTasker/uTaskerFileSystem_3.PDF

In the first case I see that there is a valid parameter block at location 0x30000 (the two values 0x55555555 + 0x55555555 indicate that the block is valid). All parameters are however 0xff.

In the second case I see that there is a temporary block at 0x30000 (only the first 0x55555555 is there). Then there are parameters 0x18, 0x00, etc (note that a complete FLASH line of 16 bytes holds only one parameter byte due to the physical characteristics of the FLASH line - see http://www.utasker.com/forum/index.php?topic=136.0).

The command fnDelPar(SWAP_PARAMETER_BLOCK); is used to swap blocks. It will delete the presently valid one and validate the present temporary one - making it the valid one. This assumes that a swap block is being used (USE_PAR_SWAP_BLOCK). The swap block is presumably at 0x38000. Often the parameter blocks are set to be in the small FLASH sectors (such as 0x7c000 and 0x7d000) rather than using large sectors for them.

I didn't really understand the problem but maybe this helps explain what you are seeing.

Regards

Mark

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: Parameters Save Command
« Reply #2 on: October 22, 2009, 02:19:32 PM »
Hi Mark,

Getting more detail on my problem I found that I had a PARAMETER_BLOCK_SIZE of 4*1024K, with PARAMETER_BLOCK_START = 0x30000.
In those addresses the LPC2387 has a block size of 32K.....
That means that both Parameter Blocks are on the same µP sector, which may cause the problem. :-\

Code: [Select]
1 / With fnSaveNewPars not modified :

After erasing all flash and uploading program :
PARAMETER_BLOCK_1
00030000:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

PARAMETER_BLOCK_2
00031000:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00031010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

After first Save Command :
PARAMETER_BLOCK_1
00030000:55 55 55 55 ff ff ff ff ff ff ff ff ff ff ff ff    UUUU............
00030010:55 55 55 55 ff ff ff ff ff ff ff ff ff ff ff ff    UUUU............

PARAMETER_BLOCK_2
00031000:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00031010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

After second Save Command :
PARAMETER_BLOCK_1
00030000:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

PARAMETER_BLOCK_2
00031000:55 55 55 55 ff ff ff ff ff ff ff ff ff ff ff ff    UUUU............
00031010:55 55 55 55 ff ff ff ff ff ff ff ff ff ff ff ff    UUUU............

and so on... the swap is working but with no data.


2 / With fnSaveNewPars modified :

After erasing all flash and uploading program :
PARAMETER_BLOCK_1
00030000:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

PARAMETER_BLOCK_2
00031000:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00031010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................


After first Save Command :
PARAMETER_BLOCK_1
00030000:55 55 55 55 ff ff ff ff ff ff ff ff ff ff ff ff    UUUU............
00030010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
...with some data
00030060:18 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00030070:00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

PARAMETER_BLOCK_2
00031000:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
00031010:ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
 

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Parameters Save Command
« Reply #3 on: October 22, 2009, 04:35:50 PM »
Hi Hervé

That does seem to be the problem since it is not possible to erase the old sector without 'also' erasing the new one!

Your new results look more as I would expect - hopefully it is now doing what you want from it...

Regards

Mark

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: Parameters Save Command
« Reply #4 on: October 22, 2009, 05:28:31 PM »
Thanks for your help.

Quote
The swap block is presumably at 0x38000.
It helps me finf my problem.

Unfortunately, I would have another question !
On fnWriteBytesFlash a test is made to detect the end of inside flash with :

Code: [Select]
    if (ucDestination >= ((unsigned char *)(FLASH_START_ADDRESS + SIZE_OF_FLASH))) // we are working from _extern_al SPI FLASH memory

with
    #elif defined (LPC2387FBD100)
        #define SIZE_OF_FLASH (512*1024)                                 // 512k FLASH

but on the LPC2387 datasheet it is noted the last sector numbers is the 27th:
(0x1B)  0x0007 D000 - 0X0007 DFFF
and the amount of flash available for user code and data is 504 K bytes in "512K"
devices.


I think I would have to define SIZE_OF_FLASH (504*1024)  to avoid this boot block gap.

Is it right ?





Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Parameters Save Command
« Reply #5 on: October 22, 2009, 06:18:41 PM »
Hi Hervé

It is correct that the final small sector in the largest LPC23XX device is occupied by the internal boot program and can not be used by the application.

It is possible to define the length to respect this but I don't think that it is usually important since the test is deciding whether the access is to internal or external FLASH. As long as the external start address is higher than the internal FLASH end address the test will be correct.

The only exception may be when configuring the uFileSystem to span both internal and external FLASH, in which case it would be best to do this as you suggest so that no attempt would be made to access the last sector (which can not be accessed). But, I don't known whether there is much sense in this configuration with the LPC23XX due to the fact that it has inconsistent FLASH block sizes, making mixing internal and external FLASH use by the uFileSystem  complicated (usually the external FLASH needs to use the same file sizes as internal FLASH, including usually sub-file operation due to the LPC2XXX's quite large FLASH granularity and this configuration is likely to be quite restrictive).

When working with the LPC23XX and external FLASH I would tend to put the whole uFileSystem there due to the external FLASH's flexibility - the parameters could go to two of the smaller internal FLASH sectors if not too large (max. 255 bytes due to the FLASH line restriction) or else also to the external FLASH... However the configuration is quite flexible, as are settings for exact regions of internal and external FLASH so the final decision will always be made based on exact project requirements.

Regards

Mark