Debugging a program with debugger

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

Debugging a program with debugger

801 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by justmakeit on Thu May 07 01:38:18 MST 2015
Hello,

Currently i'm trying to make a program with a bootloader. But i keep failing with debugging the user application in LPCxpresso. There are a lot of questions and answers on the internet about creating a bootloader, but i cant found how to implement the flash settings in lpcxpresso. i'm using the "lpc link2" as programmer

what i'm doing:
1. program the bootloader the default way.
Debug As-> C/C++ (NXP semiconductors) MCU application

2. the bootloader start the application with the next code:
PROGRAM_ADDRESS_START = 0x3000

void execute_user_code(void)
{
void (*user_code_entry)(void);

unsigned *p;// used for loading address of reset handler from user flash

/* Change the Vector Table to the USER_FLASH_START
in case the user application uses interrupts */

SCB->VTOR = (PROGRAM_ADDRESS_START & 0x1FFFFF80);

// Load contents of second word of user flash - the reset handler address
// in the applications vector table
p = (unsigned *)(PROGRAM_ADDRESS_START +4);

// Set user_code_entry to be the address contained in that second word
// of user flash
user_code_entry = (void *) *p;

// Jump to user application
    user_code_entry();

}

3. replace the user application in flash
properties->c/c++ build->mcu settings->LPC1766->MFlash256 location: 0x3000 size: 0x3d000

4. Debug the user code
Debug As-> C/C++ (NXP semiconductors) MCU application

5. Debugger jumps to the wrong code

Labels (1)
0 Kudos
10 Replies

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by justmakeit on Wed May 20 05:48:24 MST 2015
I have found my problem. CMSIS overwrite my configuration. so i was searching in the wrong code ;-) its working now :D  Thanks for your help!
0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed May 20 05:45:53 MST 2015

Quote: justmakeit
I disabled the systick in my user application and it don't fail anymore :D . But my user program uses the systick interrupt...



Don't panic early  :)

Disabling SysTick is of course a test to show you the problem...

Next step: look in your application vector table (at 0x3000) .
There's the address (+1) for SysTick interrupt handler at word 0x3C  :O

That should be in your case something > 0x3000. If it's 0x115 your vector table is wrong  :D
0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by justmakeit on Wed May 20 05:27:34 MST 2015
I disabled the systick in my user application and it don't fail anymore . But my user program uses the systick interrupt to run my timers. so how can i remap the interrupt to address 0x3114 ?
i remap the vector table with this code:
SCB->VTOR = (PROGRAM_ADDRESS_START & 0x1FFFFF80);


Thank you in advance for your help
0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 19 08:16:30 MST 2015

Quote: justmakeit
only my user code uses the SysTick_Handler. I disable it in the bootloader code. but it is still jumping to the wrong Systick_handler. I probably asking very stupid questions  :) ,  please give me some more information.



I've no idea what your bootloader or application is doing in detail  :)

So it could be a good idea to disable SysTick in your application, then the problem should disappear...

0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by justmakeit on Tue May 19 08:11:28 MST 2015
only my user code uses the SysTick_Handler. I disable it in the bootloader code. but it is still jumping to the wrong Systick_handler. I probably asking very stupid questions  :) ,  please give me some more information.
0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 19 07:41:00 MST 2015

Quote: justmakeit
my user code start at address 0x3000 so  0x114 is not in the user code.

:D



Quote: justmakeit
0x114 is the SysTick_Handler of the bootloader code.



And who is using SysTick?
0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by justmakeit on Tue May 19 07:35:55 MST 2015
Yes my simple bootloader is the code above.
i haven't turn on any interrupts. are there interrupts default on?
i'm a bit confused now... The stack of the bootloader is the same memory as my user code uses right? So why do i need to load a stack pointer?

my user code start at address 0x3000 so  0x114 is not in the user code.
0x114 is the SysTick_Handler of the bootloader code.
0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 19 06:50:59 MST 2015
Are you still using the code above?

Could be useful to load the stack pointer before the jump is executed  :O

And of course disable interrupts  :)


Quote: justmakeit
When it's failing it jumps to pc = 0x114.
How can i figureout the reason it is failing?



What's in 0x114  :quest:
0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by justmakeit on Tue May 19 06:38:49 MST 2015
Thanks for your reaction,

I made the simple bootloader to jump to my user code and he is jumping to the right code. When i set a breakpoint at te start of my main function it breaks at the right location. But when i step through my code it goes wrong after a few steps. the place of failure is random depending on the speed of stepping through my code. When it's failing it jumps to pc = 0x114 .
How can i figureout the reason it is failing?
0 Kudos

756 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu May 07 04:44:58 MST 2015

Quote: justmakeit
Currently i'm trying to make a program with a bootloader...



Usually it's enough to flash/debug  the bootlader and then debug the application (with application Flash settting)  :) 

Debugger should of course start the debug session at your MCU settings->Flash location...

If that's not working and the debugger is still starting at 0x0000 use a simple bootloader to jump to your application start address...




0 Kudos