Skip to content

target: fix STM32F765xG linker scripts — correct DTCM size and SRAM1 address#11391

Open
sensei-hacker wants to merge 1 commit intoiNavFlight:maintenance-9.xfrom
sensei-hacker:fix/f765xg-linker-sram1-address
Open

target: fix STM32F765xG linker scripts — correct DTCM size and SRAM1 address#11391
sensei-hacker wants to merge 1 commit intoiNavFlight:maintenance-9.xfrom
sensei-hacker:fix/f765xg-linker-sram1-address

Conversation

@sensei-hacker
Copy link
Member

Problem

The three stm32_flash_f765xg*.ld linker scripts were copy-pasted from the STM32F745 linker without updating the memory map for the F765's larger DTCM.

Chip DTCM size DTCM range SRAM1 start
STM32F745xG 64 KB 0x20000000–0x2000FFFF 0x20010000
STM32F765xG 128 KB 0x20000000–0x2001FFFF 0x20020000

The F765xG linker scripts kept the F745 values (TCM = 64K, RAM at 0x20010000). On STM32F765 hardware, 0x20010000 is the start of the second 64 KB of DTCM — not SRAM1. This means:

  • Only the first 64 KB of the 128 KB DTCM was mapped (the other 64 KB was unused)
  • The RAM region (containing .bss, .data, and DMA buffers) was placed in DTCM address space rather than in SRAM1

The correct stm32_flash_f765xi.ld scripts (used by MATEKF765, MATEKF765SE) already have the correct addresses at 0x20020000 and serve as the reference.

Fix

All three xG linker script variants are corrected:

  • stm32_flash_f765xg.ld
  • stm32_flash_f765xg_bl.ld
  • stm32_flash_f765xg_for_bl.ld

Changes in each file:

  • DTCM_RAM: 64 KB → 128 KB (full F765 DTCM)
  • SRAM1 origin: 0x20010000 → 0x20020000 (correct F765 SRAM1 start)
  • Added SRAM2 region (16 KB at 0x2007C000) matching xi scripts
  • Updated REGION_ALIAS("RAM") to point to SRAM1
  • Corrected stale file headers (still said "STM32F745VGTx" / "320KByte RAM")
  • Updated flash config comment from "32K on F74x" to "32K on F7xx"

Affected Targets

  • FRSKYPILOT
  • FRSKYPILOT_LED

Targets using target_stm32f765xi() (MATEKF765, MATEKF765SE) are not affected — their linker scripts already have the correct addresses.

Testing

Build test: FRSKYPILOT builds cleanly. Post-fix memory report:

  • DTCM_RAM: 21,156 B / 128 KB (16%) — stack and FASTRAM variables
  • SRAM1: 95,404 B / 368 KB (25%) — .bss, .data, DMA buffers

Previously, those 95 KB were mapped starting at 0x20010000 (inside F765 DTCM) rather than SRAM1.

Hardware test: Not performed — no physical FRSKYPILOT hardware available.

…address

The three stm32_flash_f765xg*.ld linker scripts were copy-pasted from the
STM32F745 linker without updating the memory map for the F765's larger DTCM.

STM32F745: DTCM = 64 KB (0x20000000–0x2000FFFF), SRAM1 starts at 0x20010000
STM32F765: DTCM = 128 KB (0x20000000–0x2001FFFF), SRAM1 starts at 0x20020000

The F765xG linker scripts kept the F745 values (TCM = 64 KB, RAM at
0x20010000), which places the RAM region inside the upper half of DTCM on
F765 hardware rather than in SRAM1.

Fix all three xG variants (normal, bl, for_bl):
- Expand DTCM_RAM from 64 KB to 128 KB (the full F765 DTCM)
- Move SRAM1 origin from 0x20010000 to 0x20020000 (correct F765 address)
- Add SRAM2 region (16 KB at 0x2007C000) matching the xi scripts
- Update REGION_ALIAS("RAM") to point to SRAM1
- Update stale file headers that still referenced STM32F745VGTx / 320 KB RAM
- Update flash sector comment from "32K on F74x" to "32K on F7xx"

The xi variant linker scripts (used by MATEKF765, MATEKF765SE) already had
the correct addresses and are not changed.

Affected targets: FRSKYPILOT, FRSKYPILOT_LED.
@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Fix STM32F765xG linker scripts memory mapping and SRAM1 address

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix STM32F765xG linker scripts with incorrect DTCM and SRAM1 memory mapping
  - Expand DTCM from 64 KB to 128 KB (full F765 capacity)
  - Correct SRAM1 origin from 0x20010000 to 0x20020000
  - Add missing SRAM2 region (16 KB at 0x2007C000)
• Update stale file headers referencing STM32F745 and incorrect RAM size
• Rename TCM/RAM aliases to DTCM_RAM/SRAM1 for clarity and DMA compatibility
• Add explanatory comments about F765 vs F745 memory differences
Diagram
flowchart LR
  A["STM32F765xG<br/>Linker Scripts"] -->|Expand DTCM| B["DTCM_RAM<br/>128 KB"]
  A -->|Correct SRAM1| C["SRAM1<br/>0x20020000"]
  A -->|Add SRAM2| D["SRAM2<br/>16 KB"]
  A -->|Update Headers| E["Fix F745→F765<br/>References"]
  B --> F["DMA Buffers<br/>in SRAM1"]
  C --> F
Loading

Grey Divider

File Changes

1. src/main/target/link/stm32_flash_f765xg.ld 🐞 Bug fix +13/-9

Correct DTCM size and SRAM1 address for F765xG

• Updated file header from STM32F745 to STM32F765xG with correct RAM size (320KB→512KB)
• Renamed TCM to DTCM_RAM and expanded from 64K to 128K
• Renamed RAM to SRAM1 and moved origin from 0x20010000 to 0x20020000
• Added SRAM2 region (16K at 0x2007C000)
• Updated REGION_ALIAS mappings and added detailed memory layout comments
• Changed flash config comment from "32K on F74x" to "32K on F7xx"

src/main/target/link/stm32_flash_f765xg.ld


2. src/main/target/link/stm32_flash_f765xg_bl.ld 🐞 Bug fix +13/-9

Correct DTCM size and SRAM1 address for F765xG bootloader

• Updated file header from STM32F745 to STM32F765xG_bl with correct RAM size and bootloader note
• Renamed TCM to DTCM_RAM and expanded from 64K to 128K
• Renamed RAM to SRAM1 and moved origin from 0x20010000 to 0x20020000
• Added SRAM2 region (16K at 0x2007C000)
• Updated REGION_ALIAS mappings and added detailed memory layout comments
• Changed flash config comment from "32K on F74x" to "32K on F7xx"

src/main/target/link/stm32_flash_f765xg_bl.ld


3. src/main/target/link/stm32_flash_f765xg_for_bl.ld 🐞 Bug fix +13/-9

Correct DTCM size and SRAM1 address for F765xG bootloader-aware

• Updated file header from STM32F745 to STM32F765xG_for_bl with correct RAM size and
 bootloader-aware note
• Renamed TCM to DTCM_RAM and expanded from 64K to 128K
• Renamed RAM to SRAM1 and moved origin from 0x20010000 to 0x20020000
• Added SRAM2 region (16K at 0x2007C000)
• Updated REGION_ALIAS mappings and added detailed memory layout comments
• Changed flash config comment from "32K on F74x" to "32K on F7xx"

src/main/target/link/stm32_flash_f765xg_for_bl.ld


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 2, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Test firmware build ready — commit 2d60aa1

Download firmware for PR #11391

223 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant