# Demo Poject Run Issue

**URL:** <https://forums.freertos.org/t/demo-poject-run-issue/11263>\
**Category:** Kernel\
**Created:** [December 3, 2020, 6:39pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263 "2020-12-03T18:39:29Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 3, 2020, 6:39pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/1 "2020-12-03T18:39:29Z")

</div>

Hello,

First of all, I am a newbie. I thought it was important for you to know.

I have just started reading the FreeRTOS manual where it states to start with a Demo project which should run immediately without issues.

I selected the demo project CORTEX\_M4F\_STM32F407ZG-SK from the FreeRTOS folder and opened it in IAR Workbench.

I adjusted one setting in the project options, i.e. i am using the simulator instead of a real board. I can build the code. However, if i run the code, the code gets stuck inside the function xPortStartScheduler, more specially at the line

configASSERT( ( portMAX\_PRIGROUP\_BITS - ulMaxPRIGROUPValue ) == configPRIO\_BITS );

I have seen that others also have stumbled on similar issues

> <https://github.com/beckus/qemu_stm32/issues/35>
>
> Hi,
> When starting FreeRTOS port for STM32f103c8 an assert is fired in BaseType\_t xPortStartScheduler( void )
> (Middlewares/Third\_Party/FreeRTOS/Source/portable/GCC/ARM\_CM3/port.c:310 if generated with STM32CubeMX).
> code that breaks:
> defined...

Therefore I tried to change the following line in the FreeRTOSconfig.h file:  
#define configPRIO\_BITS 4  
changed into:  
#define configPRIO\_BITS 8

With this setting the demo project runs further but now gets stuck at line  
svc 0  
in the portasm.s file.

My goal is just to make the demo code running and gradually learn my way into FreeRTOS. WOuld be pleased if you could assist in finding a possible cause.

Thank you in advance

Kind regards

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 3, 2020, 6:49pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/2 "2020-12-03T18:49:31Z")

</div>

You don’t mention which simulator you are using, but if it is QEMU as per the link below then we have found the simulator does not model the interrupt controller accurately. For example, the device being modelled in this project has three priority bits, but when run under QEMU we have to set the configuration to say it has 8 priority bits: [https://github.com/FreeRTOS/FreeRTOS/blob/master/FreeRTOS/Demo/CORTEX\_LM3S6965\_GCC\_QEMU/FreeRTOSConfig.h#L96](https://github.com/FreeRTOS/FreeRTOS/blob/master/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/FreeRTOSConfig.h#L96)

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 3, 2020, 7:38pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/3 "2020-12-03T19:38:05Z")

</div>

I actually don’t know. I am using the IAR workbench and in the project options, I chose under Debugger -\>Setup --\> Driver: Simulator .

But even if I use 8 like you mentioned , i get stuck at svc 0

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/3/31e85de9ebc8720e66cc743cbb24c690dcac13ea.png)

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 3, 2020, 8:35pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/4 "2020-12-03T20:35:33Z")

</div>

I think you will need to look up how to use interrupts with the IAR simulator in the IAR documentation.

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 3, 2020, 10:33pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/5 "2020-12-03T22:33:40Z")

</div>

Thank you for the hint. I looked up how I can monitor the SVC interrupts. It looks like the interrupts are being triggered continuously as the program counter is stuck. It seems like it can not enter the SVC handler as the breakpoint is never reached. Do you maybe have any idea why?

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/5/50925e8e9808c4d081e33278c454625d55b00b15.png)

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 4, 2020, 2:06am UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/6 "2020-12-04T02:06:09Z")

</div>

Have you installed the SVC handler? See the FAQ “my application compiles but does not run” on this page of the FAQ [https://www.freertos.org/FAQHelp.html](https://www.freertos.org/FAQHelp.html)

If you have installed the handler then my next port of call would be the IAR manual.

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 4, 2020, 10:28am UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/7 "2020-12-04T10:28:54Z")

</div>

Yes, the SVC Handler is installed by default in the DEMO project. Unfortunately i can not step into the svc instruction to see which handler is triggered. I must conclude that there is an issue in the simulator

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/9/9e679fedd772d862c4309d41884f90efe50dac64.png)

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 4, 2020, 10:29am UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/8 "2020-12-04T10:29:37Z")

</div>

I thank for your assistance.

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 4, 2020, 12:34pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/9 "2020-12-04T12:34:57Z")

</div>

Can i maybe ask one more question before we close this topic?

I noticed that the SVC interrupt is triggered but the interrupts are not serviced, i.e. they are pending. I tried to analyse the code and traced the function call chain which is like:

main function --\> vTaskStartScheduler() --\> xPortStartScheduler --\> StartFirstTask --\> svc

