S12 MCU, How to get memory size at runtime ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S12 MCU, How to get memory size at runtime ?

Jump to solution
846 Views
fmiku
Contributor III

Hello,

I'm using S12G and S12VR series MCU and I wrote an own bootloder for these device.

Everything works smootly, but I don't want to build all the time separately for different memory sized device.

Currently I determine the real P-Flash size by initiate a Section erase from Global address 0x0_8000 to 0x3_F7FF in 16 KBytes step.(Boot loader part is not erased !)

After issuing the command I check the ACCERR bit in FSTAT to detemine the validity of the address.

This method is failed on the S9S12G48 device because the command is accepted without error for address range 0x3_0000-0x3_3FFF which is valid for S9S12G64+ device.

Any other tip for determine the memory size at runtime ?

Labels (1)
0 Kudos
1 Solution
580 Views
RadekS
NXP Employee
NXP Employee

Hi Ferenc,

Unfortunately, there isn’t way how to exactly detect differences between some of the derivatives directly from a code.

S12G:

You cannot distinguish between 16kB and 32kB, between 48kB and 64kB, between 96kB and 128kB, between 192 and 240kB derivatives.

S12VR:

You cannot distinguish between 16kB and 32kB, between 48kB and 64kB derivatives.

In fact, the chips are the same, just some part of Flash is not fully tested. However, your bootloader may erase even that page.

 

The simplest way how to detect a flash size is reading Part ID. The S12G/S12VR doesn’t have special register with a flash size information.

The example of such routine may be found in AN4258. Updated version for you:

 

static UINT8 EraseFlash(void)

{   

  switch (PARTID)

  {         

    //S12G   

    case MASK_0N95B:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x004000UL, 0x03EFDFUL));

 

    case MASK_0N51A:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x020000UL, 0x03EFDFUL));

 

    case MASK_0N75C:

    case MASK_1N75C:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x030000UL, 0x03EFDFUL));

      

    case MASK_0N48A:

    case MASK_1N48A:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x038000UL, 0x03EFDFUL));

 

    //S12VR

    case MASK_0N59H:

    case MASK_0N05E:

    case MASK_1N05E:

    case MASK_2N05E:

    case MASK_0N92B:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x030000UL, 0x03EFDFUL));

    case MASK_0N11N:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x038000UL, 0x03EFDFUL));

         

    default:

          return(UnknownPartID);

  }      

}

 

Note: the 0N92B, 0N05E, 1N05E and 2N05E masksets are obsolete versions of S12VR.

PartIDs:

0N92B 0x3280

0N05E 0x3281

1N05E 0x3281

2N05E 0x3282

0N59H 0x3290

0N11N 0x3380

0N95B 0xF080

0N51A 0xF180

0N75C 0xF280

1N75C 0xF281

0N48A 0xF380

1N48A 0xF381

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

1 Reply
581 Views
RadekS
NXP Employee
NXP Employee

Hi Ferenc,

Unfortunately, there isn’t way how to exactly detect differences between some of the derivatives directly from a code.

S12G:

You cannot distinguish between 16kB and 32kB, between 48kB and 64kB, between 96kB and 128kB, between 192 and 240kB derivatives.

S12VR:

You cannot distinguish between 16kB and 32kB, between 48kB and 64kB derivatives.

In fact, the chips are the same, just some part of Flash is not fully tested. However, your bootloader may erase even that page.

 

The simplest way how to detect a flash size is reading Part ID. The S12G/S12VR doesn’t have special register with a flash size information.

The example of such routine may be found in AN4258. Updated version for you:

 

static UINT8 EraseFlash(void)

{   

  switch (PARTID)

  {         

    //S12G   

    case MASK_0N95B:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x004000UL, 0x03EFDFUL));

 

    case MASK_0N51A:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x020000UL, 0x03EFDFUL));

 

    case MASK_0N75C:

    case MASK_1N75C:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x030000UL, 0x03EFDFUL));

      

    case MASK_0N48A:

    case MASK_1N48A:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x038000UL, 0x03EFDFUL));

 

    //S12VR

    case MASK_0N59H:

    case MASK_0N05E:

    case MASK_1N05E:

    case MASK_2N05E:

    case MASK_0N92B:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x030000UL, 0x03EFDFUL));

    case MASK_0N11N:

          //erase whole P-Flash memory except bootloader area

          return(PFlash_EraseSectorBySector(0x038000UL, 0x03EFDFUL));

         

    default:

          return(UnknownPartID);

  }      

}

 

Note: the 0N92B, 0N05E, 1N05E and 2N05E masksets are obsolete versions of S12VR.

PartIDs:

0N92B 0x3280

0N05E 0x3281

1N05E 0x3281

2N05E 0x3282

0N59H 0x3290

0N11N 0x3380

0N95B 0xF080

0N51A 0xF180

0N75C 0xF280

1N75C 0xF281

0N48A 0xF380

1N48A 0xF381

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------