SWD flash programming

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SWD flash programming

2,575件の閲覧回数
Thijs1
Contributor II

I implemented an SWD interface on my own controller.

I want to flash program another (LPC1837) target board.

The SWD interface is working correctly (chipcode, deviceId, read/write SRAM, read/write registers)

I can stop/start the core

Found flash functions in ROM at 0x10408581. (init, prepare, erase, programm, etc)

Trying to execute them by the SWD seems to not function.

 

ラベル(1)
0 件の賞賛
返信
7 返答(返信)

2,527件の閲覧回数
Thijs1
Contributor II

Hello,

Sorry for some delay in my reply.

I am now discussing with my colleages where the approach with a dedicated flash programm to be downloaded to the target board and run that. (we already have that function in our application)

Here is what I am doiing now:

I implemented a stop core and start core function and tried to start the (ROM) flashfunction by SWD.

The return value should become '0' (or an error code....), but my initial value of -1 on this location does not change.

1st I try the 'init' command (also the prepare / erase and programm later, but all without success

bool CSpiProgrammer::StopTheCore() {
uint32_t dataword;
bool error = false;

error |= WriteDP(DP_SELECT, MEMAP_BANK_0);
error |= WriteAP(AP_TAR, AHB_DHCSR); // 0xE000EDF0
dataword = DBGKEY | C_HALT | C_DEBUGEN;
error |= WriteAP(AP_DRW, dataword);
error |= WriteAP(AP_TAR, AHB_DEMCR); // 0xE000EDFC
error |= WriteAP(AP_DRW, 1); // VC_CORERESET
Tm0(8); // 8 bit delay
error |= WriteAP(AP_TAR, AHB_AIRCR); // 0xE000ED0C
dataword = VECTKEY | SYSRESETREQ; // VECTKEY 05FA + SYSRESETREQ
error |= WriteAP(AP_DRW, dataword);
error |= WriteDP(DP_SELECT, 0x00);
Tm0(8);

return(error);
} // StopTheCore()

bool CSpiProgrammer::StartTheCore() {
uint32_t dataword;
bool error = false;

error |= WriteDP(DP_SELECT, MEMAP_BANK_0);
error |= WriteAP(AP_TAR, AHB_DHCSR); // 0xE000EDF0
dataword = DBGKEY | 0x0000 | C_DEBUGEN; // clear the C_HALT bit
error |= WriteAP(AP_DRW, dataword);

error |= WriteAP(AP_TAR, AHB_DEMCR); // 0xE000EDFC
error |= WriteAP(AP_DRW, 0); // VC_CORERESET -> OFF

dataword = VECTKEY | VECTRESET; // VECTKEY 05FA + SYSRESETREQ //0x0004;
error |= WriteAP(AP_TAR, AHB_AIRCR); // 0xE000ED0C
error |= WriteAP(AP_DRW, dataword); // 0x05FA0004);
Tm0(8); // 8 bit delay

return(error);
} // StartTheCore()

/*............part of main program..............*/

StopTheCore();
flashAddr = 0x1b000000; // flash bank2 (sector 0)
error = ReadArray(flashAddr, (uint32_t *)data, 15); // see, what's on flashAddr now

error = FPenable(); // Flash Port enable
error = ReadWord(ROM_TABLE, &flashFunc); // get the flashAddres = IAP flash calls (0x1040bfdd)
flashFunc = flashFunc & 0xfffffffe; // necessary?

error = WriteCoreReg(REG0, RAM_TARGET); // Reg 0 input structure
error = WriteCoreReg(REG1, RAM_TARGET + 32); // Reg 1 output structure
WriteWord(RAM_TARGET, 49); // init command (RAM TARGET = 0x20008e00)
WriteWord(RAM_TARGET+4, 0); // future....
WriteWord(RAM_TARGET+8, 0);
WriteWord(RAM_TARGET+12, 0);
WriteWord(RAM_TARGET+16, 0);
WriteWord(RAM_TARGET+32, -1); // clear the return value (0x20008e20 = -1)
error = WriteWord(AHB_VTOR, RAM_TARGET); // VTOR start RAM address code (0x20008000)
// some checks
error = ReadWord(RAM_TARGET+32, &retVal); // check return value still is -1
error = ReadArray(RAM_TARGET, data_flash, 5); // double check input structure

error = WriteCoreReg(REG_SP, RAM_STACK); // Give some stack space (RAM_STACK = 0x20008ff0)
error = WriteCoreReg(REG_PC, flashFunc); // PC counter points to flah function in ROM (0x1040bfdc)

error = StartTheCore();

retry = 10;
error = ReadWord(RAM_TARGET+32, &retVal);
while(retVal && retry) {
Delayt(1); // short delay
retry--;
error = ReadWord(RAM_TARGET+32, &retVal);
}

error = StopTheCore();
// next commands......

/*...........etc etc.............*/

0 件の賞賛
返信

2,481件の閲覧回数
Thijs1
Contributor II

Hello,

Unfortunately I don't have it working yet.

I did not make the RAM vector table, I do now, but it did not solve my problem.

I will give up running the flash functions directly from SWD and write a small application to do it.

I have not yet finished doiing that.

regards, Thijs

0 件の賞賛
返信

2,506件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport
0 件の賞賛
返信

2,562件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Thijs1,

How about use a mature debugger test your chip? For example LPC-link2 or J-link ?

 

Regards,

Alice

0 件の賞賛
返信

2,555件の閲覧回数
Thijs1
Contributor II

That is what we do in our development department. (LPC-link2)

But for production we prefer a standalone programmer. We did that for other products (using jtag)

Our own software uses the ARM flash functions (in ROM) to do customer software updates in flash (in the field).

So I made the SWD interface working, but for some reason I cannot get these built-in flash functions to work.

Am I overlooking something?

 

To be honest, I also have problems starting a program in SRAM from SWD, otherwise I could copy our own flash program to SRAM and run that.

0 件の賞賛
返信

2,535件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Thijs1,

Yes, I think you can provide more information about your question as converse said.

Or we don't know what issue you are facing. thanks!

 

Regards,

Alice

0 件の賞賛
返信

2,545件の閲覧回数
converse
Senior Contributor V

Perhaps you can explain what you are doing, and what is not working?

I know that the debugger downloads an application to RAM and that app programs the flash.

0 件の賞賛
返信