Skip to content

Commit

Permalink
Allocate more buffers on heap reducing task stack size
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Jan 30, 2025
1 parent 79be9f8 commit eb3aba8
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion firmware/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[env]
# Task arena size of embassy-executor, see https://docs.embassy.dev/embassy-executor/git/cortex-m/index.html#task-arena
EMBASSY_EXECUTOR_TASK_ARENA_SIZE = "26624"
EMBASSY_EXECUTOR_TASK_ARENA_SIZE = "14336"
# Log filter for esp-println to apply at runtime. Also, a feature of the log crate strips all
# logging above info level from release builds at compile time (feature `release_max_level_info`).
ESP_LOG = "info,touch_n_drink=debug"
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Config {
};

// Read first sector (4 kb) of config data partition
let mut bytes = [0; FlashStorage::SECTOR_SIZE as usize];
let mut bytes = vec![0; FlashStorage::SECTOR_SIZE as usize];
if let Err(_err) = storage.read(config_offset, &mut bytes) {
warn!("Config: Unable to read config partition");
return Self::default();
Expand Down
8 changes: 4 additions & 4 deletions firmware/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use reqwless::headers::ContentType;
use reqwless::request::{RequestBody, RequestBuilder};
use reqwless::response::{BodyReader, StatusCode};

/// Maximum size of response from server
const MAX_RESPONSE_SIZE: usize = 4096;
/// Maximum size of response headers from server
const MAX_RESPONSE_HEADER_SIZE: usize = 2048;

/// TLS read buffer size
const READ_BUFFER_SIZE: usize = 16640;
Expand Down Expand Up @@ -133,7 +133,7 @@ impl fmt::Debug for Connection<'_> {
impl<'a> Connection<'a> {
/// Send GET request, deserialize JSON response
pub async fn get<T: FromJson>(&mut self, path: &str) -> Result<T, Error> {
let mut rx_buf = [0; MAX_RESPONSE_SIZE];
let mut rx_buf = vec![0; MAX_RESPONSE_HEADER_SIZE];
let mut json = self.get_json(path, &mut rx_buf).await?;
json.read().await.map_err(Error::MalformedResponse)
}
Expand All @@ -159,7 +159,7 @@ impl<'a> Connection<'a> {
/// Serialize data to JSON, send POST request, deserialize JSON response
pub async fn post<T: ToJson, U: FromJson>(&mut self, path: &str, data: &T) -> Result<U, Error> {
let body = Self::prepare_body(data).await?;
let mut rx_buf = [0; MAX_RESPONSE_SIZE];
let mut rx_buf = vec![0; MAX_RESPONSE_HEADER_SIZE];
let mut json = self.post_json(path, &body, &mut rx_buf).await?;
json.read().await.map_err(Error::MalformedResponse)
}
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/nfc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl fmt::Display for Error {
/// NFC reader
#[derive(Debug)]
pub struct Nfc<I2C, IRQ> {
driver: Pn532<I2CInterfaceWithIrq<I2C, IRQ>>,
driver: Pn532<I2CInterfaceWithIrq<I2C, IRQ>, 64>,
}

impl<I2C: I2c, IRQ: Wait<Error = Infallible>> Nfc<I2C, IRQ> {
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/pn532.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use pn532::requests::{Command, SAMMode};
pub use pn532::{Error, Request};

/// Response buffer size (32 is the PN532 default)
pub const BUFFER_SIZE: usize = 64;
pub const BUFFER_SIZE: usize = 32;

/// Command ACK timeout
const ACK_TIMEOUT: Duration = Duration::from_millis(50);
Expand Down
5 changes: 3 additions & 2 deletions firmware/src/vereinsflieger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::time;
use crate::user::{UserId, Users};
use alloc::format;
use alloc::string::String;
use alloc::vec;
use core::cell::RefCell;
use core::fmt;
use embassy_time::{with_timeout, Duration};
Expand Down Expand Up @@ -157,7 +158,7 @@ impl Connection<'_> {
})
.await
.map_err(Error::FetchArticles)?;
let mut rx_buf = [0; 4096];
let mut rx_buf = vec![0; 2048];
let mut json = with_timeout(
TIMEOUT,
self.http
Expand Down Expand Up @@ -199,7 +200,7 @@ impl Connection<'_> {
})
.await
.map_err(Error::FetchUsers)?;
let mut rx_buf = [0; 4096];
let mut rx_buf = vec![0; 2048];
let mut json = with_timeout(
TIMEOUT,
self.http.post_json("user/list", &request_body, &mut rx_buf),
Expand Down

0 comments on commit eb3aba8

Please sign in to comment.