Azzera filtri
Azzera filtri

Code generation changes behavior from Matlab 2020b to 2023b

18 visualizzazioni (ultimi 30 giorni)
"Not too long ago, I switched from Matlab version 2020b to 2023b, upgrading all Simulink files in the process. Now, I'm encountering an issue where the Simulink code generation structures the C files differently (see the code snippet below), causing the compiler to fail to compile them.
C-Code from Matlab-Version 2020b:
actuator_state = (uint8_T)!Process_U.alive;
if (Process_U.actuator_flag) {
actuator_state = (uint8_T)(int32_T)((int32_T)actuator_state | 2);
}
if (Process_U.state == 2) {
actuator_state = (uint8_T)(int32_T)((int32_T)actuator_state | 4);
}
if (Process_U.state == 3) {
actuator_state = (uint8_T)(int32_T)((int32_T)actuator_state | 8);
}
C-Code from Matlab-Version 2023b
if (Process_U.actuator_flag) {
b_a = (uint8_T)(int32_T)(!Process_U.alive | 2);
} else {
b_a = (uint8_T)!Process_U.alive;
}
if (Process_U.state == 2) {
b_a = (uint8_T)(int32_T)((int32_T)b_a | 4);
}
if (Process_U.state == 3) {
b_a = (uint8_T)(int32_T)((int32_T)b_a | 8);
}
I wanted to ask if you know which setting might be causing this change.
Thank you very much.
  2 Commenti
Brahmadev
Brahmadev il 1 Apr 2024
Looking at both the codes, they seem logically identical, except that in 2020b, "actuator_state" is defined before the if-else conditional statement. Can you provide more information on what exact issue you are facing while compiling the generated C code in 2023b or a model to reproduce the issue?
If you have the license for Embedded Coder, the following Code Generation > Optimization parameters can be tweaked to control the code generation as per your usage:
  1. Turn on "Inline invariant signals" to precompute and inline values of invariant signals ingenerated code.
  2. Optimize global data access > Use Global to hold temporary results for using global variables for temporary data.
  3. Eliminate superfluous local variables (expression folding) can be turned off to compute local variables at each stage and allow better readability.
Also, if more control is needed over the generation of if-else conditional statements, if block can be used instead of switch block in simulink.
Steffen
Steffen il 2 Apr 2024
Thank you for the response. I will make these adjustments. Yes, we use Embedded Coder, Simulink Coder, and MATLAB Coder. The toolboxes operate in a pipeline that generates this C code.
During compilation, there is this error:
Process.c: In function 'Process_step':
Process.c:2896:30: error: suggest parentheses around operand of '!' or change '|' to '||' or '!' to '~' [-Werror=parentheses]
2896 | b_a = (uint8_T)(int32_T)(!Process_U.alive | 2);
|
Since compilation worked in the last MATLAB version, I thought that the generated C code in MATLAB 2023b might not be suitable for the compiler. Especially since we haven't modified the compiler.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by