-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix bug # add AT32-F435 sram config #11774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,79 @@ | |
| #include "target/system.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(); | ||
|
Comment on lines
+89
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Usd erase wipes settings init_sram_config() uses flash_user_system_data_erase() (documented to erase all USD except FAP) but then only restores eopb0, so any existing USD fields (SSB/DATA/EPP/QSPIKEY/etc.) are lost whenever SRAM config differs. Agent Prompt
|
||
| } | ||
|
Comment on lines
+88
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Flash ops unchecked init_sram_config() erases/programs USD and immediately resets without checking flash_user_system_data_erase()/flash_eopb0_config() return values; if the operations fail, the board can reboot into the same mismatch and get stuck in a persistent reset loop. Agent Prompt
|
||
| } | ||
|
|
||
| // void systemReset(void) | ||
| // { | ||
| // __disable_irq(); | ||
| // NVIC_SystemReset(); | ||
| // } | ||
|
|
||
|
|
||
|
|
||
| void SetSysClock(void); | ||
|
|
||
| void enableGPIOPowerUsageAndNoiseReductions(void) | ||
|
|
@@ -116,6 +189,7 @@ uint32_t systemBootloaderAddress(void) | |
|
|
||
| void systemInit(void) | ||
| { | ||
| init_sram_config(); | ||
| //config system clock to 288mhz usb 48mhz | ||
| system_clock_config(); | ||
| // Configure NVIC preempt/priority groups | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |
|
|
||
| */ | ||
|
|
||
|
|
||
| _SRAM_SIZE = 192; | ||
|
|
||
| MEMORY | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |
|
|
||
| */ | ||
|
|
||
|
|
||
| _SRAM_SIZE = 192; | ||
|
|
||
| MEMORY | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |
|
|
||
| */ | ||
|
|
||
|
|
||
| _SRAM_SIZE = 192; | ||
|
|
||
| MEMORY | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |
|
|
||
| */ | ||
|
|
||
|
|
||
| _SRAM_SIZE = 192; | ||
|
|
||
| MEMORY | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Flash size macro missing
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools