Conversation
| @@ -0,0 +1,1006 @@ | |||
| /* Copyright (c) 2002, 2005, 2007 Joerg Wunsch | |||
There was a problem hiding this comment.
so this is not the default avr libs stdio.h?
There was a problem hiding this comment.
I took it from here https://www.nongnu.org/avr-libc/user-manual/stdio_8h_source.html
There was a problem hiding this comment.
Is it a verbatim copy? If so, note that avr-libc is used anyway for all AVR boards anyway.
| include ../Makefile.tests_common | ||
|
|
||
| CFLAGS += -DAVR_STDIO_PGMSPACE | ||
| FEATURES_REQUIRES += arch_avr |
There was a problem hiding this comment.
| FEATURES_REQUIRES += arch_avr | |
| FEATURES_REQUIRED += arch_avr |
|
This should at least be optional and not default. Too bad the compiler cannot do this (use `puts_p() if used on a constant string literal)) automatically... |
|
I was thinking about using However, I'm not sure if overwriting (parts of) One point that I was specifically looking at is the stringification in |
Yes probably all the shell commands function could use this.
Yes this would be better than refining |
|
What I do not understand: If Cortex-M3 is also a Harvard machine, why can it be handled transparency by the compiler there? |
The difference between the Harvard and the von-Neumann architecture in the "original" sense is that Harvard has two distinct address spaces for program and data, and von-Neumann only has one for both. Many modern Harvard architectures however map program space also into the data address space. (Even the ATtiny of the AVR family do so.) If that is the case, you can safely access ROM data in the very same way as RAM data (except it is read-only). In the classic Harvard machine, it is completely impossible to read data from program memory - you can only run it. The ATmega family is already an improvement upon this, as it has two load instructions - one working with data addresses, one with program addresses. However, the compiler must now which instruction it has to emit at compile time. And as data and program address can have the same value range, you couldn't even provide a generic helper like: void memcpy_program_or_data(void *dest, void *src, size_t len)
if (is_program_memory(src)) {
memcpy_from_program_memory(dest, src, len);
}
else {
memcpy(dest, src, len);
}
}So, yes: It is a limitation of the AVR (or specifically, the ATmega family - it would work fine for ATtinys). |
fcbf9b5 to
b21c5eb
Compare
- Add vendor files to define all stdio functions as their PGMSPACE equivalent. This can be enabled by setting the flag AVR_STDIO_PGMSPACE.
b21c5eb to
7826ed2
Compare
Contribution description
When testing #12461 I realized many tests where not compiling on
arduino-%platforms because a lot of new strings were going into.bss. This pushed me to explore how to force storing them in flash.When compiling for AVR because of harvard architecture constant data goes into RAM instead of flash. This can be quite a strain for prints loaded applications with small memory like
arduino-uno.pgmspacecan be used to force strings and other variables to go intro flash, this POC overwritessome of the stdio functions to use there
pgmspaceversions.Maybe it could make sense to enable this by default for the smaller platforms. This can work as long as the
stdiofunctions receive a string literal and not variables. This is because the variable needs to be stored inpgmspaceby using thePROGMEMkey word ass well as using thepgmspaceversion of the function.puts("toto")PROGMEMkey word.In the case of
putsthere are some uses that prevent this, but they could be migrated.printfand others could not be enabled by default since too much code uses a variable instead of a string literal.Maybe the best way of doing this is modifying the linker script itself? I tried doing it as well but it was quite dirty to be honest, maybe someone else can find a good solution? This would probably work better since all constant initialized data could be moved and not only strings.
Testing procedure
Does this make sense? Maybe it is too much of a hack and I know we don't like this kind of macro usage.
Run the test, enable globally and compare some compiled firmware
.bss,.data,.txtusage.Is this worth exploring further??