From 4607fef9d2f7cf65ae831c8eeee61c9d98287d26 Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Mon, 21 Sep 2020 01:42:12 +0100 Subject: [PATCH] Switch USB serial communication to explicit UART, attermpt use to FAT on internal flash --- main/ctrl.cpp | 4 ++-- main/hal.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- main/hal.h | 5 +++-- main/main.cpp | 1 + partitions.csv | 3 ++- sdkconfig | 4 ++-- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/main/ctrl.cpp b/main/ctrl.cpp index 3303dae..6cbdbc7 100644 --- a/main/ctrl.cpp +++ b/main/ctrl.cpp @@ -411,14 +411,14 @@ void vTaskCTRL(void* pvParameters) #endif int32_t PressRelease=Button_TimerCheck(); // 0 = no change -// #ifdef DEBUG_PRINT +#ifdef DEBUG_PRINT if(PressRelease!=0) { xSemaphoreTake(CONS_Mutex, portMAX_DELAY); Format_String(CONS_UART_Write, "Button: "); Format_SignDec(CONS_UART_Write, PressRelease); Format_String(CONS_UART_Write, "ms\n"); xSemaphoreGive(CONS_Mutex); } -// #endif +#endif if(PressRelease>0) { if(PressRelease<=700) // short button push: switch pages { KeyBuffer.Write(0x01); } diff --git a/main/hal.cpp b/main/hal.cpp index bb65423..265edc1 100644 --- a/main/hal.cpp +++ b/main/hal.cpp @@ -6,6 +6,7 @@ #include "driver/gpio.h" #include "driver/uart.h" +#include "esp_vfs_dev.h" #include "driver/spi_master.h" #include "driver/i2c.h" @@ -23,6 +24,7 @@ #include "nvs_flash.h" #ifdef WITH_SPIFFS +// #include "esp_vfs_fat.h" #include "esp_spiffs.h" #endif @@ -787,6 +789,22 @@ int BT_SPP_Init(void) SemaphoreHandle_t CONS_Mutex; +void CONS_UART_Init(void) +{ setvbuf(stdin, NULL, _IONBF, 0); // Disable buffering on stdin + esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + const uart_config_t UARTconfig = + { .baud_rate = DEFAULT_CONbaud, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .use_ref_tick = true + }; + uart_param_config(CONS_UART, &UARTconfig); + uart_driver_install(CONS_UART, 1024, 0, 0, NULL, 0); + esp_vfs_dev_uart_use_driver(CONS_UART); +} + /* bool CONS_InpReady(void) { struct timeval tv = { tv_sec:0, tv_usec:0} ; @@ -798,8 +816,10 @@ bool CONS_InpReady(void) */ // int CONS_UART_Read (uint8_t &Byte) { return uart_read_bytes (CONS_UART, &Byte, 1, 0); } // non-blocking // void CONS_UART_Write (char Byte) { uart_write_bytes (CONS_UART, &Byte, 1); } // blocking ? + void CONS_UART_Write (char Byte) -{ putchar(Byte); +{ uart_write_bytes (CONS_UART, &Byte, 1); + // putchar(Byte); #ifdef WITH_BT_SPP BT_SPP_Write(Byte); #endif @@ -807,8 +827,10 @@ void CONS_UART_Write (char Byte) Stratux_Write(Byte); #endif } // it appears the NL is translated into CR+NL + int CONS_UART_Read (uint8_t &Byte) -{ int Ret=getchar(); if(Ret>=0) { Byte=Ret; return 1; } +{ int Ret=uart_read_bytes (CONS_UART, &Byte, 1, 0); if(Ret==1) return 1; + // int Ret=getchar(); if(Ret>=0) { Byte=Ret; return 1; } #ifdef WITH_BT_SPP Ret=BT_SPP_Read(Byte); if(Ret>0) { return 1; } #endif @@ -820,7 +842,7 @@ int CONS_UART_Read (uint8_t &Byte) // int CONS_UART_Free (void) { return UART2_Free(); } // int CONS_UART_Full (void) { return UART2_Full(); } -void CONS_UART_SetBaudrate(int BaudRate) { uart_set_baudrate(CONS_UART, BaudRate); } +void CONS_UART_SetBaudrate(int BaudRate) { uart_set_baudrate(CONS_UART, BaudRate); } //-------------------------------------------------------------------------------------------------------- // ADS-B UART @@ -1932,6 +1954,20 @@ int NVS_Init(void) // ====================================================================================================== #ifdef WITH_SPIFFS +/* +// this part is for the FAT filesystem in the internal flash +int SPIFFS_Register(const char *Path, const char *Label, size_t MaxOpenFiles) +{ esp_vfs_fat_mount_config_t FSconf; + FSconf.max_files = MaxOpenFiles; + FSconf.format_if_mount_failed = true; + FSconf.allocation_unit_size = 4096; + static wl_handle_t Handle = WL_INVALID_HANDLE; + return esp_vfs_fat_spiflash_mount(Path, Label, &FSconf, &Handle); } + +int SPIFFS_Info(size_t &Total, size_t &Used, const char *Label) +{ Total=0; Used=0; return 0; } +*/ + int SPIFFS_Register(const char *Path, const char *Label, size_t MaxOpenFiles) { esp_vfs_spiffs_conf_t FSconf = { base_path: Path, @@ -1942,6 +1978,7 @@ int SPIFFS_Register(const char *Path, const char *Label, size_t MaxOpenFiles) int SPIFFS_Info(size_t &Total, size_t &Used, const char *Label) { return esp_spiffs_info(Label, &Total, &Used); } + #endif // ====================================================================================================== diff --git a/main/hal.h b/main/hal.h index 1f6c1e9..3593183 100644 --- a/main/hal.h +++ b/main/hal.h @@ -56,6 +56,7 @@ uint32_t getUniqueAddress(void); // get unique 24-bit address for the #include "parameters.h" extern FlashParameters Parameters; +void CONS_UART_Init (void); int CONS_UART_Read (uint8_t &Byte); // non-blocking void CONS_UART_Write (char Byte); // blocking int CONS_UART_Free (void); // how many bytes can be written to the transmit buffer @@ -172,8 +173,8 @@ bool BT_SPP_isConnected(void); #endif #ifdef WITH_SPIFFS -int SPIFFS_Register(const char *Path="/spiffs", const char *Label=0, size_t MaxOpenFiles=5); -int SPIFFS_Info(size_t &Total, size_t &Used, const char *Label=0); +int SPIFFS_Register(const char *Path="/spiffs", const char *Label="intlog", size_t MaxOpenFiles=5); +int SPIFFS_Info(size_t &Total, size_t &Used, const char *Label="intlog"); #endif uint8_t I2C_Read (uint8_t Bus, uint8_t Addr, uint8_t Reg, uint8_t *Data, uint8_t Len, uint8_t Wait=10); diff --git a/main/main.cpp b/main/main.cpp index dcacee6..fc22c1d 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -37,6 +37,7 @@ void app_main(void) { // printf("OGN Tracker on ESP32\n"); + CONS_UART_Init(); CONS_Mutex = xSemaphoreCreateMutex(); // semaphore for sharing the writing to the console I2C_Mutex = xSemaphoreCreateMutex(); // semaphore for sharing the I2C bus diff --git a/partitions.csv b/partitions.csv index 2427255..51a59ef 100644 --- a/partitions.csv +++ b/partitions.csv @@ -3,4 +3,5 @@ nvs,data,nvs,0x9000,24K, phy_init,data,phy,0xf000,4K, factory,app,factory,0x10000,1800K, -files,data,spiffs,,0x1F0000, +intlog,data,spiffs,,0x1F0000, +# intlog,data,fat,,0x1F0000, diff --git a/sdkconfig b/sdkconfig index cb7b2e8..2d6ce9e 100644 --- a/sdkconfig +++ b/sdkconfig @@ -704,14 +704,14 @@ CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y # CONFIG_SPI_FLASH_USE_LEGACY_IMPL is not set CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y -CONFIG_SPIFFS_MAX_PARTITIONS=3 +CONFIG_SPIFFS_MAX_PARTITIONS=2 CONFIG_SPIFFS_CACHE=y CONFIG_SPIFFS_CACHE_WR=y # CONFIG_SPIFFS_CACHE_STATS is not set CONFIG_SPIFFS_PAGE_CHECK=y CONFIG_SPIFFS_GC_MAX_RUNS=10 # CONFIG_SPIFFS_GC_STATS is not set -CONFIG_SPIFFS_PAGE_SIZE=256 +CONFIG_SPIFFS_PAGE_SIZE=1024 CONFIG_SPIFFS_OBJ_NAME_LEN=32 CONFIG_SPIFFS_USE_MAGIC=y CONFIG_SPIFFS_USE_MAGIC_LENGTH=y