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

Fix: Unsupported use of %f in printf #21001

Merged
merged 18 commits into from
Feb 8, 2021

Conversation

MKS-Sean
Copy link
Contributor

@MKS-Sean MKS-Sean commented Feb 5, 2021

Description

When using the arduinoststm32 library (robin nano v3.0), using sprintf_P to copy float variables will make an error, but the test in the maple library is normal (robin nano v2.0)

Tested in MKS Robin nano V3.0 motherboard:
Before modification:
image

After modification:
image

Requirements

Use arduinoststm32 library (MKS Robin nano V3.0 mainboard using it).
Use sprintf_P(buf,PSTR(“%.1f”),float_var);

Benefits

LVGL UI can display float type variable parameters normally

Configurations

default_envs = mks_robin_nano_v3_usb_flash_drive_msc
Configurations.zip

Related Issues

No

@thinkyhead thinkyhead changed the title Fixed an error in LVGL UI copying float variables using sprintf_P Fix: Unsupported use of %f in printf Feb 5, 2021
@X-Ryl669
Copy link
Contributor

X-Ryl669 commented Feb 5, 2021

Wouldn't it be easier to set the right linker flags to use the full sprintf version, instead of relying on such painful code?
See here
Basically, it boils down to adding -Wl,-u,vfprintf -lprintf_flt -lm to the linker's command.
Nano v3 is pretty powerful it can support few kB of flash for printing float.

@rhapsodyv
Copy link
Member

@MKS-Sean Can you take a look if it's working after Scott reviews?

@thinkyhead
Copy link
Member

@X-Ryl669 — For now Marlin is keen to retain Arduino IDE build support, even for code (such as FSMC LCD) that theoretically might never be compiled and run on an AVR.

@thinkyhead
Copy link
Member

thinkyhead commented Feb 8, 2021

What would be very useful would be a lightweight C++ string class with operator overrides that would turn our ugly string code into something more elegant. The entire codebase would benefit. I wrote my own C++ string class once many moons ago, but there are probably a million examples around that we could use as a starting-point.

Our only caveat is no dynamic allocation. All buffers must be provided by the caller or allocated on the stack. But, given the ubiquity of "string stuff" it wouldn't be the worst thing to add a dedicated buffer for "current string" work, thus making many function stack frames smaller.

@thinkyhead thinkyhead merged commit 57e4b82 into MarlinFirmware:bugfix-2.0.x Feb 8, 2021
rmpel added a commit to rmpel/Marlin that referenced this pull request Feb 11, 2021
* bugfix-2.0.x: (177 commits)
  [cron] Bump distribution date (2021-02-11)
  chmod and paths
  [cron] Bump distribution date (2021-02-10)
  Reheat bed first
  Ender 3 V2 DWIN cleanup (MarlinFirmware#21026)
  Update M808 comment
  MAX Thermocouples rework (MarlinFirmware#20447)
  [cron] Bump distribution date (2021-02-09)
  Serial refactor. Default 8-bit ECHO to int, not char (MarlinFirmware#20985)
  Fix STM32F1 emergency parser (MarlinFirmware#21011)
  Allow SERVO0_PIN override on Creality Melzi (MarlinFirmware#21007)
  Fix animated boot screen
  Fix: Unsupported use of %f in printf (MarlinFirmware#21001)
  Fix mini12864 v2.1 + PSU control + NeoPixel backlight (MarlinFirmware#21021)
  [cron] Bump distribution date (2021-02-08)
  Fix LVGL "more" menu user items (MarlinFirmware#21004)
  Fix TEMP_0_TR_ENABLE, rename temp conditions (MarlinFirmware#21016)
  Fix ESP32 I2S init placement (MarlinFirmware#21019)
  Improve RPi host kernel panic mitigation
  Melzi, comments cleanup
  ...
rmpel added a commit to rmpel/Marlin that referenced this pull request Feb 13, 2021
…rmpel/Marlin into rmpel/bugfix-2.0.x/ender-3-skr-14-turbo

* 'rmpel/bugfix-2.0.x/ender-3-skr-14-turbo' of github.com:rmpel/Marlin: (177 commits)
  [cron] Bump distribution date (2021-02-11)
  chmod and paths
  [cron] Bump distribution date (2021-02-10)
  Reheat bed first
  Ender 3 V2 DWIN cleanup (MarlinFirmware#21026)
  Update M808 comment
  MAX Thermocouples rework (MarlinFirmware#20447)
  [cron] Bump distribution date (2021-02-09)
  Serial refactor. Default 8-bit ECHO to int, not char (MarlinFirmware#20985)
  Fix STM32F1 emergency parser (MarlinFirmware#21011)
  Allow SERVO0_PIN override on Creality Melzi (MarlinFirmware#21007)
  Fix animated boot screen
  Fix: Unsupported use of %f in printf (MarlinFirmware#21001)
  Fix mini12864 v2.1 + PSU control + NeoPixel backlight (MarlinFirmware#21021)
  [cron] Bump distribution date (2021-02-08)
  Fix LVGL "more" menu user items (MarlinFirmware#21004)
  Fix TEMP_0_TR_ENABLE, rename temp conditions (MarlinFirmware#21016)
  Fix ESP32 I2S init placement (MarlinFirmware#21019)
  Improve RPi host kernel panic mitigation
  Melzi, comments cleanup
  ...
rmpel added a commit to rmpel/Marlin that referenced this pull request Feb 13, 2021
* bugfix-2.0.x: (177 commits)
  [cron] Bump distribution date (2021-02-11)
  chmod and paths
  [cron] Bump distribution date (2021-02-10)
  Reheat bed first
  Ender 3 V2 DWIN cleanup (MarlinFirmware#21026)
  Update M808 comment
  MAX Thermocouples rework (MarlinFirmware#20447)
  [cron] Bump distribution date (2021-02-09)
  Serial refactor. Default 8-bit ECHO to int, not char (MarlinFirmware#20985)
  Fix STM32F1 emergency parser (MarlinFirmware#21011)
  Allow SERVO0_PIN override on Creality Melzi (MarlinFirmware#21007)
  Fix animated boot screen
  Fix: Unsupported use of %f in printf (MarlinFirmware#21001)
  Fix mini12864 v2.1 + PSU control + NeoPixel backlight (MarlinFirmware#21021)
  [cron] Bump distribution date (2021-02-08)
  Fix LVGL "more" menu user items (MarlinFirmware#21004)
  Fix TEMP_0_TR_ENABLE, rename temp conditions (MarlinFirmware#21016)
  Fix ESP32 I2S init placement (MarlinFirmware#21019)
  Improve RPi host kernel panic mitigation
  Melzi, comments cleanup
  ...
kpishere pushed a commit to kpishere/Marlin that referenced this pull request Feb 19, 2021
zillarob pushed a commit to zillarob/Marlin that referenced this pull request Feb 25, 2021
vyacheslav-shubin pushed a commit to vyacheslav-shubin/Marlin that referenced this pull request Mar 10, 2021
vyacheslav-shubin pushed a commit to vyacheslav-shubin/Marlin that referenced this pull request Mar 10, 2021
W4tel-BiDi pushed a commit to W4tel-BiDi/Marlin that referenced this pull request Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants