<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: GPIO pointer strange issue in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535806#M11061</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MSalvati on Thu Feb 12 08:12:35 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;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).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca" style="border:1px solid black;background-color:#cacaca;"&gt; &lt;PRE&gt;int main(void){
uint8_t continuar=1,depurar=0;
struct sEventoTecla ev;
uint8_t continuar_a_calibracion;

SystemInit(); 
LED_init();&amp;nbsp; // &lt;STRONG&gt;Here &lt;/STRONG&gt;is the hard fault 
inicializarLedsEstadoCarga();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... (continues) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So this is LED_init():&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca" style="border:1px solid black;background-color:#cacaca;"&gt; &lt;PRE&gt;
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-&amp;gt;R_PIO1_1=0x01|0&amp;lt;&amp;lt;3; 
LPC_IOCON-&amp;gt;PIO1_4=1&amp;lt;&amp;lt;3;


#endif

for (k=0;k smaller than NLED;k++){
GPIOSetDir(leds[k].port,leds[k].bit,1);// &lt;STRONG&gt;HERE&lt;/STRONG&gt; 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;
}
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you !!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: Something goes wrong in code format in the post, so I modified the smaller than symbol.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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 &lt;SPAN class="lia-unicode-emoji" title=":disappointed_face:"&gt;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 19:35:14 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T19:35:14Z</dc:date>
    <item>
      <title>GPIO pointer strange issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535804#M11059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MSalvati on Thu Feb 12 07:24:24 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;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 !&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Now after days of debbuging I've come to this situation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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 :(.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Project has a &lt;/SPAN&gt;&lt;STRONG&gt;main.c&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;STRONG&gt;gpio.c&lt;/STRONG&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;STRONG&gt;gpio.h&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp; and &lt;/SPAN&gt;&lt;STRONG&gt;gpio.h&lt;/STRONG&gt;&lt;SPAN&gt; is included in both main and gpio source codes. &lt;/SPAN&gt;&lt;STRONG&gt;LPC11xx.h&lt;/STRONG&gt;&lt;SPAN&gt; is included in both as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The pointer, defined in &lt;/SPAN&gt;&lt;STRONG&gt;gpio.h&lt;/STRONG&gt;&lt;SPAN&gt; it is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;static LPC_GPIO_TypeDef (* const LPC_GPIO[4]) = { LPC_GPIO0, LPC_GPIO1, LPC_GPIO2, LPC_GPIO3 };&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;LPC_GPIOn is the position in memory 0x500n8000, as noted in UM10398.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So by now, I just want to access LPC_GPIO[0]-&amp;gt;DIR and store the number 0x08. The function in &lt;/SPAN&gt;&lt;STRONG&gt;gpio.c&lt;/STRONG&gt;&lt;SPAN&gt; which does this is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir )&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Which stores in LPC_GPIOn-&amp;gt;DIR the correct value&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When it gets into GPIOSetDir() pointer keeps pointing elsewhere (0x46bd50d1, for example) and then, expectedly, hard faults.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This happens in the very first lines of main.c, there is no other function call before, except for the &lt;/SPAN&gt;&lt;STRONG&gt;SystemInit()&lt;/STRONG&gt;&lt;SPAN&gt; function (which I assume you're familiar with, the one that sets PLL clocking etc, from LPC library) which remains unchanged.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help is welcome! If you need more data, please ask me, I'll post as soon as possible. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:35:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535804#M11059</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO pointer strange issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535805#M11060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by R2D2 on Thu Feb 12 07:39:16 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Which LPCXpresso version are you using? And which MCU?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could be useful if you post your project&amp;nbsp; :) &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:35:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535805#M11060</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO pointer strange issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535806#M11061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MSalvati on Thu Feb 12 08:12:35 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;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).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca" style="border:1px solid black;background-color:#cacaca;"&gt; &lt;PRE&gt;int main(void){
uint8_t continuar=1,depurar=0;
struct sEventoTecla ev;
uint8_t continuar_a_calibracion;

SystemInit(); 
LED_init();&amp;nbsp; // &lt;STRONG&gt;Here &lt;/STRONG&gt;is the hard fault 
inicializarLedsEstadoCarga();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... (continues) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So this is LED_init():&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca" style="border:1px solid black;background-color:#cacaca;"&gt; &lt;PRE&gt;
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-&amp;gt;R_PIO1_1=0x01|0&amp;lt;&amp;lt;3; 
LPC_IOCON-&amp;gt;PIO1_4=1&amp;lt;&amp;lt;3;


#endif

for (k=0;k smaller than NLED;k++){
GPIOSetDir(leds[k].port,leds[k].bit,1);// &lt;STRONG&gt;HERE&lt;/STRONG&gt; 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;
}
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you !!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: Something goes wrong in code format in the post, so I modified the smaller than symbol.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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 &lt;SPAN class="lia-unicode-emoji" title=":disappointed_face:"&gt;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:35:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535806#M11061</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO pointer strange issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535807#M11062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by R2D2 on Thu Feb 12 09:11:03 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry, I can't debug a Version 6 CMSIS1.3 workspace&amp;nbsp; :(( &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would recommend to install the actual LPCXpresso, create a new workspace and import your project. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If the hard fault does not disappear, start to reduce your project and post it again...&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:35:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535807#M11062</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO pointer strange issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535808#M11063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MSalvati on Fri Feb 13 04:22:30 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Well thank you very much for your replies !&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm moving to LPC1115, thank you for your help R2D2! &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:35:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535808#M11063</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO pointer strange issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535809#M11064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by lpcxpresso-support on Fri Feb 13 05:02:56 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt; It's such a pity that the LPCXpresso does not tell us that bytes written are less than program size. &lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please explain:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- If the application does not fit in the memory for the selected MCU, the linker will generate an error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- if the application does not fit in the flash when trying to download, the debugger will report an error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I do not know what you mean...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:35:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/GPIO-pointer-strange-issue/m-p/535809#M11064</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:35:16Z</dc:date>
    </item>
  </channel>
</rss>

