title: FreeRTOS - Stack corruption on STM32F4
body: <p>I am currently having problems with what I think is stack corruption of some error of configuration while running FreeRTOS on an STM32F407 target.</p>
  
  <p>I have looked at <a href="https://stackoverflow.com/questions/14959663/freertos-stack-corruption-on-stm32f4-with-gcc">FreeRTOS stack corruption on STM32F4 with gcc</a> but got no help there.</p>
  
  <p>The application runs two tasks and relies on one CAN interrupt. The workflow is as follows:</p>
  
  <ol>
  <li>The two tasks, network_task and app_task is created along with two queues, raw_msg_queue and app_msg_queue. The CAN interrupt is also set up.</li>
  <li>The network_task has the highest priority and starts waiting on the raw_msg_queue, indefinitely.</li>
  <li>The app_task is next and starts waiting on the app_msg_queue.</li>
  <li>The CAN interrupt then triggers because of an external event, adding a CAN message to the raw_msg_queue.</li>
  <li>The network_task wakes up, process the message, adds the processed message to the app_msg_queue and then continues to wait on the raw_msg_queue.</li>
  <li>The app_task wakes up and I get a hard fault.</li>
  </ol>
  
  <p>The thing is that I have wrapped the calls that app_task makes to xQueueReceive in two steps because of end-user convenience and portability. The app_task total function chain is that it calls network_receive(..) -> os_queue_receive(..) -> xQueueReceive(..). This works well, but when it returns from xQueueReceive(..) it only manages to return to os_queue_receive(..) before it returns to a seemingly random memory location and i get a hard-fault.</p>
  
  <p>The stack sizes should be adequate and are set to 2048 for both, all large data structures are passed around as pointers.</p>
  
  <p>I am running my code on two STM32F407. FreeRTOS is at version 7.4.2, the latest at the time of writing.</p>
  
  <p>I am really hoping that someone can help me out here!</p>