Skip to content

%zu not supported by newlib's printf in Arduino_STM32 toolchain #38

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

Closed
fronders opened this issue Feb 4, 2024 · 2 comments · Fixed by #39 or #40
Closed

%zu not supported by newlib's printf in Arduino_STM32 toolchain #38

fronders opened this issue Feb 4, 2024 · 2 comments · Fixed by #39 or #40

Comments

@fronders
Copy link
Contributor

fronders commented Feb 4, 2024

People have been reporting same problem when using newlib printf. This is what's included into Arduino STM32 toolchain and so the %zu format specifier doesn't work, and instead of putting the number it puts "zu" into the resulting string.

As a consequence the getFileBlock() just freezes and never returns

size_t cmd_len = filename.length() + 32;
char* cmd = sara_r5_calloc_char(cmd_len);
sprintf(cmd, "at+urdblock=\"%s\",%zu,%zu\r\n", filename.c_str(), offset, requested_length);
sendCommand(cmd, false);

Here's the debugger screenshot:
image

Changing those to %lu fixes the issue.

UPD:
By default, the sketches use newlib nano option which passes linker flags --specs=nano.specs
I'm usually compiling using the "newlib nano + float printf" which is --specs=nano.specs -u _printf_float cause I need floats support in printfs. After switching to the full-featured "newlib standard" (which doesn't pass any additional flags) the %zu specifier worked! I assume the nano option supplied with ARM toolchain newlib is built without C99 formatting support. But I don't use it because it makes the flash size (program storage space) explode - the same sketch went from 82376 to 188208 bytes, as well as RAM went +1kB!

@fronders fronders changed the title %zu not supported by newlib printf Arduino_STM32 toolchain %zu not supported by newlib's printf in Arduino_STM32 toolchain Feb 4, 2024
@PaulZC
Copy link
Collaborator

PaulZC commented Feb 4, 2024

Hi @fronders ,

Glad you got it working. How would you like to resolve this? I am happy to pin it, to make it easier for others to find and re-use your solution.

Best wishes,
Paul

fronders added a commit to haydenth/SparkFun_u-blox_SARA-R5_Arduino_Library that referenced this issue Feb 5, 2024
This fixes sparkfun#38
When used with ARM GCC Toolchain supplied with Arduino_STM32 newlib nano version is built without C99 formats support, so the %zu format specifier doesn't work, and instead of putting the number it puts "zu" into the resulting string
@fronders
Copy link
Contributor Author

fronders commented Feb 5, 2024

Hi @PaulZC,

I think the best would be to update the code to make it usable for everyone, even ARM toolchain with nano version of newlib.
See the PR with some more fixes :)

@PaulZC PaulZC linked a pull request Feb 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants