From 477f05a52427580b22a33a959fc79972033a5fd3 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 2 May 2026 16:47:41 +0200 Subject: [PATCH] Decreased limit of frame size to 10 words to cater for static DRAM_ATTR frames --- ads131m08/ads131m08.cpp | 11 +++++------ ads131m08/ads131m08_defs.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ads131m08/ads131m08.cpp b/ads131m08/ads131m08.cpp index d565a22..3e57264 100644 --- a/ads131m08/ads131m08.cpp +++ b/ads131m08/ads131m08.cpp @@ -17,7 +17,6 @@ namespace ads131m08 { static const char *const TAG = "ads131m08"; static const char *const white_space = " \t\n\r\f\v"; // Defines whitespace -//TODO: RREG might be longer than allocated frame size. work out max length and update following accordingly DRAM_ATTR static spiframe tx_frame(ADS131M08Hub::numFrameWords * 4, 0); DRAM_ATTR static spiframe rx_frame(ADS131M08Hub::numFrameWords * 4, 0); @@ -327,7 +326,7 @@ bool ADS131M08Hub::set_frame_word(spiframe &frame, int w_index, uint16_t data) size_t frame_words = frame.size() / word_nbytes; int b_index = w_index * word_nbytes; if (w_index >= frame_words) { - if (w_index > MAX_FRAME_SIZE) { + if (w_index >= MAX_FRAME_SIZE) { ESP_LOGE(TAG, "Word index of %d out of bounds", w_index); // esp_crosscore_int_send_print_backtrace(xPortGetCoreID()); return false; // invalid - something has gone wrong @@ -357,7 +356,7 @@ bool ADS131M08Hub::set_frame_word(spiframe &frame, int w_index, uint32_t data) size_t frame_words = frame.size() / word_nbytes; int b_index = w_index * word_nbytes; if (w_index >= frame_words) { - if (w_index > MAX_FRAME_SIZE) { + if (w_index >= MAX_FRAME_SIZE) { ESP_LOGE(TAG, "Word index of %d out of bounds", w_index); // esp_crosscore_int_send_print_backtrace(xPortGetCoreID()); return false; // invalid - something has gone wrong @@ -1028,9 +1027,9 @@ uint16_str ADS131M08Hub::adc_register_read(uint8_t address, uint8_t nregs) { if (nregs == 0) { return result; // invalid } - if (nregs > 31) { - // We are limited to 31 registers, otherwise we will ran into DMA / SPI buffer problems - ESP_LOGE(TAG, "Trying to read %d registers. This exceeds maximum register read count of 31!", nregs); + if (nregs > MAX_FRAME_SIZE - 2) { + // We are limited to 8 registers, otherwise we will exceed our static DMA / SPI buffer size + ESP_LOGE(TAG, "Trying to read %d registers. This exceeds maximum register read count of %d!", nregs, MAX_FRAME_SIZE - 2); return result; // invalid } int word_nbytes = adc_word_length_ >> 3; diff --git a/ads131m08/ads131m08_defs.h b/ads131m08/ads131m08_defs.h index d3f8725..a6792c1 100644 --- a/ads131m08/ads131m08_defs.h +++ b/ads131m08/ads131m08_defs.h @@ -6,7 +6,7 @@ namespace esphome { namespace ads131m08 { static constexpr size_t MAX_FRAME_SIZE = - 50; // in frame_words. This is an arbitrary limit, if frame is above this size something must have gone wrong + 10; // in frame_words. If frame is above this size something must have gone wrong enum ADC_DRDY_STATE : uint8_t { DS_LOGIC_HIGH = 0, // DEFAULT