# Pic32mz issues with free RTOS

**URL:** <https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206>\
**Category:** Microchip\
**Created:** [February 18, 2024, 3:12pm UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206 "2024-02-18T15:12:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suleman](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@Suleman](https://forums.freertos.org/u/Suleman)\
**Post date:** [February 18, 2024, 3:12pm UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206/1 "2024-02-18T15:12:52Z")

</div>

I am facing problems while using free RTOS with PIC32MZ2048EFM100… it works well and then all of a sudden when the code is modified it just fails to work although there is no syntax or logical error in the project… for example when a variable is added it stops working and gives refill exception and once a dummy variable is added along with it starts working… it takes a lot of time to code with these issues… has anyone else faced these issues? Has anyone resolved such issue kindly help… thankyou

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [February 18, 2024, 8:07pm UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206/2 "2024-02-18T20:07:01Z")

</div>

sounds like a stack problem. Either you write over your stack (size too small), or you try to pass a pointer pointing into a task stack to another task , or you write past the boundary of a local array, or… impossible to say without seeing code. Make a minimal code example showing the problem and post the code here, or on github.

---

<div class="post-metadata">

**Author:** ![joshzarr](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@joshzarr](https://forums.freertos.org/u/joshzarr)\
**Post date:** [February 21, 2024, 3:02pm UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206/3 "2024-02-21T15:02:30Z")

</div>

This might be a long shot, but maybe give this suggestion a try?

> [@configLIST\_VOLATILE required - Missing configASSERT in listREMOVE\_ITEM](https://forums.freertos.org/t/configlist-volatile-required-missing-configassert-in-listremove-item/16400):
>
> Using the provided sample code for the PIC32 platform and FreeRTOS v202112.00. I ran into an issue in tasks.c when enabling the compiler optimizations (XC32 v4.00 compiler, -O2 optimization). The exception happens in xTaskResumeAll() when the listREMOVE\_ITEM macro tries to remove an item with a null pointer as the container. The macro creates a pointer pxList and de-references it without checking if it is NULL, causing an exception. In my case, it seemed to be caused by an aggressive compiler …

I would be very curious if this helps resolve the problem you are seeing.

---

<div class="post-metadata">

**Author:** ![maharvey](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@maharvey](https://forums.freertos.org/u/maharvey)\
**Post date:** [February 21, 2024, 6:06pm UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206/4 "2024-02-21T18:06:53Z")

</div>

Definitely for PIC32 you will want to add this to your FreeRTOS config file:  
`#define configLIST_VOLATILE volatile`

Other things you have to consider:  
1: Timer1 is used as the tick timer. make sure to enable its clock.  
2: Using the base examples, make sure to divide the peripheral clocks to 40MHz as this is what the sample code expects.  
3: Disable the shadow registers feature  
4: If you have any floating point operation in the task, you have to call portTASK\_USES\_FLOATING\_POINT() at the beginning of your task so the floating point registers are saved on context switch.

---

<div class="post-metadata">

**Author:** ![Suleman](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@Suleman](https://forums.freertos.org/u/Suleman)\
**Post date:** [March 9, 2024, 7:08am UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206/5 "2024-03-09T07:08:29Z")

</div>

I have narrowed down the issues and it looks like an alignment issue when I use align attribute it starts working… but I want a fix so that I don’t have align them manually is there any option which I can set and it can automatically align the array or structures, etc.

Another thing which I have noticed is that when data memory is multiple of 16 it works fine but other than that it stops working…

I have tried to explore manual memory allocation of pickit but I am unable to find a way to sort this issue.

Any help will be appreciated

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 12, 2024, 7:43am UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206/6 "2024-03-12T07:43:19Z")

</div>

> [@Suleman](#):
>
> it looks like an alignment issue when I use align attribute it starts working…

Where are you adding the alignment attribute?

> [@Suleman](#):
>
> when data memory is multiple of 16 it works fine but other than that it stops working…

Do you mean the size of the data section in the linker script or something else?

---

<div class="post-metadata">

**Author:** ![Suleman](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@Suleman](https://forums.freertos.org/u/Suleman)\
**Post date:** [March 13, 2024, 11:43am UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206/7 "2024-03-13T11:43:31Z")

</div>

I use attribute align() with variables

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 13, 2024, 2:59pm UTC](https://forums.freertos.org/t/pic32mz-issues-with-free-rtos/19206/8 "2024-03-13T14:59:19Z")

</div>

Which variables do you add this attribute to? Can you share code?
