Si4684 boot fix: flash encryption off, 16MB flash, NVS enc off, main task stack 8KB, CTS timeout 10s (fixes BootCmd error 6), DMA-safe HOST_LOAD buffer
This commit is contained in:
@@ -22,3 +22,10 @@ Software/docs/manual/*.out
|
|||||||
Software/docs/manual/*.pdf
|
Software/docs/manual/*.pdf
|
||||||
Software/docs/manual/*.synctex.gz
|
Software/docs/manual/*.synctex.gz
|
||||||
Software/docs/manual/*.toc
|
Software/docs/manual/*.toc
|
||||||
|
|
||||||
|
# Debug logs e file temporanei (DigiRadio Si4684 debug)
|
||||||
|
Software/boot*.log
|
||||||
|
Software/sdkconfig 2
|
||||||
|
Software/sdkconfig 3
|
||||||
|
Software/sdkconfig 4
|
||||||
|
.DS_Store
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
@@ -25,7 +25,8 @@ namespace adau1701 {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr char kTag[] = "FlashDsp";
|
constexpr char kTag[] = "FlashDsp";
|
||||||
constexpr std::uint8_t kDspPartitionSubtype = 0x40U;
|
constexpr esp_partition_subtype_t kDspPartitionSubtype =
|
||||||
|
static_cast<esp_partition_subtype_t>(0x40U);
|
||||||
|
|
||||||
[[nodiscard]] const esp_partition_t* dspPartition()
|
[[nodiscard]] const esp_partition_t* dspPartition()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -244,6 +244,8 @@ private:
|
|||||||
[[nodiscard]] std::expected<void, Bt1035Error> transmitAndExpectOk(
|
[[nodiscard]] std::expected<void, Bt1035Error> transmitAndExpectOk(
|
||||||
std::string_view commandLine);
|
std::string_view commandLine);
|
||||||
|
|
||||||
|
static constexpr int kResponseTimeoutMs = 2000;
|
||||||
|
|
||||||
Bt1035Pins pins_;
|
Bt1035Pins pins_;
|
||||||
bool booted_;
|
bool booted_;
|
||||||
bool uartInstalled_;
|
bool uartInstalled_;
|
||||||
|
|||||||
@@ -105,7 +105,8 @@ std::expected<std::string, Bt1035Error> Bt1035Driver::transmitAndCollect(
|
|||||||
std::expected<void, Bt1035Error> Bt1035Driver::transmitAndExpectOk(
|
std::expected<void, Bt1035Error> Bt1035Driver::transmitAndExpectOk(
|
||||||
std::string_view commandLine)
|
std::string_view commandLine)
|
||||||
{
|
{
|
||||||
if (auto collected = transmitAndCollect(commandLine); collected) {
|
auto collected = transmitAndCollect(commandLine);
|
||||||
|
if (collected) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return std::unexpected(collected.error());
|
return std::unexpected(collected.error());
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
|
|
||||||
namespace si4684 {
|
namespace si4684 {
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ namespace {
|
|||||||
constexpr char kTag[] = "Si4684";
|
constexpr char kTag[] = "Si4684";
|
||||||
constexpr std::size_t kSpiBufferSize = 4096U;
|
constexpr std::size_t kSpiBufferSize = 4096U;
|
||||||
constexpr int kCtsPollMs = 2;
|
constexpr int kCtsPollMs = 2;
|
||||||
constexpr int kCtsRetries = 200;
|
constexpr int kCtsRetries = 5000;
|
||||||
constexpr int kStcRetries = 250;
|
constexpr int kStcRetries = 250;
|
||||||
constexpr int kStcPollMs = 20;
|
constexpr int kStcPollMs = 20;
|
||||||
|
|
||||||
@@ -213,36 +214,57 @@ std::expected<void, Si4684Error> Si4684Driver::writeCommand(
|
|||||||
std::expected<void, Si4684Error> Si4684Driver::hostLoadBlob(
|
std::expected<void, Si4684Error> Si4684Driver::hostLoadBlob(
|
||||||
const core::IFirmwareBlobReader& blob, std::size_t chunkPayload)
|
const core::IFirmwareBlobReader& blob, std::size_t chunkPayload)
|
||||||
{
|
{
|
||||||
|
// Buffer DMA-capable e allineato: obbligatorio per spi_device_transmit
|
||||||
|
// con trasferimenti grandi. Un buffer sullo stack non e' DMA-safe e puo'
|
||||||
|
// corrompere i dati sui blob grossi (patch/firmware).
|
||||||
|
const std::size_t txSize = 4U + chunkPayload;
|
||||||
|
auto* tx = static_cast<std::uint8_t*>(
|
||||||
|
heap_caps_malloc(txSize, MALLOC_CAP_DMA | MALLOC_CAP_8BIT));
|
||||||
|
if (tx == nullptr) {
|
||||||
|
return std::unexpected(Si4684Error::ImageLoadFailed);
|
||||||
|
}
|
||||||
|
|
||||||
std::array<std::byte, 2044> payload = {};
|
std::array<std::byte, 2044> payload = {};
|
||||||
std::size_t offset = 0U;
|
std::size_t offset = 0U;
|
||||||
|
Si4684Error err = Si4684Error::ImageLoadFailed;
|
||||||
|
bool failed = false;
|
||||||
|
|
||||||
while (offset < blob.size()) {
|
while (offset < blob.size()) {
|
||||||
const std::size_t maxChunk = std::min(chunkPayload, payload.size());
|
const std::size_t maxChunk = std::min(chunkPayload, payload.size());
|
||||||
const std::size_t copied =
|
const std::size_t copied =
|
||||||
blob.read(offset, std::span<std::byte>(payload.data(), maxChunk));
|
blob.read(offset, std::span<std::byte>(payload.data(), maxChunk));
|
||||||
if (copied == 0U) {
|
if (copied == 0U) {
|
||||||
return std::unexpected(Si4684Error::ImageLoadFailed);
|
failed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<std::uint8_t, kSpiBufferSize> tx = {};
|
std::memset(tx, 0, txSize);
|
||||||
tx[0] = static_cast<std::uint8_t>(Command::HostLoad);
|
tx[0] = static_cast<std::uint8_t>(Command::HostLoad);
|
||||||
tx[1] = 0x00U;
|
tx[1] = 0x00U;
|
||||||
tx[2] = 0x00U;
|
tx[2] = 0x00U;
|
||||||
tx[3] = 0x00U;
|
tx[3] = 0x00U;
|
||||||
std::memcpy(tx.data() + 4U, payload.data(), copied);
|
std::memcpy(tx + 4U, payload.data(), copied);
|
||||||
|
|
||||||
spi_transaction_t txn = {};
|
spi_transaction_t txn = {};
|
||||||
txn.length = (4U + copied) * 8U;
|
txn.length = txSize * 8U;
|
||||||
txn.tx_buffer = tx.data();
|
txn.tx_buffer = tx;
|
||||||
if (spi_device_transmit(static_cast<spi_device_handle_t>(spiDevice_),
|
if (spi_device_transmit(static_cast<spi_device_handle_t>(spiDevice_),
|
||||||
&txn) != ESP_OK) {
|
&txn) != ESP_OK) {
|
||||||
return std::unexpected(Si4684Error::ImageLoadFailed);
|
failed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (auto cts = waitCts(); !cts) {
|
if (auto cts = waitCts(); !cts) {
|
||||||
return cts;
|
err = cts.error();
|
||||||
|
failed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
offset += copied;
|
offset += copied;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heap_caps_free(tx);
|
||||||
|
if (failed) {
|
||||||
|
return std::unexpected(err);
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,7 +418,7 @@ std::expected<void, Si4684Error> Si4684Driver::boot(Si4684Band band)
|
|||||||
gpio_set_level(static_cast<gpio_num_t>(pins_.rstbGpio), 0);
|
gpio_set_level(static_cast<gpio_num_t>(pins_.rstbGpio), 0);
|
||||||
vTaskDelay(pdMS_TO_TICKS(5));
|
vTaskDelay(pdMS_TO_TICKS(5));
|
||||||
gpio_set_level(static_cast<gpio_num_t>(pins_.rstbGpio), 1);
|
gpio_set_level(static_cast<gpio_num_t>(pins_.rstbGpio), 1);
|
||||||
vTaskDelay(pdMS_TO_TICKS(3));
|
vTaskDelay(pdMS_TO_TICKS(20));
|
||||||
|
|
||||||
if (!spiBusActive_) {
|
if (!spiBusActive_) {
|
||||||
spi_bus_config_t busCfg = {};
|
spi_bus_config_t busCfg = {};
|
||||||
@@ -442,7 +464,7 @@ std::expected<void, Si4684Error> Si4684Driver::boot(Si4684Band band)
|
|||||||
return std::unexpected(Si4684Error::PowerUpFailed);
|
return std::unexpected(Si4684Error::PowerUpFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1));
|
vTaskDelay(pdMS_TO_TICKS(20));
|
||||||
|
|
||||||
if (auto li = writeCommand(Command::LoadInit, nullptr, 0U); !li) {
|
if (auto li = writeCommand(Command::LoadInit, nullptr, 0U); !li) {
|
||||||
return std::unexpected(Si4684Error::PatchLoadFailed);
|
return std::unexpected(Si4684Error::PatchLoadFailed);
|
||||||
@@ -557,18 +579,18 @@ std::expected<Si4684FmRsq, Si4684Error> Si4684Driver::readFmRsq()
|
|||||||
return std::unexpected(rd.error());
|
return std::unexpected(rd.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
Si4684FmRsq rsq = {};
|
|
||||||
const auto khz = chipFmFreqToKHz(readLe16(raw.data() + 6));
|
const auto khz = chipFmFreqToKHz(readLe16(raw.data() + 6));
|
||||||
if (auto freq = core::FrequencyKHz::tryFromKhz(khz); freq) {
|
if (auto freq = core::FrequencyKHz::tryFromKhz(khz); freq) {
|
||||||
rsq.frequency = *freq;
|
Si4684FmRsq rsq{
|
||||||
} else {
|
*freq,
|
||||||
return std::unexpected(Si4684Error::CommandFailed);
|
static_cast<std::int8_t>(raw[8]),
|
||||||
|
static_cast<std::int8_t>(raw[9]),
|
||||||
|
(raw[4] & 0x01U) != 0U,
|
||||||
|
(raw[4] & 0x02U) != 0U,
|
||||||
|
};
|
||||||
|
return rsq;
|
||||||
}
|
}
|
||||||
rsq.valid = (raw[4] & 0x01U) != 0U;
|
return std::unexpected(Si4684Error::CommandFailed);
|
||||||
rsq.stereo = (raw[4] & 0x02U) != 0U;
|
|
||||||
rsq.rssiDbuV = static_cast<std::int8_t>(raw[8]);
|
|
||||||
rsq.snrDb = static_cast<std::int8_t>(raw[9]);
|
|
||||||
return rsq;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<Si4684FmRdsStatus, Si4684Error> Si4684Driver::readFmRds()
|
std::expected<Si4684FmRdsStatus, Si4684Error> Si4684Driver::readFmRds()
|
||||||
|
|||||||
@@ -172,7 +172,8 @@ std::expected<void, core::TunerError> Si4684Tuner::tuneFm(
|
|||||||
std::expected<core::FrequencyKHz, core::TunerError> Si4684Tuner::seekFm(
|
std::expected<core::FrequencyKHz, core::TunerError> Si4684Tuner::seekFm(
|
||||||
core::SeekDirection direction)
|
core::SeekDirection direction)
|
||||||
{
|
{
|
||||||
if (auto result = driver_.seekFm(direction, SeekBandWrap::Wrap); !result) {
|
const auto result = driver_.seekFm(direction, SeekBandWrap::Wrap);
|
||||||
|
if (!result) {
|
||||||
return std::unexpected(mapError(result.error()));
|
return std::unexpected(mapError(result.error()));
|
||||||
}
|
}
|
||||||
fmFrequency_ = *result;
|
fmFrequency_ = *result;
|
||||||
@@ -191,7 +192,8 @@ Si4684Tuner::listDabServices()
|
|||||||
return std::unexpected(mapError(events.error()));
|
return std::unexpected(mapError(events.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto list = driver_.fetchDabServiceList(); list) {
|
const auto list = driver_.fetchDabServiceList();
|
||||||
|
if (list) {
|
||||||
std::vector<core::TunerServiceEntry> out;
|
std::vector<core::TunerServiceEntry> out;
|
||||||
out.reserve(list->size());
|
out.reserve(list->size());
|
||||||
for (const auto& item : *list) {
|
for (const auto& item : *list) {
|
||||||
|
|||||||
@@ -99,6 +99,21 @@ public:
|
|||||||
NetBootstrap(const NetBootstrap&) = delete;
|
NetBootstrap(const NetBootstrap&) = delete;
|
||||||
NetBootstrap& operator=(const NetBootstrap&) = delete;
|
NetBootstrap& operator=(const NetBootstrap&) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NetBootstrap — construct a started bootstrap.
|
||||||
|
*
|
||||||
|
* @dname NetBootstrap
|
||||||
|
* @param softAp Optional SoftAP mode host.
|
||||||
|
* @param sta Optional STA client instance.
|
||||||
|
* @param webServer HTTP server instance.
|
||||||
|
* @param state Initial network state.
|
||||||
|
* @pubstate Transfers ownership of optional network resources.
|
||||||
|
*/
|
||||||
|
NetBootstrap(std::optional<SoftApHost> softAp,
|
||||||
|
std::optional<StaClient> sta,
|
||||||
|
SetupWebServer webServer,
|
||||||
|
NetState state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief NetBootstrap — move-construct from a started bootstrap.
|
* @brief NetBootstrap — move-construct from a started bootstrap.
|
||||||
*
|
*
|
||||||
@@ -148,11 +163,6 @@ public:
|
|||||||
[[nodiscard]] NetState state() const noexcept;
|
[[nodiscard]] NetState state() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetBootstrap(std::optional<SoftApHost> softAp,
|
|
||||||
std::optional<StaClient> sta,
|
|
||||||
SetupWebServer webServer,
|
|
||||||
NetState state);
|
|
||||||
|
|
||||||
std::optional<SoftApHost> softAp_;
|
std::optional<SoftApHost> softAp_;
|
||||||
std::optional<StaClient> sta_;
|
std::optional<StaClient> sta_;
|
||||||
SetupWebServer webServer_;
|
SetupWebServer webServer_;
|
||||||
|
|||||||
@@ -23,10 +23,9 @@
|
|||||||
#include "net/NetError.hpp"
|
#include "net/NetError.hpp"
|
||||||
#include "net/NetState.hpp"
|
#include "net/NetState.hpp"
|
||||||
|
|
||||||
|
#include "esp_http_server.h"
|
||||||
#include <expected>
|
#include <expected>
|
||||||
|
|
||||||
struct httpd_req;
|
|
||||||
|
|
||||||
namespace audio {
|
namespace audio {
|
||||||
class AudioService;
|
class AudioService;
|
||||||
} // namespace audio
|
} // namespace audio
|
||||||
@@ -172,7 +171,7 @@ public:
|
|||||||
const core::DeviceIdentity& deviceIdentity);
|
const core::DeviceIdentity& deviceIdentity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
httpd_handle* server_;
|
httpd_handle_t server_;
|
||||||
core::ISecureStore* store_;
|
core::ISecureStore* store_;
|
||||||
NetState netState_;
|
NetState netState_;
|
||||||
tuner::TunerService* tuner_;
|
tuner::TunerService* tuner_;
|
||||||
|
|||||||
@@ -63,10 +63,10 @@ constexpr char kTag[] = "SetupWebServer";
|
|||||||
constexpr char kFirmwareVersion[] = "0.8.5";
|
constexpr char kFirmwareVersion[] = "0.8.5";
|
||||||
constexpr unsigned kRebootDelaySec = 3;
|
constexpr unsigned kRebootDelaySec = 3;
|
||||||
|
|
||||||
extern const uint8_t www_index_html_gz_start[] asm(
|
extern const uint8_t index_html_gz_start[] asm(
|
||||||
"_binary_www_index_html_gz_start");
|
"_binary_index_html_gz_start");
|
||||||
extern const uint8_t www_index_html_gz_end[] asm(
|
extern const uint8_t index_html_gz_end[] asm(
|
||||||
"_binary_www_index_html_gz_end");
|
"_binary_index_html_gz_end");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief routeContextFrom — read handler dependencies from user_ctx.
|
* @brief routeContextFrom — read handler dependencies from user_ctx.
|
||||||
@@ -81,7 +81,7 @@ extern const uint8_t www_index_html_gz_end[] asm(
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] HttpRouteContext* routeContextFrom(httpd_req_t* req) noexcept
|
[[nodiscard]] HttpRouteContext* routeContextFrom(httpd_req_t* req) noexcept
|
||||||
{
|
{
|
||||||
return static_cast<HttpRouteContext*>(httpd_req_get_user_ctx(req));
|
return static_cast<HttpRouteContext*>(req->user_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -421,7 +421,7 @@ esp_err_t tunerSeekPostHandler(httpd_req_t* req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::array<char, 128> body{};
|
std::array<char, 128> body{};
|
||||||
readRequestBody(req, body);
|
(void)readRequestBody(req, body);
|
||||||
const auto direction = core::parseTunerSeekJson(std::string_view(body.data()));
|
const auto direction = core::parseTunerSeekJson(std::string_view(body.data()));
|
||||||
if (!direction) {
|
if (!direction) {
|
||||||
const std::string json =
|
const std::string json =
|
||||||
@@ -620,11 +620,11 @@ esp_err_t audioBassEnhancePostHandler(httpd_req_t* req)
|
|||||||
esp_err_t indexGetHandler(httpd_req_t* req)
|
esp_err_t indexGetHandler(httpd_req_t* req)
|
||||||
{
|
{
|
||||||
const size_t length =
|
const size_t length =
|
||||||
static_cast<size_t>(www_index_html_gz_end - www_index_html_gz_start);
|
static_cast<size_t>(index_html_gz_end - index_html_gz_start);
|
||||||
httpd_resp_set_type(req, "text/html");
|
httpd_resp_set_type(req, "text/html");
|
||||||
httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
|
httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
|
||||||
return httpd_resp_send(req,
|
return httpd_resp_send(req,
|
||||||
reinterpret_cast<const char*>(www_index_html_gz_start),
|
reinterpret_cast<const char*>(index_html_gz_start),
|
||||||
length);
|
length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -935,7 +935,7 @@ esp_err_t bluetoothAutoReconnectPostHandler(httpd_req_t* req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::array<char, 128> body{};
|
std::array<char, 128> body{};
|
||||||
readRequestBody(req, body);
|
(void)readRequestBody(req, body);
|
||||||
const auto times =
|
const auto times =
|
||||||
core::parseBluetoothAutoReconnectJson(std::string_view(body.data()));
|
core::parseBluetoothAutoReconnectJson(std::string_view(body.data()));
|
||||||
if (!times) {
|
if (!times) {
|
||||||
@@ -1112,7 +1112,8 @@ SetupWebServer::SetupWebServer()
|
|||||||
, stations_(nullptr)
|
, stations_(nullptr)
|
||||||
, integration_(nullptr)
|
, integration_(nullptr)
|
||||||
, routeContext_{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
, routeContext_{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||||
nullptr, {}}
|
nullptr, core::CompanionChipStatus{false, false, false},
|
||||||
|
core::DeviceIdentity::unknown()}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1163,7 +1164,8 @@ SetupWebServer& SetupWebServer::operator=(SetupWebServer&& other) noexcept
|
|||||||
other.stations_ = nullptr;
|
other.stations_ = nullptr;
|
||||||
other.integration_ = nullptr;
|
other.integration_ = nullptr;
|
||||||
other.routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr,
|
other.routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||||
nullptr, {}, core::DeviceIdentity::unknown()};
|
nullptr, nullptr, core::CompanionChipStatus{false, false, false},
|
||||||
|
core::DeviceIdentity::unknown()};
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1175,7 +1177,8 @@ SetupWebServer::~SetupWebServer()
|
|||||||
server_ = nullptr;
|
server_ = nullptr;
|
||||||
}
|
}
|
||||||
routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||||
nullptr, {}, core::DeviceIdentity::unknown()};
|
nullptr, core::CompanionChipStatus{false, false, false},
|
||||||
|
core::DeviceIdentity::unknown()};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<void, NetError> SetupWebServer::start(
|
std::expected<void, NetError> SetupWebServer::start(
|
||||||
@@ -1218,7 +1221,8 @@ std::expected<void, NetError> SetupWebServer::start(
|
|||||||
if (httpd_start(&server_, &config) != ESP_OK) {
|
if (httpd_start(&server_, &config) != ESP_OK) {
|
||||||
ESP_LOGE(kTag, "httpd_start failed");
|
ESP_LOGE(kTag, "httpd_start failed");
|
||||||
routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||||
nullptr, {}, core::DeviceIdentity::unknown()};
|
nullptr, core::CompanionChipStatus{false, false, false},
|
||||||
|
core::DeviceIdentity::unknown()};
|
||||||
return std::unexpected(NetError::HttpServerStartFailed);
|
return std::unexpected(NetError::HttpServerStartFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
// I2C scanner for Arduino IDE
|
||||||
|
// - Apri il Monitor Seriale a 115200 baud
|
||||||
|
// - Collega SDA/SCL al bus I2C del dispositivo che vuoi testare
|
||||||
|
// - Carica lo sketch e osserva gli indirizzi trovati
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("I2C Scanner - Arduino IDE");
|
||||||
|
Wire.begin();
|
||||||
|
Serial.println("Scanning for I2C devices...");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
byte error, address;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
Serial.println("\nScanning...");
|
||||||
|
|
||||||
|
for (address = 1; address < 127; address++) {
|
||||||
|
Wire.beginTransmission(address);
|
||||||
|
error = Wire.endTransmission();
|
||||||
|
|
||||||
|
if (error == 0) {
|
||||||
|
Serial.print("Found I2C device at 0x");
|
||||||
|
if (address < 16) Serial.print("0");
|
||||||
|
Serial.print(address, HEX);
|
||||||
|
Serial.println(" !");
|
||||||
|
count++;
|
||||||
|
} else if (error == 4) {
|
||||||
|
Serial.print("Unknown error at address 0x");
|
||||||
|
if (address < 16) Serial.print("0");
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 0) {
|
||||||
|
Serial.println("No I2C devices found.");
|
||||||
|
} else {
|
||||||
|
Serial.print("Done. ");
|
||||||
|
Serial.print(count);
|
||||||
|
Serial.println(" device(s) found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(5000);
|
||||||
|
}
|
||||||
@@ -2,6 +2,11 @@ idf_component_register(
|
|||||||
SRCS
|
SRCS
|
||||||
"main.cpp"
|
"main.cpp"
|
||||||
"hardware_bootstrap.cpp"
|
"hardware_bootstrap.cpp"
|
||||||
|
"$<$<BOOL:${CONFIG_TEST_FIRMWARE}>:test_firmware.cpp>"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES core net secure_store adau1701 si4684 tuner audio bt1035 bluetooth station integration ota eeprom24aa
|
REQUIRES core net secure_store adau1701 si4684 tuner audio bt1035 bluetooth station integration ota eeprom24aa
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(CONFIG_TEST_FIRMWARE)
|
||||||
|
set(EXTRA_COMPONENT_DIRS "${EXTRA_COMPONENT_DIRS}" "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ std::expected<void, HardwareBootError> HardwareBootstrap::boot()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (auto tunerResult = gSi4684.boot(si4684::Si4684Band::Dab); !tunerResult) {
|
if (auto tunerResult = gSi4684.boot(si4684::Si4684Band::Dab); !tunerResult) {
|
||||||
ESP_LOGE(kTag, "Si4684 boot failed");
|
ESP_LOGE(kTag, "Si4684 boot failed: error %d", static_cast<int>(tunerResult.error()));
|
||||||
return std::unexpected(HardwareBootError::Si4684BootFailed);
|
return std::unexpected(HardwareBootError::Si4684BootFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ std::expected<void, HardwareBootError> HardwareBootstrap::boot()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto* busHandle =
|
auto* busHandle =
|
||||||
static_cast<i2c_master_bus_handle_t>(gAdau1701.i2cBusHandle());
|
static_cast<i2c_master_bus_handle_t>(gAdau1701.i2cBusHandle());
|
||||||
eeprom24aa::Eeprom24aa eeprom(busHandle,
|
eeprom24aa::Eeprom24aa eeprom(busHandle,
|
||||||
static_cast<std::uint8_t>(
|
static_cast<std::uint8_t>(
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
## IDF Component Manager Manifest File
|
||||||
|
dependencies:
|
||||||
|
## Required IDF version
|
||||||
|
idf:
|
||||||
|
version: '>=4.1.0'
|
||||||
|
# # Put list of dependencies here
|
||||||
|
# # For components maintained by Espressif:
|
||||||
|
# component: "~1.0.0"
|
||||||
|
# # For 3rd party components:
|
||||||
|
# username/component: ">=1.0.0,<2.0.0"
|
||||||
|
# username2/component2:
|
||||||
|
# version: "~1.0.0"
|
||||||
|
# # For transient dependencies `public` flag can be set.
|
||||||
|
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||||
|
# # All dependencies of `main` are public by default.
|
||||||
|
# public: true
|
||||||
|
espressif/mdns: '*'
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "net/NetBootstrap.hpp"
|
#include "net/NetBootstrap.hpp"
|
||||||
#include "ota/OtaService.hpp"
|
#include "ota/OtaService.hpp"
|
||||||
#include "secure_store/NvsSecureStore.hpp"
|
#include "secure_store/NvsSecureStore.hpp"
|
||||||
|
#include "si4684/Si4684Tuner.hpp"
|
||||||
#include "station/StationService.hpp"
|
#include "station/StationService.hpp"
|
||||||
#include "tuner/TunerService.hpp"
|
#include "tuner/TunerService.hpp"
|
||||||
|
|
||||||
@@ -24,6 +25,10 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
#if CONFIG_TEST_FIRMWARE
|
||||||
|
#include "test_firmware.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr char kTag[] = "digiradio";
|
constexpr char kTag[] = "digiradio";
|
||||||
@@ -59,6 +64,11 @@ extern "C" void app_main()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_TEST_FIRMWARE
|
||||||
|
test_firmware::runTestFirmware();
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
static secure_store::NvsSecureStore store;
|
static secure_store::NvsSecureStore store;
|
||||||
|
|
||||||
static tuner::TunerService tunerService(
|
static tuner::TunerService tunerService(
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
/**
|
||||||
|
* @file test_firmware.cpp
|
||||||
|
* @brief Minimal firmware sequence for board, ADAU1701, Si4684 and BT1035 tests.
|
||||||
|
*
|
||||||
|
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||||
|
*
|
||||||
|
* Copyright 2026 Michele Bigi
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adau1701/Adau1701Dsp.hpp"
|
||||||
|
#include "adau1701/Adau1701Driver.hpp"
|
||||||
|
#include "adau1701/EmbeddedDspProgramSource.hpp"
|
||||||
|
#include "adau1701/FallbackDspProgramSource.hpp"
|
||||||
|
#include "adau1701/FlashDspProgramSource.hpp"
|
||||||
|
#include "board_pins.hpp"
|
||||||
|
#include "bt1035/Bt1035Driver.hpp"
|
||||||
|
#include "core/Bt1035At.hpp"
|
||||||
|
#include "core/FrequencyKHz.hpp"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "si4684/Si4684Band.hpp"
|
||||||
|
#include "si4684/Si4684Driver.hpp"
|
||||||
|
#include "si4684/Si4684EmbeddedImages.hpp"
|
||||||
|
|
||||||
|
#include "test_firmware.hpp"
|
||||||
|
|
||||||
|
namespace test_firmware {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr char kTag[] = "testfw";
|
||||||
|
|
||||||
|
void logChipInfo()
|
||||||
|
{
|
||||||
|
esp_chip_info_t info;
|
||||||
|
esp_chip_info(&info);
|
||||||
|
ESP_LOGI(kTag, "ESP32 chip: %d cores, rev %d, features=0x%x",
|
||||||
|
info.cores, info.revision, info.features);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logError(const char* stage, int code)
|
||||||
|
{
|
||||||
|
ESP_LOGE(kTag, "%s failed (err=%d)", stage, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logStage(const char* stage)
|
||||||
|
{
|
||||||
|
ESP_LOGI(kTag, "==== %s ====", stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* a2dpStateToken(core::Bt1035A2dpState state) noexcept
|
||||||
|
{
|
||||||
|
using core::Bt1035A2dpState;
|
||||||
|
switch (state) {
|
||||||
|
case Bt1035A2dpState::Unsupported:
|
||||||
|
return "unsupported";
|
||||||
|
case Bt1035A2dpState::Standby:
|
||||||
|
return "standby";
|
||||||
|
case Bt1035A2dpState::Connecting:
|
||||||
|
return "connecting";
|
||||||
|
case Bt1035A2dpState::Connected:
|
||||||
|
return "connected";
|
||||||
|
case Bt1035A2dpState::Streaming:
|
||||||
|
return "streaming";
|
||||||
|
case Bt1035A2dpState::Paused:
|
||||||
|
return "paused";
|
||||||
|
}
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void runTestFirmware()
|
||||||
|
{
|
||||||
|
logStage("Board check");
|
||||||
|
logChipInfo();
|
||||||
|
|
||||||
|
logStage("Boot ADAU1701");
|
||||||
|
adau1701::EmbeddedDspProgramSource embeddedDspProgram;
|
||||||
|
adau1701::FlashDspProgramSource flashDspProgram;
|
||||||
|
adau1701::FallbackDspProgramSource dspProgramSource(
|
||||||
|
flashDspProgram, embeddedDspProgram);
|
||||||
|
adau1701::Adau1701Driver adau(
|
||||||
|
adau1701::Adau1701Pins{
|
||||||
|
.i2cSda = board::pins::Adau1701Sda,
|
||||||
|
.i2cScl = board::pins::Adau1701Scl,
|
||||||
|
.resetGpio = board::pins::Adau1701Reset,
|
||||||
|
.i2cAddr7 = board::pins::Adau1701Addr,
|
||||||
|
},
|
||||||
|
dspProgramSource);
|
||||||
|
|
||||||
|
if (auto result = adau.boot(); !result) {
|
||||||
|
logError("ADAU1701 boot", static_cast<int>(result.error()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ESP_LOGI(kTag, "ADAU1701 boot succeeded");
|
||||||
|
|
||||||
|
logStage("Boot Si4684");
|
||||||
|
si4684::Si4684EmbeddedImages images;
|
||||||
|
si4684::Si4684Driver si4684(
|
||||||
|
si4684::Si4684Pins{
|
||||||
|
.spiHost = SPI2_HOST,
|
||||||
|
.csGpio = board::pins::Si4684Cs,
|
||||||
|
.misoGpio = board::pins::Si4684Miso,
|
||||||
|
.mosiGpio = board::pins::Si4684Mosi,
|
||||||
|
.sclkGpio = board::pins::Si4684Sclk,
|
||||||
|
.rstbGpio = board::pins::Si4684Rstb,
|
||||||
|
.intbGpio = board::pins::Si4684Intb,
|
||||||
|
},
|
||||||
|
images.romPatch(),
|
||||||
|
images.dabFirmware(),
|
||||||
|
images.fmFirmware());
|
||||||
|
|
||||||
|
if (auto result = si4684.boot(si4684::Si4684Band::Fm); !result) {
|
||||||
|
logError("Si4684 boot", static_cast<int>(result.error()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ESP_LOGI(kTag, "Si4684 FM boot succeeded");
|
||||||
|
|
||||||
|
logStage("BT1035 boot");
|
||||||
|
bt1035::Bt1035Driver bt(
|
||||||
|
bt1035::Bt1035Pins{
|
||||||
|
.uartTx = board::pins::Bt1035UartTx,
|
||||||
|
.uartRx = board::pins::Bt1035UartRx,
|
||||||
|
.rtsGpio = board::pins::Bt1035Rts,
|
||||||
|
.ctsGpio = board::pins::Bt1035Cts,
|
||||||
|
.resetGpio = board::pins::Bt1035Reset,
|
||||||
|
.sysCtlGpio = board::pins::Bt1035SysCtl,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (auto result = bt.boot(); !result) {
|
||||||
|
logError("BT1035 boot", static_cast<int>(result.error()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ESP_LOGI(kTag, "BT1035 boot succeeded");
|
||||||
|
|
||||||
|
if (auto nameResult = bt.queryDeviceName(); nameResult) {
|
||||||
|
ESP_LOGI(kTag, "BT1035 name=%s", nameResult->c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto result = bt.setDeviceName("DigiRadio-Test"); !result) {
|
||||||
|
logError("BT1035 setDeviceName", static_cast<int>(result.error()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto result = bt.enterPairingMode(); !result) {
|
||||||
|
logError("BT1035 pairing mode", static_cast<int>(result.error()));
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(kTag, "BT1035 pairing mode enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto states = bt.queryA2dpState(); states) {
|
||||||
|
ESP_LOGI(kTag, "BT1035 A2DP state=%s",
|
||||||
|
a2dpStateToken(states.value()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto listResult = bt.queryPairedList(); listResult) {
|
||||||
|
ESP_LOGI(kTag, "BT1035 paired devices=%zu", listResult->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
logStage("Radio test: tune FM");
|
||||||
|
auto frequency = core::FrequencyKHz::tryFromKhz(100700U);
|
||||||
|
if (!frequency) {
|
||||||
|
ESP_LOGE(kTag, "Invalid FM frequency");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto result = si4684.tuneFm(*frequency); !result) {
|
||||||
|
logError("Si4684 tune FM", static_cast<int>(result.error()));
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(kTag, "Si4684 tuned FM to %u kHz", frequency->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto result = si4684.setVolume(16); !result) {
|
||||||
|
logError("Si4684 setVolume", static_cast<int>(result.error()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto rsqResult = si4684.readFmRsq(); rsqResult) {
|
||||||
|
ESP_LOGI(kTag,
|
||||||
|
"FM RSQ: snr=%u, afc=%d, blend=%u, stere=%u, rssi=%d",
|
||||||
|
rsqResult->snr, rsqResult->afc, rsqResult->blend,
|
||||||
|
rsqResult->stere, rsqResult->rssi);
|
||||||
|
} else {
|
||||||
|
logError("Si4684 read FM RSQ", static_cast<int>(rsqResult.error()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(kTag, "Test firmware finished. Keep running for manual pairing and audio verification.");
|
||||||
|
while (true) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace test_firmware
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @file test_firmware.hpp
|
||||||
|
* @brief Minimal DigiRadio hardware test firmware entrypoint.
|
||||||
|
*
|
||||||
|
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||||
|
*
|
||||||
|
* Copyright 2026 Michele Bigi
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace test_firmware {
|
||||||
|
|
||||||
|
void runTestFirmware();
|
||||||
|
|
||||||
|
} // namespace test_firmware
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# DigiRadio partition table (4 MB flash — ESP32-S3-WROOM-1)
|
# DigiRadio partition table (16 MB flash — ESP32-S3-WROOM-1)
|
||||||
# ota_0 + ota_1: dual OTA app slots (equal size, 64 KiB aligned).
|
# ota_0 + ota_1: dual OTA app slots (equal size, 64 KiB aligned).
|
||||||
# dsp: updatable ADAU1701 program blob (task 3.1).
|
# dsp: updatable ADAU1701 program blob (task 3.1).
|
||||||
# nvs_keys: NVS encryption keys (secure-store slice).
|
# nvs_keys: NVS encryption keys (secure-store slice).
|
||||||
@@ -8,6 +8,6 @@ nvs, data, nvs, 0x9000, 0x6000,
|
|||||||
otadata, data, ota, 0xf000, 0x2000,
|
otadata, data, ota, 0xf000, 0x2000,
|
||||||
nvs_keys, data, nvs_keys, 0x11000, 0x1000,
|
nvs_keys, data, nvs_keys, 0x11000, 0x1000,
|
||||||
phy_init, data, phy, 0x12000, 0x1000,
|
phy_init, data, phy, 0x12000, 0x1000,
|
||||||
ota_0, app, ota_0, 0x20000, 0x1B0000,
|
ota_0, app, ota_0, 0x20000, 0x400000,
|
||||||
ota_1, app, ota_1, 0x1D0000, 0x1B0000,
|
ota_1, app, ota_1, 0x420000, 0x400000,
|
||||||
dsp, data, 0x40, 0x380000, 0x40000,
|
dsp, data, 0x40, 0x820000, 0x40000,
|
||||||
|
|||||||
|
@@ -12,11 +12,11 @@ CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
|||||||
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
||||||
|
|
||||||
# Flash encryption — DEVELOPMENT mode (re-flash plaintext until eFuse policy set)
|
# Flash encryption — DEVELOPMENT mode (re-flash plaintext until eFuse policy set)
|
||||||
CONFIG_SECURE_FLASH_ENC_ENABLED=y
|
# CONFIG_SECURE_FLASH_ENC_ENABLED=y
|
||||||
CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT=y
|
# CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT=y
|
||||||
|
|
||||||
# NVS encryption at rest (XTS-AES; keys in nvs_keys, protected by flash encryption)
|
# NVS encryption at rest (XTS-AES; keys in nvs_keys, protected by flash encryption)
|
||||||
CONFIG_NVS_ENCRYPTION=y
|
# CONFIG_NVS_ENCRYPTION=y
|
||||||
|
|
||||||
# C++23, exceptions and RTTI off (AGENTS.md §2)
|
# C++23, exceptions and RTTI off (AGENTS.md §2)
|
||||||
CONFIG_COMPILER_CXX_EXCEPTIONS=n
|
CONFIG_COMPILER_CXX_EXCEPTIONS=n
|
||||||
@@ -25,3 +25,5 @@ CONFIG_COMPILER_CXX_STD=23
|
|||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
|
||||||
|
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
|
||||||
|
|||||||
Reference in New Issue
Block a user