mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
Merge pull request #9370 from jflyper/bfdev-g4-config-streamer
[G4] config_streamer support
This commit is contained in:
commit
a2aeb0cef4
2 changed files with 51 additions and 3 deletions
|
@ -72,6 +72,10 @@ uint8_t eepromData[EEPROM_SIZE];
|
||||||
// H7
|
// H7
|
||||||
# elif defined(STM32H743xx) || defined(STM32H750xx)
|
# elif defined(STM32H743xx) || defined(STM32H750xx)
|
||||||
# define FLASH_PAGE_SIZE ((uint32_t)0x20000) // 128K sectors
|
# define FLASH_PAGE_SIZE ((uint32_t)0x20000) // 128K sectors
|
||||||
|
# elif defined(STM32G4)
|
||||||
|
// G4 V1.0.0 library forces us to use dual bank mode
|
||||||
|
// 2 bank * 128 page/bank * 2KB/page
|
||||||
|
# define FLASH_PAGE_SIZE ((uint32_t)0x800) // 2K page
|
||||||
// SIMULATOR
|
// SIMULATOR
|
||||||
# elif defined(SIMULATOR_BUILD)
|
# elif defined(SIMULATOR_BUILD)
|
||||||
# define FLASH_PAGE_SIZE (0x400)
|
# define FLASH_PAGE_SIZE (0x400)
|
||||||
|
@ -94,7 +98,7 @@ void config_streamer_start(config_streamer_t *c, uintptr_t base, int size)
|
||||||
#if defined(CONFIG_IN_RAM) || defined(CONFIG_IN_EXTERNAL_FLASH) || defined(CONFIG_IN_SDCARD)
|
#if defined(CONFIG_IN_RAM) || defined(CONFIG_IN_EXTERNAL_FLASH) || defined(CONFIG_IN_SDCARD)
|
||||||
// NOP
|
// NOP
|
||||||
#elif defined(CONFIG_IN_FLASH) || defined(CONFIG_IN_FILE)
|
#elif defined(CONFIG_IN_FLASH) || defined(CONFIG_IN_FILE)
|
||||||
#if defined(STM32F7) || defined(STM32H7)
|
#if defined(STM32F7) || defined(STM32H7) || defined(STM32G4)
|
||||||
HAL_FLASH_Unlock();
|
HAL_FLASH_Unlock();
|
||||||
#else
|
#else
|
||||||
FLASH_Unlock();
|
FLASH_Unlock();
|
||||||
|
@ -116,6 +120,8 @@ void config_streamer_start(config_streamer_t *c, uintptr_t base, int size)
|
||||||
// NOP
|
// NOP
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
// NOP
|
// NOP
|
||||||
|
#elif defined(STM32G4)
|
||||||
|
// NOP
|
||||||
#elif defined(UNIT_TEST) || defined(SIMULATOR_BUILD)
|
#elif defined(UNIT_TEST) || defined(SIMULATOR_BUILD)
|
||||||
// NOP
|
// NOP
|
||||||
#else
|
#else
|
||||||
|
@ -351,6 +357,26 @@ static void getFLASHSectorForEEPROM(uint32_t *bank, uint32_t *sector)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#elif defined(STM32G4)
|
||||||
|
/*
|
||||||
|
The G4 V1.0.0 HAL library forces dual bank mode: 2 bank * 128 page/bank * 2KB/page
|
||||||
|
*/
|
||||||
|
#define FLASH_BANK_SIZE_G4 (128 * 2048)
|
||||||
|
#define FLASH_BANK1_BASE 0x08000000
|
||||||
|
#define FLASH_BANK2_BASE (FLASH_BANK1_BASE + FLASH_BANK_SIZE_G4)
|
||||||
|
|
||||||
|
static void getFLASHSectorForEEPROM(uint32_t address, uint32_t *bank, uint32_t *page)
|
||||||
|
{
|
||||||
|
if (address < FLASH_BANK2_BASE) {
|
||||||
|
*bank = FLASH_BANK_1;
|
||||||
|
address -= FLASH_BANK1_BASE;
|
||||||
|
} else {
|
||||||
|
*bank = FLASH_BANK_2;
|
||||||
|
address -= FLASH_BANK2_BASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*page = address / FLASH_PAGE_SIZE;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -466,7 +492,26 @@ static int write_word(config_streamer_t *c, config_streamer_buffer_align_type_t
|
||||||
if (status != HAL_OK) {
|
if (status != HAL_OK) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
#else // !STM32H7 && !STM32F7
|
#elif defined(STM32G4)
|
||||||
|
if (c->address % FLASH_PAGE_SIZE == 0) {
|
||||||
|
|
||||||
|
FLASH_EraseInitTypeDef EraseInitStruct = {
|
||||||
|
.TypeErase = FLASH_TYPEERASE_PAGES,
|
||||||
|
.NbPages = 1
|
||||||
|
};
|
||||||
|
getFLASHSectorForEEPROM(c->address, &EraseInitStruct.Banks, &EraseInitStruct.Page);
|
||||||
|
uint32_t SECTORError;
|
||||||
|
const HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);
|
||||||
|
if (status != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, c->address, (uint64_t)*buffer);
|
||||||
|
if (status != HAL_OK) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
#else // !STM32H7 && !STM32F7 && !STM32G4
|
||||||
if (c->address % FLASH_PAGE_SIZE == 0) {
|
if (c->address % FLASH_PAGE_SIZE == 0) {
|
||||||
#if defined(STM32F4)
|
#if defined(STM32F4)
|
||||||
const FLASH_Status status = FLASH_EraseSector(getFLASHSectorForEEPROM(), VoltageRange_3); //0x08080000 to 0x080A0000
|
const FLASH_Status status = FLASH_EraseSector(getFLASHSectorForEEPROM(), VoltageRange_3); //0x08080000 to 0x080A0000
|
||||||
|
@ -529,7 +574,7 @@ int config_streamer_finish(config_streamer_t *c)
|
||||||
#elif defined(CONFIG_IN_FILE)
|
#elif defined(CONFIG_IN_FILE)
|
||||||
FLASH_Lock();
|
FLASH_Lock();
|
||||||
#elif defined(CONFIG_IN_FLASH)
|
#elif defined(CONFIG_IN_FLASH)
|
||||||
#if defined(STM32F7) || defined(STM32H7)
|
#if defined(STM32F7) || defined(STM32H7) || defined(STM32G4)
|
||||||
HAL_FLASH_Lock();
|
HAL_FLASH_Lock();
|
||||||
#else
|
#else
|
||||||
FLASH_Lock();
|
FLASH_Lock();
|
||||||
|
|
|
@ -32,6 +32,9 @@ typedef uint32_t config_streamer_buffer_align_type_t;
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
#define CONFIG_STREAMER_BUFFER_SIZE 32 // Flash word = 256-bits
|
#define CONFIG_STREAMER_BUFFER_SIZE 32 // Flash word = 256-bits
|
||||||
typedef uint64_t config_streamer_buffer_align_type_t;
|
typedef uint64_t config_streamer_buffer_align_type_t;
|
||||||
|
#elif defined(STM32G4)
|
||||||
|
#define CONFIG_STREAMER_BUFFER_SIZE 8 // Flash word = 64-bits
|
||||||
|
typedef uint64_t config_streamer_buffer_align_type_t;
|
||||||
#else
|
#else
|
||||||
#define CONFIG_STREAMER_BUFFER_SIZE 4
|
#define CONFIG_STREAMER_BUFFER_SIZE 4
|
||||||
typedef uint32_t config_streamer_buffer_align_type_t;
|
typedef uint32_t config_streamer_buffer_align_type_t;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue