diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index cce0f7e88950..dae89c48bbae 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -233,9 +233,6 @@ else # Teensy EEPROM implementations OPT_DEFS += -DEEPROM_KINETIS_FLEXRAM SRC += eeprom_kinetis_flexram.c - else ifneq ($(filter $(MCU_SERIES),SN32F240B SN32F260),) - OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_SN32_FLASH_EMULATED - SRC += eeprom_driver.c eeprom_sn32.c else # Fall back to transient, i.e. non-persistent OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_TRANSIENT @@ -253,7 +250,7 @@ else endif endif -VALID_WEAR_LEVELING_DRIVER_TYPES := custom embedded_flash spi_flash rp2040_flash legacy sn32_flash +VALID_WEAR_LEVELING_DRIVER_TYPES := custom embedded_flash spi_flash rp2040_flash legacy WEAR_LEVELING_DRIVER ?= none ifneq ($(strip $(WEAR_LEVELING_DRIVER)),none) ifeq ($(filter $(WEAR_LEVELING_DRIVER),$(VALID_WEAR_LEVELING_DRIVER_TYPES)),) @@ -281,9 +278,6 @@ ifneq ($(strip $(WEAR_LEVELING_DRIVER)),none) COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/flash SRC += legacy_flash_ops.c wear_leveling_legacy.c POST_CONFIG_H += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/wear_leveling/wear_leveling_legacy_config.h - else ifeq ($(strip $(WEAR_LEVELING_DRIVER)), sn32_flash) - SRC += wear_leveling_sn32_flash.c - POST_CONFIG_H += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/wear_leveling/wear_leveling_sn32_flash_config.h endif endif endif diff --git a/platforms/chibios/chibios_config.h b/platforms/chibios/chibios_config.h index 90c06437dee1..77beeec5ff25 100644 --- a/platforms/chibios/chibios_config.h +++ b/platforms/chibios/chibios_config.h @@ -173,4 +173,7 @@ #if defined(SN32F2) # define CPU_CLOCK SN32_HCLK +# ifndef WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT +# define WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT 1 +# endif #endif diff --git a/platforms/chibios/drivers/eeprom/eeprom_sn32.c b/platforms/chibios/drivers/eeprom/eeprom_sn32.c deleted file mode 100644 index e4a5bf85092f..000000000000 --- a/platforms/chibios/drivers/eeprom/eeprom_sn32.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * This software is experimental and a work in progress. - * Under no circumstances should these files be used in relation to any critical system(s). - * Use of these files is at your own risk. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * This files are free to use from http://engsta.com/stm32-flash-memory-eeprom-emulator/ by - * Artur F. - * - * Modifications for QMK and STM32F303 by Yiancar - * Adapted for SONIX chips by dexter93 and gloryhzw - */ - -#include -#include -#include "debug.h" -#include "Flash.h" -#include "eeprom_sn32.h" - -/***************************************************************************** - * Allows to use the internal flash to store non volatile data. To initialize - * the functionality use the EEPROM_Init() function. Be sure that by reprogramming - * of the controller just affected pages will be deleted. In other case the non - * volatile data will be lost. - ******************************************************************************/ -#include "eeprom_sn32_defs.h" -#if !defined(FEE_PAGE_SIZE) || !defined(FEE_TOTAL_PAGES) || !defined(FEE_DENSITY_PAGES) || !defined(FEE_MCU_FLASH_SIZE) || !defined(FEE_PAGE_BASE_ADDRESS) -# error "not implemented." -#endif - -#define FEE_DENSITY_BYTES (FEE_PAGE_SIZE * FEE_DENSITY_PAGES - 1) -#define FEE_LAST_PAGE_ADDRESS (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES)) -#define FEE_ADDR_OFFSET(Address) (Address) - -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* Functions -----------------------------------------------------------------*/ -/* - * Debug print utils - */ - -// #define DEBUG_EEPROM_OUTPUT - -#if defined(DEBUG_EEPROM_OUTPUT) - -# define debug_eeprom debug_enable -# define eeprom_println(s) println(s) -# define eeprom_printf(fmt, ...) xprintf(fmt, ##__VA_ARGS__); - -#else /* NO_DEBUG */ - -# define debug_eeprom false -# define eeprom_println(s) -# define eeprom_printf(fmt, ...) - -#endif /* NO_DEBUG */ - -/***************************************************************************** - * Delete Flash Space used for user Data, deletes the whole space between - * RW_PAGE_BASE_ADDRESS and the last uC Flash Page - ******************************************************************************/ -uint16_t EEPROM_Init(void) { - // Clear Flags - // SN_FLASH->STATUS &= ~FLASH_PGERR - if (debug_eeprom) { - println("EEPROM_Init"); - } - - return FEE_DENSITY_BYTES; -} - -/***************************************************************************** - * Erase the whole reserved Flash Space used for user Data - ******************************************************************************/ -void EEPROM_Erase(void) { - int page_num = 0; - - // delete all pages from specified start page to the last page - do { - eeprom_println("EEPROM_Erase"); - FLASH_EraseSector(FEE_PAGE_BASE_ADDRESS + (page_num * FEE_PAGE_SIZE)); - page_num++; - } while (page_num < FEE_DENSITY_PAGES); -} - -/***************************************************************************** - * Writes data to flash on specified address. - *******************************************************************************/ -uint8_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte) { - FLASH_Status FlashStatus = FLASH_OKAY; - - /* if the address is out-of-bounds, do nothing */ - if (Address > FEE_DENSITY_BYTES) { - eeprom_printf("EEPROM_WriteDataByte(0x%04x, 0x%02x) [BAD ADDRESS]\n", Address, DataByte); - return FLASH_FAIL; - } - uint32_t addr = FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address); - - /* if the value is the same, don't bother writing it */ - if (DataByte == *(__IO uint8_t *)addr) { - eeprom_printf("EEPROM_WriteDataByte(0x%04x, 0x%02x) [SKIP SAME]\n", Address, DataByte); - return FLASH_OKAY; - } - - // update the data byte aligned in a 32-bit dword - uint32_t value = *((uint32_t *)(addr & 0xFFFFFFFC)); - uint8_t *v8 = (uint8_t *)&value; - v8[addr & 3] = DataByte; - - // program the 32-bit dword - eeprom_printf("FLASH_ProgramDWord(0x%08x, 0x%04x) [DIRECT]\n", Address, value); - FlashStatus = FLASH_ProgramDWord(addr & 0xFFFFFFFC, value); - - return FlashStatus; -} - -/***************************************************************************** - * Read data from a specified address. - *******************************************************************************/ -uint8_t EEPROM_ReadDataByte(uint16_t Address) { - uint8_t DataByte = 0xFF; - - if (Address <= FEE_DENSITY_BYTES) { - // Get Byte from specified address - DataByte = (*(__IO uint8_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))); - } - - eeprom_printf("EEPROM_ReadDataByte(0x%04x): 0x%02x\n", Address, DataByte); - - return DataByte; -} - -/***************************************************************************** - * Bind to eeprom_driver.c - *******************************************************************************/ -void eeprom_driver_init(void) { - EEPROM_Init(); -} - -void eeprom_driver_erase(void) { - EEPROM_Erase(); -} - -void eeprom_read_block(void *buf, const void *addr, size_t len) { - const uint8_t *p = (const uint8_t *)addr; - uint8_t * dest = (uint8_t *)buf; - while (len--) { - *dest++ = EEPROM_ReadDataByte((uint16_t)(uint32_t)(p++)); - } -} - -void eeprom_write_block(const void *buf, void *addr, size_t len) { - uint8_t * p = (uint8_t *)addr; - const uint8_t *src = (const uint8_t *)buf; - while (len--) { - EEPROM_WriteDataByte((uint16_t)(uint32_t)p++, *src++); - } -} diff --git a/platforms/chibios/drivers/eeprom/eeprom_sn32.h b/platforms/chibios/drivers/eeprom/eeprom_sn32.h deleted file mode 100644 index 9f96baa0c8b7..000000000000 --- a/platforms/chibios/drivers/eeprom/eeprom_sn32.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This software is experimental and a work in progress. - * Under no circumstances should these files be used in relation to any critical system(s). - * Use of these files is at your own risk. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * This files are free to use from http://engsta.com/stm32-flash-memory-eeprom-emulator/ by - * Artur F. - * - * Modifications for QMK and SONIX chips by smplman and dexter93 - * - * This library assumes 8-bit data locations. To add a new MCU, please provide the flash - * page size and the total flash size in Kb. The number of available pages must be a multiple - * of 2. Only half of the pages account for the total EEPROM size. - * This library also assumes that the pages are not used by the firmware. - */ - -#pragma once - -// Use this function to initialize the functionality -uint16_t EEPROM_Init(void); -void EEPROM_Erase(void); -uint8_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte); -uint8_t EEPROM_ReadDataByte(uint16_t Address); diff --git a/platforms/chibios/drivers/eeprom/eeprom_sn32_defs.h b/platforms/chibios/drivers/eeprom/eeprom_sn32_defs.h deleted file mode 100644 index 4a8f779f02c1..000000000000 --- a/platforms/chibios/drivers/eeprom/eeprom_sn32_defs.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright 2021 SonixQMK - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once - -#include - -#if !defined(FEE_PAGE_SIZE) || !defined(FEE_TOTAL_PAGES) || !defined(FEE_DENSITY_PAGES) -# if defined(SN32F240B) -# ifndef FEE_PAGE_SIZE -# define FEE_PAGE_SIZE (uint16_t)0x0040 // Page size = 64bytes -# endif -# ifndef FEE_TOTAL_PAGES -# define FEE_TOTAL_PAGES 1024 // How many pages are available -# endif -# ifndef FEE_DENSITY_PAGES -# define FEE_DENSITY_PAGES 23 // How many pages are used as EEPROM -# endif -# elif defined(SN32F260) -# ifndef FEE_PAGE_SIZE -# define FEE_PAGE_SIZE (uint16_t)0x0040 // Page size = 64bytes -# endif -# ifndef FEE_TOTAL_PAGES -# define FEE_TOTAL_PAGES 480 // How many pages are available -# endif -# ifndef FEE_DENSITY_PAGES -# define FEE_DENSITY_PAGES 23 // How many pages are used as EEPROM -# endif -# endif -#endif - -#if !defined(FEE_MCU_FLASH_SIZE) -# if defined(SN32F240B) -# define FEE_MCU_FLASH_SIZE 64 // Size in Kb -# elif defined(SN32F260) -# define FEE_MCU_FLASH_SIZE 30 // Size in Kb -# endif -#endif - -/* Start of the emulated eeprom */ -#if !defined(FEE_PAGE_BASE_ADDRESS) -# if defined(SN32F240B) || defined(SN32F260) -# ifndef FEE_PAGE_BASE_ADDRESS -# define FEE_PAGE_BASE_ADDRESS ((uint32_t)(FEE_PAGE_SIZE * FEE_TOTAL_PAGES - ((FEE_DENSITY_PAGES + 1) * FEE_PAGE_SIZE))) // Guard the last page -# endif -# endif -#endif diff --git a/platforms/chibios/drivers/wear_leveling/wear_leveling_efl_config.h b/platforms/chibios/drivers/wear_leveling/wear_leveling_efl_config.h index 0f0fa694e9c5..2be061de5743 100644 --- a/platforms/chibios/drivers/wear_leveling/wear_leveling_efl_config.h +++ b/platforms/chibios/drivers/wear_leveling/wear_leveling_efl_config.h @@ -16,6 +16,8 @@ # define BACKING_STORE_WRITE_SIZE 4 // from hal_efl_lld.c # elif defined(QMK_MCU_FAMILY_WB32) # define BACKING_STORE_WRITE_SIZE 8 // from hal_efl_lld.c +# elif defined(QMK_MCU_FAMILY_SN32) +# define BACKING_STORE_WRITE_SIZE 4 // from hal_efl_lld.c # elif defined(QMK_MCU_FAMILY_STM32) # if defined(STM32_FLASH_LINE_SIZE) // from some family's stm32_registry.h file # define BACKING_STORE_WRITE_SIZE (STM32_FLASH_LINE_SIZE) diff --git a/platforms/chibios/drivers/wear_leveling/wear_leveling_sn32_flash.c b/platforms/chibios/drivers/wear_leveling/wear_leveling_sn32_flash.c deleted file mode 100644 index f7ec1cc59582..000000000000 --- a/platforms/chibios/drivers/wear_leveling/wear_leveling_sn32_flash.c +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2022 Jose Pablo Ramirez (@jpe230) -// SPDX-License-Identifier: GPL-2.0-or-later -#include -#include "timer.h" -#include "wear_leveling.h" -#include "wear_leveling_internal.h" -#include "Flash.h" - -bool backing_store_init(void) { - bs_dprintf("Init\n"); - return true; -} - -bool backing_store_unlock(void) { - bs_dprintf("Unlock\n"); - return true; -} - -bool backing_store_erase(void) { -#ifdef WEAR_LEVELING_DEBUG_OUTPUT - uint32_t start = timer_read32(); -#endif - - bool ret = true; - FLASH_Status status; - for (int i = 0; i < (WEAR_LEVELING_SN32_EMULATION_PAGE_COUNT); ++i) { - status = FLASH_EraseSector(WEAR_LEVELING_SN32_EMULATION_BASE_PAGE_ADDRESS + (i * WEAR_LEVELING_SN32_PAGE_SIZE)); - if (status == FLASH_FAIL) { - ret = false; - } - } - - bs_dprintf("Backing store erase took %ldms to complete\n", ((long)(timer_read32() - start))); - return ret; -} - -bool backing_store_write(uint32_t address, backing_store_int_t value) { - uint32_t offset = ((WEAR_LEVELING_SN32_EMULATION_BASE_PAGE_ADDRESS) + address); - bs_dprintf("Write "); - wl_dump(offset, &value, sizeof(backing_store_int_t)); - return FLASH_ProgramDWord(offset & 0xFFFFFFFC, value) == FLASH_OKAY; -} - -bool backing_store_lock(void) { - bs_dprintf("Lock \n"); - return true; -} - -bool backing_store_read(uint32_t address, backing_store_int_t* value) { - uint32_t offset = ((WEAR_LEVELING_SN32_EMULATION_BASE_PAGE_ADDRESS) + address); - backing_store_int_t* loc = (backing_store_int_t*)offset; - *value = *loc; - bs_dprintf("Read "); - wl_dump(offset, loc, sizeof(backing_store_int_t)); - return true; -} diff --git a/platforms/chibios/drivers/wear_leveling/wear_leveling_sn32_flash_config.h b/platforms/chibios/drivers/wear_leveling/wear_leveling_sn32_flash_config.h deleted file mode 100644 index 7ac9b6555297..000000000000 --- a/platforms/chibios/drivers/wear_leveling/wear_leveling_sn32_flash_config.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2022 Jose Pablo Ramirez (@jpe230) -// SPDX-License-Identifier: GPL-2.0-or-later -#pragma once - -// Work out the page size to use -#ifndef WEAR_LEVELING_SN32_PAGE_SIZE -# if defined(QMK_MCU_SERIES_SN32F240B) -# define WEAR_LEVELING_SN32_PAGE_SIZE 64 -# elif defined(QMK_MCU_SERIES_SN32F260) -# define WEAR_LEVELING_SN32_PAGE_SIZE 64 -# endif -#endif - -// Number of pages we have -#ifndef WEAR_LEVELING_SN32_EMULATION_TOTAL_PAGE -# if defined(QMK_MCU_SERIES_SN32F240B) -# define WEAR_LEVELING_SN32_EMULATION_TOTAL_PAGE 1024 -# elif defined(QMK_MCU_SERIES_SN32F260) -# define WEAR_LEVELING_SN32_EMULATION_TOTAL_PAGE 480 -# endif -#endif - -// The number of pages to use -#ifndef WEAR_LEVELING_SN32_EMULATION_PAGE_COUNT -# if defined(QMK_MCU_SERIES_SN32F240B) -# define WEAR_LEVELING_SN32_EMULATION_PAGE_COUNT 23 -# elif defined(QMK_MCU_SERIES_SN32F260) -# define WEAR_LEVELING_SN32_EMULATION_PAGE_COUNT 23 -# endif -#endif - -// The origin of the emulated eeprom -#ifndef WEAR_LEVELING_SN32_EMULATION_BASE_PAGE_ADDRESS -# define WEAR_LEVELING_SN32_EMULATION_BASE_PAGE_ADDRESS ((uint32_t)(WEAR_LEVELING_SN32_PAGE_SIZE * WEAR_LEVELING_SN32_EMULATION_TOTAL_PAGE - ((WEAR_LEVELING_SN32_EMULATION_PAGE_COUNT + 1) * WEAR_LEVELING_SN32_PAGE_SIZE))) -#endif - -// 4-byte writes -#ifndef BACKING_STORE_WRITE_SIZE -# define BACKING_STORE_WRITE_SIZE 4 -#endif - -// The amount of space to use for the entire set of emulation -#ifndef WEAR_LEVELING_BACKING_SIZE -# define WEAR_LEVELING_BACKING_SIZE ((WEAR_LEVELING_SN32_EMULATION_PAGE_COUNT)*WEAR_LEVELING_SN32_PAGE_SIZE) -#endif - -// The logical amount of eeprom available -#ifndef WEAR_LEVELING_LOGICAL_SIZE -# define WEAR_LEVELING_LOGICAL_SIZE ((WEAR_LEVELING_BACKING_SIZE) / 2) -#endif