PIC32 Release vs Debug problem

anonymous wrote on Monday, June 11, 2012:

I’m having a strange problem. I have an application that uses FreeRTOS and I’ve been building debug versions on MPLAB-X for a couple of months now. I switched to a release build today and the program builds but stops running after starting the scheduler. I’ve stripped out all of my code except the toggling of an LED when a queue times out in the main loop. There is now only one task running with a single queue. If I switch to a debug build, it works fine. It’s a newer processor from Microchip, the PIC32MX250F128D. I have another application for a different client that does not use FreeRTOS and it builds and deploys a release version with no problems. I have the Dotstack Bluetooth stack in the app that doesn’t work in release mode but I have it commented out for now. I know it’s probably something stupid that I’m missing but… I upgraded to the latest stable build of FreeRTOS, V 7.1.1 and that didn’t fix the problem.  I recently upgraded the compiler to the new xC32 compiler and have tried it and the 2.02 version of the C32 compiler and neither one works. Same symptoms, builds fine, stops after starting up the task scheduler.

Any ideas? Thanks in advance…

edwards3 wrote on Monday, June 11, 2012:

XC32 is GCC right? How far up did you crank the optimization? I have no direct experience of that particular compiler, but it is not uncommon for GCC to be overly optimistic at the top optimization levels. What happens if you optimize at O2? There will not be much difference between O2 and O3 in performance anyway.

rtel wrote on Monday, June 11, 2012:

I have just tried the following setup:

PIC32MX460
(X)C32 V2.02
Optimisation set to -Os
Release build
Standard FreeRTOS PIC32 demo running on an Explorer 16 board.

So far, everything is running without any errors being indicated…it has been running since about ten minutes after your post and is still running on the desk next to me now.

How long is yours taking to fall over?

Regards.

anonymous wrote on Tuesday, June 12, 2012:

I have optimizations turned off for now. I don;t usually turn them on until everything is up and running solid.

My code runs until I call xQueueReceive( xExecQueue, &xNewMessage, 10 / portTICK_RATE_MS );

It never returns in release mode but works fine in debug mode.

I found another thread on this forum from ulmus71 who is having the same problem with a different PIC32 part.

anonymous wrote on Tuesday, June 12, 2012:

This is the line of code I’m using:

        if ( xQueueReceive( xExecQueue, &xNewMessage, 10 / portTICK_RATE_MS ) == pdTRUE )
        {
        }

Just for clarification…

rtel wrote on Tuesday, June 12, 2012:

So if not the optimisation level, what is different between your debug and release builds?

Regards.

anonymous wrote on Tuesday, June 12, 2012:

Same linker file. I have not set anything different between the debug and release modes. What do you think the problem is related to? It seems as if the timer isn’t running that is used for the scheduler.

rtel wrote on Tuesday, June 12, 2012:

If the debug build works, but the release build does not work, there must be a difference between the two.  I’m afraid I cannot guess what that might be - you have both builds in front of you and I don’t.  Maybe you could look at the command line generated by two builds (shown as the code builds) to see what the differences are.

Regards.

anonymous wrote on Wednesday, June 13, 2012:

Using a bit twiddler to toggle an LED I managed to confirm my suspicion. Timer 1 is used by the FreeRTOS scheduler and is not working properly in the release build. I put the LED toggle in the starting of the timer and the code gets there. If I move it to the T1 interrupt handler, it never gets there. Interrupts are enabled because my timer 2 interrupt will toggle the LED but the timer 1 interrupt never fires. I’ll take a look at the command lines next…. 

anonymous wrote on Tuesday, July 03, 2012:

I found the problem. It turned out to be the Bluetooth stack, which required an update to be used with the XC32 compiler. Even though I commented out it’s use in my first testing, it had to be removed entirely from the project. I received an update from the stack vendor and everything is happy now.