Skip to content

Commit 46b746a

Browse files
committed
Fix STM32H735G build failure with Cargo 1.88+ and display issues
This commit fixes two issues with STM32H735G support: 1. Build failure with Cargo 1.88+ - Cargo 1.88 (PR rust-lang/cargo#15221) changed linker search path ordering to prioritize OUT_DIR paths over external paths - This caused ft5336's generic memory.x to take precedence over STM32H735G's board-specific memory.x, resulting in undefined symbol errors (__e_slint_assets, __s_slint_assets, __si_slint_assets) - Fixed by copying board-specific memory.x to OUT_DIR in build.rs, ensuring it takes precedence due to build dependency order 2. Display and size optimizations - Corrected window size from 320x240 to 480x272 to match actual STM32H735G-DK display dimensions - Added opt-level="z" to fit within FLASH constraints - Improved touch error handling to gracefully handle I2C errors Tested on STM32H735G-DK hardware with full UI and touch functionality.
1 parent ea0d0be commit 46b746a

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ windows-core = { version = "0.62.0" }
185185
[profile.release]
186186
lto = true
187187
panic = "abort"
188+
opt-level = "z" # Optimize for size (needed for STM32H735G FLASH constraints)
188189

189190
[profile.dev]
190191
panic = "abort"

demos/printerdemo_mcu/ui/printerdemo.slint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ component SideBarIcon inherits Rectangle {
3333
}
3434

3535
export component MainWindow inherits Window {
36-
width: 320px;
37-
height: 240px;
36+
width: 480px;
37+
height: 272px;
3838
title: "Slint printer demo";
3939
background: DemoPalette.main-background;
4040
default-font-family: "Noto Sans";

examples/mcu-board-support/build.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
// Copyright © SixtyFPS GmbH <[email protected]>
22
// SPDX-License-Identifier: MIT
33

4+
use std::env;
5+
use std::fs;
6+
use std::path::PathBuf;
7+
48
fn main() -> std::io::Result<()> {
59
#[allow(unused)]
6-
let mut board_config_path: Option<std::path::PathBuf> = None;
10+
let mut board_config_path: Option<PathBuf> = None;
11+
#[allow(unused)]
12+
let mut memory_x_source: Option<PathBuf> = None;
713

814
cfg_if::cfg_if! {
915
if #[cfg(feature = "pico-st7789")] {
@@ -12,6 +18,7 @@ fn main() -> std::io::Result<()> {
1218
board_config_path = Some([env!("CARGO_MANIFEST_DIR"), "pico2_st7789", "board_config.toml"].iter().collect());
1319
} else if #[cfg(feature = "stm32h735g")] {
1420
board_config_path = Some([env!("CARGO_MANIFEST_DIR"), "stm32h735g", "board_config.toml"].iter().collect());
21+
memory_x_source = Some([env!("CARGO_MANIFEST_DIR"), "stm32h735g", "memory.x"].iter().collect());
1522
} else if #[cfg(feature = "stm32u5g9j-dk2")] {
1623
board_config_path = Some([env!("CARGO_MANIFEST_DIR"), "stm32u5g9j_dk2", "board_config.toml"].iter().collect());
1724
}
@@ -21,6 +28,19 @@ fn main() -> std::io::Result<()> {
2128
println!("cargo:BOARD_CONFIG_PATH={}", path.display())
2229
}
2330

31+
// Copy memory.x to OUT_DIR and add it to the linker search path.
32+
// This ensures the board-specific memory.x takes precedence over
33+
// any generic memory.x from dependencies (e.g., ft5336).
34+
// Since Cargo 1.88 (PR #15221), OUT_DIR paths are prioritized over external paths,
35+
// so we need to place our memory.x in OUT_DIR to ensure it's found first.
36+
if let Some(source) = memory_x_source {
37+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
38+
let dest = out_dir.join("memory.x");
39+
fs::copy(&source, &dest)?;
40+
println!("cargo:rustc-link-search={}", out_dir.display());
41+
println!("cargo:rerun-if-changed={}", source.display());
42+
}
43+
2444
println!("cargo:EMBED_TEXTURES=1");
2545

2646
Ok(())

examples/mcu-board-support/stm32h735g.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,20 +353,27 @@ impl slint::platform::Platform for StmBackend {
353353
});
354354

355355
// handle touch event
356-
let touch = ft5336.detect_touch(&mut inner.touch_i2c).unwrap();
356+
let touch = ft5336.detect_touch(&mut inner.touch_i2c).ok();
357357
let button = slint::platform::PointerEventButton::Left;
358-
let event = if touch > 0 {
359-
let state = ft5336.get_touch(&mut inner.touch_i2c, 1).unwrap();
360-
let position = slint::PhysicalPosition::new(state.y as i32, state.x as i32)
361-
.to_logical(window.scale_factor());
362-
Some(match last_touch.replace(position) {
363-
Some(_) => slint::platform::WindowEvent::PointerMoved { position },
364-
None => slint::platform::WindowEvent::PointerPressed { position, button },
365-
})
358+
let event = if let Some(touch_count) = touch {
359+
if touch_count > 0 {
360+
if let Ok(state) = ft5336.get_touch(&mut inner.touch_i2c, 1) {
361+
let position = slint::PhysicalPosition::new(state.y as i32, state.x as i32)
362+
.to_logical(window.scale_factor());
363+
Some(match last_touch.replace(position) {
364+
Some(_) => slint::platform::WindowEvent::PointerMoved { position },
365+
None => slint::platform::WindowEvent::PointerPressed { position, button },
366+
})
367+
} else {
368+
None
369+
}
370+
} else {
371+
last_touch.take().map(|position| {
372+
slint::platform::WindowEvent::PointerReleased { position, button }
373+
})
374+
}
366375
} else {
367-
last_touch.take().map(|position| {
368-
slint::platform::WindowEvent::PointerReleased { position, button }
369-
})
376+
None
370377
};
371378

372379
if let Some(event) = event {

examples/mcu-board-support/stm32h735g/board_config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# SPDX-License-Identifier: MIT
33

44
link_args = ["--nmagic", "-Tlink.x", "-Tdefmt.x"]
5-
link_search_path = ["."]
5+
# link_search_path removed: memory.x is now copied to OUT_DIR in build.rs

0 commit comments

Comments
 (0)