diff --git a/crates/fbuild-build-mcu/src/ch32v/orchestrator.rs b/crates/fbuild-build-mcu/src/ch32v/orchestrator.rs index 3c297f7b..fcf50b42 100644 --- a/crates/fbuild-build-mcu/src/ch32v/orchestrator.rs +++ b/crates/fbuild-build-mcu/src/ch32v/orchestrator.rs @@ -132,9 +132,6 @@ impl BuildOrchestrator for Ch32vOrchestrator { if let Some(vh) = resolve_variant_h(&variant_dir, ctx.board.variant_h.as_deref()) { defines.insert("VARIANT_H".to_string(), format!("\\\"{}\\\"", vh)); } - if series == "ch32x035" { - defines.insert("RCC_BackupResetCmd(x)".to_string(), "((void)0)".to_string()); - } // Use resolved core_dir/variant_dir directly — board.get_include_paths() // uses the raw board core name which may differ from the actual directory // (e.g. OpenWCH core dir is "arduino", not "openwch"). diff --git a/crates/fbuild-library/src/library/ch32v_core.rs b/crates/fbuild-library/src/library/ch32v_core.rs index b034e041..3383a56f 100644 --- a/crates/fbuild-library/src/library/ch32v_core.rs +++ b/crates/fbuild-library/src/library/ch32v_core.rs @@ -91,11 +91,6 @@ impl Ch32vCores { Ok(()) } - /// Apply compatibility patches for known upstream core issues. - fn patch_compatibility(root: &Path) -> fbuild_core::Result<()> { - patch_backup_header(root) - } - /// Get the core source directory for a specific core name. /// /// The board JSON `core` field (e.g. "openwch") comes from PlatformIO's @@ -136,14 +131,12 @@ impl crate::Package for Ch32vCores { async fn ensure_installed(&self) -> fbuild_core::Result { if self.is_installed() { let root = self.resolved_dir(); - Self::patch_compatibility(&root)?; return Ok(root); } let install_path = self.base.staged_install(Self::validate).await?; let root = find_core_root(&install_path); - Self::patch_compatibility(&root)?; Ok(root) } @@ -194,39 +187,6 @@ fn find_core_root(install_dir: &Path) -> PathBuf { install_dir.to_path_buf() } -fn patch_backup_header(root: &Path) -> fbuild_core::Result<()> { - let backup_h = root - .join("cores") - .join("arduino") - .join("ch32") - .join("backup.h"); - if !backup_h.exists() { - return Ok(()); - } - - let content = std::fs::read_to_string(&backup_h).map_err(|e| { - fbuild_core::FbuildError::PackageError(format!( - "failed to read CH32V backup header {}: {}", - backup_h.display(), - e - )) - })?; - - let patched = content.replace("#ifndef CH32V00x", "#ifdef RCC_APB1Periph_BKP"); - if patched != content { - std::fs::write(&backup_h, patched).map_err(|e| { - fbuild_core::FbuildError::PackageError(format!( - "failed to patch CH32V backup header {}: {}", - backup_h.display(), - e - )) - })?; - tracing::debug!("patched {}", backup_h.display()); - } - - Ok(()) -} - #[cfg(test)] mod tests { use super::*; @@ -261,27 +221,4 @@ mod tests { assert!(result.is_err()); } - #[test] - fn test_patch_backup_header_replaces_old_guard() { - let tmp = tempfile::TempDir::new().unwrap(); - let backup_h = tmp.path().join("cores/arduino/ch32/backup.h"); - std::fs::create_dir_all(backup_h.parent().unwrap()).unwrap(); - std::fs::write( - &backup_h, - "static inline void resetBackupDomain(void)\n{\n#ifndef CH32V00x\n RCC_BackupResetCmd(ENABLE);\n RCC_BackupResetCmd(DISABLE);\n#endif\n}\n", - ) - .unwrap(); - - patch_backup_header(tmp.path()).unwrap(); - - let patched = std::fs::read_to_string(&backup_h).unwrap(); - assert!(patched.contains("#ifdef RCC_APB1Periph_BKP")); - assert!(!patched.contains("#ifndef CH32V00x")); - } - - #[test] - fn test_patch_backup_header_is_noop_when_missing() { - let tmp = tempfile::TempDir::new().unwrap(); - patch_backup_header(tmp.path()).unwrap(); - } }