Filter löschen
Filter löschen

How to optimize this generated code?

1 Ansicht (letzte 30 Tage)
Xiaojie Qiu
Xiaojie Qiu am 5 Mär. 2018
Kommentiert: Xiaojie Qiu am 20 Mär. 2018
Hi everyone,
I'm using embedded coder to generate code for an STM32 microcontroller, but having problem with optimizing generated code.
As shown in figure below, I want to reset two GPIOs to LOW.
However, the generated code for this algorithm is:
if (0.0 == 0)
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_RESET);
else
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_SET);
if (0.0 == 0)
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, GPIO_PIN_RESET);
else
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, GPIO_PIN_SET);
But I don't think it's necessary to check if 0 equels 0. Instead, to save code execution time, the code should be:
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, GPIO_PIN_RESET);
So, I'd like to know how to configue Simulink model to optimize this code?
Apart from this problem, what documentations for code optimization techniques would be highly recommended while using embedded coder?
Any recommendations would be highly appreciated.
Thanks and best regards! qxj

Antworten (1)

Mark McBroom
Mark McBroom am 9 Mär. 2018
Try changing the data type of the contant blocks to be integer or boolean.
  1 Kommentar
Xiaojie Qiu
Xiaojie Qiu am 20 Mär. 2018
Hi Mark, thanks for your help! I tried both uint8 and boolean data types for these two constant blocks. But the problem still stays.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by