Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/fbuild-build/src/apollo3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Apollo3 Build Orchestrator

Build orchestrator for the Ambiq Apollo3 platform (ARM Cortex-M4F). Uses the generic ARM compiler/linker with mbed-os response files from the SparkFun Arduino Apollo3 core.
3 changes: 3 additions & 0 deletions crates/fbuild-build/src/apollo3/configs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Apollo3 MCU Configurations

Embedded JSON configs for Apollo3 (Ambiq Micro) ARM Cortex-M4F MCUs.
65 changes: 65 additions & 0 deletions crates/fbuild-build/src/apollo3/configs/apollo3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "Apollo3",
"description": "Ambiq Micro Apollo3 (ARM Cortex-M4F)",
"architecture": "arm-cortex-m4f",

"compiler_flags": {
"common": [
"-mcpu=cortex-m4",
"-mthumb",
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16",
"-fdata-sections",
"-ffunction-sections",
"-fmessage-length=0",
"-fno-exceptions",
"-fomit-frame-pointer",
"-funsigned-char",
"-MMD"
],
"c": [
"-std=gnu11"
],
"cxx": [
"-std=gnu++14",
"-fno-rtti"
]
},

"linker_flags": [
"-mcpu=cortex-m4",
"-mthumb",
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16",
"-Wl,--gc-sections",
"-Wl,-n"
],

"linker_libs": [
"-lsupc++",
"-lstdc++",
"-lm"
],

"objcopy": {
"output_format": "binary",
"remove_sections": []
},

"profiles": {
"release": {
"compile_flags": ["-Os"],
"link_flags": []
},
"quick": {
"compile_flags": ["-Os"],
"link_flags": []
}
},

"defines": [
["ARDUINO", "10808"],
"MBED_NO_GLOBAL_USING_DIRECTIVE",
"CORDIO_ZERO_COPY_HCI"
]
}
77 changes: 77 additions & 0 deletions crates/fbuild-build/src/apollo3/mcu_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! Data-driven Apollo3 MCU configuration from embedded JSON.
//!
//! Maps Apollo3 MCU names to the appropriate ARM Cortex-M4F configuration.

use fbuild_core::Result;

use crate::generic_arm::ArmMcuConfig;

const APOLLO3_JSON: &str = include_str!("configs/apollo3.json");

/// Load MCU configuration for the Apollo3.
pub fn get_apollo3_config_for_mcu(mcu: &str) -> Result<ArmMcuConfig> {
let json = match mcu {
"apollo3" => APOLLO3_JSON,
_ => {
// Default to Apollo3 for any Ambiq MCU variant
if mcu.starts_with("ama3b") || mcu.contains("apollo") {
APOLLO3_JSON
} else {
return Err(fbuild_core::FbuildError::ConfigError(format!(
"unsupported Apollo3 MCU: '{}' (supported: apollo3, ama3b*)",
mcu
)));
}
}
};
serde_json::from_str(json).map_err(|e| {
fbuild_core::FbuildError::ConfigError(format!(
"failed to parse Apollo3 MCU config for '{}': {}",
mcu, e
))
})
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_load_apollo3_config() {
let config = get_apollo3_config_for_mcu("apollo3").unwrap();
assert_eq!(config.name, "Apollo3");
assert_eq!(config.architecture, "arm-cortex-m4f");
}

#[test]
fn test_load_apollo3_ama3b_variant() {
let config = get_apollo3_config_for_mcu("ama3b1kk").unwrap();
assert_eq!(config.name, "Apollo3");
}

#[test]
fn test_unsupported_mcu() {
assert!(get_apollo3_config_for_mcu("stm32f103").is_err());
}

#[test]
fn test_apollo3_compiler_flags() {
let config = get_apollo3_config_for_mcu("apollo3").unwrap();
assert!(config
.compiler_flags
.common
.contains(&"-mcpu=cortex-m4".to_string()));
assert!(config
.compiler_flags
.common
.contains(&"-mthumb".to_string()));
assert!(config
.compiler_flags
.common
.contains(&"-mfloat-abi=hard".to_string()));
assert!(config
.compiler_flags
.common
.contains(&"-mfpu=fpv4-sp-d16".to_string()));
}
}
27 changes: 27 additions & 0 deletions crates/fbuild-build/src/apollo3/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Apollo3 platform build support (Ambiq Micro Apollo3 / SparkFun Artemis).

pub mod mcu_config;
pub mod orchestrator;

pub use orchestrator::Apollo3Orchestrator;

/// Apollo3 platform support.
pub struct Apollo3PlatformSupport;

impl crate::PlatformSupport for Apollo3PlatformSupport {
fn create_orchestrator(&self) -> Box<dyn crate::BuildOrchestrator> {
orchestrator::create()
}

fn install_deps(&self, project_dir: &std::path::Path) -> fbuild_core::Result<()> {
use fbuild_packages::Package;
let tc = fbuild_packages::toolchain::ArmGcc8Toolchain::new(project_dir);
Package::ensure_installed(&tc)?;
tracing::info!("ARM GCC 8 toolchain installed");
Ok(())
}

fn default_board_id(&self) -> &str {
"SparkFun_RedBoard_Artemis_ATP"
}
}
Loading
Loading