LPC4357 M4 code in RAM

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

LPC4357 M4 code in RAM

927 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pgeloso on Mon Jun 15 06:43:58 MST 2015
Hi,
I'm trying to run a function from RAM in M4 core.
I'm using LPCXpresso 7.8.0 and an EA-LPC4357 eval board.

This function performs the erase of sector 0 Flash A.
If the code in RAM has no "links" with Flash A and there are no interrupts, it should run..but, actually, it crashes as soon as I try to erase sector 0 of Flash A.
...I don't understand why.

Note:
- I'm not using interrupts
- I left 32Bytes of stack offset. to use IAP
- I initialize IAP before using it
- I placed the routine routine into RAM

Here the simple code:


#include "board.h"

#include <cr_section_macros.h>

#include "iap_18xx_43xx.h"

//IAP: Settings .. ->.. stack offset=32
// Initialize IAP before using it
// Erase sector 0 from RAM

#define IAP_INIT_CMD 49

void Chip_IAP_Initialise(void)
{
uint32_t command[5], result[4];

command[0] = IAP_INIT_CMD;
iap_entry(command, result);
}



__RAMFUNC(RAM) void ram_fw_upgrade(void){

int i;
uint32_t n_sector=0;//we start writing data in this sector
uint32_t command[5], result[4];


 __disable_irq();

 // prepare sector 0
 command[0] = IAP_PREWRRITE_CMD;
 command[1] = n_sector;
 command[2] = n_sector;
 command[3] = 0;//flashBank A
 iap_entry(command, result);

 //erase sector 0
command[0] = IAP_ERSSECTOR_CMD;
command[1] = n_sector;
command[2] = n_sector;
command[3] = SystemCoreClock / 1000;
 command[4] = 0;//flashBank A
 iap_entry(command, result);           //---->crash!!

for(i=0;i<1000000;i++);//wait..do something in RAM

 __enable_irq();

 return;
}







int main(void) {
int i=0;
void (*longfunc)(void) = &ram_fw_upgrade;

    SystemCoreClockUpdate();
 //   Board_Init();
 //   Board_LED_Set(0, true);
      Board_UART_Init(0);//doing nothing, but it's needed, or it will not compile

    Chip_IAP_Initialise();

    if(i!=0){ //just for safety..we enter here only manually, during debug..
    (*longfunc)();//  running from RAM
    }
    while(1) {
    i++;
    }
    return 0 ;
}


Labels (1)
0 Kudos
Reply
6 Replies

868 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pgeloso on Tue Jun 16 00:40:01 MST 2015

Hi,
the IAP address is inside a library of LPCOpne of LPCXpresso (lpc_chip_43xx): I think it's correct and it's pointing to the ROM.

/* Pointer to ROM IAP entry functions */
#define IAP_ENTRY_LOCATION        (*((uint32_t *) 0x10400100))

static INLINE void iap_entry(unsigned int cmd_param[], unsigned int status_result[])
{
((IAP_ENTRY_T) IAP_ENTRY_LOCATION)(cmd_param, status_result);
}


IAP works fine, the problem is only related to sector 0.

Sorry, I don't understand what you mean with "!thumb bit set"..could you please explain it?

Tbnaks
Pietro

0 Kudos
Reply

868 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LessThanZero on Mon Jun 15 11:54:16 MST 2015

What address are you using as the IAP entry point? Is the thumb bit set?
0 Kudos
Reply

868 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pgeloso on Mon Jun 15 08:51:49 MST 2015
Intersting thing,
I didn't know about the hardfault debug.
Unfortunately, for me, it's quite criptic.
The fail happens at the aiap command line
iap_entry(command, result);  

and it seems vectpc register is addressing this issue..but ??.. do you have suggestions?

I'm attaching the screen shot.

Thanks
Pietro

0 Kudos
Reply

868 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Jun 15 07:57:29 MST 2015
So, debug the Hard Fault (hint - there is a FAQ for this). Or as a minimum, give as a clue as to details on the hard fault.I've got good eyesight, but I can't read your screen from here...
0 Kudos
Reply

868 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pgeloso on Mon Jun 15 07:09:25 MST 2015
Thank you for your interest, "TheFallGuy"!

Yes, it's hard fall. The debugger stops and I can't execute the lines after the "iap-erase" line.

Bye!
Pietro
0 Kudos
Reply

868 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Jun 15 07:04:34 MST 2015
What do you mean by "crashes"? What *really* happens? HardFault?
0 Kudos
Reply