<?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: program randomly stucks (Kinetis, CodeWarrior) in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486106#M29880</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the function is simply moved so that it is at a different address (move it to end of the file it is in for example), does anything change?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Dec 2015 16:45:21 GMT</pubDate>
    <dc:creator>bobpaddock</dc:creator>
    <dc:date>2015-12-18T16:45:21Z</dc:date>
    <item>
      <title>program randomly stucks (Kinetis, CodeWarrior)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486103#M29877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a problem with a program that randomly stucks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MCU: Kinetis K10DX32&lt;/P&gt;&lt;P&gt;bare metal project&lt;/P&gt;&lt;P&gt;CodeWarrior Development Studio 10.6&lt;/P&gt;&lt;P&gt;ARM Ltd. Windows GCC C compiler&lt;/P&gt;&lt;P&gt;ARM Ltd. GCC Build Tools Version: 4.7.3&lt;/P&gt;&lt;P&gt;Processor Expert&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;optimization level: optimize size (-Os)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;memory usage:&lt;/P&gt;&lt;P&gt;section size addr&lt;/P&gt;&lt;P&gt;.interrupts 248 0&lt;/P&gt;&lt;P&gt;.cfmprotect 16 1024&lt;/P&gt;&lt;P&gt;.text 25088 1040&lt;/P&gt;&lt;P&gt;.ARM 8 26128&lt;/P&gt;&lt;P&gt;.bss 2364 536866816&lt;/P&gt;&lt;P&gt;.romp 24 536869180&lt;/P&gt;&lt;P&gt;._user_heap_stack 1536 536869204&lt;/P&gt;&lt;P&gt;.ARM.attributes 51 0&lt;/P&gt;&lt;P&gt;.debug_info 43710 0&lt;/P&gt;&lt;P&gt;.debug_abbrev 10665 0&lt;/P&gt;&lt;P&gt;.debug_loc 10922 0&lt;/P&gt;&lt;P&gt;.debug_aranges 2104 0&lt;/P&gt;&lt;P&gt;.debug_line 14453 0&lt;/P&gt;&lt;P&gt;.debug_str 7221 0&lt;/P&gt;&lt;P&gt;.comment 121 0&lt;/P&gt;&lt;P&gt;.debug_frame 4284 0&lt;/P&gt;&lt;P&gt;Total 122815&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;problem description:&lt;/P&gt;&lt;P&gt;I have a nearly finished project with a quite complex program, all the functions are working well.&lt;/P&gt;&lt;P&gt;In the last time the program randomly stucks at a certain point, but it has not really crashed, because interrupts are still working.&lt;/P&gt;&lt;P&gt;After some seconds of hanging the watchdog resets the program.&lt;/P&gt;&lt;P&gt;The frequency of occurrence can differ from device to device, maybe depending on the working situation. But even worth, it varies with the code size.&lt;/P&gt;&lt;P&gt;A device that was stuck every five minutes before, was working for hours after I added some code lines in another context.&lt;/P&gt;&lt;P&gt;So changing the code size can improve or worsen the situation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was able to find out the line where the process stucks, it's a comparison of a global variable with a function parameter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint8_t myglobalvar;&lt;/P&gt;&lt;P&gt;void myFunc(uint8_t myparam)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (myparam==myglobalvar) { // here it stucks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // some other action ...&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;assembler listing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1216 .section .text.myFunc,"ax",%progbits&lt;/P&gt;&lt;P&gt;1217 .align 1&lt;/P&gt;&lt;P&gt;1218 .global myFunc&lt;/P&gt;&lt;P&gt;1219 .thumb&lt;/P&gt;&lt;P&gt;1220 .thumb_func&lt;/P&gt;&lt;P&gt;1222 myFunc:&lt;/P&gt;&lt;P&gt;1223 .LFB15:&lt;/P&gt;&lt;P&gt;1455:../Sources/xyz.c ****&lt;/P&gt;&lt;P&gt;1456:../Sources/xyz.c **** void myFunc(uint8_t myparam)&lt;/P&gt;&lt;P&gt;1457:../Sources/xyz.c **** {&lt;/P&gt;&lt;P&gt;1224 .loc 1 1457 0&lt;/P&gt;&lt;P&gt;1225 .cfi_startproc&lt;/P&gt;&lt;P&gt;1226 @ args = 0, pretend = 0, frame = 0&lt;/P&gt;&lt;P&gt;1227 @ frame_needed = 0, uses_anonymous_args = 0&lt;/P&gt;&lt;P&gt;1228 @ link register save eliminated.&lt;/P&gt;&lt;P&gt;1229 .LVL77:&lt;/P&gt;&lt;P&gt;1458:../Sources/xyz.c **** if (myparam==myglobalvar) {&lt;/P&gt;&lt;P&gt;1230 .loc 1 1458 0&lt;/P&gt;&lt;P&gt;1231 0000 094B ldr r3, .L117&lt;/P&gt;&lt;P&gt;1232 0002 1978 ldrb r1, [r3, #0] @ zero_extendqisi2&lt;/P&gt;&lt;P&gt;1233 0004 8142 cmp r1, r0&lt;/P&gt;&lt;P&gt;1234 0006 0DD0 beq .L104&lt;/P&gt;&lt;P&gt;1235 .L112:&lt;/P&gt;&lt;P&gt;1459:../Sources/xyz.c **** return;&lt;/P&gt;&lt;P&gt;1460:../Sources/xyz.c **** }&lt;/P&gt;&lt;P&gt;// some other action ...&lt;/P&gt;&lt;P&gt;1257 .L117:&lt;/P&gt;&lt;P&gt;1258 0028 00000000 .word myglobalvar&lt;/P&gt;&lt;P&gt;1259 002c 00B00340 .word 1073983488&lt;/P&gt;&lt;P&gt;1260 .cfi_endproc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not so firm with assembler code, maybe someone can see the problem at first sight.&lt;/P&gt;&lt;P&gt;It's also possible that the line itself is ok, but some other code is corrupting the memory or SP or something else.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Dec 2015 13:53:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486103#M29877</guid>
      <dc:creator>stoneface</dc:creator>
      <dc:date>2015-12-16T13:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: program randomly stucks (Kinetis, CodeWarrior)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486104#M29878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;J&amp;amp;amp;amp;ouml;rg Volger wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;optimization level: optimize size (-Os)&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P&gt;In the last time the program randomly stucks at a certain point, but it has not really crashed, because interrupts are still working.&lt;/P&gt;&lt;P&gt;So changing the code size can improve or worsen the situation.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P&gt;uint8_t myglobalvar;&lt;/P&gt;&lt;P&gt;void myFunc(uint8_t myparam)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (myparam==myglobalvar) { // here it stucks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // some other action ...&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P&gt;I'm not so firm with assembler code, maybe someone can see the problem at first sight.&lt;/P&gt;&lt;P&gt;It's also possible that the line itself is ok, but some other code is corrupting the memory or SP or something else.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try -O2 in place of -Os and see if that makes any difference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The symptoms are that of a stack overflow.&amp;nbsp; It is where the code that is 'returning' to which is likely invalid that makes it 'get stuck'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you get a back trace?&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;If your current tools can not do it, look in to using USBDM with GDB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Interrupts can often run just fine when the foreground task is lost.&amp;nbsp; This is why the watchdog shall never be refreshed inside interrupts.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Dec 2015 13:33:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486104#M29878</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2015-12-17T13:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: program randomly stucks (Kinetis, CodeWarrior)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486105#M29879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After some more debugging I found out that the above mentioned line is not the problem (... what led me there?).&lt;/P&gt;&lt;P&gt;The new suspect a is function that changes the settings of PDB and ADC (initial setup of PDB and ADC is made in Processor Expert).&lt;/P&gt;&lt;P&gt;If I omit this function the problem disappears. Of cause I need the function for a perfect measurement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the content of the function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*************************************************************************************************&lt;/P&gt;&lt;P&gt;// stop conversions&lt;/P&gt;&lt;P&gt;ADC0_SC1A &amp;amp;= ~(ADC_SC1_AIEN_MASK);&lt;/P&gt;&lt;P&gt;ADC0_SC1B &amp;amp;= ~(ADC_SC1_AIEN_MASK);&lt;/P&gt;&lt;P&gt;// stop PDB&lt;/P&gt;&lt;P&gt;PDB0_SC &amp;amp;= ~(PDB_SC_PDBEN_MASK)&lt;/P&gt;&lt;P&gt;// clear COCO flags by reading result registers&lt;/P&gt;&lt;P&gt;result[0] = ADC0_RA;&lt;/P&gt;&lt;P&gt;result[1] = ADC0_RB;&lt;/P&gt;&lt;P&gt;// set PDB modulus&lt;/P&gt;&lt;P&gt;PDB0_MOD = PDB_MOD_MOD(sm);&lt;/P&gt;&lt;P&gt;// set PDB trigger delay&lt;/P&gt;&lt;P&gt;PDB0_CH0DLY1 = PDB_DLY_DLY(sm/2);&lt;/P&gt;&lt;P&gt;// set hardware average&lt;/P&gt;&lt;P&gt;switch (avgs) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case AVGSSTD: { // averaging with 32 samples&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ADC0_SC3 |= (ADC_SC3_AVGE_MASK|ADC_SC3_AVGS(0x03));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case AVGSLOW: { // averaging with 16 samples&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ADC0_SC3 &amp;amp;= (uint32_t)~(uint32_t)(ADC_SC3_AVGS(0x03));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ADC0_SC3 |= (ADC_SC3_AVGE_MASK|ADC_SC3_AVGS(0x02));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case AVGSDIS: { // averaging off&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ADC0_SC3 &amp;amp;= ~(ADC_SC3_AVGE_MASK);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;// enable converter interrupt again&lt;/P&gt;&lt;P&gt;ADC0_SC1A |= (ADC_SC1_AIEN_MASK);&lt;/P&gt;&lt;P&gt;ADC0_SC1B |= (ADC_SC1_AIEN_MASK);&lt;/P&gt;&lt;P&gt;// enable PDB&lt;/P&gt;&lt;P&gt;PDB0_SC |= PDB_SC_PDBEN_MASK;&lt;/P&gt;&lt;P&gt;// load registers&lt;/P&gt;&lt;P&gt;PDB0_SC |= PDB_SC_LDOK_MASK;&lt;/P&gt;&lt;P&gt;// restart counter&lt;/P&gt;&lt;P&gt;PDB0_SC |= PDB_SC_SWTRIG_MASK);&lt;/P&gt;&lt;P&gt;*************************************************************************************************&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What happens? After calling the function the next check of the COCO flag in the typical loop like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((ADC0_SC1A&amp;amp;ADC_SC1_COCO_MASK)==0) {}&lt;/P&gt;&lt;P&gt;can fail if the conversion remains not completed.&lt;/P&gt;&lt;P&gt;Normally it works, but sometimes the flag remains forever 0 after exiting the above function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there somewhere a wrong order of the commands or could it be a timing problem?&lt;/P&gt;&lt;P&gt;(Quite confusing is the fact that changing the code somewhere else can influence the quantity of errors)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW: I ported the project to a MCU with double memory, still errors. Then I compiled it without any optimization, still errors.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Dec 2015 14:33:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486105#M29879</guid>
      <dc:creator>stoneface</dc:creator>
      <dc:date>2015-12-18T14:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: program randomly stucks (Kinetis, CodeWarrior)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486106#M29880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the function is simply moved so that it is at a different address (move it to end of the file it is in for example), does anything change?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Dec 2015 16:45:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486106#M29880</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2015-12-18T16:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: program randomly stucks (Kinetis, CodeWarrior)</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486107#M29881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Bob,&lt;/P&gt;&lt;P&gt;thanks for your idea, unfortunately it didn't help. I moved the function to other places inside the file, also to another file.&lt;/P&gt;&lt;P&gt;My impression is that the way of stopping and starting PDB and ADC must be the problem. Maybe it's a wrong order or a missing setting.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Dec 2015 07:30:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/program-randomly-stucks-Kinetis-CodeWarrior/m-p/486107#M29881</guid>
      <dc:creator>stoneface</dc:creator>
      <dc:date>2015-12-21T07:30:44Z</dc:date>
    </item>
  </channel>
</rss>

