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.

GPIO Bit-Structure Use in MATLAB Simulink S-Function Builder or Legacy Code Tool

Hello,

I'm trying to integrate C-code into MATLAB Simulink. This code, along with the other components of the Simulink project, are being auto-code generated and sent to CCS v3.3. I have code that accesses an RDC's position and velocity registers, but unfortunately, I had to directly manipulate GPIO registers instead of going through the TI bit-structure for GPIO. My code is not readable to the untrained eye, but it works. I'd like to move back to using the TI bit-structure in these Simulink blocks, but I am running into problems when I #include "DSP2833x_Device.h". At first, MATLAB tells me that it can't find all the other files called by the DSP2833x_Device.h file; these problems go away after I move all DSP2833x header files to my current Matlab folder. Then, the next set of problems seem to be correlated to how the TI header files are written in contrast to how MATLAB but compile/interpret them.

Here are my errors:

 Error RDCRead.c: .\DSP2833x_Device.h: 36  syntax error; found `volatile' expecting `;'

Error RDCRead.c: .\DSP2833x_Device.h: 37  syntax error; found `volatile' expecting `;'

Error RDCRead.c: .\DSP2833x_PieVect.h: 28  syntax error; found `void' expecting `;'

Error RDCRead.c: .\DSP2833x_PieVect.h: 37  invalid struct field declarations

Error RDCRead.c: .\DSP2833x_PieVect.h: 37  syntax error; found `PINT' expecting `}'

Error RDCRead.c: .\DSP2833x_PieVect.h: 37  skipping `PINT' `PIE1_RESERVED'

Error RDCRead.c: .\DSP2833x_PieVect.h: 38  redeclaration of `PINT' previously declared at .\DSP2833x_PieVect.h 28

Error RDCRead.c: .\DSP2833x_PieVect.h: 38  syntax error; found `PIE2_RESERVED' expecting `;'

...

Error RDCRead.c: .\DSP2833x_PieVect.h: 53  too many errors

Here are my questions:

1) Has anyone ever successfully integrated GPIO bit-strucutre code into an S-function block or the Legacy Code Tool?

2) Does anyone know why MATLAB might think that these are errors when the files were provided by TI in the first place? Shouldn't this integration just "work"?

3) Does anyone have any ideas for work arounds for this problem?

Thanks for the help!

 

 

  • I figured it out. If anyone it using GPIO bit-structure code (like this for example: GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;) in the 'Outputs' tab of a s-Function Builder block in MATLAB Simulink, remember to do three things:

    1) Place #include <DSP2833x_Device.h> in the 'Includes' section of the 'Libraries' tab.

    2) Click the check box for 'Generate wrapper TLC' in the 'Build Info' tab.

    3) Click the check box for 'Save code only' in the 'Build Info' tab.

    Of course you need your own code in the Outputs section as well. Point number three was the one I didn't do until today! It made everything work. So, the main point here is that checking this block just saves the code (duh) and waits until the overall system is built, which seems obvious, but for me, for the longest time, it wasn't. If you don't do the third point, you have to click a 'Build' button at the top of the S-Function Builder, and this will not have access to the necessary include and header files.

  • Hello all,

    And there's one more thing... To get this process to work properly, before steps 1-3 above are completed, first place the S-Function Builder into your model. Then, give it a name once you open the block. Build this block, pressing the build button, and having the generate tlc file in the build info tab selected. Building the block in this way, without placing any code in it, creates a .mexw32 file, which creates a "container" for the s-fn to exist in. After this, then do the steps above, and add in the code with the GPIO structures.

    hope this helps anyone out there.

  • Thank you Jonathan!

    Your follow up comments saved my day! After a couple of failed attempts I found your thread and could make my s-function work straight away :-)

    Best regards,

    Martin

    Edit: Isn't there any way of giving some kind of "star", "point" or something possitive to the answer or the user?

  • Hey Martin,

    Great to hear that my thread could help! I was hoping that someone would find it useful. It probably took me 4-6 weeks to get it to work. There wasn't any documentation out there about how to integrate the s-functions in embedded coder with the auto-gen TI code.

    Hope this leads to some great results for you!

    John

  • Hi Jonathan, 

    Thanks for sharing!! It helps me a lot on doing my project.

    Do I need to include _.c & _ wrapper. as a source files in my simulink model?

    Kevin