<?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>LPC MicrocontrollersのトピックRe: FreeRTOS bug in xQueueGenericSendFromISR ?</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/FreeRTOS-bug-in-xQueueGenericSendFromISR/m-p/583011#M20798</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by alramlechner on Fri Aug 07 13:28:29 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;just found it. IRQ priority, which uses FreeRTOS API, must have lower priority than SysTick ... (&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.freertos.org%2Fa00110.html%23kernel_priority" rel="nofollow" target="_blank"&gt;http://www.freertos.org/a00110.html#kernel_priority&lt;/A&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 20:24:49 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T20:24:49Z</dc:date>
    <item>
      <title>FreeRTOS bug in xQueueGenericSendFromISR ?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/FreeRTOS-bug-in-xQueueGenericSendFromISR/m-p/583010#M20797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by alramlechner on Fri Aug 07 07:03:51 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;currently i am developing with the LPC1768 and the LPCOpen freertos_webserver project. i have extended the project with two things:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;a) CAN ISR&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b) an task (called CAN2LAN), that is working with an TCP connection&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the scenario is very simple: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if the CAN2LAN task receives an TCP connections, it creates the queue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the CAN ISR receives CAN Messages and puts them into a FreeRTOS queue (if the queue isn't null).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this is working fine. but doing some loadtests (here: sending 10 CAN messages per seconds via another CAN node), the system watchdog is resetting the processor in irregular intervals. so i changed the watchtdog to call ISR and not to reset de device. i had a look with the debugprobe and i see the following stack:&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;webserver_freertos.axf
Thread #1 &amp;lt;main&amp;gt; (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)
HardFault_Handler() at cr_startup_lpc175x_6x.c:324 0x1f4
&amp;lt;signal handler called&amp;gt;() at 0xfffffff1
uxListRemove() at list.c:202 0xc4bc
xTaskRemoveFromEventList() at tasks.c:1.985 0xd7d8
xQueueGenericSendFromISR() at queue.c:1.002 0xc9e4
CAN_IRQHandler() at can_task.c:269 0xe570
&amp;lt;signal handler called&amp;gt;() at 0xfffffff1
uxListRemove() at list.c:201 0xc4ba
xTaskIncrementTick() at tasks.c:1.646 0xd5d2
SysTick_Handler() at port.c:450 0xc660
&amp;lt;signal handler called&amp;gt;() at 0xfffffffd
prvPortStartFirstTask() at port.c:253 0xc55a
xPortStartScheduler() at port.c:330 0xc58a
0x0&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;after investigate some research, it seems clear, that this happens. but i don't know, what i did wrong.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the problem is the following (as far as i can see):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a) the CAN2LAN task is waiting (blocked)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b) the Systick_Handler gets called&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;c) the Systick_Handler decides, that the CAN2LAN task should be going into running state; so it removes the task from the waiting list (this happens here: uxListRemove() at list.c:201 0xc4ba)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;c) in uxListRemove there is one line, that setting the container (=List?) of the item to null:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;list.c:198&lt;/SPAN&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;pxItemToRemove-&amp;gt;pvContainer = NULL;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;d) now there is a CAN ISR (received new message)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;e) the qQueueGenericSendFromISR also tries to remove the CAN2LAN task from the waiting list and call's&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;f) uxListRemove() at list.c:202 0xc4bc&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;g) now the problem in uxListRemove(): this line&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;list.c:190 &lt;/SPAN&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;pxList = ( xList * ) pxItemToRemove-&amp;gt;pvContainer;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;returns null, because this item isn't (at this time) in any list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;that seems to force the HardFault_Handler getting called.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i thought, it should be safe, to call xQueueGenericSendFromISR() in the CAN ISR?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or: should the SysTick ISR running at higher priority, so that SysTick can interrupt CAN, but not in the other way?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;can anyone give me a hint, what ist going wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alram &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:24:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/FreeRTOS-bug-in-xQueueGenericSendFromISR/m-p/583010#M20797</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS bug in xQueueGenericSendFromISR ?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/FreeRTOS-bug-in-xQueueGenericSendFromISR/m-p/583011#M20798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by alramlechner on Fri Aug 07 13:28:29 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;just found it. IRQ priority, which uses FreeRTOS API, must have lower priority than SysTick ... (&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.freertos.org%2Fa00110.html%23kernel_priority" rel="nofollow" target="_blank"&gt;http://www.freertos.org/a00110.html#kernel_priority&lt;/A&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:24:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/FreeRTOS-bug-in-xQueueGenericSendFromISR/m-p/583011#M20798</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS bug in xQueueGenericSendFromISR ?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/FreeRTOS-bug-in-xQueueGenericSendFromISR/m-p/583012#M20799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Rob65 on Fri Sep 04 04:57:05 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had the exact same problem but it was not directly clear to me this had to do with interrupt priorities.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The system always gives the error in uxListRemove but not always with the stack frame you showed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It got stuck every 20 minutes or so but after changing the interrupt priorities it has been running fine for hours&amp;nbsp; :bigsmile: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, I should have noticed the remarks in FreeRTOSConfig.h:&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;/* The lowest priority. */
#define configKERNEL_INTERRUPT_PRIORITY ( 31 &amp;lt;&amp;lt; (8 - configPRIO_BITS) )
/* Priority 5, or 160 as only the top three bits are implemented. */
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
&lt;SPAN&gt;See &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.FreeRTOS.org%2FRTOS-Cortex-M3-M4.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html&lt;/A&gt;&lt;SPAN&gt;. */&lt;/SPAN&gt;
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( 5 &amp;lt;&amp;lt; (8 - configPRIO_BITS) )

/* Priorities passed to NVIC_SetPriority() do not require shifting as the
function does the shifting itself.&amp;nbsp; Note these priorities need to be equal to
or lower than configMAX_SYSCALL_INTERRUPT_PRIORITY - therefore the numeric
value needs to be equal to or greater than 5 (on the Cortex-M3 the lower the
numeric value the higher the interrupt priority). */&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:24:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/FreeRTOS-bug-in-xQueueGenericSendFromISR/m-p/583012#M20799</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:24:50Z</dc:date>
    </item>
  </channel>
</rss>

