GPIO pointer strange issue

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

GPIO pointer strange issue

538 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MSalvati on Thu Feb 12 07:24:24 MST 2015
Hello everybody, first of all, thank you for reading :). I've been looking into this forum for a long time and it's been more than helpful !
Now after days of debbuging I've come to this situation:

I have a hard fault which, after looking at memory, I found that it's caused by a pointer which is pointing a wrong zone (typical). It seems to be a very very basic mistake but I just can't figure out what's wrong :(.
Project has a main.c, gpio.c, gpio.h  and gpio.h is included in both main and gpio source codes. LPC11xx.h is included in both as well.
The pointer, defined in gpio.h it is:

static LPC_GPIO_TypeDef (* const LPC_GPIO[4]) = { LPC_GPIO0, LPC_GPIO1, LPC_GPIO2, LPC_GPIO3 };


LPC_GPIOn is the position in memory 0x500n8000, as noted in UM10398.

So by now, I just want to access LPC_GPIO[0]->DIR and store the number 0x08. The function in gpio.c which does this is:
void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir )


Which stores in LPC_GPIOn->DIR the correct value

When I look at the Expressions window, value of LPC_GPIO[0] outside this function points, sometimes, to 0x010002000 (which curiously is where RAM starts, and I think it would be actually better to think that pointer outside has no sense) and, if I am not wrong, when it gets inside this function it should point to 0x50008000. This doesn't happens.
When it gets into GPIOSetDir() pointer keeps pointing elsewhere (0x46bd50d1, for example) and then, expectedly, hard faults.

This happens in the very first lines of main.c, there is no other function call before, except for the SystemInit() function (which I assume you're familiar with, the one that sets PLL clocking etc, from LPC library) which remains unchanged.

Any help is welcome! If you need more data, please ask me, I'll post as soon as possible.

Kind regards,

Matt
Labels (1)
0 Kudos
5 Replies

494 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Feb 13 05:02:56 MST 2015

Quote:
It's such a pity that the LPCXpresso does not tell us that bytes written are less than program size.


Please explain:
- If the application does not fit in the memory for the selected MCU, the linker will generate an error
- if the application does not fit in the flash when trying to download, the debugger will report an error

So, I do not know what you mean...
0 Kudos

494 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MSalvati on Fri Feb 13 04:22:30 MST 2015
Well thank you very much for your replies !
I think I finally found the problem: Not enough memory. A small change in a #define leaded to program rise up to 40k. Last time it was tested it seems to have been flashed on a LPC1115 target, so this wasn't a problem.
A very basic mistake, but program used to fit in the 1114. Probably the memory mismatch leaded to a stack corruption. It's such a pity that the LPCXpresso does not tell us that bytes written are less than program size.


I'm moving to LPC1115, thank you for your help R2D2!
0 Kudos

494 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Feb 12 09:11:03 MST 2015
Sorry, I can't debug a Version 6 CMSIS1.3 workspace  :((

I would recommend to install the actual LPCXpresso, create a new workspace and import your project.

If the hard fault does not disappear, start to reduce your project and post it again...   
0 Kudos

494 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MSalvati on Thu Feb 12 08:12:35 MST 2015
Sorry, I'm using LPC1114/302. LPCXpresso version v6.1.0 (didn´t update further as I got a WinXP machine, NXP no longer supports it, so I didn't bother in upgrading).

I'll upload the whole workspace, the proyect is BATCHG ExpansionBoardInterface inside the .rar file. (There's probably plenty stuff you don't need, but just to be sure). It's a 10MB file.

int main(void){
uint8_t continuar=1,depurar=0;
struct sEventoTecla ev;
uint8_t continuar_a_calibracion;

SystemInit(); 
LED_init();  // Here is the hard fault 
inicializarLedsEstadoCarga();
        ... (continues) 
        



So this is LED_init():

void LED_init(void){
uint8_t k;

leds[0].port=0;
leds[0].bit=3;

leds[1].port=0;
//leds[1].bit=5;
leds[1].bit=4;

leds[2].port=0;
//leds[2].bit=4; 
leds[2].bit=5; 

#if CONFIG_ENABLE_EXTRA_LEDS==1
leds[3].port=2;
leds[3].bit=7;

leds[4].port=2;
leds[4].bit=8;

leds[5].port=2;
leds[5].bit=9;

leds[6].port=2;
leds[6].bit=10;

leds[7].port=3;
leds[7].bit=3;

LPC_IOCON->R_PIO1_1=0x01|0<<3; 
LPC_IOCON->PIO1_4=1<<3;


#endif

for (k=0;k smaller than NLED;k++){
GPIOSetDir(leds[k].port,leds[k].bit,1);// HERE is where hard fault happens. Pointer should be poiting 0x500n 0000, n:0,1,2,3
GPIOSetValue(leds[k].port,leds[k].bit,0);
leds[k].value=0;
leds[k].blink=0;
leds[k].nblink=0;
}
}




Thank you !!

EDIT: Something goes wrong in code format in the post, so I modified the smaller than symbol.
EDIT2: I once succeeded in programming the MCU without problems, with the same code. The code I'm uploading is the one which months ago worked, it's a backup, but now doesn't work either. Very strange to me
0 Kudos

494 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Feb 12 07:39:16 MST 2015
Which LPCXpresso version are you using? And which MCU?

Could be useful if you post your project  :)
0 Kudos