From 96783826d8e5d68487d0b276072b6b36cfe57ab3 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 10 Nov 2018 18:32:16 +0100 Subject: [PATCH 1/4] rcommand.cpp: delay before restart --- platformio.ini | 4 ++-- src/rcommand.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 026c56f2..4583e8d3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.6.62 +release_version = 1.6.63 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose debug_level = 0 @@ -46,7 +46,7 @@ lib_deps_all = lib_deps_lora = ; MCCI LoRaWAN LMIC library@^2.2.2 lib_deps_display = - U8g2@>=2.23.16 + U8g2@>=2.25.0 lib_deps_rgbled = SmartLeds@>=1.1.3 lib_deps_gps = diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 37460d86..ffba3ff0 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -8,7 +8,10 @@ static const char TAG[] = "main"; // helper function void do_reset() { ESP_LOGI(TAG, "Remote command: restart device"); + if (irqHandlerTask != NULL) + vTaskDelete(irqHandlerTask); LMIC_shutdown(); + vTaskDelay(3000 / portTICK_PERIOD_MS); esp_restart(); } From 18b44f220830085df83511e0f84f992a657427f0 Mon Sep 17 00:00:00 2001 From: Christian Ambach Date: Mon, 12 Nov 2018 11:15:44 +0100 Subject: [PATCH 2/4] spi_slave: fix calculation of buffer size the previous calculation added 4 additional bytes to the buffers when the length was already dividable by 4. Signed-off-by: Christian Ambach --- src/spislave.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/spislave.cpp b/src/spislave.cpp index 6df563b1..bbcb677d 100644 --- a/src/spislave.cpp +++ b/src/spislave.cpp @@ -35,7 +35,9 @@ static const char TAG[] = __FILE__; // https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html #define BUFFER_SIZE \ (MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) + \ - (4 - MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) % 4)) + (PAYLOAD_BUFFER_SIZE % 4 == 0 \ + ? 0 \ + : 4 - MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) % 4)) DMA_ATTR uint8_t txbuf[BUFFER_SIZE]; DMA_ATTR uint8_t rxbuf[BUFFER_SIZE]; @@ -70,7 +72,11 @@ void spi_slave_task(void *param) { // set length for spi slave driver transaction_size = HEADER_SIZE + msg.MessageSize; - transaction_size += (4 - transaction_size % 4); + // SPI transaction size needs to be at least 8 bytes and dividable by 4, see + // https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html + if (transaction_size % 4 != 0) { + transaction_size += (4 - transaction_size % 4); + } // prepare spi transaction spi_slave_transaction_t spi_transaction = {0}; From 3cd43710e676e6fd00b8755fc235fa47385995d4 Mon Sep 17 00:00:00 2001 From: Christian Ambach Date: Mon, 12 Nov 2018 11:16:42 +0100 Subject: [PATCH 3/4] spi_slave: re-enable checksum for payload Signed-off-by: Christian Ambach --- src/spislave.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spislave.cpp b/src/spislave.cpp index bbcb677d..53ac8479 100644 --- a/src/spislave.cpp +++ b/src/spislave.cpp @@ -66,9 +66,9 @@ void spi_slave_task(void *param) { uint8_t *messageSize = txbuf + 3; *messageSize = msg.MessageSize; memcpy(txbuf + HEADER_SIZE, &msg.Message, msg.MessageSize); - // calculate crc16 checksum, not used yet - // uint16_t *crc = (uint16_t *)txbuf; - //*crc = crc16_be(0, messageType, msg.MessageSize + HEADER_SIZE - 2); + // calculate crc16 checksum + uint16_t *crc = (uint16_t *)txbuf; + *crc = crc16_be(0, messageType, msg.MessageSize + HEADER_SIZE - 2); // set length for spi slave driver transaction_size = HEADER_SIZE + msg.MessageSize; From 97c71428a676784f7aec4ca090d9096c7c562a50 Mon Sep 17 00:00:00 2001 From: Christian Ambach Date: Mon, 12 Nov 2018 11:17:10 +0100 Subject: [PATCH 4/4] spi_slave: run code formatter Signed-off-by: Christian Ambach --- src/spislave.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/spislave.cpp b/src/spislave.cpp index 53ac8479..b4f93c4d 100644 --- a/src/spislave.cpp +++ b/src/spislave.cpp @@ -155,7 +155,8 @@ void spi_enqueuedata(uint8_t messageType, MessageBuffer_t *message) { BaseType_t ret = xQueueSendToBack(SPISendQueue, (void *)message, (TickType_t)0); if (ret == pdTRUE) { - ESP_LOGI(TAG, "%d byte(s) enqueued for SPI interface", message->MessageSize); + ESP_LOGI(TAG, "%d byte(s) enqueued for SPI interface", + message->MessageSize); } else { ESP_LOGW(TAG, "SPI sendqueue is full"); }