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.

AM263P4-Q1: MATLAB integration with Code composer d

Part Number: AM263P4-Q1
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

I am using AM63P4 Q1 control card and able to use build and deploy into the hardware, generated the code using embedded C coder in MATLAB but when I am trying to import in Code composer studio I am unable to import it even if I manually add it to the work space through file explorer I am unable to debug or run.

how to integrate the code generated through Matlab simulink embedded C  coder into CCS theia or CCS.

I am attaching the files generated through embedded c coder

  • Nothing is attached. What errors do you get? Did you add any .h files?

  • Sorry! I think something went wrong while uploading. please find the documents below. Thank you for your prompt response. 

     TestfrCCS2.zip

  • I am uploading the code here the zip file from my previous reply has all the files generated from MATLAB

    ert_Main.c

    /*
     *
     * File: ert_main.c
     *
     * Code generated for Simulink model 'TestfrCCS2'.
     *
     * Model version                  : 1.9
     * Simulink Coder version         : 24.2 (R2024b) 21-Jun-2024
     * C/C++ source code generated on : Fri Jan 10 09:24:25 2025
     *
     * Target selection: ert.tlc
     * Embedded hardware selection: ARM Compatible->ARM Cortex
     * Code generation objectives: Unspecified
     * Validation result: Not run
     */
    
    #include "TestfrCCS2.h"
    #include "rtwtypes.h"
    #include "MW_target_hardware_resources.h"
    
    volatile int IsrOverrun = 0;
    static boolean_T OverrunFlag = 0;
    void rt_OneStep(void)
    {
      /* Check for overrun. Protect OverrunFlag against preemption */
      if (OverrunFlag++) {
        IsrOverrun = 1;
        OverrunFlag--;
        return;
      }
    
      __enable_irq();
      TestfrCCS2_step();
    
      /* Get model outputs here */
      __disable_irq();
      OverrunFlag--;
    }
    
    volatile boolean_T stopRequested;
    volatile boolean_T runModel;
    int main(int argc, char **argv)
    {
      float modelBaseRate = 4.0;
      float systemClock = 100;
    
      /* Initialize variables */
      stopRequested = false;
      runModel = false;
      am263px_My_HardwareInit_Fcn();
      rtmSetErrorStatus(TestfrCCS2_M, 0);
      TestfrCCS2_initialize();
      TickConfig(modelBaseRate);
      runModel =
        rtmGetErrorStatus(TestfrCCS2_M) == (NULL);
      __enable_irq();
      while (runModel) {
        stopRequested = !(
                          rtmGetErrorStatus(TestfrCCS2_M) == (NULL));
        runModel = !(stopRequested);
      }
    
      /* Terminate model */
      TestfrCCS2_terminate();
      return 0;
    }
    
    /*
     * File trailer for generated code.
     *
     * [EOF]
     */

    testfrccs.c

    /*
     *
     * File: TestfrCCS2.c
     *
     * Code generated for Simulink model 'TestfrCCS2'.
     *
     * Model version                  : 1.9
     * Simulink Coder version         : 24.2 (R2024b) 21-Jun-2024
     * C/C++ source code generated on : Fri Jan 10 09:24:25 2025
     *
     * Target selection: ert.tlc
     * Embedded hardware selection: ARM Compatible->ARM Cortex
     * Code generation objectives: Unspecified
     * Validation result: Not run
     */
    
    #include "TestfrCCS2.h"
    #include "MW_GPIOOUT.h"
    
    /* Block states (default storage) */
    DW_TestfrCCS2_T TestfrCCS2_DW;
    
    /* Real-time model */
    static RT_MODEL_TestfrCCS2_T TestfrCCS2_M_;
    RT_MODEL_TestfrCCS2_T *const TestfrCCS2_M = &TestfrCCS2_M_;
    
    /* Model step function */
    void TestfrCCS2_step(void)
    {
      GPIOOutputStepStruct gpioout_step_struct;
    
      /* MATLABSystem: '<Root>/GPIO OUTPUT' incorporates:
       *  Constant: '<Root>/Constant'
       */
      /*         %% Define input properties */
      /*  Call C-function implementing device output */
      /* coder.ceval('sink_output',u); */
      gpioout_step_struct.GPIOBaseAddress = TestfrCCS2_DW.obj.GPIOInstanceAddress;
      gpioout_step_struct.pinInstance = 22U;
      gpioout_step_struct.input_signal = 1.0;
      GPIOOutput_step(&gpioout_step_struct);
    }
    
    /* Model initialize function */
    void TestfrCCS2_initialize(void)
    {
      {
        GPIOOutputSetupStruct gpioout_init_struct;
    
        /* Start for MATLABSystem: '<Root>/GPIO OUTPUT' */
        /*  Constructor */
        /*  Support name-value pair arguments when constructing the object. */
        TestfrCCS2_DW.obj.matlabCodegenIsDeleted = false;
        TestfrCCS2_DW.obj.isInitialized = 1;
    
        /*         %% Define input properties */
        /*  Call C-function implementing device initialization */
        /*  coder.cinclude('sink.h'); */
        /*  coder.ceval('sink_init'); */
        TestfrCCS2_DW.obj.GPIOInstanceAddress = CSL_GPIO0_U_BASE;
        gpioout_init_struct.GPIOBaseAddress = TestfrCCS2_DW.obj.GPIOInstanceAddress;
        gpioout_init_struct.pinInstance = 22U;
        gpioout_init_struct.trigType = 0U;
        gpioout_init_struct.EnableInterrupt = false;
        GPIOOutput_setup(&gpioout_init_struct);
    
        /* Move to init.c */
        /* coder.ceval('util_iomux_config_for_gpio', obj.GPIO_PINS); */
        TestfrCCS2_DW.obj.isSetupComplete = true;
      }
    }
    
    /* Model terminate function */
    void TestfrCCS2_terminate(void)
    {
      GPIOOutputReleaseStruct gpio_release_struct;
    
      /* Terminate for MATLABSystem: '<Root>/GPIO OUTPUT' */
      if (!TestfrCCS2_DW.obj.matlabCodegenIsDeleted) {
        TestfrCCS2_DW.obj.matlabCodegenIsDeleted = true;
        if ((TestfrCCS2_DW.obj.isInitialized == 1) &&
            TestfrCCS2_DW.obj.isSetupComplete) {
          /*  Call C-function implementing device termination */
          /* coder.ceval('sink_terminate'); */
    has popup

    testfrccs.h

    /*
     *
     * File: TestfrCCS2.h
     *
     * Code generated for Simulink model 'TestfrCCS2'.
     *
     * Model version                  : 1.9
     * Simulink Coder version         : 24.2 (R2024b) 21-Jun-2024
     * C/C++ source code generated on : Fri Jan 10 09:24:25 2025
     *
     * Target selection: ert.tlc
     * Embedded hardware selection: ARM Compatible->ARM Cortex
     * Code generation objectives: Unspecified
     * Validation result: Not run
     */
    
    #ifndef TestfrCCS2_h_
    #define TestfrCCS2_h_
    #ifndef TestfrCCS2_COMMON_INCLUDES_
    #define TestfrCCS2_COMMON_INCLUDES_
    #include "rtwtypes.h"
    #include "math.h"
    #include "MW_GPIOOUT.h"
    #endif                                 /* TestfrCCS2_COMMON_INCLUDES_ */
    
    #include "TestfrCCS2_types.h"
    #include <stddef.h>
    
    /* Macros for accessing real-time model data structure */
    #ifndef rtmGetErrorStatus
    #define rtmGetErrorStatus(rtm)         ((rtm)->errorStatus)
    #endif
    
    #ifndef rtmSetErrorStatus
    #define rtmSetErrorStatus(rtm, val)    ((rtm)->errorStatus = (val))
    #endif
    
    /* user code (top of header file) */
    #include "gpio.h"
    
    /* Block states (default storage) for system '<Root>' */
    typedef struct {
      GPIO_OUT_TestfrCCS2_T obj;           /* '<Root>/GPIO OUTPUT' */
    } DW_TestfrCCS2_T;
    
    /* Real-time Model Data Structure */
    struct tag_RTM_TestfrCCS2_T {
      const char_T * volatile errorStatus;
    };
    
    /* Block states (default storage) */
    extern DW_TestfrCCS2_T TestfrCCS2_DW;
    
    /* Model entry point functions */
    extern void TestfrCCS2_initialize(void);
    extern void TestfrCCS2_step(void);
    extern void TestfrCCS2_terminate(void);
    
    /* Real-time Model object */
    extern RT_MODEL_TestfrCCS2_T *const TestfrCCS2_M;
    extern volatile boolean_T stopRequested;
    extern volatile boolean_T runModel;
    
    /*-
     * The generated code includes comments that allow you to trace directly
     * back to the appropriate location in the model.  The basic format
     * is <system>/block_name, where system is the system number (uniquely
     * assigned by Simulink) and block_name is the name of the block.
     *
     * Use the MATLAB hilite_system command to trace the generated code back
     * to the model.  For example,
     *
     * hilite_system('<S3>')    - opens system 3
     * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
     *
     * Here is the system hierarchy for this model
     *
     * '<Root>' : 'TestfrCCS2'
     */
    #endif                                 /* TestfrCCS2_h_ */
    
    /*
     * File trailer for generated code.
     *
    has popup

    tesfrccs2_private.h

    /*
     *
     * File: TestfrCCS2.h
     *
     * Code generated for Simulink model 'TestfrCCS2'.
     *
     * Model version                  : 1.9
     * Simulink Coder version         : 24.2 (R2024b) 21-Jun-2024
     * C/C++ source code generated on : Fri Jan 10 09:24:25 2025
     *
     * Target selection: ert.tlc
     * Embedded hardware selection: ARM Compatible->ARM Cortex
     * Code generation objectives: Unspecified
     * Validation result: Not run
     */
    
    #ifndef TestfrCCS2_h_
    #define TestfrCCS2_h_
    #ifndef TestfrCCS2_COMMON_INCLUDES_
    #define TestfrCCS2_COMMON_INCLUDES_
    #include "rtwtypes.h"
    #include "math.h"
    #include "MW_GPIOOUT.h"
    #endif                                 /* TestfrCCS2_COMMON_INCLUDES_ */
    
    #include "TestfrCCS2_types.h"
    #include <stddef.h>
    
    /* Macros for accessing real-time model data structure */
    #ifndef rtmGetErrorStatus
    #define rtmGetErrorStatus(rtm)         ((rtm)->errorStatus)
    #endif
    
    #ifndef rtmSetErrorStatus
    #define rtmSetErrorStatus(rtm, val)    ((rtm)->errorStatus = (val))
    #endif
    
    /* user code (top of header file) */
    #include "gpio.h"
    
    /* Block states (default storage) for system '<Root>' */
    typedef struct {
      GPIO_OUT_TestfrCCS2_T obj;           /* '<Root>/GPIO OUTPUT' */
    } DW_TestfrCCS2_T;
    
    /* Real-time Model Data Structure */
    struct tag_RTM_TestfrCCS2_T {
      const char_T * volatile errorStatus;
    };
    
    /* Block states (default storage) */
    extern DW_TestfrCCS2_T TestfrCCS2_DW;
    
    /* Model entry point functions */
    extern void TestfrCCS2_initialize(void);
    extern void TestfrCCS2_step(void);
    extern void TestfrCCS2_terminate(void);
    
    /* Real-time Model object */
    extern RT_MODEL_TestfrCCS2_T *const TestfrCCS2_M;
    extern volatile boolean_T stopRequested;
    extern volatile boolean_T runModel;
    
    /*-
     * The generated code includes comments that allow you to trace directly
     * back to the appropriate location in the model.  The basic format
     * is <system>/block_name, where system is the system number (uniquely
     * assigned by Simulink) and block_name is the name of the block.
     *
     * Use the MATLAB hilite_system command to trace the generated code back
     * to the model.  For example,
     *
     * hilite_system('<S3>')    - opens system 3
     * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
     *
     * Here is the system hierarchy for this model
     *
     * '<Root>' : 'TestfrCCS2'
     */
    #endif                                 /* TestfrCCS2_h_ */
    
    /*
     * File trailer for generated code.
     *
    has popup

    testfrccs2_types.h

    /*
     *
     * File: TestfrCCS2_types.h
     *
     * Code generated for Simulink model 'TestfrCCS2'.
     *
     * Model version                  : 1.9
     * Simulink Coder version         : 24.2 (R2024b) 21-Jun-2024
     * C/C++ source code generated on : Fri Jan 10 09:24:25 2025
     *
     * Target selection: ert.tlc
     * Embedded hardware selection: ARM Compatible->ARM Cortex
     * Code generation objectives: Unspecified
     * Validation result: Not run
     */
    
    #ifndef TestfrCCS2_types_h_
    #define TestfrCCS2_types_h_
    #include "rtwtypes.h"
    
    /* Custom Type definition for MATLABSystem: '<Root>/GPIO OUTPUT' */
    #include "MW_GPIOOUT.h"
    #include "MW_GPIOOUT.h"
    #include "MW_GPIOOUT.h"
    #ifndef struct_tag_0PhTFesxrI8SkRHYv7ghUF
    #define struct_tag_0PhTFesxrI8SkRHYv7ghUF
    
    struct tag_0PhTFesxrI8SkRHYv7ghUF
    {
      boolean_T matlabCodegenIsDeleted;
      int32_T isInitialized;
      boolean_T isSetupComplete;
      uint32_t GPIOInstanceAddress;
    };
    
    #endif                                 /* struct_tag_0PhTFesxrI8SkRHYv7ghUF */
    
    #ifndef typedef_GPIO_OUT_TestfrCCS2_T
    #define typedef_GPIO_OUT_TestfrCCS2_T
    
    typedef struct tag_0PhTFesxrI8SkRHYv7ghUF GPIO_OUT_TestfrCCS2_T;
    
    #endif                                 /* typedef_GPIO_OUT_TestfrCCS2_T */
    
    /* Forward declaration for rtModel */
    typedef struct tag_RTM_TestfrCCS2_T RT_MODEL_TestfrCCS2_T;
    
    #endif                                 /* TestfrCCS2_types_h_ */
    
    /*
     * File trailer for generated code.
     *
     * [EOF]
     */
    has popup

    rtwtypes.h

    /*
     *
     * File: rtwtypes.h
     *
     * Code generated for Simulink model 'TestfrCCS2'.
     *
     * Model version                  : 1.9
     * Simulink Coder version         : 24.2 (R2024b) 21-Jun-2024
     * C/C++ source code generated on : Fri Jan 10 09:24:25 2025
     *
     * Target selection: ert.tlc
     * Embedded hardware selection: ARM Compatible->ARM Cortex
     * Code generation objectives: Unspecified
     * Validation result: Not run
     */
    
    #ifndef RTWTYPES_H
    #define RTWTYPES_H
    
    /* Logical type definitions */
    #if (!defined(__cplusplus))
    #ifndef false
    #define false                          (0U)
    #endif
    
    #ifndef true
    #define true                           (1U)
    #endif
    #endif
    
    /*=======================================================================*
     * Target hardware information
     *   Device type: ARM Compatible->ARM Cortex
     *   Number of bits:     char:   8    short:   16    int:  32
     *                       long:  32
     *                       native word size:  32
     *   Byte ordering: LittleEndian
     *   Signed integer division rounds to: Zero
     *   Shift right on a signed integer as arithmetic shift: on
     *=======================================================================*/
    #ifdef PORTABLE_WORDSIZES              /* PORTABLE_WORDSIZES defined */
    
    /*=======================================================================*
     * Host information
     *   Number of bits:     char:   8    short:   16    int:  32
     *                       long:  32
     *                       long long:  64
     *                       native word size:  64
     *=======================================================================*/
    
    /*=======================================================================*
     * Fixed width word size data types:                                     *
     *   int8_T, int16_T, int32_T     - signed 8, 16, or 32 bit integers     *
     *   uint8_T, uint16_T, uint32_T  - unsigned 8, 16, or 32 bit integers   *
     *   real32_T, real64_T           - 32 and 64 bit floating point numbers *
     *=======================================================================*/
    typedef signed char int8_T;
    typedef unsigned char uint8_T;
    typedef short int16_T;
    typedef unsigned short uint16_T;
    typedef int int32_T;
    typedef unsigned int uint32_T;
    typedef float real32_T;
    typedef double real64_T;
    
    /*===========================================================================*
     * Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T,       *
     *                           real_T, time_T, ulong_T.                        *
     *===========================================================================*/
    typedef double real_T;
    typedef double time_T;
    typedef unsigned char boolean_T;
    typedef int int_T;
    typedef unsigned int uint_T;
    typedef unsigned int ulong_T;
    typedef char char_T;
    typedef unsigned char uchar_T;
    typedef char_T byte_T;
    
    #else                                  /* PORTABLE_WORDSIZES not defined */
    
    /*=======================================================================*
     * Fixed width word size data types:                                     *
     *   int8_T, int16_T, int32_T     - signed 8, 16, or 32 bit integers     *
    has popup

    and few other files like rtwmodel.h, MW_GPIOOUT.c, MW target hardwre resource .h, am26px_init.c, am263px_multitasking.c, am263px_tick.c, gpio.c

  • I am unable to import

    You problem description is not specific enough. You mean CCS does not "see" the source code file? What error messages are you getting?

    how to integrate the code generated through Matlab simulink embedded C  coder into CCS theia or CCS.

    In general, if your primary focus is developing code in Simulink my advice is for you to use "MATLAB Simulink Embedded Coder Hardware Support package for AM26x". This package also supports AM263PX. You can request access at this link: ti.com/secureresources/AM26X-SL-EC

  • Hi Kier,

    I am currently using the latest "MATLAB Simulink Embedded Coder Hardware Support package for AM26x V24.2.0.12," which is the latest version available in MATLAB, but I couldn't locate it on the TI website. Could you let me know when the updated version will be released on the TI website?

    Additionally, when trying to import the package, the "Finish" option is disabled, and I am unable to proceed. To work around this, I manually added all the .c and .h files to an empty project example in the workspace. I cleared the errors by excluding the initialization files, but the drivers are being referenced in those files. After debugging, I noticed that there is no response from the board.

    Thank you for your help!

  • I am currently using the latest "MATLAB Simulink Embedded Coder Hardware Support package for AM26x V24.2.0.12," which is the latest version available in MATLAB

    OK, thank you. It looks like TI have now made this package available to Mathworks. Last year it was only available by special request to TI directly. That version was 24.1. Therefore, I think you have the latest version from Mathworks.

    Additionally, when trying to import the package, the "Finish" option is disabled, and I am unable to proceed.

    You mean when trying to import the package into Simulink? It's not clear. Pls post screenshots of the problem.

  • Sorry for the confusion.
    when I am trying to import the generated code into CCS theia or CCS.
    I am attaching a video of it.
    and i figured out that the initialization files are causing the issues so i excluded them and run the remaining

  • 4 Examples.pdf

    causing the issues

    But it's not clear what the issue is. I doubt that excluding any files is going to fix whatever the problem is.

    In any case, the main advantage of the Simulink HSP is that you don't have to worry about managing the project in CCS. Simulink does this work for you.

    Can you first confirm that the examples work?. See attached.



  • yes they do work,


    but these examples are for am263x in need to change the hardware settings for am263Px control card (I have tries GPIO led and UART echo)


    Reason why I went to CCS is because I cannot access IO expander through matlab simulink

    I am not sure how to run both subsystems R5FSS0 and R5FSS1 through simulink and I want to inegrate some part of the code which is developed through matlab into the code which is being developed by my team through CCS

  • OK, I understand why you want to use CCS now.

    Unless Simulink generates a .project and .cproject files, you can't really import a project to CCS, only add source files to an existing project.

    Does Simulink generate a .project / .cproject file?

  • Hi Rama,

    You can start with any example from mcu plus sdk, which is close to your example(like multi-core), then add the .c and .h file to that project, as Kier mentioned.

    This way you can access io-expander and also multi-core feature.

  • Hi, Kier

    Sorry that I am on vacation and didn't get a chance to access my pc

    Does Simulink generate a .project / .cproject file?
    It generates .c and .h files which I have linked and posted above and yes I have tried adding source files to an existing example but it didn't work.

    So, I am trying to add .c and .h files one by one and trying to clear the errors. The main challenges I’m facing involve reinitialization of timers and pins because they are being configured in both example.sysconfig and in the code generated by MATLAB. Additionally, driver initialization in the example projects is spread across different .c files, which creates conflicts with the MATLAB-generated code.

    And this is the reason why I've reached out for help.

    Thank you.

  • Hi,

    Thank you for the suggestion. I have already tried starting with an example from the MCU+ SDK, like taking an example, and adding the .c and .h files as Kier mentioned. Unfortunately, this approach didn’t work as expected.

    The main challenges I’m facing involve reinitialization of timers and pins because they are being configured in both example.sysconfig and in the code generated by MATLAB. Additionally, driver initialization in the example projects is spread across different .c files, which creates conflicts with the MATLAB-generated code.

    As I try to resolve these issues, It feels like coding all over again and missing the advantage of code generated through matlab, but I would appreciate any further guidance to streamline this process.

    Thank you for your help!

    Best regards,
    Rama Krishna

  • Sorry but I'm going to have to bail on this question. It's simply not specific enough. It sounds like you need the assistance of a software engineer in your organisation who is familiar with basic/platform software compilation and register level debugging.

  • Hi Kier,
    I am able to figure it out. It was because of double initialization
    thanks