How to remove 'sl_padding' fields in the generated code using Simulink Coder in MATLAB R2022b?
조회 수: 7 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2025년 4월 9일
답변: MathWorks Support Team
2025년 4월 10일
I am generating code for a top model using Simulink Coder in MATLAB R2022b. When using "rtwsfcn.tlc," I noticed extra "sl_padding" fields in the generated code, specifically in the *_types.h file. Please refer to the following code snippets for more details:
Using rtwsfcn.tlc:
typedef struct {
boolean_T EN[2];
uint8_T sl_padding0[2]; -> padding here
real32_T Value[2];
int32_T Time[2];
uint8_T sl_padding1[4]; -> padding here
} EN_Value_Time2;
Using a custom TLC:
typedef struct {
boolean_T EN[2];
real32_T Value[2];
int32_T Time[2];
} EN_Value_Time2;
How to avoid having "sl_padding" in the generated code using "rtwsfcn.tlc" target?
채택된 답변
MathWorks Support Team
2025년 4월 10일
For the "rtwsfcn" target, we currently do not support the absence of paddings in the generated code. This limitation arises from how buses (structs in code) are interpreted in Simulink. Simulink requires padding to ensure safety when copying elements, which helps prevent crashes or incorrect results.
In this case, you might benefit from using model references or a protected model for the low-level model. You can then generate code for the top model with the referenced model. In that case, there is no need to work with S-Functions or TLC, which will eliminate the "sl_padding" fields. For more information, please refer to the MATLAB Answers post on using reference models instead of S-Functions for target code generation.
Another alternative is to utilize a Functional Mockup Unit (FMU) for the low-level model and import that into Simulink to generate code. Please note that this workflow is supported starting from MATLAB R2024a. You can learn more about FMU on the FMU importing documentation page.
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!