1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 00:35:39 +03:00

AT32F43x: make sure the SRAM configuration is valid (#13031)

This commit is contained in:
Cru Waller 2023-08-14 21:37:12 +03:00 committed by GitHub
parent a5791814c0
commit 632a13b821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 2 deletions

View file

@ -23,13 +23,15 @@
MEM : 0x2000 0000 -- 0x2007 FFFF
*/
_SRAM_SIZE = 192;
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K
FLASH_CONFIG (r) : ORIGIN = 0x08004000, LENGTH = 16K
FLASH1 (rx) : ORIGIN = 0x08008000, LENGTH = 992K
SYSTEM_MEMORY (rx) : ORIGIN = 0x1FFF0000, LENGTH = 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = _SRAM_SIZE * 1024
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K /* external ram */
}

View file

@ -23,13 +23,15 @@
MEM : 0x2000 0000 -- 0x2007 FFFF
*/
_SRAM_SIZE = 192;
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K
FLASH_CONFIG (r) : ORIGIN = 0x08004000, LENGTH = 16K
FLASH1 (rx) : ORIGIN = 0x08008000, LENGTH = 4000K
SYSTEM_MEMORY (rx) : ORIGIN = 0x1FFF0000, LENGTH = 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = _SRAM_SIZE * 1024
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K /* external ram */
}

View file

@ -29,6 +29,71 @@
#include "drivers/persistent.h"
#include "at32f435_437_clock.h"
// See RM_AT32F435_437_EN_V2.05.pdf reference manual table 5-6 for more info.
#if 256 < TARGET_FLASH_SIZE
#define USD_EOPB0_SRAM_CONFIG_MASK 0x7
#else
#define USD_EOPB0_SRAM_CONFIG_MASK 0x3
#endif
static flash_usd_eopb0_type get_sram_config(void)
{
extern uint32_t _SRAM_SIZE; // Defined in linker file
switch ((uint32_t)&_SRAM_SIZE) {
#if 256 == TARGET_FLASH_SIZE
case 448:
return FLASH_EOPB0_SRAM_448K;
case 512:
return FLASH_EOPB0_SRAM_512K;
case 384:
default:
return FLASH_EOPB0_SRAM_384K;
#elif 448 == TARGET_FLASH_SIZE
case 256:
return FLASH_EOPB0_SRAM_256K;
case 320:
return FLASH_EOPB0_SRAM_320K;
case 384:
return FLASH_EOPB0_SRAM_384K;
case 448:
return FLASH_EOPB0_SRAM_448K;
case 512:
return FLASH_EOPB0_SRAM_512K;
case 192:
default:
return FLASH_EOPB0_SRAM_192K;
#elif 1024 <= TARGET_FLASH_SIZE
case 128:
return FLASH_EOPB0_SRAM_128K;
case 256:
return FLASH_EOPB0_SRAM_256K;
case 320:
return FLASH_EOPB0_SRAM_320K;
case 384:
return FLASH_EOPB0_SRAM_384K;
case 448:
return FLASH_EOPB0_SRAM_448K;
case 512:
return FLASH_EOPB0_SRAM_512K;
case 192:
default:
return FLASH_EOPB0_SRAM_192K;
#endif
}
}
static void init_sram_config(void)
{
// Make sure the SRAM config is correct
const flash_usd_eopb0_type sram_cfg = get_sram_config();
if (((USD->eopb0) & USD_EOPB0_SRAM_CONFIG_MASK) != sram_cfg) {
flash_unlock();
flash_user_system_data_erase();
flash_eopb0_config(sram_cfg);
systemReset();
}
}
void systemReset(void)
{
__disable_irq();
@ -96,6 +161,8 @@ bool isMPUSoftReset(void)
void systemInit(void)
{
init_sram_config();
persistentObjectInit();
checkForBootLoaderRequest();