From 76a20673390df27066c6d34faf83d85859a0f1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Quentin?= Date: Fri, 20 May 2022 11:38:39 +0200 Subject: [PATCH] Add feature to reserve Bluetooth RAM for ESP32 (#63) --- esp32-hal/Cargo.toml | 1 + esp32-hal/build.rs | 29 +++++++++++++++++++++++++++++ esp32-hal/ld/memory.x | 10 +--------- esp32s3-hal/src/lib.rs | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/esp32-hal/Cargo.toml b/esp32-hal/Cargo.toml index 784a17824..395010b2a 100644 --- a/esp32-hal/Cargo.toml +++ b/esp32-hal/Cargo.toml @@ -45,3 +45,4 @@ smart-leds = "0.3" default = ["rt"] rt = ["xtensa-lx-rt/esp32"] ufmt = ["esp-hal-common/ufmt"] +bluetooth = [] diff --git a/esp32-hal/build.rs b/esp32-hal/build.rs index e057c9ce0..ae04bba55 100644 --- a/esp32-hal/build.rs +++ b/esp32-hal/build.rs @@ -23,9 +23,38 @@ fn main() { .write_all(include_bytes!("ld/linkall.x")) .unwrap(); + let memory_extras = generate_memory_extras(); + File::create(out.join("memory_extras.x")) + .unwrap() + .write_all(&memory_extras) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); // Only re-run the build script when memory.x is changed, // instead of when any part of the source code changes. println!("cargo:rerun-if-changed=memory.x"); } + +fn generate_memory_extras() -> Vec { + let reserve_dram = if cfg!(feature = "bluetooth") { + "0x10000" + } else { + "0x0" + }; + + format!( + " + /* reserved at the start of DRAM for e.g. the BT stack */ + RESERVE_DRAM = {reserve_dram}; + + /* reserved at the start of the RTC memories for use by the ULP processor */ + RESERVE_RTC_FAST = 0; + RESERVE_RTC_SLOW = 0; + + /* define stack size for both cores */ + STACK_SIZE = 8k;" + ) + .as_bytes() + .to_vec() +} diff --git a/esp32-hal/ld/memory.x b/esp32-hal/ld/memory.x index d3e0b57a6..d9a8b00da 100644 --- a/esp32-hal/ld/memory.x +++ b/esp32-hal/ld/memory.x @@ -8,15 +8,7 @@ /* override entry point */ ENTRY(ESP32Reset) -/* reserved at the start of DRAM for e.g. teh BT stack */ -RESERVE_DRAM = 0; - -/* reserved at the start of the RTC memories for use by the ULP processor */ -RESERVE_RTC_FAST = 0; -RESERVE_RTC_SLOW = 0; - -/* define stack size for both cores */ -STACK_SIZE = 8k; +INCLUDE "memory_extras.x" /* Specify main memory areas */ MEMORY diff --git a/esp32s3-hal/src/lib.rs b/esp32s3-hal/src/lib.rs index 139cf2828..cf409fadf 100644 --- a/esp32s3-hal/src/lib.rs +++ b/esp32s3-hal/src/lib.rs @@ -9,8 +9,8 @@ pub use esp_hal_common::{ pulse_control, ram, spi, - utils, usb_serial_jtag, + utils, Cpu, Delay, PulseControl,