This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM48L952ZWT FreeRtos issue

Other Parts Discussed in Thread: HALCOGEN

1145.RM48L952ZWT.zipSorry to ask here, probably is not a TI related issue.

With Halcogen I have created a FreeRtos project for RM48L950ZWT as there aren't any freertos project for the RM48L952ZWT.I have generated the code for IAR.

I have than create an other project for the RM48L952ZWT and generated the code for IAR.I have followed all the instruction on the instruction in order to set RAM and interrupt ready for FreeRtos.

 

I have than copied across all the FreeRtos file and sys_link.cmd.

 

Doing that I was able to create a simple software, with 2 tasks that every 1000 and 2000 ms write on a serial port. That is working fine.

My final goal then is to make one task write on the serial port only when an RX interrupt have been received from the UART, for this I have used the xTaskNotifyFromISR in the ISR and added xTaskNotifyWait to one of the task.

The problem is that, as soon the scheduler start and the task waiting for the event, is being scheduled, as soon as it enter the function xTaskNotifyWait, after some instruction, it go to execute portYIELD_WITHIN_API(); where everything stop working as the core enter the function prefetchEntry. So I presume that the memory have been corrupted somewhere or I have some stack issue.

It's not an interrupt problem, as at that point the interrupt is not enabled yet, so no events have been created yet.

Please, if possible, give me some imput, i'm happy to try all the options available.

 

I attach the projects used.

 

Thanks again

 

Giorgio

