Skip to content

Conversation

@ivmarkov
Copy link
Collaborator

@ivmarkov ivmarkov commented Jan 13, 2022

With embuild 0.28.1, this code is just "convenience", i.e. it can be coded outside of embuild itself, but it might be annoying to repeat this code block in all binary crates that need to build their own one for or two ULP FSM assembly files.

And the code block is not so trivial, and not so small either (250 LOCs).

Note that while the ulp_fsm module is a sub-module of espidf, it does not really require anything from the espidf "native" build facilities. I.e. it does not use cmake, nor does build the ESP-IDF.

With that said:

  • It can optionally take advantage of environment variables set when building esp-idf-sys - either with PIO or natively - basically access to the ULP GCC toolchain as well as various ESP-DIF include directories
  • It should be possible to use with bare-metal crates which are not using ESP-IDF and do not depend on esp-idf-sys. However in that case, the user has to manually put (or supply a path var to) the Espressif GCC ULP toolchain, as well as a path to a valid ESP-IDF SDK. The latter is necessary because ULP assembly files can contain macros, which in turn use a very small, ulp-specific set of headers inside ESP-IDF. Primarily for easier access to the RTC registers on the chip, as the ULP might read/write data through them (as in RTC pins, ADC and RTC I2C).

Here's a sample binary crate build.rs file, which utilizes this code:

use std::iter;
use std::path::Path;
use std::{env, path::PathBuf};

use embuild::build;
use embuild::espidf::ulp_fsm;

fn main() -> anyhow::Result<()> {
    build_ulp()?;

    // Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641
    build::CfgArgs::output_propagated("ESP_IDF")?;
    build::LinkArgs::output_propagated("ESP_IDF")?;

    Ok(())
}

fn build_ulp() -> anyhow::Result<()> {
    let ulp_source = path_buf![env::current_dir()?, "src", "ulp.S"];
    cargo::track_file(&ulp_source);

    let build_result = Builder::try_from_embuild_env("ESP_IDF", vec![])?.build(
        iter::once(ulp_source.as_path()),
        PathBuf::from(env::var("OUT_DIR")?).join("ulp"),
    )?;

    cargo::set_rustc_env("ULP_BIN", build_result.bin_file.try_to_str()?);
    cargo::set_rustc_env("ULP_RS", build_result.sym_rs_file.try_to_str()?);

    Ok(())
}

@ivmarkov ivmarkov requested a review from N3xed January 13, 2022 14:16
@ivmarkov
Copy link
Collaborator Author

Oh well. It is such a small and isolated piece of code, that I'll just gone merge it. :)

@ivmarkov ivmarkov merged commit bb589f9 into master Jan 19, 2022
@N3xed
Copy link
Collaborator

N3xed commented Jan 19, 2022

@ivmarkov

Oh, yeah I'm sorry totally forgot to review this (currently busy with end-of-semester exams).
But it's not bad and we can always improve the code later.

@ivmarkov ivmarkov deleted the ulp-fsm branch August 27, 2023 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants