From 8698bcfb8448e8101b227819656e6666199638c2 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 30 Mar 2013 15:20:05 +0100 Subject: [PATCH] Moved OSD settings from SDCard to mcu internal flash memory --- flight/targets/OSD/System/inc/pios_config.h | 6 ++-- flight/targets/OSD/System/pios_board.c | 10 +++++++ flight/targets/UAVObjects/uavobjectmanager.c | 30 +++++++++++-------- .../targets/board_hw_defs/osd/board_hw_defs.c | 24 +++++++++++++++ make/boards/osd/board-info.mk | 23 +++++++++++++- make/boot-defs.mk | 3 -- make/common-defs.mk | 10 +++++++ 7 files changed, 87 insertions(+), 19 deletions(-) diff --git a/flight/targets/OSD/System/inc/pios_config.h b/flight/targets/OSD/System/inc/pios_config.h index cda229055..391c59861 100644 --- a/flight/targets/OSD/System/inc/pios_config.h +++ b/flight/targets/OSD/System/inc/pios_config.h @@ -103,9 +103,11 @@ /* #define PIOS_INCLUDE_OVERO */ /* #define PIOS_OVERO_SPI */ #define PIOS_INCLUDE_SDCARD +/* #define PIOS_USE_SETTINGS_ON_SDCARD */ #define LOG_FILENAME "startup.log" -/* #define PIOS_INCLUDE_FLASH */ -/* #define PIOS_INCLUDE_FLASH_SECTOR_SETTINGS */ +#define PIOS_INCLUDE_FLASH +#define PIOS_INCLUDE_FLASH_INTERNAL +#define PIOS_INCLUDE_FLASH_SECTOR_SETTINGS /* #define FLASH_FREERTOS */ /* #define PIOS_INCLUDE_FLASH_EEPROM */ diff --git a/flight/targets/OSD/System/pios_board.c b/flight/targets/OSD/System/pios_board.c index 84595f320..f85f6faf2 100644 --- a/flight/targets/OSD/System/pios_board.c +++ b/flight/targets/OSD/System/pios_board.c @@ -161,6 +161,16 @@ void PIOS_Board_Init(void) { #endif #endif /* PIOS_INCLUDE_SPI */ +#ifdef PIOS_INCLUDE_FLASH_SECTOR_SETTINGS +uintptr_t flash_id; +uintptr_t fs_id; +PIOS_Flash_Internal_Init(&flash_id, &flash_internal_cfg); +PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_internal_cfg, &pios_internal_flash_driver, flash_id); +#elif !defined(PIOS_USE_SETTINGS_ON_SDCARD) +#error No setting storage specified. (define PIOS_USE_SETTINGS_ON_SDCARD or INCLUDE_FLASH_SECTOR_SETTINGS) +#endif + + /* Initialize UAVObject libraries */ EventDispatcherInitialize(); UAVObjInitialize(); diff --git a/flight/targets/UAVObjects/uavobjectmanager.c b/flight/targets/UAVObjects/uavobjectmanager.c index aa550faa0..6e6edc38a 100644 --- a/flight/targets/UAVObjects/uavobjectmanager.c +++ b/flight/targets/UAVObjects/uavobjectmanager.c @@ -158,7 +158,11 @@ static int32_t connectObj(UAVObjHandle obj_handle, xQueueHandle queue, static int32_t disconnectObj(UAVObjHandle obj_handle, xQueueHandle queue, UAVObjEventCallback cb); -#if defined(PIOS_INCLUDE_SDCARD) +#if defined(PIOS_USE_SETTINGS_ON_SDCARD) && defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) +#error Both PIOS_USE_SETTINGS_ON_SDCARD and PIOS_INCLUDE_FLASH_SECTOR_SETTINGS. Only one settings storage allowed. +#endif + +#if defined(PIOS_USE_SETTINGS_ON_SDCARD) static void objectFilename(UAVObjHandle obj_handle, uint8_t * filename); static void customSPrintf(uint8_t * buffer, uint8_t * format, ...); #endif @@ -668,7 +672,7 @@ unlock_exit: return rc; } -#if defined(PIOS_INCLUDE_SDCARD) +#if defined(PIOS_USE_SETTINGS_ON_SDCARD) /** * Save the data of the specified object instance to the file system (SD card). * The object will be appended and the file will not be closed. @@ -743,7 +747,7 @@ int32_t UAVObjSaveToFile(UAVObjHandle obj_handle, uint16_t instId, xSemaphoreGiveRecursive(mutex); return 0; } -#endif /* PIOS_INCLUDE_SDCARD */ +#endif /* PIOS_USE_SETTINGS_ON_SDCARD */ /** * Save the data of the specified object to the file system (SD card). @@ -779,7 +783,7 @@ int32_t UAVObjSave(UAVObjHandle obj_handle, uint16_t instId) return -1; } #endif -#if defined(PIOS_INCLUDE_SDCARD) +#if defined(PIOS_USE_SETTINGS_ON_SDCARD) FILEINFO file; uint8_t filename[14]; @@ -807,11 +811,11 @@ int32_t UAVObjSave(UAVObjHandle obj_handle, uint16_t instId) // Done, close file and unlock PIOS_FCLOSE(file); xSemaphoreGiveRecursive(mutex); -#endif /* PIOS_INCLUDE_SDCARD */ +#endif /* PIOS_USE_SETTINGS_ON_SDCARD */ return 0; } -#if defined(PIOS_INCLUDE_SDCARD) +#if defined(PIOS_USE_SETTINGS_ON_SDCARD) /** * Load an object from the file system (SD card). * @param[in] file File to read from @@ -899,7 +903,7 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO * file) xSemaphoreGiveRecursive(mutex); return obj_handle; } -#endif /* PIOS_INCLUDE_SDCARD */ +#endif /* PIOS_USE_SETTINGS_ON_SDCARD */ /** * Load an object from the file system (SD card). @@ -939,7 +943,7 @@ int32_t UAVObjLoad(UAVObjHandle obj_handle, uint16_t instId) #endif -#if defined(PIOS_INCLUDE_SDCARD) +#if defined(PIOS_USE_SETTINGS_ON_SDCARD) FILEINFO file; UAVObjHandle loadedObj; uint8_t filename[14]; @@ -975,7 +979,7 @@ int32_t UAVObjLoad(UAVObjHandle obj_handle, uint16_t instId) // Done, close file and unlock PIOS_FCLOSE(file); xSemaphoreGiveRecursive(mutex); -#endif /* PIOS_INCLUDE_SDCARD */ +#endif /* PIOS_USE_SETTINGS_ON_SDCARD */ return 0; } @@ -991,7 +995,7 @@ int32_t UAVObjDelete(UAVObjHandle obj_handle, uint16_t instId) #if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) PIOS_FLASHFS_ObjDelete(0, UAVObjGetID(obj_handle), instId); #endif -#if defined(PIOS_INCLUDE_SDCARD) +#if defined(PIOS_USE_SETTINGS_ON_SDCARD) uint8_t filename[14]; // Check for file system availability @@ -1009,7 +1013,7 @@ int32_t UAVObjDelete(UAVObjHandle obj_handle, uint16_t instId) // Done xSemaphoreGiveRecursive(mutex); -#endif /* PIOS_INCLUDE_SDCARD */ +#endif /* PIOS_USE_SETTINGS_ON_SDCARD */ return 0; } @@ -1995,7 +1999,7 @@ static int32_t disconnectObj(UAVObjHandle obj_handle, xQueueHandle queue, return -1; } -#if defined(PIOS_INCLUDE_SDCARD) +#if defined(PIOS_USE_SETTINGS_ON_SDCARD) /** * Wrapper for the sprintf function */ @@ -2013,4 +2017,4 @@ static void objectFilename(UAVObjHandle obj_handle, uint8_t * filename) { customSPrintf(filename, (uint8_t *) "%X.obj", UAVObjGetID(obj_handle)); } -#endif /* PIOS_INCLUDE_SDCARD */ +#endif /* PIOS_USE_SETTINGS_ON_SDCARD */ diff --git a/flight/targets/board_hw_defs/osd/board_hw_defs.c b/flight/targets/board_hw_defs/osd/board_hw_defs.c index 44434c392..7eaa327de 100644 --- a/flight/targets/board_hw_defs/osd/board_hw_defs.c +++ b/flight/targets/board_hw_defs/osd/board_hw_defs.c @@ -71,6 +71,30 @@ const struct pios_led_cfg * PIOS_BOARD_HW_DEFS_GetLedCfg (uint32_t board_revisio #endif /* PIOS_INCLUDE_LED */ + +#if defined(PIOS_INCLUDE_FLASH) +#include "pios_flashfs_logfs_priv.h" +#include "pios_flash_internal_priv.h" + +static const struct pios_flash_internal_cfg flash_internal_cfg = { +}; + +static const struct flashfs_logfs_cfg flashfs_internal_cfg = { +.fs_magic = 0x99abcfef, +.total_fs_size = EE_BANK_SIZE, /* 32K bytes (2x16KB sectors) */ +.arena_size = 0x00004000, /* 64 * slot size = 16K bytes = 1 sector */ +.slot_size = 0x00000100, /* 256 bytes */ + +.start_offset = EE_BANK_BASE, /* start after the bootloader */ +.sector_size = 0x00004000, /* 16K bytes */ +.page_size = 0x00004000, /* 16K bytes */ +}; + +#include "pios_flash.h" + +#endif /* PIOS_INCLUDE_FLASH */ + + #if defined(PIOS_INCLUDE_SPI) #include diff --git a/make/boards/osd/board-info.mk b/make/boards/osd/board-info.mk index d93151488..b33eb53d9 100644 --- a/make/boards/osd/board-info.mk +++ b/make/boards/osd/board-info.mk @@ -13,15 +13,36 @@ OPENOCD_JTAG_CONFIG := stlink-v2.cfg OPENOCD_CONFIG := stm32f4xx.stlink.cfg #OPENOCD_CONFIG := stm32f4xx.cfg +# Flash memory map for OSD: +# Sector start size use +# 0 0x0800 0000 16k BL +# 1 0x0800 4000 16k BL +# 2 0x0800 8000 16k EE +# 3 0x0800 C000 16k EE +# 4 0x0801 0000 64k Unused +# 5 0x0802 0000 128k FW +# 6 0x0804 0000 128k FW +# 7 0x0806 0000 128k FW +# 8 0x0808 0000 128k Unused +# .. .. +# 11 0x080E 0000 128k Unused + # Note: These must match the values in link_$(BOARD)_memory.ld BL_BANK_BASE := 0x08000000 # Start of bootloader flash BL_BANK_SIZE := 0x00008000 # Should include BD_INFO region -# Leave the remaining 16KB and 64KB sectors for other uses + +# Leave the remaining 16KB for settings storage + +EE_BANK_BASE := 0x08008000 # EEPROM storage area +EE_BANK_SIZE := 0x00008000 # Size of EEPROM storage area + +# Leave the reamaining 64KB sectors for other uses FW_BANK_BASE := 0x08020000 # Start of firmware flash FW_BANK_SIZE := 0x00060000 # Should include FW_DESC_SIZE + FW_DESC_SIZE := 0x00000064 OSCILLATOR_FREQ := 8000000 diff --git a/make/boot-defs.mk b/make/boot-defs.mk index 5c0bbf32e..44d8c27a8 100644 --- a/make/boot-defs.mk +++ b/make/boot-defs.mk @@ -112,9 +112,6 @@ BLONLY_CDEFS += -DBOARD_TYPE=$(BOARD_TYPE) BLONLY_CDEFS += -DBOARD_REVISION=$(BOARD_REVISION) BLONLY_CDEFS += -DHW_TYPE=$(HW_TYPE) BLONLY_CDEFS += -DBOOTLOADER_VERSION=$(BOOTLOADER_VERSION) -BLONLY_CDEFS += -DFW_BANK_BASE=$(FW_BANK_BASE) -BLONLY_CDEFS += -DFW_BANK_SIZE=$(FW_BANK_SIZE) -BLONLY_CDEFS += -DFW_DESC_SIZE=$(FW_DESC_SIZE) # Compiler flags CDEFS += $(BLONLY_CDEFS) diff --git a/make/common-defs.mk b/make/common-defs.mk index 60be74a6f..7bea9bf1a 100644 --- a/make/common-defs.mk +++ b/make/common-defs.mk @@ -95,6 +95,15 @@ endif #ADEFS = -DUSE_IRQ_ASM_WRAPPER ADEFS = -D__ASSEMBLY__ +# Provide board-specific defines +CDEFS += -DFW_BANK_BASE=$(FW_BANK_BASE) +CDEFS += -DFW_BANK_SIZE=$(FW_BANK_SIZE) +CDEFS += -DFW_DESC_SIZE=$(FW_DESC_SIZE) + +CDEFS += -DEE_BANK_BASE=$(EE_BANK_BASE) +CDEFS += -DEE_BANK_SIZE=$(EE_BANK_SIZE) + + # Compiler flag to set the C Standard level. # c89 - "ANSI" C # gnu89 - c89 plus GCC extensions @@ -122,6 +131,7 @@ CFLAGS += -Wall CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. CFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) + # FIXME: STM32F4xx library raises strict aliasing and const qualifier warnings ifneq ($(MCU),cortex-m4) CFLAGS += -Werror