3021.RM48L950ZWT.zip

 

  • Hi Giorgio,

    Prefetch abort as you know happens when CPU(Cortex R4) is not able to fetch the required instruction for execution.

    This mostly happens due to issues with your software where in the next instruction to fetch is being a corrupted address leading to this abort.

    Improper stack definition might be a typical case where this might happen as well.

    Pls give me sometime for me to take a look at your project and find the exact location of the issue.
  • KARTHIKEYAN RAJAMANICKAM said:
    Hi Giorgio,

    Prefetch abort as you know happens when CPU(Cortex R4) is not able to fetch the required instruction for execution.

    This mostly happens due to issues with your software where in the next instruction to fetch is being a corrupted address leading to this abort.

    Improper stack definition might be a typical case where this might happen as well.

    Pls give me sometime for me to take a look at your project and find the exact location of the issue.

    Thanks for your help, i will also try to dig in the problem more to try to understand the issue.

    Thanks again

    Giorgio

  • Hi again,

    I haven't found a solution yet, I guess the problem could be in the file sys_link.cmd where the memory areas are defined, perhaps there is something wrong there when I define the STACK and KRAM memory area. Or something doesn't match with the definition of the stack size in the FreeRTOSConfig.h

     

    I forgot to mention that i'm using TMDSRM48HDK.

     

    Please let me know if you see something strange.

     

    Thanks again

     

    Giorgio

     

     

     

     

  • Giorgio,

    This port of FreeRtos is using the memory protection unit to protect the Kernel RAM (KRAM) from being accessed from User Mode (Non-Privilege).
    All Kernel function call, when called from a Task, have to have a special wrapper to rise the privilege. (Task are running in User Mode)

    Here is an example.

    In Task2, there is a call to vTaskDelay( 5000 );
    Based on the os_mpu_wrappers.h, this function call is defined as following:

            #define vTaskDelayUntil                    MPU_vTaskDelayUntil

    In os_mpu_wrappers.c we have:

    /*----------------------------------------------------------------------------*/

    #if ( INCLUDE_vTaskDelay == 1 )
        void MPU_vTaskDelay( const TickType_t xTicksToDelay  )
        {
            BaseType_t xRunningPrivileged = prvRaisePrivilege();
            vTaskDelay( xTicksToDelay );
            portRESET_PRIVILEGE( xRunningPrivileged );
        }
    #endif

    This is a wrapper that will raise the privilege (from User to System mode) prior to call the vTaskDelay function. Upon exit, the privilege is restored to original value.

    I'm not sure and don't know why these wrapper are not done for every single Kernel API.

    So you will have to create this wrapper yourself.

    a] create a define in os_mpu_wrappers.h
    b] create the wrapper function for the given Kernel API.

    Please let me know if I've answered your question.

  • Dear Jean-Marc,

    Thank you very much for your help, I have create the wrapper for the function xTaskNotifyWait, as you suggested, and now everything is working :)

    Thanks again!!!!!!

    Giorgio
  • Giorgio,


    Glad to see that it is now working.

    Anyway, can you tell me how the SCI_ISR is informing the Rtos? In the code you published few days ago, I don't see the connection.
    Did you modified linHighLevelInterrupt?

    It will be great if you can re-post your project now that it is working.

  • Hi Jean-Marc,

    Thank again for your message and help.

    I'm new to R4 microcontroller so i'm still experimenting at this stage for future project.

    At the moment these are my 2 tasks:

    /* Task 1 function */
    void vTask1(void *pvParameters)
      {
    	uint32_t ulNotifiedValue;
    	ulNotifiedValue=0;
    
    
    	for(;;)
    	  {
    		xTaskNotifyWait( 0x00,               /* Don't clear any bits on entry. */
                      0xffffffff,          /* Clear all bits on exit. */
                      &ulNotifiedValue, /* Receives the notification value. */
                             portMAX_DELAY );    /* Block indefinitely. */
            if(  ulNotifiedValue ==1 )
            {
                // send to uart
    
    		  sciSend(UART, TSIZE1, TEXT1);
    
    		  //prepare to receive next byte
    		  sciReceive(UART, 1, &RX_data);
            }
    
    
    	  }
      }
    
    /* Task 2 function */
    void vTask2(void *pvParameters)
      {
    	for(;;)
    	  {
    		sciSend(UART, TSIZE2, TEXT2);
    		vTaskDelay( 2000 );
    	  }
      }

     

    Task number 1 wait for an event that is generated by

    xTaskNotifyFromISR function that i'm using within sciNotification function that I have enable for UART_RX interrupt, this is my sciNotification, when it receive the event it print a string to the uart.

    void sciNotification(sciBASE_t *sci, uint32 flags)

    {

    /*  enter user code between the USER CODE BEGIN and USER CODE END. */

    /* USER CODE BEGIN (29) */

     BaseType_t xHigherPriorityTaskWoken = pdTRUE;

      uint32_t ulStatusRegister=1;

      /* Notify the task that the transmission is complete. */

       xTaskNotifyFromISR( xTask1Handle,ulStatusRegister,eSetBits,&xHigherPriorityTaskWoken );

    portYIELD_FROM_ISR( xHigherPriorityTaskWoken );

    /* USER CODE END */

    }

     

    This is my main() function where I enable the SCI, interrupt and notification for the UART RX and I  create the tasks and enable the scheduler.

    As next step I will try to move all the initialization into a task that will kill itself after the init is complete.

    void main(void)
    {
    /* USER CODE BEGIN (3) */
      	 sciInit();
    	_enable_interrupt_();
      	sciEnableNotification(UART,SCI_RX_INT);
    
    //prepare to receive from UART
    sciReceive(UART, 1, &RX_data); /* Create Task Init */ // if (xTaskCreate(vTask_Init,"Task_Init", configMINIMAL_STACK_SIZE, NULL, 1, &xTask_Init_Handle) != pdTRUE) //{ /* Task could not be created */ // while(1); //} /* Create Task 1 */ if (xTaskCreate(vTask1,"Task1", configMINIMAL_STACK_SIZE, NULL, 2, &xTask1Handle) != pdTRUE) { /* Task could not be created */ while(1); } /* Create Task 2 */ if (xTaskCreate(vTask2,"Task2", configMINIMAL_STACK_SIZE, NULL, 2, &xTask2Handle) != pdTRUE) { /* Task could not be created */ while(1); } /* Start Scheduler */ vTaskStartScheduler(); /* Run forever */ while(1); /* USER CODE END */ }


    I would be happy to post the project again, now it is still in a mess , but when I have removed most of the debugging code I will post it again.

     

    Thanks again

     

    Giorgio

     

  • Giorgio,

    Thank you for the clarification.

    One comment, I think it is not necessary to call the _enable_interrupt_(); in main().
    FreeRtos has to do it to enable the Tick interrupt. Also it could create problem if you do so.
    If interrupt (SCI or other) are enable and the CPU is ready to service interrupt before FreeRtos is initialized, it may create unpredictable results.
    So I will suggest to remove _enable_interrupt_();

    Also, the modification in os_mpu_wrapper.c amd .h will be overwritten if you have to regenerate your project via Halcogen.
    One way to overcome this problem is to implement these modification directly in the source driver within Halcogen.

    In your Halcogen installation directory you will find:

    C:\ti\Hercules\HALCoGen\v04.05.00\drivers\FreeRTOS\include
    C:\ti\Hercules\HALCoGen\v04.05.00\drivers\FreeRTOS\portable\CCS\Cortex-R4

    In the include directory the file mpu_wrappers.h can be modified to implement the modifications I've mentioned.
    Same for mpu_wrappers.c
    Note that these 2 files are not pure C or H files, and will be customized based on Halcogen Freertos configuration, but the syntax is pretty easy to understand.

    Let me know if you have problem modifying these files.

  • Hi Jean Marc,

    Thanks again for your help.

    I have removed _enable_interrupt_(); and everything is still working, thanks again.

    I attach to this post my working sample project, with all the suggestions from you. It contain the HalCogen Project and the IAR project.

    I'm going to try to implement the wrappers in Halcogen as you suggested, I will let you know if any problem arise.

    Thanks again

    Giorgio