Interrupt Handlers in Ram (lpc1114)

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

Interrupt Handlers in Ram (lpc1114)

653 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArtjomGromak on Mon Sep 10 13:36:00 MST 2012
Hi.
I try place Systick_Handler in Ram and program .don't work.
Program text:
#include "lpc11xx.h"
#include <core_cm0.h>

extern "C" void SystemTimer_ISR(void);

volatile uint_fast32_t SysTickWas;
__attribute__ ((__section__(".ramfunc")))
void SystemTimer_ISR()
{
SysTickWas=1;
}

int main()
{
LPC_GPIO0->DIR=(1<<7);
LPC_GPIO0->DATA=0;
uint16_t tick_counter=0;
SysTick_Config(48000);
while (1) {
if (SysTickWas) {
SysTickWas=0;
uint16_t tick_limit = (LPC_GPIO0->DATA&(1<<7)) ? (30) : (970);
if (++tick_counter>=tick_limit) {
tick_counter=0;
LPC_GPIO0->DATA^=(1<<7);
}
}
}
}


ramfunc-section(from LPC1114_3xx.ld)
.ramfunc :
    {
        . = ALIGN(4);
        _sdata = .;                /* start of .data label */
        *(.ramfunc)
        *(.ramfunc.*)
    } > RAM AT > TEXT
    _sidata = LOADADDR(.ramfunc);    /* start of initialized data label */


SystemTimer_ISR (SysTick_Handler) happens 1 time and can't return to main function.
In Cortex-M3 same program work without errors.
Why it not work on Cortex-M0? What is wrong?
I use Yagarto.


Thanks.

P.S. Arcive with project: [ATTACH]835[/ATTACH]
0 Kudos
6 Replies

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArtjomGromak on Mon Sep 10 16:43:38 MST 2012

Quote: kayoda
No :rolleyes:
You've changed your vector table, so is your stack pointer entry still valid?


Table valid and program work if SystemTimer_ISR placed in flash:

__attribute__ ((section(".isr_vector")))
void (* const g_pfnVectors[])(void) =
{
/* Core interrupt vectors */
    (intfunc)_estack,
Reset_Handler,
NMI_Handler,
HardFault_Handler,
0,
0,
0,
0,
0,
0,
0,
SVC_Handler,
0,
0,
PendSVC_ISR,
SystemTimer_ISR,
        // .....other handlers



Quote: kayoda
No :rolleyes:

If your stack isn't working, all functions (or returns from function) are failing. Did you test this?


Function call-return from main function work.
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Mon Sep 10 15:36:30 MST 2012
No :rolleyes:

You've changed your vector table, so is your stack pointer entry still valid?

void (* const g_pfnVectors[])(void) = {
    &_vStackTop,                            // The initial stack pointer
    ResetISR,                               // The reset handler
    NMI_Handler,                            // The NMI handler
    HardFault_Handler,                      // The hard fault handler
    0,
.....


This might look a little bit different in Yagarto

If your stack isn't working, all functions (or returns from function) are failing. Did you test this?
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArtjomGromak on Mon Sep 10 15:22:18 MST 2012

Quote: kayoda
Wild guess: Stack problems


You think that this handler
__attribute__ ((__section__(".ramfunc")))
void SystemTimer_ISR()
{
SysTickWas=1;
}

need bigger stack then this:
void SystemTimer_ISR()
{
SysTickWas=1;
}

?
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Mon Sep 10 14:58:47 MST 2012

Quote: ArtjomGromak
And now I see that after return from SystemTimer_ISR executes HardFault_Handler. Why?



Wild guess: Stack problems :)
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArtjomGromak on Mon Sep 10 14:36:52 MST 2012

Quote: Zero
Where's your SysTick_Handler() :confused::eek::confused:

Probably the first interrupt is ending somewhere in a loop :mad:

void SysTick_Handler(void)
{
    while(1)
    {
    }
}


No, it is not my case.
But thank you Zero: I found one more error in my startup.c.
My vector table incorrect:
/* Core interrupt vectors */
    (intfunc)_estack,
Reset_Handler,
0,
0,
0,
0,
0,
0,
0,
0,
0,
SVC_Handler,
0,
0,
PendSVC_ISR,
SystemTimer_ISR,

I correct vector table
Reset_Handler,
NMI_Handler,                            // The NMI handler
HardFault_Handler,
0,
0,
0,
0,
0,
0,
0,
SVC_Handler,
0,
0,
PendSVC_ISR,
SystemTimer_ISR,

In test_flash_write.cpp (main-function defined in test_flash_write.cpp) I add code
extern "C" void HardFault_Handler()
{

uint8_t blink_counter=0;
while (++blink_counter<100) {
LPC_GPIO0->DATA&=~(1<<7);
volatile uint32_t delay=0;
while (++delay<1000000) ;

delay=0;
LPC_GPIO0->DATA|=(1<<7);
while (++delay<10000) ;
}
NVIC_SystemReset();
}

And now I see that after return from SystemTimer_ISR executes HardFault_Handler. Why?
0 Kudos

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Sep 10 14:05:38 MST 2012
Where's your SysTick_Handler() :confused::eek::confused:

Probably the first interrupt is ending somewhere in a loop :mad:

void SysTick_Handler(void)
{
    while(1)
    {
    }
}
0 Kudos