diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 013e5a61..54e31813 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -30,13 +30,6 @@ typedef bool boolean; typedef uint8_t byte; typedef uint16_t word; -// some libraries and sketches depend on this AVR stuff, -// assuming Arduino.h or WProgram.h automatically includes it... -// -#include "avr/pgmspace.h" -#include "avr/interrupt.h" -#include "avr/io.h" - #include "binary.h" #include "itoa.h" @@ -89,6 +82,12 @@ void loop( void ) ; // Include board variant #include "variant.h" +// some libraries and sketches depend on this AVR stuff, +// assuming Arduino.h or WProgram.h automatically includes it... +#include "avr/pgmspace.h" +#include "avr/interrupt.h" +#include "avr/io.h" + #include "wiring.h" #include "wiring_digital.h" #include "wiring_analog.h" diff --git a/cores/arduino/avr/io.h b/cores/arduino/avr/io.h index 01982e0b..5793ede4 100644 --- a/cores/arduino/avr/io.h +++ b/cores/arduino/avr/io.h @@ -25,10 +25,27 @@ #ifndef _IO_H_ #define _IO_H_ -#define RAMSTART 0x20000000 -#define RAMSIZE (20 * 1024) +#include +#include + +#define RAMSTART (SRAM_BASE) +#define RAMSIZE (SRAM_SIZE_MAX) #define RAMEND (RAMSTART + RAMSIZE - 1) -#define E2END 0xfff +#if defined(DATA_EEPROM_BASE) && defined(DATA_EEPROM_END) + #define REAL_E2END (DATA_EEPROM_END - DATA_EEPROM_BASE) +#elif defined(DATA_EEPROM_BASE) && defined(DATA_EEPROM_BANK2_BASE) && defined(DATA_EEPROM_BANK1_END) && defined(DATA_EEPROM_BANK2_END) + #define REAL_E2END (DATA_EEPROM_BANK1_END - DATA_EEPROM_BASE + 1 + DATA_EEPROM_BANK2_END - DATA_EEPROM_BANK2_BASE) +#else + #error "Cannot determine EEPROM size" +#endif + +#if defined(STM32L0_CONFIG_EEPROM_RESERVED) + static_assert(STM32L0_CONFIG_EEPROM_RESERVED <= REAL_E2END + 1, "STM32L0_CONFIG_EEPROM_RESERVED bigger than EEPROM"); + #define E2END (REAL_E2END - STM32L0_CONFIG_EEPROM_RESERVED) +#else + #define E2END REAL_E2END +#endif + #endif diff --git a/variants/B-L072Z-LRWAN1/variant.h b/variants/B-L072Z-LRWAN1/variant.h index e1249656..52f11fcc 100644 --- a/variants/B-L072Z-LRWAN1/variant.h +++ b/variants/B-L072Z-LRWAN1/variant.h @@ -37,6 +37,9 @@ #define STM32L0_CONFIG_HSECLK 0 #define STM32L0_CONFIG_SYSOPT 0 +// Reserve some room at the end of EEPROM for LoRaWAN library +#define STM32L0_CONFIG_EEPROM_RESERVED 2048 + /** Master clock frequency */ #define VARIANT_MCK F_CPU diff --git a/variants/Cicada-L082CZ/variant.h b/variants/Cicada-L082CZ/variant.h index ac6b4304..1994bae4 100644 --- a/variants/Cicada-L082CZ/variant.h +++ b/variants/Cicada-L082CZ/variant.h @@ -46,6 +46,9 @@ #define STM32L0_CONFIG_SFLASH_DATA_START (256 * 1024) +// Reserve some room at the end of EEPROM for LoRaWAN library +#define STM32L0_CONFIG_EEPROM_RESERVED 2048 + #define USBCON /** Master clock frequency */ diff --git a/variants/Cricket-L082CZ/variant.h b/variants/Cricket-L082CZ/variant.h index fbea4971..63ada1b3 100644 --- a/variants/Cricket-L082CZ/variant.h +++ b/variants/Cricket-L082CZ/variant.h @@ -52,6 +52,9 @@ #define STM32L0_CONFIG_SFLASH_DATA_START (256 * 1024) +// Reserve some room at the end of EEPROM for LoRaWAN library +#define STM32L0_CONFIG_EEPROM_RESERVED 2048 + #define USBCON /** Master clock frequency */ diff --git a/variants/Gnat-L082CZ/variant.h b/variants/Gnat-L082CZ/variant.h index 5ec123e2..e46c1263 100644 --- a/variants/Gnat-L082CZ/variant.h +++ b/variants/Gnat-L082CZ/variant.h @@ -50,6 +50,9 @@ #define STM32L0_CONFIG_PIN_GNSS_RX STM32L0_GPIO_PIN_PA10_USART1_RX #define STM32L0_CONFIG_PIN_GNSS_TX STM32L0_GPIO_PIN_PA9_USART1_TX +// Reserve some room at the end of EEPROM for LoRaWAN library +#define STM32L0_CONFIG_EEPROM_RESERVED 2048 + #define USBCON /** Master clock frequency */ diff --git a/variants/Grasshopper-L082CZ/variant.h b/variants/Grasshopper-L082CZ/variant.h index 6048dac7..5fdd4e9d 100644 --- a/variants/Grasshopper-L082CZ/variant.h +++ b/variants/Grasshopper-L082CZ/variant.h @@ -42,6 +42,9 @@ #define STM32L0_CONFIG_SFLASH_DATA_START (256 * 1024) +// Reserve some room at the end of EEPROM for LoRaWAN library +#define STM32L0_CONFIG_EEPROM_RESERVED 2048 + #define USBCON /** Master clock frequency */ diff --git a/variants/I-NUCLEO-LRWAN1/variant.h b/variants/I-NUCLEO-LRWAN1/variant.h index 2c092dde..552293b6 100644 --- a/variants/I-NUCLEO-LRWAN1/variant.h +++ b/variants/I-NUCLEO-LRWAN1/variant.h @@ -37,6 +37,9 @@ #define STM32L0_CONFIG_HSECLK 0 #define STM32L0_CONFIG_SYSOPT 0 +// Reserve some room at the end of EEPROM for LoRaWAN library +#define STM32L0_CONFIG_EEPROM_RESERVED 2048 + /** Master clock frequency */ #define VARIANT_MCK F_CPU diff --git a/variants/NUCLEO-L073RZ/variant.h b/variants/NUCLEO-L073RZ/variant.h index 5036804f..157c1720 100644 --- a/variants/NUCLEO-L073RZ/variant.h +++ b/variants/NUCLEO-L073RZ/variant.h @@ -37,6 +37,9 @@ #define STM32L0_CONFIG_HSECLK 0 #define STM32L0_CONFIG_SYSOPT 0 +// Reserve some room at the end of EEPROM for LoRaWAN library +#define STM32L0_CONFIG_EEPROM_RESERVED 2048 + /** Master clock frequency */ #define VARIANT_MCK F_CPU diff --git a/variants/P-NUCLEO-LRWAN1/variant.h b/variants/P-NUCLEO-LRWAN1/variant.h index 1ee4f78d..b717fa2f 100644 --- a/variants/P-NUCLEO-LRWAN1/variant.h +++ b/variants/P-NUCLEO-LRWAN1/variant.h @@ -37,6 +37,9 @@ #define STM32L0_CONFIG_HSECLK 0 #define STM32L0_CONFIG_SYSOPT 0 +// Reserve some room at the end of EEPROM for LoRaWAN library +#define STM32L0_CONFIG_EEPROM_RESERVED 2048 + /** Master clock frequency */ #define VARIANT_MCK F_CPU