aboutsummaryrefslogtreecommitdiff
path: root/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'platforms')
-rw-r--r--platforms/arm_atsam/hardware_id.c2
-rw-r--r--platforms/avr/hardware_id.c2
-rw-r--r--platforms/chibios/boards/common/ld/STM32F405xG_tinyuf2.ld89
-rw-r--r--platforms/chibios/converters/promicro_to_promicro_rp2040/pre_converter.mk2
-rw-r--r--platforms/chibios/converters/promicro_to_sparkfun_pm2040/_pin_defs.h (renamed from platforms/chibios/converters/promicro_to_promicro_rp2040/_pin_defs.h)0
-rw-r--r--platforms/chibios/converters/promicro_to_sparkfun_pm2040/converter.mk (renamed from platforms/chibios/converters/promicro_to_promicro_rp2040/converter.mk)0
-rw-r--r--platforms/chibios/drivers/eeprom/eeprom_legacy_emulated_flash.c7
-rw-r--r--platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c6
-rw-r--r--platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.h2
-rw-r--r--platforms/chibios/drivers/spi_master.c9
-rw-r--r--platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c33
-rw-r--r--platforms/chibios/hardware_id.c2
12 files changed, 141 insertions, 13 deletions
diff --git a/platforms/arm_atsam/hardware_id.c b/platforms/arm_atsam/hardware_id.c
index 8b3b35a492..fc193e46d8 100644
--- a/platforms/arm_atsam/hardware_id.c
+++ b/platforms/arm_atsam/hardware_id.c
@@ -3,7 +3,7 @@
#include "hardware_id.h"
-hardware_id_t get_hardware_id(void) {
+__attribute__((weak)) hardware_id_t get_hardware_id(void) {
hardware_id_t id = {0};
return id;
}
diff --git a/platforms/avr/hardware_id.c b/platforms/avr/hardware_id.c
index b61f0d92df..302a800e0b 100644
--- a/platforms/avr/hardware_id.c
+++ b/platforms/avr/hardware_id.c
@@ -10,7 +10,7 @@
#include <avr/boot.h>
#include "hardware_id.h"
-hardware_id_t get_hardware_id(void) {
+__attribute__((weak)) hardware_id_t get_hardware_id(void) {
hardware_id_t id = {0};
for (uint8_t i = 0; i < 10; i += 1) {
((uint8_t*)&id)[i] = boot_signature_byte_get(i + 0x0E);
diff --git a/platforms/chibios/boards/common/ld/STM32F405xG_tinyuf2.ld b/platforms/chibios/boards/common/ld/STM32F405xG_tinyuf2.ld
new file mode 100644
index 0000000000..1ee4aa1a06
--- /dev/null
+++ b/platforms/chibios/boards/common/ld/STM32F405xG_tinyuf2.ld
@@ -0,0 +1,89 @@
+/*
+ ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/*
+ * STM32F405xG memory setup.
+ * Note: Use of ram1 and ram2 is mutually exclusive with use of ram0.
+ */
+MEMORY
+{
+ flash0 (rx) : org = 0x08000000 + 64k, len = 1M - 64k /* tinyuf2 bootloader requires app to be located at 64k offset for this MCU */
+ flash1 (rx) : org = 0x00000000, len = 0
+ flash2 (rx) : org = 0x00000000, len = 0
+ flash3 (rx) : org = 0x00000000, len = 0
+ flash4 (rx) : org = 0x00000000, len = 0
+ flash5 (rx) : org = 0x00000000, len = 0
+ flash6 (rx) : org = 0x00000000, len = 0
+ flash7 (rx) : org = 0x00000000, len = 0
+ ram0 (wx) : org = 0x20000000, len = 128k /* SRAM1 + SRAM2 */
+ ram1 (wx) : org = 0x20000000, len = 112k /* SRAM1 */
+ ram2 (wx) : org = 0x2001C000, len = 16k /* SRAM2 */
+ ram3 (wx) : org = 0x00000000, len = 0
+ ram4 (wx) : org = 0x10000000, len = 64k /* CCM SRAM */
+ ram5 (wx) : org = 0x40024000, len = 4k /* BCKP SRAM */
+ ram6 (wx) : org = 0x00000000, len = 0
+ ram7 (wx) : org = 0x00000000, len = 0
+}
+
+/* For each data/text section two region are defined, a virtual region
+ and a load region (_LMA suffix).*/
+
+/* Flash region to be used for exception vectors.*/
+REGION_ALIAS("VECTORS_FLASH", flash0);
+REGION_ALIAS("VECTORS_FLASH_LMA", flash0);
+
+/* Flash region to be used for constructors and destructors.*/
+REGION_ALIAS("XTORS_FLASH", flash0);
+REGION_ALIAS("XTORS_FLASH_LMA", flash0);
+
+/* Flash region to be used for code text.*/
+REGION_ALIAS("TEXT_FLASH", flash0);
+REGION_ALIAS("TEXT_FLASH_LMA", flash0);
+
+/* Flash region to be used for read only data.*/
+REGION_ALIAS("RODATA_FLASH", flash0);
+REGION_ALIAS("RODATA_FLASH_LMA", flash0);
+
+/* Flash region to be used for various.*/
+REGION_ALIAS("VARIOUS_FLASH", flash0);
+REGION_ALIAS("VARIOUS_FLASH_LMA", flash0);
+
+/* Flash region to be used for RAM(n) initialization data.*/
+REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0);
+
+/* RAM region to be used for Main stack. This stack accommodates the processing
+ of all exceptions and interrupts.*/
+REGION_ALIAS("MAIN_STACK_RAM", ram0);
+
+/* RAM region to be used for the process stack. This is the stack used by
+ the main() function.*/
+REGION_ALIAS("PROCESS_STACK_RAM", ram0);
+
+/* RAM region to be used for data segment.*/
+REGION_ALIAS("DATA_RAM", ram0);
+REGION_ALIAS("DATA_RAM_LMA", flash0);
+
+/* RAM region to be used for BSS segment.*/
+REGION_ALIAS("BSS_RAM", ram0);
+
+/* RAM region to be used for the default heap.*/
+REGION_ALIAS("HEAP_RAM", ram0);
+
+/* Generic rules inclusion.*/
+INCLUDE rules.ld
+
+/* TinyUF2 bootloader reset support */
+_board_dfu_dbl_tap = ORIGIN(ram0) + 64k - 4; /* this is based off the linker file for tinyuf2 */
diff --git a/platforms/chibios/converters/promicro_to_promicro_rp2040/pre_converter.mk b/platforms/chibios/converters/promicro_to_promicro_rp2040/pre_converter.mk
new file mode 100644
index 0000000000..303d3135ce
--- /dev/null
+++ b/platforms/chibios/converters/promicro_to_promicro_rp2040/pre_converter.mk
@@ -0,0 +1,2 @@
+CONVERTER:=platforms/chibios/converters/promicro_to_sparkfun_pm2040
+ACTIVE_CONVERTER:=sparkfun_pm2040
diff --git a/platforms/chibios/converters/promicro_to_promicro_rp2040/_pin_defs.h b/platforms/chibios/converters/promicro_to_sparkfun_pm2040/_pin_defs.h
index 0a1f4112a3..0a1f4112a3 100644
--- a/platforms/chibios/converters/promicro_to_promicro_rp2040/_pin_defs.h
+++ b/platforms/chibios/converters/promicro_to_sparkfun_pm2040/_pin_defs.h
diff --git a/platforms/chibios/converters/promicro_to_promicro_rp2040/converter.mk b/platforms/chibios/converters/promicro_to_sparkfun_pm2040/converter.mk
index 03863eeb02..03863eeb02 100644
--- a/platforms/chibios/converters/promicro_to_promicro_rp2040/converter.mk
+++ b/platforms/chibios/converters/promicro_to_sparkfun_pm2040/converter.mk
diff --git a/platforms/chibios/drivers/eeprom/eeprom_legacy_emulated_flash.c b/platforms/chibios/drivers/eeprom/eeprom_legacy_emulated_flash.c
index a81fe3353c..9857ac046b 100644
--- a/platforms/chibios/drivers/eeprom/eeprom_legacy_emulated_flash.c
+++ b/platforms/chibios/drivers/eeprom/eeprom_legacy_emulated_flash.c
@@ -24,6 +24,7 @@
#include "debug.h"
#include "eeprom_legacy_emulated_flash.h"
#include "legacy_flash_ops.h"
+#include "eeprom_driver.h"
/*
* We emulate eeprom by writing a snapshot compacted view of eeprom contents,
@@ -564,6 +565,12 @@ void eeprom_driver_init(void) {
EEPROM_Init();
}
+void eeprom_driver_format(bool erase) {
+ /* emulated eepron requires the write log data structures to be erased before use. */
+ (void)erase;
+ eeprom_driver_erase();
+}
+
void eeprom_driver_erase(void) {
EEPROM_Erase();
}
diff --git a/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c b/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c
index ed26cc7145..628137a0b3 100644
--- a/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c
+++ b/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c
@@ -52,6 +52,12 @@ static inline void STM32_L0_L1_EEPROM_Lock(void) {
void eeprom_driver_init(void) {}
+void eeprom_driver_format(bool erase) {
+ if (erase) {
+ eeprom_driver_erase();
+ }
+}
+
void eeprom_driver_erase(void) {
STM32_L0_L1_EEPROM_Unlock();
diff --git a/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.h b/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.h
index 616d7ccbee..c1d801f225 100644
--- a/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.h
+++ b/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.h
@@ -20,7 +20,7 @@
The size used by the STM32 L0/L1 EEPROM driver.
*/
#ifndef STM32_ONBOARD_EEPROM_SIZE
-# ifdef VIA_ENABLE
+# ifdef DYNAMIC_KEYMAP_ENABLE
# define STM32_ONBOARD_EEPROM_SIZE 1024
# else
# include "eeconfig.h"
diff --git a/platforms/chibios/drivers/spi_master.c b/platforms/chibios/drivers/spi_master.c
index 57fc53d49f..fcdbc9ecf0 100644
--- a/platforms/chibios/drivers/spi_master.c
+++ b/platforms/chibios/drivers/spi_master.c
@@ -64,9 +64,14 @@ __attribute__((weak)) void spi_init(void) {
}
bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) {
+#if (SPI_USE_MUTUAL_EXCLUSION == TRUE)
+ spiAcquireBus(&SPI_DRIVER);
+#endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE)
+
if (spiStarted) {
return false;
}
+
#if SPI_SELECT_MODE != SPI_SELECT_MODE_NONE
if (slavePin == NO_PIN) {
return false;
@@ -326,4 +331,8 @@ void spi_stop(void) {
spiStop(&SPI_DRIVER);
spiStarted = false;
}
+
+#if (SPI_USE_MUTUAL_EXCLUSION == TRUE)
+ spiReleaseBus(&SPI_DRIVER);
+#endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE)
}
diff --git a/platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c b/platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c
index 3d6ed52e5c..f49c4a45b0 100644
--- a/platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c
+++ b/platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c
@@ -14,11 +14,15 @@ static flash_sector_t first_sector = WEAR_LEVELING_EFL_FIRST_SECTOR;
static flash_sector_t first_sector = UINT16_MAX;
#endif // defined(WEAR_LEVELING_EFL_FIRST_SECTOR)
+#if !defined(WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT)
+# define WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT 0
+#endif // WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT
+
static flash_sector_t sector_count = UINT16_MAX;
static BaseFlash * flash;
-
-static volatile bool is_issuing_read = false;
-static volatile bool ecc_error_occurred = false;
+static bool flash_erased_is_one;
+static volatile bool is_issuing_read = false;
+static volatile bool ecc_error_occurred = false;
// "Automatic" detection of the flash size -- ideally ChibiOS would have this already, but alas, it doesn't.
static inline uint32_t detect_flash_size(void) {
@@ -51,10 +55,19 @@ bool backing_store_init(void) {
uint32_t counter = 0;
uint32_t flash_size = detect_flash_size();
+ // Check if the hardware erase is logic 1
+ flash_erased_is_one = (desc->attributes & FLASH_ATTR_ERASED_IS_ONE) ? true : false;
+
+ if (WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT >= desc->sectors_count) {
+ // Last sector defined is greater than available number of sectors. Can't do anything here. Fault.
+ chSysHalt("Last sector intended to be used with wear_leveling is beyond available flash descriptor range");
+ }
+
#if defined(WEAR_LEVELING_EFL_FIRST_SECTOR)
// Work out how many sectors we want to use, working forwards from the first sector specified
- for (flash_sector_t i = 0; i < desc->sectors_count - first_sector; ++i) {
+ flash_sector_t last_sector = desc->sectors_count - WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT;
+ for (flash_sector_t i = 0; i < last_sector - first_sector; ++i) {
counter += flashGetSectorSize(flash, first_sector + i);
if (counter >= (WEAR_LEVELING_BACKING_SIZE)) {
sector_count = i + 1;
@@ -70,9 +83,9 @@ bool backing_store_init(void) {
#else // defined(WEAR_LEVELING_EFL_FIRST_SECTOR)
// Work out how many sectors we want to use, working backwards from the end of the flash
- flash_sector_t last_sector = desc->sectors_count;
- for (flash_sector_t i = 0; i < desc->sectors_count; ++i) {
- first_sector = desc->sectors_count - i - 1;
+ flash_sector_t last_sector = desc->sectors_count - WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT;
+ for (flash_sector_t i = 0; i < last_sector; ++i) {
+ first_sector = last_sector - i - 1;
if (flashGetSectorOffset(flash, first_sector) >= flash_size) {
last_sector = first_sector;
continue;
@@ -124,7 +137,9 @@ bool backing_store_write(uint32_t address, backing_store_int_t value) {
uint32_t offset = (base_offset + address);
bs_dprintf("Write ");
wl_dump(offset, &value, sizeof(value));
- value = ~value;
+ if (flash_erased_is_one) {
+ value = ~value;
+ }
return flashProgram(flash, offset, sizeof(value), (const uint8_t *)&value) == FLASH_NO_ERROR;
}
@@ -138,7 +153,7 @@ static backing_store_int_t backing_store_safe_read_from_location(backing_store_i
backing_store_int_t value;
is_issuing_read = true;
ecc_error_occurred = false;
- value = ~(*loc);
+ value = flash_erased_is_one ? ~(*loc) : (*loc);
is_issuing_read = false;
return value;
}
diff --git a/platforms/chibios/hardware_id.c b/platforms/chibios/hardware_id.c
index 1097db5966..fb67a0a63e 100644
--- a/platforms/chibios/hardware_id.c
+++ b/platforms/chibios/hardware_id.c
@@ -4,7 +4,7 @@
#include <ch.h>
#include "hardware_id.h"
-hardware_id_t get_hardware_id(void) {
+__attribute__((weak)) hardware_id_t get_hardware_id(void) {
hardware_id_t id = {0};
#if defined(RP2040)
// Forward declare as including "hardware/flash.h" here causes more issues...