Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error management: save space when core logs are not enabled #1739

Merged
merged 4 commits into from
Jun 16, 2022

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Jun 10, 2022

This PR refactor the core debug log management:

  • Add menu entries to enable the Core logs:
    image
  • Remove CORE_DEBUG usage as replaced by the menu.
  • Refactor error handler definition to save space when core logs are not enabled (removed unused const char array from .rodata).
    When core logs are not enable, NDEBUG is defined and used to prevent print from Error_Handler thanks to core_debug.

Build result of AnalogReadSerial.ino for NucleoWL55JC1

  • Before this PR:

Sketch uses 18780 bytes (7%) of program storage space. Maximum is 262144 bytes.
Global variables use 896 bytes (1%) of dynamic memory, leaving 64640 bytes for local variables. Maximum is 65536 bytes.

  • With this PR and Core logs disabled:

Sketch uses 17832 bytes (6%) of program storage space. Maximum is 262144 bytes.
Global variables use 896 bytes (1%) of dynamic memory, leaving 64640 bytes for local variables. Maximum is 65536 bytes.

  • With this PR and Core logs enabled:

Sketch uses 24012 bytes (9%) of program storage space. Maximum is 262144 bytes.
Global variables use 1108 bytes (1%) of dynamic memory, leaving 64428 bytes for local variables. Maximum is 65536 bytes.

Finally, to reduce const char array size from .rodata and also having the same binary size whatever the core location.
__FILE__ has been shorten to be relative to the core path using -fmacro-prefix-map option. It simply replaces absolute core path by .
See https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html

Ex:

AnalogReadSerial.ino.elf:     file format elf32-littlearm

Contents of section .rodata:
 8005d6c 433a5c53 544d3332 5c617264 75696e6f  C:\STM32\arduino
 8005d7c 5c617264 75696e6f 2d312e38 2e31395c  \arduino-1.8.19\
 8005d8c 706f7274 61626c65 5c706163 6b616765  portable\package
 8005d9c 735c5354 4d696372 6f656c65 6374726f  s\STMicroelectro
 8005dac 6e696373 5c686172 64776172 655c7374  nics\hardware\st
 8005dbc 6d33325c 322e322e 305c6c69 62726172  m32\2.2.0\librar
 8005dcc 6965735c 53726357 72617070 65725c73  ies\SrcWrapper\s
 8005ddc 72635c48 61726477 61726554 696d6572  rc\HardwareTimer
 8005dec 2e637070 00040208 00101010 04101010  .cpp............

to:

AnalogReadSerial.ino.elf:     file format elf32-littlearm

Contents of section .rodata:
 8005d6c 2e5c6c69 62726172 6965735c 53726357  .\libraries\SrcW
 8005d7c 72617070 65725c73 72635c48 61726477  rapper\src\Hardw
 8005d8c 61726554 696d6572 2e637070 00040208  areTimer.cpp....
  • With this PR and Core logs enabled and shorten __FILE__ :

Sketch uses 23572 bytes (8%) of program storage space. Maximum is 262144 bytes.
Global variables use 1108 bytes (1%) of dynamic memory, leaving 64428 bytes for local variables. Maximum is 65536 bytes.

N.B. to check .rodata contents:
arm-none-eabi-objdump.exe -s -j .rodata *.elf

N.B.2: huge size of the binary is mainly due to the libc printf() usage. Maybe a tiny printf implementation could be done to decrease it.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Copy link
Contributor

@ABOSTM ABOSTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fpistm fpistm added this to the 2.3.0 milestone Jun 15, 2022
@fpistm fpistm requested a review from ABOSTM June 15, 2022 16:17
When core logs are not enable, NDEBUG is defined and used to prevent
print from Error_Handler thanks to core_debug.

Remove CORE_DEBUG usage.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Append -fmacro-prefix-map option to change __FILE__
absolute path of the board platform folder to a
relative path by using '.'.
(i.e. the folder containing boards.txt)

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm added this to In progress in STM32 core based on ST HAL via automation Jun 16, 2022
@fpistm fpistm self-assigned this Jun 16, 2022
Copy link
Contributor

@ABOSTM ABOSTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

STM32 core based on ST HAL automation moved this from In progress to Reviewer approved Jun 16, 2022
@fpistm
Copy link
Member Author

fpistm commented Jun 16, 2022

/cc @massonal FYI

@fpistm fpistm merged commit 72add56 into stm32duino:main Jun 16, 2022
STM32 core based on ST HAL automation moved this from Reviewer approved to Done Jun 16, 2022
@fpistm fpistm deleted the error_management branch June 16, 2022 13:56
mriscoc added a commit to mriscoc/Arduino_Core_STM32 that referenced this pull request Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants