Skip to content

Commit

Permalink
Optimize memory and other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Apr 30, 2024
1 parent fb0f4a8 commit c7145c5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
32 changes: 8 additions & 24 deletions .github/configs/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y

# Examples often require a larger than the default stack size for the main thread and for the sysloop event task.
# rs-matter needs a large stack size
CONFIG_ESP_MAIN_TASK_STACK_SIZE=20000
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=8192
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192
#CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192

# Go figure...
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096

# Enable WS support
CONFIG_HTTPD_WS_SUPPORT=y

# SPI Ethernet demo
CONFIG_ETH_SPI_ETHERNET_DM9051=y
CONFIG_ETH_SPI_ETHERNET_W5500=y
CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL=y

## Uncomment to enable Classic BT
# BT
CONFIG_BT_ENABLED=y
CONFIG_BT_BLUEDROID_ENABLED=y
CONFIG_BT_CLASSIC_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=n
CONFIG_BT_CLASSIC_ENABLED=n
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BT_A2DP_ENABLE=y
CONFIG_BT_HFP_ENABLE=y
CONFIG_BT_HFP_CLIENT_ENABLE=y
CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI=y
CONFIG_BT_A2DP_ENABLE=n
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=y

# Support for TLS with a pre-shared key.
#CONFIG_ESP_TLS_PSK_VERIFICATION=y
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=n
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ jobs:
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || '' }} ${{ '-C default-linker-libraries' }}"
if: matrix.target == 'riscv32imc-esp-espidf'
run: cargo build --examples --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
run: cargo build --examples --features examples --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
resolver = "2"
categories = ["embedded", "hardware-support"]
keywords = ["matter", "embedded", "esp-idf", "esp32"]
description = "Implementation of the embedded-svc traits for ESP-IDF (Espressif's IoT Development Framework)"
description = "Run rs-matter on Espressif chips with ESP IDF"
repository = "https://github.com/ivmarkov/esp-idf-matter"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -20,9 +20,17 @@ esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc", branch = "gatt" }
rs-matter = { git = "https://github.com/ivmarkov/rs-matter", branch = "wifi" }
rs-matter-macros = { git = "https://github.com/ivmarkov/rs-matter", branch = "wifi" }

[profile.release]
opt-level = "s"

[profile.dev]
debug = true
opt-level = "z"

[features]
default = ["std"]
std = ["async-io", "rs-matter/std", "rs-matter/async-io"]
std = ["async-io", "rs-matter/std", "rs-matter/async-io", "esp-idf-svc/std"]
examples = ["std", "esp-idf-svc/binstart", "esp-idf-svc/critical-section"] # Enable only when building the examples

[dependencies]
log = { version = "0.4", default-features = false }
Expand All @@ -48,4 +56,4 @@ static_cell = "2.1"
[[example]]
name = "light"
path = "examples/light.rs"
required-features = ["std"]
required-features = ["examples"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ The examples could be built and flashed conveniently with [`cargo-espflash`](htt

with `cargo-espflash`:
```sh
$ MCU=esp32c3 cargo espflash flash --target riscv32imc-esp-espidf --example light --monitor
$ MCU=esp32c3 cargo espflash flash --target riscv32imc-esp-espidf --example light --features examples --monitor
```

| MCU | "--target" |
Expand Down
3 changes: 2 additions & 1 deletion src/ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use rs_matter::utils::ifmutex::IfMutex;
use crate::error::Error;

const MAX_CONNECTIONS: usize = MAX_BTP_SESSIONS;
const MAX_MTU_SIZE: usize = 512;

#[derive(Debug, Clone)]
struct Connection {
Expand All @@ -59,7 +60,7 @@ struct State {
#[derive(Debug, Clone)]
struct IndBuffer {
addr: BtAddr,
data: heapless::Vec<u8, 512>,
data: heapless::Vec<u8, MAX_MTU_SIZE>,
}

pub struct BtpGattContext {
Expand Down
25 changes: 17 additions & 8 deletions src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ use crate::multicast::{join_multicast_v4, join_multicast_v6};
use crate::netif::{get_ips, NetifAccess};
use crate::nvs;

const MAX_SUBSCRIPTIONS: usize = 3;
const MAX_IM_BUFFERS: usize = 10;
const PSM_BUFFER_SIZE: usize = 4096;

#[cfg(all(
not(esp32h2),
not(esp32s2),
Expand All @@ -55,9 +59,9 @@ where
T: Network,
{
matter: Matter<'a>,
buffers: PooledBuffers<10, NoopRawMutex, IMBuffer>,
psm_buffer: PooledBuffers<1, NoopRawMutex, heapless::Vec<u8, 4096>>,
subscriptions: Subscriptions<3>,
buffers: PooledBuffers<MAX_IM_BUFFERS, NoopRawMutex, IMBuffer>,
psm_buffer: PooledBuffers<1, NoopRawMutex, heapless::Vec<u8, PSM_BUFFER_SIZE>>,
subscriptions: Subscriptions<MAX_SUBSCRIPTIONS>,
#[allow(unused)]
network: T,
}
Expand Down Expand Up @@ -176,6 +180,8 @@ where
let mut psm = nvs::Psm::new(self.matter(), network, nvs, &mut psm_buf)?;

psm.run().await

// core::future::pending().await
}

async fn run_responder<H>(&self, handler: H) -> Result<(), Error>
Expand Down Expand Up @@ -340,10 +346,12 @@ mod wifible {
use crate::wifi::{comm, diag, WifiContext};
use crate::{MatterStack, Network};

const MAX_WIFI_NETWORKS: usize = 2;

pub struct WifiBle {
btp_context: BtpContext<EspRawMutex>,
btp_gatt_context: BtpGattContext,
wifi_context: WifiContext<3, NoopRawMutex>,
wifi_context: WifiContext<MAX_WIFI_NETWORKS, NoopRawMutex>,
}

impl WifiBle {
Expand Down Expand Up @@ -374,7 +382,8 @@ mod wifible {
}

pub async fn is_commissioned(&self, _nvs: EspDefaultNvsPartition) -> Result<bool, Error> {
todo!()
// TODO
Ok(false)
}

pub async fn operate<'d, T>(
Expand Down Expand Up @@ -480,7 +489,7 @@ mod wifible {
HandlerCompat<descriptor::DescriptorCluster<'a>>,
HandlerCompat<cluster_basic_information::BasicInfoCluster<'a>>,
HandlerCompat<general_commissioning::GenCommCluster<'a>>,
comm::WifiNwCommCluster<'a, 3, NoopRawMutex>,
comm::WifiNwCommCluster<'a, MAX_WIFI_NETWORKS, NoopRawMutex>,
HandlerCompat<admin_commissioning::AdminCommCluster<'a>>,
HandlerCompat<noc::NocCluster<'a>>,
HandlerCompat<access_control::AccessControlCluster<'a>>,
Expand All @@ -505,7 +514,7 @@ mod wifible {
fn handler<'a, T>(
endpoint_id: u16,
matter: &'a T,
networks: &'a WifiContext<3, NoopRawMutex>,
networks: &'a WifiContext<MAX_WIFI_NETWORKS, NoopRawMutex>,
) -> RootEndpointHandler<'a>
where
T: Borrow<BasicInfoConfig<'a>>
Expand Down Expand Up @@ -546,7 +555,7 @@ mod wifible {
mdns: &'a dyn Mdns,
epoch: Epoch,
rand: Rand,
networks: &'a WifiContext<3, NoopRawMutex>,
networks: &'a WifiContext<MAX_WIFI_NETWORKS, NoopRawMutex>,
) -> RootEndpointHandler<'a> {
EmptyHandler
.chain(
Expand Down

0 comments on commit c7145c5

Please sign in to comment.