Requesting Freertos port code to CR-(4) series

Are you saying that executing the above instruction takes the control to prvTaskExitError? If yes, that does not seem correct as the above instruction does not alter PC. I am running out of ideas here - would you like to have a debugging session to debug this together. If yes, please DM me your email and some preferred time slots.

IRQ Handler takes care of that - FreeRTOS-Kernel/portable/GCC/ARM_CRx_No_GIC/portASM.S at main · FreeRTOS/FreeRTOS-Kernel · GitHub.

Hi Gaurav,
Yes that’s the observation i as seeing. i think we may not be calling “portSAVE_CONTEXT” as part of task context switching which i am checking more on this related to TCB access and then jumping to prvTaskExitError. Will let know if i found more info on this.
My mail id:- supreeth.i@synaptics.com

I have one quirey related to xTaskIncrementTick. In this there is api called as vApplicationTickHook. What code should we add here? any reference code can i get here

vApplicationTickHook will be called by each tick interrupt if configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be added here, but the tick hook is called from an interrupt context, so code must not attempt to block, and only the interrupt safe FreeRTOS API functions can be used .
You can use this as a reference from Posix simulator, which calls this user code

Does it mean you are modifying the FreeRTOS port code?

Do not add anything. Set configUSE_TICK_HOOK to 0 in your FreeRTOSConfig.h.

I had not mapped the timer interupt for invoking the task switch for setting the ulPortYieldRequired, which is required to store the thread task in TCb.

Do not add anything. Set configUSE_TICK_HOOK to 0 in your FreeRTOSConfig.h.
Q2) so this code is not required for CR4 ? in that case why is this added if we don’t need

You can use the tick hook but it is not required. It is optional. Read more about it here - Hook Functions - FreeRTOS™.

The reason I asked to not do anything is to first figure out where the issue is.

Does the code work now?

Hi Gaurav,
Still i am doing some code changes and still task scheduling is not happening
Q1) For now i have disabled api Tick Hook code and For getting timer to FreeRtos code for scheduling we need to use the Chip specific running clock based on ticks right? as this hook also seems to be runs based on ticks.
Q2) Where can we call this api “FreeRTOS_IRQ_Handler” from as this takes care of task switching. If we need to call this from Tr_irq interupt ? then is there any condition to be added to call this or we need to call every time when Tr_irq interrupt occurs
q3) we have api FreeRTOS_SVC_Handler, where can we use this? it seems like this api is used to start first task?

As mentioned previously, if ok means we can connect and debug for some time to fix this issue.
My mail id:- supreeth.i@synaptics.com

These questions suggest a potential gap in understanding how interrupts work. An interrupt can occur at any moment during program execution. When an interrupt is triggered, the processor core immediately halts its current operation and switches to executing the corresponding Interrupt Service Routine (ISR). The process unfolds as follows:

  1. The core suspends its current task.
  2. It then executes the appropriate ISR.
  3. Once the ISR is completed, the core resumes its original task from the point of interruption.

You might wonder how the core determines which ISR to execute. Typically, there’s a predetermined location (or set of locations) to which the core jumps when an interrupt occurs. This information is stored in what’s known as the Interrupt Vector Table, which is usually situated at a fixed memory address. In the case of Cortex-R, the Interrupt Vector Table looks like the following:

+------------------+
| Reset Handler    |
+------------------+
| Undef Handler    |
+------------------+
| SVC Handler      | /* Executed when software interrupt is raised. */
+------------------+
| Prefetch Handler |
+------------------+
| Abort Handler    |
+------------------+
| IRQ Handler      | /* Executed when asynchronous interrupt happens. */
+------------------+
| FIQ Handler      |
+------------------+

You need to install FreeRTOS_SVC_Handler and FreeRTOS_IRQ_Handler in this table as shown here. FreeRTOS_IRQ_Handler is the common entry point for all the interrupts and its code roughly looks like the following:

FreeRTOS_IRQ_Handler:
    /* Interrupt Entry code.  */
    vApplicationIRQHandler();
    /* Interrupt Exit code. Context switch is handled here */

The application need to implement interrupt handling logic invApplicationIRQHandler. An example would look something like the following:

