mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Make flash and bootloader sizes configurable
This patch makes allocating special pages automatic and flexible, allowing flash size and application start offset specification with linker command line arguments. It should allow easier porting to different targets and experimentation without adding code complexity. Many original STM32F103x8 chips have fully functional 128 kiB flash and so this additional space might come useful for experimentation, additional optional features etc. Tested on v2.51A board, including writing and verifying 128 kiB of random data. Make variables are added to control that, so to build for the full undocumented flash size and dapboot configured to start the app from 8 kiB offset one can run: make flash_size=128k bootldr_size=0x2000
This commit is contained in:
@@ -9,15 +9,15 @@
|
||||
#include "BSP.h"
|
||||
#include "string.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
/*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/
|
||||
/*We use the last 1024 byte page*/
|
||||
#define FLASH_ADDR (0x8000000 |0xFC00)
|
||||
|
||||
static uint16_t settings_page[512] __attribute__ ((section (".settings_page")));
|
||||
|
||||
uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||
FLASH_EraseInitTypeDef pEraseInit;
|
||||
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
pEraseInit.Banks = FLASH_BANK_1;
|
||||
pEraseInit.NbPages = 1;
|
||||
pEraseInit.PageAddress = FLASH_ADDR;
|
||||
pEraseInit.PageAddress = (uint32_t)settings_page;
|
||||
uint32_t failingAddress = 0;
|
||||
resetWatchdog();
|
||||
__HAL_FLASH_CLEAR_FLAG(
|
||||
@@ -33,7 +33,7 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||
HAL_FLASH_Unlock();
|
||||
for (uint8_t i = 0; i < (length / 2); i++) {
|
||||
resetWatchdog();
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2),
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, (uint32_t)&settings_page[i],
|
||||
data[i]);
|
||||
}
|
||||
HAL_FLASH_Lock();
|
||||
@@ -42,8 +42,5 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||
|
||||
void flash_read_buffer(uint8_t *buffer, const uint16_t length) {
|
||||
|
||||
uint16_t *data = (uint16_t*) buffer;
|
||||
for (uint8_t i = 0; i < (length / 2); i++) {
|
||||
data[i] = *((uint16_t*) (FLASH_ADDR + (i * 2)));
|
||||
}
|
||||
memcpy(buffer, settings_page, length);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include "BSP.h"
|
||||
#include "OLED.hpp"
|
||||
// Second last page of flash set aside for logo image.
|
||||
#define FLASH_LOGOADDR (0x8000000 | 0xF800)
|
||||
|
||||
static uint8_t logo_page[1024] __attribute__ ((section (".logo_page")));
|
||||
|
||||
// Logo header signature.
|
||||
#define LOGO_HEADER_VALUE 0xF00DAA55
|
||||
@@ -16,11 +16,11 @@
|
||||
uint8_t showBootLogoIfavailable() {
|
||||
// Do not show logo data if signature is not found.
|
||||
if (LOGO_HEADER_VALUE
|
||||
!= *(reinterpret_cast<const uint32_t*>(FLASH_LOGOADDR))) {
|
||||
!= *(reinterpret_cast<const uint32_t*>(logo_page))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OLED::drawAreaSwapped(0, 0, 96, 16, (uint8_t*) (FLASH_LOGOADDR + 4));
|
||||
OLED::drawAreaSwapped(0, 0, 96, 16, (uint8_t*) (logo_page + 4));
|
||||
OLED::refresh();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -11,16 +11,13 @@
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
//#define LOCAL_BUILD
|
||||
#ifndef LOCAL_BUILD
|
||||
|
||||
#ifndef VECT_TAB_OFFSET
|
||||
#define VECT_TAB_OFFSET 0x00004000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#else
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#warning LOCAL_BUILD SETUP
|
||||
#endif
|
||||
//We offset this by 0x4000 to because of the bootloader
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Clock Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
@@ -12,9 +12,7 @@
|
||||
#include "Setup.h"
|
||||
#include "../../configuration.h"
|
||||
#include "BSP.h"
|
||||
#define FLASH_ADDR \
|
||||
(0x8000000 | \
|
||||
0xFC00) /*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/
|
||||
|
||||
#include "string.h"
|
||||
volatile systemSettingsType systemSettings;
|
||||
|
||||
|
||||
@@ -9,17 +9,15 @@ _estack = 0x20005000; /* end of RAM */
|
||||
_Min_Heap_Size = 0x300; /* required amount of heap */
|
||||
_Min_Stack_Size = 1024; /* required amount of stack */
|
||||
|
||||
__APP_BASE_ADDRESS__ = 0x08000000 + __BOOTLDR_SIZE__;
|
||||
__ROM_REGION_LENGTH__ = __FLASH_SIZE__ - __BOOTLDR_SIZE__;
|
||||
__FLASH_END_ADDR__ = __APP_BASE_ADDRESS__ + __ROM_REGION_LENGTH__;
|
||||
|
||||
/* Memories definition */
|
||||
MEMORY
|
||||
{
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
/* LOCAL_BUILD*/
|
||||
/*ROM (rx) : ORIGIN = 0x08000000, LENGTH = 48K*/
|
||||
/* production*/
|
||||
ROM (rx) : ORIGIN = 0x08004000, LENGTH = 46K
|
||||
|
||||
|
||||
|
||||
ROM (rx) : ORIGIN = __APP_BASE_ADDRESS__, LENGTH = __ROM_REGION_LENGTH__
|
||||
}
|
||||
/* ROM is normally 48K after the bootloader, however we allocate the last page for settings, and the second last one for display boot logo*/
|
||||
|
||||
@@ -118,11 +116,22 @@ SECTIONS
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >RAM AT> ROM
|
||||
|
||||
|
||||
/* Uninitialized data section into RAM memory */
|
||||
. = ALIGN(4);
|
||||
.logo_page (NOLOAD) :
|
||||
{
|
||||
. = ABSOLUTE(__FLASH_END_ADDR__ - 2048);
|
||||
KEEP (*(.logo_page*))
|
||||
} > ROM
|
||||
|
||||
.settings_page (NOLOAD) :
|
||||
{
|
||||
. = ABSOLUTE(__FLASH_END_ADDR__ - 1024);
|
||||
KEEP (*(.settings_page*))
|
||||
} > ROM
|
||||
|
||||
.bss :
|
||||
{
|
||||
/* Uninitialized data section into RAM memory */
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
@@ -157,4 +166,4 @@ SECTIONS
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,9 +49,11 @@ OUTPUT_DIR=Objects
|
||||
# code optimisation ------------------------------------------------------------
|
||||
OPTIM=-Os -flto -ffat-lto-objects -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections
|
||||
|
||||
flash_size=64k
|
||||
bootldr_size=0x4000
|
||||
|
||||
# global defines ---------------------------------------------------------------
|
||||
GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG -D MODEL_$(model)
|
||||
GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG -D MODEL_$(model) -DVECT_TAB_OFFSET=$(bootldr_size)U
|
||||
|
||||
# Enable debug code generation
|
||||
DEBUG=-g3
|
||||
@@ -93,6 +95,8 @@ LINKER_FLAGS=-Wl,--gc-sections \
|
||||
-mthumb \
|
||||
-mfloat-abi=soft \
|
||||
-lm -Os -flto -Wl,--undefined=vTaskSwitchContext \
|
||||
-Wl,--defsym=__FLASH_SIZE__=$(flash_size) \
|
||||
-Wl,--defsym=__BOOTLDR_SIZE__=$(bootldr_size) \
|
||||
--specs=nano.specs
|
||||
|
||||
# compiler flags ---------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user