<?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: KDS/KSDK K20 USB Driver Mutex Problem in Kinetis Software Development Kit</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KDS-KSDK-K20-USB-Driver-Mutex-Problem/m-p/507853#M5112</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Issac&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the quick response.&amp;nbsp; I tried the first option of excluding fsl_misc_utilities.c and it worked.&amp;nbsp; I no longer see null mutex pointers in the lock and unlock functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was hoping it might also be a resolution for my other USB Driver issue, see&amp;nbsp; &lt;A href="https://community.nxp.com/thread/384023"&gt;USB Driver Issues on K20 with KDS/KSK demo code&lt;/A&gt;&amp;nbsp; but I still have this other problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am struggling to get the USB HID Driver working for two endpoints (one is fine) using PE for a K20 processor.&amp;nbsp; Any help you can provide with this would be much appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sean&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 23 Jan 2016 10:22:24 GMT</pubDate>
    <dc:creator>seanbolton</dc:creator>
    <dc:date>2016-01-23T10:22:24Z</dc:date>
    <item>
      <title>KDS/KSDK K20 USB Driver Mutex Problem</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KDS-KSDK-K20-USB-Driver-Mutex-Problem/m-p/507851#M5110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using KDS 3.0.0 and KSDK 1.3.0 on a Windows 10 platform developing for a Kinetis K20&amp;nbsp;&amp;nbsp; MK20DX256VLK10&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I select the Processor Expert Demo USB HID code the resultant code always crashes on startup when calling OSA_MutexLock()&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The processor is halted in the asset(pMutex);&amp;nbsp;&amp;nbsp; as the pMutex pointer is NULL.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I add some code to check for and bypass null pMutex pointers then the code runs fine and the USB Demo works as expected.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I added to the start of the Lock and Unlock functions.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;osa_status_t OSA_MutexLock(mutex_t *pMutex, uint32_t timeout)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;{&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#if 1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp; // SEAN:&amp;nbsp; Check for null pointer and return as otherwise CPU hangs in the assert&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( pMutex == NULL )&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nullMutexLockCounter++ ;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return kStatus_OSA_Idle;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#endif&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#if (FSL_OSA_BM_TIMER_CONFIG != FSL_OSA_BM_TIMER_NONE)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t currentTime;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#endif&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert(pMutex);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;osa_status_t OSA_MutexUnlock(mutex_t *pMutex)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;{&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#if 0&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp; // SEAN:&amp;nbsp; Check for null pointer and return as otherwise CPU hangs in the assert&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( pMutex == NULL )&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nullMutexUnlockCounter++ ;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return kStatus_OSA_Success;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#endif&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;assert(pMutex);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can also see from the counters I added that the Lock and Unlock is called continously with a null pointer.&amp;nbsp; This would suggest a mutex needed by the FSL USB Driver is not getting created on initialisation.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is a screenshot showing the stack trace when the processor crashes in the mutex call.&amp;nbsp; Also my modified fsl_os_abstraction_bm.c&amp;nbsp; file.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This problem might be related to my other USB Issue (that of adding a 2nd endpoint) as described in thread 384023&amp;nbsp; &lt;A _jive_internal="true" data-containerid="11234" data-containertype="14" data-objectid="384023" data-objecttype="1" href="https://community.nxp.com/thread/384023"&gt;USB Driver Issues on K20 with KDS/KSK demo code&lt;/A&gt; &lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My workaround works but could there be an underlying problem if the USB Driver cannot correctly create and use its mutex?&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Sean&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-338607"&gt;fsl_os_abstraction_bm_modified.c.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jan 2016 18:20:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KDS-KSDK-K20-USB-Driver-Mutex-Problem/m-p/507851#M5110</guid>
      <dc:creator>seanbolton</dc:creator>
      <dc:date>2016-01-21T18:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: KDS/KSDK K20 USB Driver Mutex Problem</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KDS-KSDK-K20-USB-Driver-Mutex-Problem/m-p/507852#M5111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Sean,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If fact, this problem&amp;nbsp; is related to allocation memory scheme.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In KSDK 1.3, when you use PEx, you are also importing the fsl_misc_utilities.c file (located at: SDK &amp;gt; platform &amp;gt; utilities &amp;gt; src &amp;gt; fsl_misc_utilities.c) where _sbrk function is declared and it is used to allocate memory. However, there is no definition for HEAP size so this function cannot allocate memory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In USB stack, a mutex is created and it calls the _sbrk function, but, like this function does not define HEAP size, there is no memory to be used and mutex allocation fails (But USB stack does not uses a warning or validate if Mutex was created correctly and it never takes care about it, fortunately, this bug has been resolved in future releases).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So there are two different ways to solve this issue:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt; To use _sbrk function defined by default (and not in fsl_misc_utilities) where HEAP size is defined.&lt;/LI&gt;&lt;LI&gt;use fsl_misc_utilities but add a HEAP size define in linker options.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For first solution, you will only need to "Exclude from Build..." the fsl_misc_utilities.c function. Right click under fsl_misc_utilities.c file and select the Exclude From builiding... option located in Resource Configurations. After this, compile the project again and it should work.&lt;/P&gt;&lt;P style="text-align: center;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Exclude from building.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/56148i9A78340B33BD7263/image-size/large?v=v2&amp;amp;px=999" role="button" title="Exclude from building.jpg" alt="Exclude from building.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="text-align: center;"&gt;&lt;/P&gt;&lt;P&gt;The second solution is to add a HEAP size definition in linker configuration, right click under project and select "properties", then, on C/C++ Build, select the Settings option and then locate Cross ARM C++ Linker. In this section, you can see the Miscellaneous option and a field where you can add next definiton -Xlinker --defsym=__heap_size__=0x400. Add this HEAP definition and then compile the project again and it should work without excluding fsl_misc_utilities.c file.&lt;/P&gt;&lt;P style="text-align: center;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Add Linker definition for HEAP size.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/56185iB8037D99D06774F1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Add Linker definition for HEAP size.jpg" alt="Add Linker definition for HEAP size.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="text-align: justify;"&gt;&lt;/P&gt;&lt;P style="text-align: justify;"&gt;I hope this can help you,&lt;/P&gt;&lt;P style="text-align: justify;"&gt;Best Regards,&lt;/P&gt;&lt;P style="text-align: justify;"&gt;Isaac&lt;/P&gt;&lt;P&gt;----------------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;/P&gt;&lt;P&gt;----------------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jan 2016 21:52:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KDS-KSDK-K20-USB-Driver-Mutex-Problem/m-p/507852#M5111</guid>
      <dc:creator>isaacavila</dc:creator>
      <dc:date>2016-01-22T21:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: KDS/KSDK K20 USB Driver Mutex Problem</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KDS-KSDK-K20-USB-Driver-Mutex-Problem/m-p/507853#M5112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Issac&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the quick response.&amp;nbsp; I tried the first option of excluding fsl_misc_utilities.c and it worked.&amp;nbsp; I no longer see null mutex pointers in the lock and unlock functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was hoping it might also be a resolution for my other USB Driver issue, see&amp;nbsp; &lt;A href="https://community.nxp.com/thread/384023"&gt;USB Driver Issues on K20 with KDS/KSK demo code&lt;/A&gt;&amp;nbsp; but I still have this other problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am struggling to get the USB HID Driver working for two endpoints (one is fine) using PE for a K20 processor.&amp;nbsp; Any help you can provide with this would be much appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sean&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Jan 2016 10:22:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KDS-KSDK-K20-USB-Driver-Mutex-Problem/m-p/507853#M5112</guid>
      <dc:creator>seanbolton</dc:creator>
      <dc:date>2016-01-23T10:22:24Z</dc:date>
    </item>
  </channel>
</rss>

