MPC560xB - Bad RAM initialization at startup

cancel
Showing results for 
Search instead for 
Did you mean: 

MPC560xB - Bad RAM initialization at startup

348 Views
romainbenet
Contributor III

Hi,

I use CodeWarrior 10.6 with CPU MPC5604B (MPC560xB Qorriva) and I find an error on default source file when I create a project.

In the file MPC5604B_HWInit.c there is the function INIT_Derivative():

__asm void INIT_Derivative(void)
{
nofralloc
/* Disable WatchDog*/
// *(volatile unsigned int*)0xfff38010 = 0x0000c520;
e_lis r9,0x0001
e_add16i r9,r9,-15072
e_lis r8,0xfff4
e_stw r9,-32752(r8)

// *(volatile unsigned int*) 0xfff38010 = 0x0000d928;
e_lis r9,0x0001
e_add16i r9,r9,-9944
e_lis r8,0xfff4
e_stw r9,-32752(r8)
// *(volatile unsigned int*) 0xfff38000 = 0xff00000A;
e_lis r3,0xff00
se_addi r3,0x000a
e_lis r8,0xfff4
e_stw r3,-32768(r8)

/* SRAM initialization code*/
lis r11,L2SRAM_LOCATION@h
ori r11,r11,L2SRAM_LOCATION@l

/* Loops to cover L2SRAM, stmw allows 128 bytes (32 GPRS x 4 bytes) writes */
lis r12,L2SRAM_CNT@h
ori r12,r12,L2SRAM_CNT@l
mtctr r12

init_l2sram_loop:
stmw r0, 0(r11) /* Write 32 GPRs to SRAM*/
addi r11,r11,128 /* Inc the ram ptr; 32 GPRs * 4 bytes = 128B */
bdnz init_l2sram_loop /* Loop for 48k of SRAM */
blr
}

I set the important part of this function in bolt.

My problem is: the RAM is not initialized to value 0 by default.

Register r0 contains correctly value 0x00000000 (32 bits register) but there is other value write in all RAM memory.

But if I change the RAM access size from 128 to 4 bits the RAM is correctly initialized to value 0 as expected.

Where is the issue ? Bad initial source code or/and the ECU doesn't support 128 bits access ?

Thanks for your help.

Best regards,

Romain

0 Kudos
2 Replies

134 Views
petervlna
NXP Employee
NXP Employee

Hi,

There is no issue at all.

There in no need to have ram initialized with 0x0000 0000 patern.

And it is also not recommended to have all 0 in SRAM.

Your RAM will be initialed with R0 to R31 GPRs in 128bytes loops. And the address on R11 will be incremented by 128B.

Peter

0 Kudos

134 Views
romainbenet
Contributor III

Hi,

I understand that there is no necessary to initialze the RAM with a specified pattern.

But for my application I initialize or not a part of the RAM depending of DES register of RGM peripheral (DES = 0, no initialization, otherwise done).

How, in this case, can I be sure that (I can't know in advance value of the word in this RAM part) my data have the expected value ?

For example I use 2 bool data and 1 counter. At startup if DES != 0 my 2 bool data and my counter are initialized with default function INIT_Derivative() and never modified between end of the function INIT_Derivative() and the call of my function in my application (I have add the option NO_INIT_BSS in linker to remove default value of these data from function __init_data() ). What is the risk that my bool data are not by accident corrupted and my counter is corrupted ? I can't afford to have this behaviour becuase this counter is used to enter in critical mode if its value is greater than a specified value.

What is the reason to avoid the initialization with 0x0000 0000 pattern ?

Thanks for your help,

Best regards,

Romain

0 Kudos