I noticed the following comment which disables interrupts in the vTaskStartScheduler. I am a little confused because of the comment. If interrupts are disabled, how can the SVC interrupt handling occur to start the first task?

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/a/a98fcefe167d08464c0c9b828541ae301a0fe6be.png)

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 4, 2020, 2:39pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/10 "2020-12-04T14:39:49Z")

</div>

I have done some further investigation.

I disabled the demo functionalities inside the main function and triggered an external SVC interrupt through the simulator. I was able to enter the SVC\_Handler. So I think there is actually something wrong in the code that disables interrupts?

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/3/3df535355672b7a044c4f7978d03ead3cdc8457e.png)

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 4, 2020, 2:42pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/11 "2020-12-04T14:42:49Z")

</div>

At least we can assume that the simulator is working correctly and the SVC\_Handler is installed correctly. I just don’t know why the svc 0 instruction in the startFirstTask does not have the same effect?

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 4, 2020, 3:03pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/12 "2020-12-04T15:03:48Z")

</div>

Finally I put an portEnable\_Interrupts(); instruction in the port.c file just before the StartFirstTask call and now the scheduler is starting and my tasks are executing.

Maybe somebody from your side can look into this topic further?

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/6/685cbf8495751d897de9444e79cc249c0d46f457.png)

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 4, 2020, 7:33pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/13 "2020-12-04T19:33:02Z")

</div>

> [@user3](#):
>
> Finally I put an portEnable\_Interrupts(); instruction in the port.c file just before the StartFirstTask

What is portEnable\_Interrupts() doing? Globally enabling interrupts or updating the BASEPRI register? If the former then you should probably get a fault if you execute and SVC instruction with interrupts disabled - the kernel code doesn’t disable interrupts it only manipulates BASEPRI so if you disable interrupts then you should enable again before starting the scheduler. BASEPRI on the other hand is deliberately set when the scheduler is started, and then reset to zero [inside the SVC handler](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/master/portable/IAR/ARM_CM4F/portasm.s#L109).

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 5, 2020, 9:42am UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/14 "2020-12-05T09:42:54Z")

</div>

Sorry, the naming is indeed a bit confusing.  
I am using the macro form the portmacro.h file  
portENABLE\_INTERRUPTS() \_\_set\_BASEPRI( 0 )

But then I do not understand why I need to add this line to make it running. As I understand, when the scheduler is started, the interrupts are disabled/masked through the macro  
portDISABLE\_INTERRUPTS() which basically masks/disables all interrupts with priority \<= configMAX\_SYSCALL\_INTERRUPT\_PRIORITY through the call  
\_\_set\_BASEPRI( configMAX\_SYSCALL\_INTERRUPT\_PRIORITY );

And with the instruction I set the basepri back to 0.

I assume there must be something wrong with the priorities then? I can not seem to find the location where the interrupt priorities have been set in the DEMO projects?

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 5, 2020, 11:27am UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/15 "2020-12-05T11:27:59Z")

</div>

I think i found the problem.

As mentioned above, I was forced to set the following macro to 8 instead of the default 4.  
#define configPRIO\_BITS 8

However, doing this messes up the interrupt priorities as i see there are interdependencies e.g.  
#define configMAX\_SYSCALL\_INTERRUPT\_PRIORITY ( configLIBRARY\_MAX\_SYSCALL\_INTERRUPT\_PRIORITY \<\< (8 - configPRIO\_BITS) )

So changing the nr of bits to 8 leads to getting stuck at the SVC 0 call. Therefore I changed the nr of prio bits back to 4 and commented out the following check

#ifdef configPRIO\_BITS  
{  
/\* Check the FreeRTOS configuration that defines the number of  
\* priority bits matches the number of priority bits actually queried  
\* from the hardware. \*/  
configASSERT( ( portMAX\_PRIGROUP\_BITS - ulMaxPRIGROUPValue ) == configPRIO\_BITS );  
}  
#endif

In that case, the scheduler is able to start again with the SVC call. Does that seem feasible to you?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 5, 2020, 5:03pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/16 "2020-12-05T17:03:30Z")

</div>

I don’t think basepri should effect the SVC instruction (although the global interrupt flag will) - I would recommend trying on real hardware.

---

<div class="post-metadata">

**Author:** ![user3](https://avatars.discourse-cdn.com/v4/letter/u/ec9cab/32.png) [@user3](https://forums.freertos.org/u/user3)\
**Post date:** [December 6, 2020, 7:05pm UTC](https://forums.freertos.org/t/demo-poject-run-issue/11263/17 "2020-12-06T19:05:18Z")

</div>

I just started reading the FreeRTOS guide and hope that everything will get clearer as I progress through he guide. It was important for me to start with something that i can run without errors. This will allow me to experiment and change things and see what happens.  
I achieved that with your help. Thank you very much.
