S32K144: Read 1s All Blocks command

cancel
Showing results for 
Search instead for 
Did you mean: 

S32K144: Read 1s All Blocks command

836 Views
MPC8313ERDB_h
Contributor III

I run the "Read 1s All Blocks" command over a S32K144 block (0x800B) which I know it's all erased (I checked it with a customized function as depicted below).
When I issued the command (see below) the return MGSTAT0 bit in register FSTAT is set, suggesting that Read-1s fails.

I run this command with all 3 Margin levels which return the same result.

int  chk_block_earesed(u32 addr, int Margin_level)
{
int rc;

addr &= ~(PROG_SEC_SIZE-1);
FTFC->FSTAT= 0x70;
FTFC->FCCOB[3]= 0x00; /* (RD1BLK) Read 1s Block command */
FTFC->FCCOB[2]= (addr>>16)&0xff ;
FTFC->FCCOB[1]= (addr>> 8)&0xff ;
FTFC->FCCOB[0]= 0x00 ; /* address [2:0] = 000 */
FTFC->FCCOB[7]= Margin_level ;

rc= (int)FlashCommandSequence();
rc= (int)(FTFC->FSTAT & 0x7f);
return rc;
}

The stand alone-function (assembler, to speed-up the loop) is:

/***************************************
check if a given block is all-one
int DG_isAll_One(uint32_t addr, int16_t byte_size);
note: byte_size must be N*4
note: addr must be aligned to 4
r2= cur loop fetch addr
r3= loop-cnt
r4= temp fetch
r5= result

Author: David Gabbay
***************************************/
.thumb_func
.align 2
.globl DG_isAll_One
.weak DG_isAll_One
.type DG_isAll_One, %function
/*------------------------------------*/

DG_isAll_One:
lsrs r3, r1, #2 /* div by 4 */
bgt all_1s_cont /* do the job if valid size */
blx lr /* return if not valid size */

all_1s_cont:
push {r4-r5,lr} /* save non-volatile reg */
orr r2,r0,r0 /* make r2 loop_addr */
ldr r5,[r2] /* get 1st operand */
b all_1s_lp

all_1s_lp:
add r2,0x4
ldr r4,[r2]
and r5,r5,r4

all_1s_chk:
subs r3,r3,1 /* chk loop-cnt */
bgt all_1s_lp /* continue if */
mvns r0,r5 /* set result */

pop {r4-r5,pc} /* restore reg + return to caller */
/*------------------------------------*/

I decided to use this command because I had encountered issues (always the same address out of many) when I tried to program the p-flash.

3 Replies

707 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello David,

The Read 1s Block command checks to see if an entire program flash or data flash block has been erased to the specified margin level.
That is whole PFlash block 0x00000000 – 0x0007FFFF in this case.
Are you sure that the whole block is erased?

If you want to read just a part of the PFlash block, use the Read 1s Section command instead.

Regards,
Daniel

707 Views
MPC8313ERDB_h
Contributor III

Hi Daniel,
Thank you for your clarification.

In my case the program-flash was not fully erased, so the returned value is actually correct.
However, I would like to comment that the definitions of  "section" and "block" in the RM are not that clear. My recommendation (for next RM revision) is to include these items in paragraph  36.1.2 (Flash memory sizes)

 

Many thanks

David

707 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi David,

The Flash memory sizes section in the RM will be updated.

It should contain the number of PFlash blocks and their size (for each derivative).

"Section" is explained in the description of the commands (Read 1s Section, Program Section) that use it, for example:

pastedImage_1.png

In other words, the commands take the starting address of a PFlash section and the number of double-phrases in the section.

Regards,

Daniel

0 Kudos