void vApplicationIRQHandler()
{
    switch interruptCause:
    {
        case UART:
        /* Handle UART interrupt. */
        break;

        case DMA:
        /* Handle DMA interrupt. */
        break;

        case TIMER:
        ulPortYieldRequired = xTaskIncrementTick();
        break;
    }
}

Here is an example.

Are you able to install SVC and IRQ handler correctly? If yes, how did you verify that?

Hi Gaurav,
I have added FreeRTOS_SVC_Handler to svc handler(vector table index-2) index starting from 0 and added FreeRTOS_IRQ_Handler to irq handler (vector table index-6) but interupts are not getting triggered.
Just for checking other interupts i have added code for invalid address access and data abort interrupt also not getting raised. Is there any think i need to do changes for interrupts to get triggered?

This is the first issue that we need to resolve. Can you move this code to as early as possible in main to ensure that interrupt are not disabled by any other code. Note that calling a FreeRTOS API (such as xTaskCreate) will leave interrupts disabled until the scheduler is started.

Can you please let me know which code you want me to move in main as early as possible? sorry i coudln’t get clarity on above message.

Are you saying to call vTaskStartScheduler(); before xTaskCreateStatic? can you plaese provide some clarity? attached my main.c for reference
main.c (5.0 KB)

Remove the FreeRTOS API calls (i.e. xTaskCreateStatic and vTaskStartScheduler) from main and see if you are able to the interrupts working.

Hi Gaurav,
I have enabled invalid address access code in main by commenting all other code as suggested by you. After invalid address access the code jumps to tr_rst interupt which is registered in vector table at 0th index. but expectation was to call the data abort interupt. Is there something i need to check here?

For getting the FreeRTOS working, we need to get the following 2 working:

  1. SVC - You can use this assembly to raise an SVC and verify if the control reaches FreeRTOS_SVC_Handler.
  2. IRQ - Configure your timer so that it fires a timer interrupt. Verify if the control reaches FreeRTOS_IRQ_Handler and then vApplicationIRQHandler.

Hi Gaurav,
I have tried calling the portYield api from main and upon step instruction from gdb i see below invalid address access. so basically for pc enter’s on to invalid address for portYield api call.
Q1) What can be done here?

(gdb) s
0x00000008 in ?? ()

q2) one more observation is that i am using the Kernel version -“FreeRTOS Kernel V11.1.0” so the definitions are different and most of the code api’s are not present in PortAsm.S. Is the version “FreeRTOS Kernel V11.1.0” good to use or should we use latest code from website which you have shared?
q3) This portField is called from api’s defined under Macro "configNUMBER_OF_CORES > 1 " for single code code where this api should be called from in our code base?

You need to figure out how to install handlers for your part? Do you have some examples form your vendor?

It should be good.

You do not need to call it explicitly
. The kernel invokes it internally.

Hi Gaurav,
Regarding this scheduler error which i had messaged you previously. I had checked more code and Confiremd that our vector table is also copied properly. Need your info on below error

  1. we are creating 3 tasks (Example, idle , timer task)
  2. Assigning FreeRtos timer task to pxCurrentTCB(Task control block) and calling for scheduling it via xPortStartScheduler
  3. in xPortStartScheduler we call vPortRestoreTaskContext
  4. in vPortRestoreTaskContext we try to load R0 with content of pxCurrentTCB
    LDR R0, pxCurrentTCBConst
    LDR R1, [R0]
    LDR SP, [R1]
  5. during step-4 the pc jumps to prvTaskExitError. Not sure why its jumping here. Need your suggestions on this issue?

Would you please share how you confirmed this?

Are you modifying pxCurrentTCB manually?

Hi Gaurav,
Below are the response for your queries
Q1) Would you please share how you confirmed this?
A) i have checked the context of ASM file related to Vector table and then used telnet session command MDW from location zero to 0x00032 to see if same contexts are coppied are not. This is how i verified vector content is coppied properly
Q2) Are you modifying pxCurrentTCB manually?
A) No i am not doing any explicit changes to pxCurrentTCB, as part of vTaskStartScheduler api timer task is created and assigned to pxCurrentTCB as per priority and then this task is being tried to get scheduled using pxCurrentTCBConst in vPortRestoreTaskContext as part of first task scheduling

As you mentioned that you are on leave on Mon and tuesday so debug session not possible for you. Can any of your team members can guide this on debug session? as this is little urgent