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.

[FAQ] TDA4VH-Q1: Running SDL applications on Freertos/Safertos

Part Number: TDA4VH-Q1

Tool/software:

Can SDL applications be run on Freertos/Safertos? If yes, what are the changes to be made?

  • Hi,

    FREERTOS

    Please be aware that there are 2 ways to execute SDL applications on FreeRTOS:

    Approach A: In this method, you would build SDL standalone applications on FreeRTOS by changing the BUILD_OS_TYPE. The esm_main_app, lbist_test_app and osal_app in SDL have been validated to build and test the application on Freertos (BUILD_OS_TYPE=freertos). The expectation is to port the other examples referring to these examples.

    The following are the required changes to port standalone examples on freertos -

    1. Changes in the makefile build infra to enable and link with the proper PDK osal library
    2. These are the OSAL APIs which need to be provided to SDL for any OS which is used along with SDL: SDL API Guide for J784S4: SDL_OSAL_Interface Struct Reference
    3. Changes in the main() API to create a Freertos task to call the application.

    You can refer to the following patch with steps to port the vtm_app to build using freertos -

    0001-Port-vtm_app-to-FreeRTOS.txt
    From 3fdef35f94835945f0956c2bf4255c5c4f9683f6 Mon Sep 17 00:00:00 2001
    From: Josiitaa RL <j-rl@ti.com>
    Date: Fri, 15 Nov 2024 13:39:00 +0530
    Subject: [PATCH] Port vtm_app to FreeRTOS
    
    ---
     build/makerules/component.mk |  3 ++-
     examples/vtm/main.c          | 43 ++++++++++++++++++++++++++++++++++--
     examples/vtm/makefile        | 10 +++++++--
     3 files changed, 51 insertions(+), 5 deletions(-)
    
    diff --git a/build/makerules/component.mk b/build/makerules/component.mk
    index 4c0d443..0241d2d 100755
    --- a/build/makerules/component.mk
    +++ b/build/makerules/component.mk
    @@ -957,7 +957,8 @@ vtm_app_RELPATH = examples/vtm
     vtm_app_PATH= $(sdl_PATH)/$(vtm_app_RELPATH)
     vtm_app_PLATFORM_DEPENDENCY = yes
     vtm_app_SOCLIST = $(DEFAULT_SOCLIST)
    -export vtm_app_OSLIST = $(DEFAULT_OSLIST)
    +vtm_app_OSLIST = baremetal freertos
    +export vtm_app_OSLIST
     export vtm_app_SOCLIST
     export vtm_app_PLATFORM_DEPENDENCY
     export vtm_app_SBL_APPIMAGEGEN = yes
    diff --git a/examples/vtm/main.c b/examples/vtm/main.c
    index 8d62bc6..d99933f 100644
    --- a/examples/vtm/main.c
    +++ b/examples/vtm/main.c
    @@ -66,6 +66,15 @@
     #define SDLR_WKUP_ESM0_ESM_LVL_EVENT_WKUP_VTM0_THERM_LVL_LT_TH0_INTR_0                             (9U)
     #define APP_ARG (1)
     
    +#if defined (FREERTOS) || defined (SAFERTOS)
    +#define APP_TSK_STACK_MAIN              (32U * 1024U)
    +/**< Test application stack size */
    +#endif
    +#if defined (FREERTOS)
    +/* Test application stack */
    +static uint8_t  gAppTskStackMain[APP_TSK_STACK_MAIN]
    +__attribute__ ((aligned(8192)));
    +#endif
     /* #define DEBUG */
     
     static uint32_t totalEventsLogged   = 0;
    @@ -538,7 +547,7 @@ void vtm_example_test_app_runner(void)
         return;
     }
     
    -int32_t main(void)
    +void testFxn(void *a0, void *a1)
     {
         int32_t  testResult;
         /* Init Board */
    @@ -555,9 +564,39 @@ int32_t main(void)
         {
             UART_printStatus("\r\nBoard Init failed. Exiting the app.\r\n");
         }
    -    while (true)
    +    // while (true)
    +    // {
    +    // }
    +}
    +
    +int32_t main(void)
    +{
    +#if defined (FREERTOS) || defined (SAFERTOS)
    +    TaskP_Handle task;
    +    TaskP_Params taskParams;
    +
    +    OS_init();
    +
    +    /* Initialize the task params */
    +    TaskP_Params_init(&taskParams);
    +    /* Set the task priority higher than the default priority (1) */
    +    taskParams.priority = 2;
    +    taskParams.stack        = gAppTskStackMain;
    +    taskParams.stacksize    = sizeof (gAppTskStackMain);
    +
    +    task = TaskP_create(testFxn, &taskParams);
    +    if(NULL == task)
         {
    +        OS_stop();
         }
    +    OS_start();    /* does not return */
    +
    +    return(0);
    +#else
    +    testFxn(NULL, NULL);
    +
    +    return (0);
    +#endif
     }
     
     /* Nothing past this point */
    diff --git a/examples/vtm/makefile b/examples/vtm/makefile
    index f063a9f..18e797d 100755
    --- a/examples/vtm/makefile
    +++ b/examples/vtm/makefile
    @@ -40,11 +40,17 @@ EXT_LIB_LIST_COMMON += $(board_LIBPATH)/$(BOARD)/$(ISA_EXT)/$(PROFILE)/$(board_L
     EXT_LIB_LIST_COMMON += $(i2c_LIBPATH)/$(SOC)/$(ISA_EXT)/$(PROFILE)/$(i2c_LIBNAME).$(LIBEXT)
     EXT_LIB_LIST_COMMON += $(sciclient_direct_LIBPATH)/$(SOC)/$(BUILD_CORE)/$(PROFILE)/$(sciclient_direct_LIBNAME).$(LIBEXT)
     EXT_LIB_LIST_COMMON += $(rm_pm_hal_LIBPATH)/$(SOC)/$(BUILD_CORE)/$(PROFILE)/$(rm_pm_hal_LIBNAME).$(LIBEXT)
    -EXT_LIB_LIST_COMMON += $(osal_nonos_LIBPATH)/$(SOC)/$(ISA_EXT)/$(PROFILE)/$(osal_nonos_LIBNAME).$(LIBEXT)
    +#EXT_LIB_LIST_COMMON += $(osal_nonos_LIBPATH)/$(SOC)/$(ISA_EXT)/$(PROFILE)/$(osal_nonos_LIBNAME).$(LIBEXT)
     EXT_LIB_LIST_COMMON += $(uart_LIBPATH)/$(SOC)/$(ISA_EXT)/$(PROFILE)/$(uart_LIBNAME).$(LIBEXT)
     EXT_LIB_LIST_COMMON += $(csl_LIBPATH)/$(SOC)/$(ISA_EXT)/$(PROFILE)/$(csl_LIBNAME).$(LIBEXT)
     EXT_LIB_LIST_COMMON += $(csl_init_LIBPATH)/$(SOC)/$(ISA_EXT)/$(PROFILE)/$(csl_init_LIBNAME).$(LIBEXT)
    -
    +ifeq ($(BUILD_OS_TYPE),$(filter $(BUILD_OS_TYPE), baremetal))
    + EXT_LIB_LIST_COMMON += $(osal_nonos_LIBPATH)/$(SOC)/$(ISA_EXT)/$(PROFILE)/$(osal_nonos_LIBNAME).$(LIBEXT)
    +endif
    +ifeq ($(BUILD_OS_TYPE),$(filter $(BUILD_OS_TYPE), freertos))
    + EXT_LIB_LIST_COMMON += $(freertos_LIBPATH)/$(SOC)/$(BUILD_CORE)/$(PROFILE)/$(freertos_LIBNAME).$(LIBEXT)
    + EXT_LIB_LIST_COMMON += $(osal_freertos_LIBPATH)/$(SOC)/$(ISA_EXT)/$(PROFILE)/$(osal_freertos_LIBNAME).$(LIBEXT)
    +endif
     # Common source files and CFLAGS across all platforms and cores
     PACKAGE_SRCS_COMMON = .
     CFLAGS_LOCAL_COMMON = $(SDL_CFLAGS) -DUNITY_INCLUDE_CONFIG_H
    -- 
    2.34.1
    
    

    Approach B: Calling the SDL APIs from a Freertos application directly. An example of this would be integrating the SDL applications to the PDK Bootapp running on FreeRTOS. The PDK Bootapp currently has PBIST and LBIST integration available in SDK 10.0 and onwards. In SDK 10.1, along with PBIST and LBIST, VTM, POK and TOG self test integration will also be available - https://software-dl.ti.com/jacinto7/esd/processor-sdk-rtos-j784s4/10_01_00_04/exports/docs/pdk_j784s4_10_01_00_25/docs/userguide/j784s4/boot/boot_app.html#integration-of-functional-safety-with-bootapp

    SAFERTOS

    The esm_main_app, lbist_test_app and osal_app in SDL have been validated to build and test the application on Freertos (BUILD_OS_TYPE=safertos). TI does not validate other SDL examples on safertos.

    To build the esm_main_app for saertos, please follow the below steps -

    1. Download and install the Safertos package from WHIS.
    2. Provide the path to the SAFERTOS_KERNEL_INSTALL_PATH in sdl/Rules.make

    3. Build the application using the following command: make esm_main_app SOC=j784s4 BUILD_OS_TYPE=safertos

    NOTE: Please use the following linker file for SDKs before 11.0 - linker_r5f_ecc_safertos.lds. This has been updated in SDK 11.0 and onwards.

    Regards,

    Josiitaa