diff --git a/Makefile b/Makefile index abbbe32..a5e5a36 100644 --- a/Makefile +++ b/Makefile @@ -421,46 +421,46 @@ stlink-bl-old: $(ST_FLASH) write bin/$(BINBIN_F1BL) 0x8002000 serial: - $(STM32FLASH) -v -w bin/$(BINBIN_F1) -g 0x0 $(devser) + $(STM32FLASH) -b 115200 -v -w bin/$(BINBIN_F1) -g 0x0 $(devser) serial-nobl: - $(STM32FLASH) -v -w bin/$(BINBIN_F1NOBL) -g 0x0 $(devser) + $(STM32FLASH) -b 115200 -v -w bin/$(BINBIN_F1NOBL) -g 0x0 $(devser) serial-bl: - $(STM32FLASH) -v -w $(F1_LIB_PATH)/utils/bootloader/generic_boot20_pc13_long_rst.bin -g 0x0 $(devser) + $(STM32FLASH) -b 115200 -v -w $(F1_LIB_PATH)/utils/bootloader/generic_boot20_pc13_long_rst.bin -g 0x0 $(devser) sleep 3 - $(STM32FLASH) -v -w bin/$(BINBIN_F1BL) -g 0x0 -S 0x08002000 $(devser) + $(STM32FLASH) -b 115200 -v -w bin/$(BINBIN_F1BL) -g 0x0 -S 0x08002000 $(devser) serial-bl-old: - $(STM32FLASH) -v -w $(F1_LIB_PATH)/utils/bootloader/generic_boot20_pc13.bin -g 0x0 $(devser) + $(STM32FLASH) -b 115200 -v -w $(F1_LIB_PATH)/utils/bootloader/generic_boot20_pc13.bin -g 0x0 $(devser) sleep 3 - $(STM32FLASH) -v -w bin/$(BINBIN_F1BL) -g 0x0 -S 0x08002000 $(devser) + $(STM32FLASH) -b 115200 -v -w bin/$(BINBIN_F1BL) -g 0x0 -S 0x08002000 $(devser) nano-hotspot: ifneq ($(wildcard /usr/local/bin/stm32flash),) - /usr/local/bin/stm32flash -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 200,-3,3:-200,3 /dev/ttyAMA0 + /usr/local/bin/stm32flash -b 115200 -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 200,-3,3:-200,3 /dev/ttyAMA0 endif ifneq ($(wildcard /usr/bin/stm32flash),) - /usr/bin/stm32flash -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 200,-3,3:-200,3 /dev/ttyAMA0 + /usr/bin/stm32flash -b 115200 -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 200,-3,3:-200,3 /dev/ttyAMA0 endif nano-dv: ifneq ($(wildcard /usr/local/bin/stm32flash),) - /usr/local/bin/stm32flash -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 66,-67,67:-66,67 /dev/ttyAMA0 + /usr/local/bin/stm32flash -b 115200 -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 66,-67,67:-66,67 /dev/ttyAMA0 endif ifneq ($(wildcard /usr/bin/stm32flash),) - /usr/bin/stm32flash -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 66,-67,67:-66,67 /dev/ttyAMA0 + /usr/bin/stm32flash -b 115200 -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 66,-67,67:-66,67 /dev/ttyAMA0 endif zumspot-pi: ifneq ($(wildcard /usr/local/bin/stm32flash),) - /usr/local/bin/stm32flash -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 20,-21,21:-20,21 /dev/ttyAMA0 + /usr/local/bin/stm32flash -b 115200 -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 20,-21,21:-20,21 /dev/ttyAMA0 endif ifneq ($(wildcard /usr/bin/stm32flash),) - /usr/bin/stm32flash -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 20,-21,21:-20,21 /dev/ttyAMA0 + /usr/bin/stm32flash -b 115200 -v -w bin/$(BINBIN_F1) -g 0x0 -R -i 20,-21,21:-20,21 /dev/ttyAMA0 endif mmdvm_hs_hat: zumspot-pi diff --git a/README.md b/README.md index 5ef7188..45d6bfe 100644 --- a/README.md +++ b/README.md @@ -262,11 +262,12 @@ Install the necessary software tools: sudo apt-get update sudo apt-get install gcc-arm-none-eabi gdb-arm-none-eabi libstdc++-arm-none-eabi-newlib libnewlib-arm-none-eabi - cd ~ - git clone https://git.code.sf.net/p/stm32flash/code stm32flash - cd stm32flash - make - sudo make install +Note: The Pi-Star image contains an executable for stm32flash. The next five steps can be skipped! +# cd ~ +# git clone https://git.code.sf.net/p/stm32flash/code stm32flash +# cd stm32flash +# make +# sudo make install Download the firmware sources: diff --git a/SerialPort.cpp b/SerialPort.cpp index 9fb20a3..0e8c8e3 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -82,6 +82,9 @@ CSerialPort::CSerialPort() : m_buffer(), m_ptr(0U), m_len(0U), +m_serial_buffer(), +m_serial_ptr(0U), +m_serial_len(0U), m_debug(false), m_firstCal(false) { @@ -136,7 +139,7 @@ void CSerialPort::getStatus() reply[3U] |= 0x10U; if (m_pocsagEnable) reply[3U] |= 0x20U; - + reply[4U] = uint8_t(m_modemState); reply[5U] = m_tx ? 0x01U : 0x00U; @@ -253,7 +256,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) uint8_t colorCode = data[6U]; if (colorCode > 15U) return 4U; - + #if defined(DUPLEX) uint8_t dmrDelay = data[7U]; #endif @@ -317,7 +320,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) nxdnTX.setTXDelay(txDelay); pocsagTX.setTXDelay(txDelay); dmrDMOTX.setTXDelay(txDelay); - + #if defined(DUPLEX) dmrTX.setColorCode(colorCode); dmrRX.setColorCode(colorCode); @@ -536,7 +539,7 @@ void CSerialPort::start() beginInt(1U, 115200); #if defined(SERIAL_REPEATER) || defined(SERIAL_REPEATER_USART1) - beginInt(3U, 9600); + beginInt(3U, SERIAL_REPEATER_BAUD); #endif } @@ -859,12 +862,62 @@ void CSerialPort::process() } #if defined(SERIAL_REPEATER) || defined(SERIAL_REPEATER_USART1) - // Drain any incoming serial data + // Check for any incoming serial data from a device/screen on UART2 + // !!Notice!! on powerup the Nextion screen dumps FF FF FF 88 FF FF FF to the serial port. while (availableInt(3U)) - readInt(3U); + { + uint8_t ch = readInt(3U); + // read UART2 + + m_serial_buffer[m_serial_ptr] = ch; + m_serial_ptr++; + // fill the buffer one char at a time + + if (m_serial_len > 128) + m_serial_len = 0U; + // if length is > 128 reset it + else + m_serial_len++; + // increase length + } + + if ((m_serial_buffer[m_serial_len - 3] == 0xFF) && (m_serial_buffer[m_serial_len - 2] == 0xFF) && (m_serial_buffer[m_serial_len - 1] == 0xFF)) + { + serial.writeSerialRpt(m_serial_buffer, m_serial_len); + // if the last 3 bytes are FF's then the screen is done sending data so send the m_serial_buffer to serial.writeSerialRpt() + + m_serial_ptr = 0U; + m_serial_len = 0U; + // set ptr and reset length of buffer data since last message was valid and get ready for new data + + } + #endif } +#if defined(SERIAL_REPEATER) || defined(SERIAL_REPEATER_USART1) +void CSerialPort::writeSerialRpt(const uint8_t* data, uint8_t length) +{ + if (m_modemState != STATE_IDLE) + return; + + uint8_t reply[131U]; + + reply[0U] = MMDVM_FRAME_START; + reply[1U] = 0U; + reply[2U] = MMDVM_SERIAL; + + uint8_t count = 3U; + for (uint8_t i = 0U; i < length; i++, count++) + reply[count] = data[i]; + + reply[1U] = count; + + writeInt(1U, reply, count); +} +#endif + + void CSerialPort::writeDStarHeader(const uint8_t* header, uint8_t length) { if (m_modemState != STATE_DSTAR && m_modemState != STATE_IDLE) @@ -1187,7 +1240,7 @@ void CSerialPort::writeDebugI(const char* text, int32_t n1) for (uint8_t i = 0U; text[i] != '\0'; i++, count++) reply[count] = text[i]; - reply[count++] = ' '; + reply[count++] = ' '; i2str(&reply[count], 130U - count, n1); diff --git a/SerialPort.h b/SerialPort.h index b1fa6b7..ffb4553 100644 --- a/SerialPort.h +++ b/SerialPort.h @@ -30,6 +30,10 @@ public: void process(); +#if defined(SERIAL_REPEATER) || defined(SERIAL_REPEATER_USART1) + void writeSerialRpt(const uint8_t* data, uint8_t length); +#endif + void writeDStarHeader(const uint8_t* header, uint8_t length); void writeDStarData(const uint8_t* data, uint8_t length); void writeDStarLost(); @@ -65,6 +69,10 @@ private: uint8_t m_buffer[256U]; uint8_t m_ptr; uint8_t m_len; + uint8_t m_serial_buffer[128U]; + uint8_t m_serial_ptr; + uint8_t m_serial_len; + bool m_debug; bool m_firstCal; diff --git a/configs/MMDVM_HS_Dual_Hat-12mhz.h b/configs/MMDVM_HS_Dual_Hat-12mhz.h index 0da2989..0c9eb94 100644 --- a/configs/MMDVM_HS_Dual_Hat-12mhz.h +++ b/configs/MMDVM_HS_Dual_Hat-12mhz.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/MMDVM_HS_Dual_Hat.h b/configs/MMDVM_HS_Dual_Hat.h index c968edd..9962883 100644 --- a/configs/MMDVM_HS_Dual_Hat.h +++ b/configs/MMDVM_HS_Dual_Hat.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/MMDVM_HS_Hat-12mhz.h b/configs/MMDVM_HS_Hat-12mhz.h index 45433fd..4c47dfb 100644 --- a/configs/MMDVM_HS_Hat-12mhz.h +++ b/configs/MMDVM_HS_Hat-12mhz.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/MMDVM_HS_Hat.h b/configs/MMDVM_HS_Hat.h index c9f1a9d..f0234a0 100644 --- a/configs/MMDVM_HS_Hat.h +++ b/configs/MMDVM_HS_Hat.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/NanoDV_NPI.h b/configs/NanoDV_NPI.h index f2aea7d..24560ff 100644 --- a/configs/NanoDV_NPI.h +++ b/configs/NanoDV_NPI.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/NanoDV_USB.h b/configs/NanoDV_USB.h index ba74b85..a9f99b3 100644 --- a/configs/NanoDV_USB.h +++ b/configs/NanoDV_USB.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/Nano_hotSPOT.h b/configs/Nano_hotSPOT.h index cbe6d3d..dec34f5 100644 --- a/configs/Nano_hotSPOT.h +++ b/configs/Nano_hotSPOT.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/ZUMspot_Libre.h b/configs/ZUMspot_Libre.h index b2d0678..9dfa893 100644 --- a/configs/ZUMspot_Libre.h +++ b/configs/ZUMspot_Libre.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/ZUMspot_RPi.h b/configs/ZUMspot_RPi.h index 4f5a0f6..aa52621 100644 --- a/configs/ZUMspot_RPi.h +++ b/configs/ZUMspot_RPi.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/ZUMspot_duplex.h b/configs/ZUMspot_duplex.h index 4f5f9f6..73ba1e1 100644 --- a/configs/ZUMspot_duplex.h +++ b/configs/ZUMspot_duplex.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/generic_duplex_gpio.h b/configs/generic_duplex_gpio.h index cea9e4c..70743ba 100644 --- a/configs/generic_duplex_gpio.h +++ b/configs/generic_duplex_gpio.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1 diff --git a/configs/generic_gpio.h b/configs/generic_gpio.h index 6173f82..a83895f 100644 --- a/configs/generic_gpio.h +++ b/configs/generic_gpio.h @@ -71,6 +71,7 @@ // Enable Nextion LCD serial port repeater on USART2 (ZUMspot Libre Kit and ZUMspot RPi): #define SERIAL_REPEATER +#define SERIAL_REPEATER_BAUD 115200 // Enable Nextion LCD serial port repeater on USART1 (Do not use with STM32_USART1_HOST enabled): // #define SERIAL_REPEATER_USART1