-
Notifications
You must be signed in to change notification settings - Fork 67
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 memory size defines #166
base: master
Are you sure you want to change the base?
Fix memory size defines #166
Conversation
Not quite. I am using hardcoded values for EEPROM, because 2k of the EEPROM is reserved for system purposes (in that case LoRaWAN session data). The value for the RAM size was hardcoded originally to avoid pulling in stm32l0xx.h. Some of the code still pulls that in via Arduino.h, so it's kind of a "who cares" at that point of time. Ideally this should be going into some "wiring_xyz.h" file so that another port can properly set that. |
Ah, I see. Though just hardcodedly reserving 2k of EEPROM is probably not the best approach in general, since:
I'm working on a board that uses this core but indeed does not use the LoRaWAN library, but I want to store some write-once Unfortunately, the standard EEPROM library has no meaningful API for this, i.e. no way to say "this bit of EEPROM is reserved for use by libraries" or something like that. This could be useful, but should probably be done in the default Arduino cores first in order to standardize (or maybe there is some third-party library that does something like this alread that could be adopted or recommended?). Also, not all of the chips in the L0 series have 6k of EEPROM, some don't even have 2k it seems. Maybe all currently supported boards do have 6k, but it would of course be nicer to make this stuff as general as possible (to allow defining boards with smaller chips too). Maybe a compromise could be to define this as a board option? i.e. An alternative could be to use In particular, this would mean adding a #define REAL_E2END (...calculation...)
if __has_include(<stm32l0_lorawan_used>)
#define E2END (REAL_E2END - 2048)
#else
#define E2END REAL_E2END
#endif I'm not quite sure what the best approach is here, though.
But given there are also L0 chips that have smaller RAM, autodetecting this would probably be more correct?
What do you mean by "another port" here? I.e. to allow sharing code between STM32l0 and l4? |
You are right about different L0 chips. Got to fix that. L052 has 8k SRAM and 2k EEPROM (no LoRaWAN support there). LoRaWAN needs 2k. I do not want to go into all the gory details, but yes it needs that. What might be the best way to handle this is to have some STM32L0_CONFIG_xyz style defines to override the EEPROM size. Just needed to change Arduino.h then to include "variant.h" before "avr/eeprom.h"
SRAM probably yes, EEPROM no.
Perhaps ... who knows. At least the STM32WB/WL port share the same core/arduino and libraries as a starting point. |
This was previously hardcoded to a single value, but is now derived from the STM32 chip-specific header files.
This was previously hardcoded to 4k, which is intended for devices with 6k of EEPROM reserving 2k for the LoRaWAN library. For devices like the L053, that only has 2k of EEPROM, this would result in an invalid EEPROM size. Now, this reserved value is more explicit and is configured on a per-board basis in variant.h using the new `STM32L0_CONFIG_EEPROM_RESERVED` macro. This is set to 2048 for all boards that have an embedded LoRaWAN transceiver and left undefined for the more generic boards. Then the full EEPROM size is autodetected using the STM32 CMSIS header files and exposed as `REAL_E2END`, and the reserved area is subtracted from that and exposed as `E2END` (and also through `EEPROM.length()`). This also changes `Arduino.h` to move the `avr/*.h` includes down to below the `variant.h` include (just moving `avr/io.h` would have been enough, but this is more consistent), so `variant.h` can be used in io.h. This also includes `Arduino.h` from `io.h`, in case `io.h` is included directly by a sketch. Note that the autodetection uses macros that include a typecast, so the resulting `E2END` macro cannot be examined by the preprocessor (e.g. an `#if` statement), which is why this uses a `static_assert` instead to check that `STM32L0_CONFIG_EEPROM_RESERVED` is not too big. The resulting expression is a valid constant expression in both C and C++ contexts, though.
c544f48
to
b98a094
Compare
I'm not sure if board-dependent reservation is the perfect solution, but it would work for me for now (I can just disable the reservation in my board file then). Note that I think
Wouldn't it be cleaner to just autodetect the EEPROM size (and set e.g. I've implemented the combination of the above and replaced the commits in this PR. See the commit message for additional details. Open questions:
|
I am not happy with messing with the size there. I see I need to fix L052, but nobody complianed yet. For L072, do you have a real problem with only 4k EEPROM, or is it a matter of cleanness of the code ? My issue there is that memory is managed in general by the platform code. Say some boot code ... you could say, yes but I don't need it ... Or the section layout in the linker file with some reserved holes. Or the fact that the I2C code is using ISR/DMA, where you could write blocking code that needs less. Or the fact that 4 or the 5 RTC_BKUP registers are used up internally. The L072 platform has 2k EEPROM reserved for system purposes. L052 will not reserve anything at the moment, but might move to reserve 512 bytes, or 1024 bytes going forward. |
How is setting the correct size messing?
I need to put my write-once settings (i.e. id and keys) at the end of EEPROM (both because I want to keep the EEPROM start free for sketches to use, and because I need to coordinate this with my board manufacturer that also wants to store some tracing code and is settling on an "end of EEPROM" convention). I can probably bypass the |
Mind pining me directly via [email protected].
…On Wed, Nov 4, 2020 at 10:43 AM Matthijs Kooijman ***@***.***> wrote:
I am not happy with messing with the size there. I see I need to fix L052,
but nobody complianed yet.
How is setting the correct size messing?
For L072, do you have a real problem with only 4k EEPROM, or is it a
matter of cleanness of the code ?
I need to put my write-once settings (i.e. id and keys) at the end of
EEPROM (both because I want to keep the EEPROM start free for sketches to
use, and because I need to coordinate this with my board manufacturer that
also wants to store some tracing code and is settling on an "end of EEPROM"
convention).
I can probably bypass the EEPROM.length() / E2END and do the detection
myself (and then just call the STM32 EEPROM functiosn or eeprom_read_block
or so directly), but even then I'm losing up to 2k of EEPROM for no good
reason. I don't have any specific need for that memory right now, but this
is intented as a generic development platform, so I'm not quite prepared to
make this part of the EEPROM inaccessible just because that was easier.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#166 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABXBA7AANZXO6UN2JTDEO4LSOGHFJANCNFSM4TKDCJSQ>
.
|
This fixes a number of macros in
avr/io.h
that used to hardcode memory sizes, but now base on the actual STM32 header files. In particular, this affects the EEPROM sizeE2END
, which also affectsEEPROM.length()
.