Full boot working: ADAU1701 DSP fallback (probe empty partition), BT1035 flow control disabled + reset timing — all companion chips ready
This commit is contained in:
Binary file not shown.
+54318
-27581
File diff suppressed because one or more lines are too long
@@ -19,6 +19,7 @@
|
|||||||
#include "esp_partition.h"
|
#include "esp_partition.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace adau1701 {
|
namespace adau1701 {
|
||||||
|
|
||||||
@@ -56,15 +57,44 @@ FlashDspProgramSource::loadProgram()
|
|||||||
return std::unexpected(core::DspProgramError::FlashReadFailed);
|
return std::unexpected(core::DspProgramError::FlashReadFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::uint8_t> buffer(part->size);
|
// Rileva la partizione vuota leggendo solo un piccolo header, PRIMA di
|
||||||
if (esp_partition_read(part, 0, buffer.data(), part->size) != ESP_OK) {
|
// allocare l'intera partizione (256KB). Con eccezioni C++ disabilitate,
|
||||||
|
// allocare un vector cosi' grande su OOM chiama abort(). La partizione
|
||||||
|
// vergine e' tutta 0xFF.
|
||||||
|
constexpr std::size_t kProbeSize = 64U;
|
||||||
|
std::uint8_t probe[kProbeSize] = {};
|
||||||
|
if (esp_partition_read(part, 0, probe, kProbeSize) != ESP_OK) {
|
||||||
return std::unexpected(core::DspProgramError::FlashReadFailed);
|
return std::unexpected(core::DspProgramError::FlashReadFailed);
|
||||||
}
|
}
|
||||||
if (partitionLooksEmpty(buffer)) {
|
bool allErased = true;
|
||||||
|
for (std::size_t i = 0; i < kProbeSize; ++i) {
|
||||||
|
if (probe[i] != 0xFFU) { allErased = false; break; }
|
||||||
|
}
|
||||||
|
if (allErased) {
|
||||||
|
ESP_LOGW(kTag, "dsp partition empty (erased) - using fallback");
|
||||||
return std::unexpected(core::DspProgramError::Empty);
|
return std::unexpected(core::DspProgramError::Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
return core::parseDspProgramBlob(buffer);
|
// Partizione non vuota: alloca il backing store con new(nothrow), cosi'
|
||||||
|
// un OOM ritorna nullptr invece di abortire (nessuna eccezione).
|
||||||
|
auto* raw = new (std::nothrow) std::uint8_t[part->size];
|
||||||
|
if (raw == nullptr) {
|
||||||
|
ESP_LOGE(kTag, "dsp buffer alloc failed (%u byte)",
|
||||||
|
static_cast<unsigned>(part->size));
|
||||||
|
return std::unexpected(core::DspProgramError::FlashReadFailed);
|
||||||
|
}
|
||||||
|
std::unique_ptr<std::uint8_t[]> guard(raw);
|
||||||
|
|
||||||
|
if (esp_partition_read(part, 0, raw, part->size) != ESP_OK) {
|
||||||
|
return std::unexpected(core::DspProgramError::FlashReadFailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::span<const std::uint8_t> view(raw, part->size);
|
||||||
|
if (partitionLooksEmpty(view)) {
|
||||||
|
return std::unexpected(core::DspProgramError::Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
return core::parseDspProgramBlob(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<void, core::DspProgramError>
|
std::expected<void, core::DspProgramError>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ constexpr int kBaudRate = 115200;
|
|||||||
constexpr int kUartRxBuffer = 512;
|
constexpr int kUartRxBuffer = 512;
|
||||||
constexpr int kUartTxBuffer = 256;
|
constexpr int kUartTxBuffer = 256;
|
||||||
constexpr int kResponseTimeoutMs = 2000;
|
constexpr int kResponseTimeoutMs = 2000;
|
||||||
constexpr int kPostResetMs = 300;
|
constexpr int kPostResetMs = 500;
|
||||||
constexpr int kPostUartMs = 100;
|
constexpr int kPostUartMs = 100;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ std::expected<void, Bt1035Error> Bt1035Driver::boot()
|
|||||||
|
|
||||||
gpio_set_level(static_cast<gpio_num_t>(pins_.sysCtlGpio), 1);
|
gpio_set_level(static_cast<gpio_num_t>(pins_.sysCtlGpio), 1);
|
||||||
gpio_set_level(static_cast<gpio_num_t>(pins_.resetGpio), 0);
|
gpio_set_level(static_cast<gpio_num_t>(pins_.resetGpio), 0);
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
gpio_set_level(static_cast<gpio_num_t>(pins_.resetGpio), 1);
|
gpio_set_level(static_cast<gpio_num_t>(pins_.resetGpio), 1);
|
||||||
vTaskDelay(pdMS_TO_TICKS(kPostResetMs));
|
vTaskDelay(pdMS_TO_TICKS(kPostResetMs));
|
||||||
|
|
||||||
@@ -286,8 +286,8 @@ std::expected<void, Bt1035Error> Bt1035Driver::boot()
|
|||||||
.data_bits = UART_DATA_8_BITS,
|
.data_bits = UART_DATA_8_BITS,
|
||||||
.parity = UART_PARITY_DISABLE,
|
.parity = UART_PARITY_DISABLE,
|
||||||
.stop_bits = UART_STOP_BITS_1,
|
.stop_bits = UART_STOP_BITS_1,
|
||||||
.flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
|
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||||
.rx_flow_ctrl_thresh = 122,
|
.rx_flow_ctrl_thresh = 0,
|
||||||
.source_clk = UART_SCLK_DEFAULT,
|
.source_clk = UART_SCLK_DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ std::expected<void, Bt1035Error> Bt1035Driver::boot()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (uart_set_pin(static_cast<uart_port_t>(uartPort_), pins_.uartTx,
|
if (uart_set_pin(static_cast<uart_port_t>(uartPort_), pins_.uartTx,
|
||||||
pins_.uartRx, pins_.rtsGpio, pins_.ctsGpio)
|
pins_.uartRx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)
|
||||||
!= ESP_OK) {
|
!= ESP_OK) {
|
||||||
return std::unexpected(Bt1035Error::UartInitFailed);
|
return std::unexpected(Bt1035Error::UartInitFailed);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user