Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Files at this revision

API Documentation at this revision

Comitter:
mbriggs_vortex
Date:
Sat Nov 18 18:01:43 2017 -0700
Parent:
90:32f9d043561a
Child:
92:1f86edb14cbe
Commit message:
Added new 1.01 bootloader, removed unimplemented prints, removed secrets from being printed (using MACRO in dot_util.h)

Changed in this revision

bootloader/xDotBootloader.bin Show annotated file Show diff for this revision Revisions of this file
bootloader/xDotBootloader_v1_01_20171118.bin Show annotated file Show diff for this revision Revisions of this file
xDotBridge/inc/SerialTermMgr.h Show annotated file Show diff for this revision Revisions of this file
xDotBridge/inc/bootloader.h Show diff for this revision Revisions of this file
xDotBridge/inc/dot_util.h Show annotated file Show diff for this revision Revisions of this file
xDotBridge/inc/xdot_flash.h Show diff for this revision Revisions of this file
xDotBridge/src/CommProtocolPeerBrute.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/SerialTermMgr.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/dot_util.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/main.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/xdot_flash.cpp Show diff for this revision Revisions of this file
Binary file bootloader/xDotBootloader.bin has changed
Binary file bootloader/xDotBootloader_v1_01_20171118.bin has changed
--- a/xDotBridge/inc/SerialTermMgr.h	Sat Nov 18 22:58:20 2017 +0000
+++ b/xDotBridge/inc/SerialTermMgr.h	Sat Nov 18 18:01:43 2017 -0700
@@ -20,7 +20,8 @@
 const unsigned char MAX_TIMEOUTS = 6; // multiple by TIMEOUT above.  60 total seconds
 const uint16_t FLASH_BIN_OFFSET = 256; // Skip first flash page
 const uint16_t XMODEM_PACKET_SIZE = 128;
-//const char NEW_CODE [] = "NEWCODE0";
+const char NEW_CODE [] = "NEWCODE0";
+const char END0LINE [] = "END0LINE";
 
 enum ScreenId {
     mainScreenId,
--- a/xDotBridge/inc/bootloader.h	Sat Nov 18 22:58:20 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,189 +0,0 @@
-/*
- * bootloader.h
- *
- *  Created on: Nov 12, 2017
- *      Author: mbriggs
- */
-
-#ifndef XDOTBRIDGE_INC_BOOTLOADER_H_
-#define XDOTBRIDGE_INC_BOOTLOADER_H_
-
-const char NEW_CODE [] = "NEWCODE0";
-const char END0LINE [] = "END0LINE";
-#define XDOT_FLASH_START       0x08000000
-#define XDOT_FLASH_SIZE        0x00040000
-#define XDOT_SECTOR_SIZE	   4096
-#define BOOTLOADER_OFFSET 	   81920 // 80 KB
-//#define APPLICATION_ADDRESS    XDOT_FLASH_START
-#define APPLICATION_ADDRESS    XDOT_FLASH_START+BOOTLOADER_OFFSET
-#define PAGE_SIZE			   256
-
-//FLASH_ProcessTypeDef pFlash;
-__attribute__( ( section(".data") ) )
-void writeBootLoaderReprogramDone(WinbondSPIFlash *flash)
-{
-	// This should always be less than 256 bytes
-	const uint32_t zero = 0;
-	const unsigned int ctrlSize = sizeof(END0LINE)+sizeof(uint32_t);
-	char buf[ctrlSize];
-	std::memcpy(buf, END0LINE, sizeof(END0LINE));
-	std::memcpy(buf+sizeof(END0LINE), &zero, sizeof(zero));
-	// TODO add reprogram counter just for fun
-
-	// Copy to first page of flash
-    flash->writeStream(0, buf, sizeof(buf));
-}
-
-__attribute__( ( section(".data") ) )
-uint32_t readBootLoaderCtrlPage(WinbondSPIFlash *flash)
-{
-	const unsigned int ctrlSize = sizeof(NEW_CODE)+sizeof(uint32_t);
-	char buf[ctrlSize];
-    flash->readStream(0, buf, sizeof(buf));
-	uint32_t nBytes = 0;
-	char ctrlCode[sizeof(NEW_CODE)];
-	// This should always be less than 256 bytes
-	std::memcpy(&ctrlCode, buf, sizeof(NEW_CODE));
-	std::memcpy(&nBytes, buf+sizeof(NEW_CODE), sizeof(nBytes));
-	// TODO add reprogram counter just for fun
-
-	// Check NEW_CODE str
-	for (unsigned int i=0;i<sizeof(NEW_CODE);i++) {
-		if (ctrlCode[i] != NEW_CODE[i]) {
-			return 0;
-		}
-	}
-
-	// Copy to first page of flash
-    return nBytes;
-}
-
-//__attribute__( ( section(".data")) )
-//HAL_StatusTypeDef RAM_HAL_FLASH_Unlock(void)
-//{
-//  if (HAL_IS_BIT_SET(FLASH->PECR, FLASH_PECR_PRGLOCK))
-//  {
-//    /* Unlocking FLASH_PECR register access*/
-//    if(HAL_IS_BIT_SET(FLASH->PECR, FLASH_PECR_PELOCK))
-//    {
-//      WRITE_REG(FLASH->PEKEYR, FLASH_PEKEY1);
-//      WRITE_REG(FLASH->PEKEYR, FLASH_PEKEY2);
-//    }
-//
-//    /* Unlocking the program memory access */
-//    WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY1);
-//    WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY2);
-//  }
-//  else
-//  {
-//    return HAL_ERROR;
-//  }
-//
-//  return HAL_OK;
-//}
-//
-//__attribute__( ( section(".data")) )
-//HAL_StatusTypeDef RAM_HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
-//{
-//  HAL_StatusTypeDef status = HAL_ERROR;
-//
-//  /* Process Locked */
-//  __HAL_LOCK(&pFlash);
-//
-//  /* Check the parameters */
-//  assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
-//  assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
-//
-//  /* Wait for last operation to be completed */
-//  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
-//
-//  if(status == HAL_OK)
-//  {
-//    /* Clean the error context */
-//    pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
-//
-//    /*Program word (32-bit) at a specified address.*/
-//    *(__IO uint32_t *)Address = Data;
-//
-//    /* Wait for last operation to be completed */
-//    status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
-//  }
-//
-//  /* Process Unlocked */
-//  __HAL_UNLOCK(&pFlash);
-//
-//  return status;
-//}
-//
-//__attribute__( ( section(".data")) )
-//HAL_StatusTypeDef RAM_HAL_FLASH_Lock(void)
-//{
-//  /* Set the PRGLOCK Bit to lock the FLASH Registers access */
-//  SET_BIT(FLASH->PECR, FLASH_PECR_PRGLOCK);
-//
-//
-//  return HAL_OK;
-//}
-
-__attribute__( ( section(".data") ) )
-void copyNewProgram ()
-{
-	uint32_t nBytes, updateBytes;
-    WinbondSPIFlash *flash = new WinbondSPIFlash(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_NSS);
-    char *charbuf = new char [PAGE_SIZE];
-	HAL_FLASH_Unlock();
-
-    flash->releaseFromPowerDown();
-
-	nBytes = readBootLoaderCtrlPage(flash);
-
-	if (nBytes > 0) {
-//		printf("flash read address %lu\r\n", readBootLoaderCtrlPage);
-//		printf("Updating main application %lu bytes...\r\n", nBytes);
-
-		uint32_t nBytesCopied=0;
-		unsigned int pageIdx=0;
-		while (nBytesCopied < nBytes){
-//	    	printf("Start read %d.\r\n", us_ticker_read());
-			flash->readStream(pageIdx*PAGE_SIZE, charbuf, PAGE_SIZE);
-
-//	    	printf("Stop read, start erase %d.\r\n", us_ticker_read());
-			// Erase page
-			// Erasing may not be required but it seems like good practice
-			FLASH_EraseInitTypeDef eraseStruct;
-			eraseStruct.TypeErase = FLASH_TYPEERASE_PAGES;
-			eraseStruct.NbPages = 1;
-			eraseStruct.PageAddress = APPLICATION_ADDRESS+nBytesCopied;
-		//	eraseStruct.PageAddress = 0x0801E000; // Sector 30, Page 478
-
-			uint32_t eraseError;
-			if (HAL_FLASHEx_Erase(&eraseStruct, &eraseError) != HAL_OK) {
-//				printf("Error erasing flash. \r\n");
-			}
-
-//	    	printf("Stop erase, start write %d.\r\n", us_ticker_read());
-			// Write page
-			for (unsigned int i=0;i<(PAGE_SIZE/sizeof(uint32_t));i++) {
-				if (HAL_FLASH_Program(TYPEPROGRAM_WORD, APPLICATION_ADDRESS+nBytesCopied,
-						*((uint32_t *)(charbuf+sizeof(uint32_t)*i))) != HAL_OK) {
-//					printf("Error programming flash. \r\n");
-				}
-				nBytesCopied += sizeof(uint32_t);
-			}
-//	    	printf("Stop write %d.\r\n", us_ticker_read());
-			pageIdx++;
-			printf("%lu / %lu\r\n", nBytesCopied, nBytes);
-		}
-		HAL_FLASH_Lock();
-	}
-
-	// FIXME add some prints and checking code
-
-    flash->powerDown();
-    delete flash;
-
-//    printf("Restarting main application...\r\n");
-	NVIC_SystemReset();
-}
-
-#endif /* XDOTBRIDGE_INC_BOOTLOADER_H_ */
--- a/xDotBridge/inc/dot_util.h	Sat Nov 18 22:58:20 2017 +0000
+++ b/xDotBridge/inc/dot_util.h	Sat Nov 18 18:01:43 2017 -0700
@@ -7,7 +7,8 @@
 #include "mDot.h"
 #include "MTSText.h"
 #include "MTSLog.h"
-//#include "ISL29011.h"
+
+#define SHOW_SECRETS 0 // This will hide all the keys from printing
 
 extern mDot* dot;
 
--- a/xDotBridge/inc/xdot_flash.h	Sat Nov 18 22:58:20 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/* mbed Microcontroller Library
- *******************************************************************************
- * Copyright (c) 2016, MultiTech Systems
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- * 3. Neither the name of MultiTech nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *******************************************************************************
- */
-
-#ifndef __XDOT_FLASH_H__
-#define __XDOT_FLASH_H__
-
-#include "cmsis.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* xdot_eeprom_write_buf FIXME
- * attempts to write size bytes from buf to addr
- * implements read-before-write because writes are expensive
- * uses most efficient write possible (byte, half-word, or word write) based on alignment
- *  and number of bytes that need to be written
- * buf must be non-null and size bytes or larger
- * valid addresses are 0x0000 - 0x1FFF
- * returns 0 if all data was successfully written otherwise -1
- */
-int xdot_flash_write_buf(uint32_t addr, uint8_t* buf, uint32_t size);
-
-/* xdot_eeprom_read_buf FIXME
- * attempts to read size bytes into buf starting at addr
- * buf must be non-null and size bytes or larger
- * valid addresses are 0x0000 - 0x1FFF
- * returns 0 if all data was successfully read otherwise -1
- */
-int xdot_flash_read_buf(uint32_t addr, uint8_t* buf, uint32_t size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __XDOT_FLASH_H__ */
-
--- a/xDotBridge/src/CommProtocolPeerBrute.cpp	Sat Nov 18 22:58:20 2017 +0000
+++ b/xDotBridge/src/CommProtocolPeerBrute.cpp	Sat Nov 18 18:01:43 2017 -0700
@@ -556,13 +556,17 @@
     myLogInfo("network join mode -------- %s", mDot::JoinModeStr(dot->getJoinMode()).c_str());
     if (dot->getJoinMode() == mDot::MANUAL || dot->getJoinMode() == mDot::PEER_TO_PEER) {
 	myLogInfo("network address ---------- %s", mts::Text::bin2hexString(dot->getNetworkAddress()).c_str());
+#if SHOW_SECRETS
 	myLogInfo("network session key------- %s", mts::Text::bin2hexString(dot->getNetworkSessionKey()).c_str());
 	myLogInfo("data session key---------- %s", mts::Text::bin2hexString(dot->getDataSessionKey()).c_str());
+#endif
     } else {
 	myLogInfo("network name ------------- %s", dot->getNetworkName().c_str());
 	myLogInfo("network phrase ----------- %s", dot->getNetworkPassphrase().c_str());
+#if SHOW_SECRETS
 	myLogInfo("network EUI -------------- %s", mts::Text::bin2hexString(dot->getNetworkId()).c_str());
 	myLogInfo("network KEY -------------- %s", mts::Text::bin2hexString(dot->getNetworkKey()).c_str());
+#endif
     }
     myLogInfo("========================");
     myLogInfo("communication parameters");
@@ -574,7 +578,7 @@
     }
     myLogInfo("TX datarate -------------- %s", mDot::DataRateStr(dot->getTxDataRate()).c_str());
     myLogInfo("TX power ----------------- %lu dBm", dot->getTxPower());
-    myLogInfo("atnenna gain ------------- %u dBm", dot->getAntennaGain());
+    myLogInfo("antenna gain ------------- %u dBm", dot->getAntennaGain());
 }
 
 // NvmProtocolObj
--- a/xDotBridge/src/SerialTermMgr.cpp	Sat Nov 18 22:58:20 2017 +0000
+++ b/xDotBridge/src/SerialTermMgr.cpp	Sat Nov 18 18:01:43 2017 -0700
@@ -7,7 +7,7 @@
 
 #include "SerialTermMgr.h"
 #include "UserInterface.h"
-#include "bootloader.h"
+//#include "bootloader.h"
 
 extern Serial pc;
 const char ACK = 0x06;
@@ -86,28 +86,29 @@
         mCurrScreen = genInfoScreenId;
         break;
     case '2':
-        mPc->printf("\r\nNot implemented yet.\r\n");
-//        mCurrScreen = settingsScreenId;
-        break;
-    case '3':
-        mPc->printf("\r\nNot implemented yet.\r\n");
-//        mCurrScreen = statsScreenId;
-        break;
-    case '4':
-        mPc->printf("\r\nNot implemented yet.\r\n");
-//        mCurrScreen = errorLogScreenId;
-        break;
-    case '5':
-        mPc->printf("\r\nNot implemented yet.\r\n");
-//        mCurrScreen = liveLogScreenId;
-        break;
-    case '6':
-        mPc->printf("\r\nNot implemented yet.\r\n");
-//        mCurrScreen = enterSerialBridgeScreenId;
-        break;
-    case '7':
         mCurrScreen = enterProgModeScreenId;
         break;
+    // Future
+//    case '3':
+//        mPc->printf("\r\nNot implemented yet.\r\n");
+////        mCurrScreen = settingsScreenId;
+//        break;
+//    case '4':
+//        mPc->printf("\r\nNot implemented yet.\r\n");
+////        mCurrScreen = statsScreenId;
+//        break;
+//    case '5':
+//        mPc->printf("\r\nNot implemented yet.\r\n");
+////        mCurrScreen = errorLogScreenId;
+//        break;
+//    case '6':
+//        mPc->printf("\r\nNot implemented yet.\r\n");
+////        mCurrScreen = liveLogScreenId;
+//        break;
+//    case '7':
+//        mPc->printf("\r\nNot implemented yet.\r\n");
+////        mCurrScreen = enterSerialBridgeScreenId;
+//        break;
     case 0x11: // ctrl-q
         quit=true;
         break;
@@ -134,12 +135,13 @@
     mPc->printf("===============================================\r\n");
     mPc->printf("= 0: Refresh (Enter and space also work)      =\r\n");
     mPc->printf("= 1: General information                      =\r\n");
-    mPc->printf("= 2: Settings                                 =\r\n");
-    mPc->printf("= 3: Statistics                               =\r\n");
-    mPc->printf("= 4: Error log                                =\r\n");
-    mPc->printf("= 5: Live log                                 =\r\n");
-    mPc->printf("= 6: Enter serial bridge mode                 =\r\n");
-    mPc->printf("= 7: Enter programming mode                   =\r\n");
+    mPc->printf("= 2: Enter programming mode                   =\r\n");
+    // Future
+//    mPc->printf("= 3: Settings                                 =\r\n");
+//    mPc->printf("= 4: Statistics                               =\r\n");
+//    mPc->printf("= 5: Error log                                =\r\n");
+//    mPc->printf("= 6: Live log                                 =\r\n");
+//    mPc->printf("= 7: Enter serial bridge mode                 =\r\n");
     mPc->printf("= <ctrl>-q: Exit terminal                     =\r\n");
     mPc->printf("===============================================\r\n");
 }
@@ -149,7 +151,7 @@
         return;
     }
     switch (in) {
-    case 0x1B:
+    case 0x1B: // esc
         mCurrScreen = mainScreenId;
         break;
     case 'r':
@@ -181,10 +183,10 @@
                                                                             "Normally closed");
     mPc->printf("= WB Mode: %s                        =\r\n", mBbio->isTx() ? "Transmitter" :
                                                                               "Receiver   ");
-    mPc->printf("= Comm Mode: %s                     =\r\n", mBbio->isLoRaWANMode() ? "LoRaWAN     " :
-                                                                                      "Peer-to-peer");
-    mPc->printf("= Serial Mode: %s                       =\r\n", mBbio->isSerialEnabled() ? "Enabled " :
-                                                                                            "Disabled");
+//    mPc->printf("= Comm Mode: %s                     =\r\n", mBbio->isLoRaWANMode() ? "LoRaWAN     " :
+//                                                                                      "Peer-to-peer");
+//    mPc->printf("= Serial Mode: %s                       =\r\n", mBbio->isSerialEnabled() ? "Enabled " :
+//                                                                                            "Disabled");
     if (mBbio->isTx()) {
         mPc->printf("= Currently no rotary switches apply for TX   =\r\n");
     }
@@ -202,7 +204,7 @@
     }
     mPc->printf("\r\n\r\n");
     mPc->printf("===============================================\r\n");
-    mPc->printf("= Serial Firmware Prog Mode (Esc to return)    =\r\n");
+    mPc->printf("= Serial Firmware Prog Mode (Esc to return)   =\r\n");
     mPc->printf("===============================================\r\n");
     mPc->printf("===============================================\r\n");
     mPc->printf("= To program firmware:                         \r\n");
@@ -211,7 +213,7 @@
     mPc->printf("= 3: In terminal program (such as teraterm)   =\r\n");
     mPc->printf("=    select transfer via XMODEM               =\r\n");
     mPc->printf("= 4: Programming may take up to a minute      =\r\n");
-    mPc->printf("= 5: If successful terminal will print \"Success\" =\r\n");
+    mPc->printf("= 5: If successful terminal prints \"Success\"  =\r\n");
     mPc->printf("= 6: Wireless Bridge will then automatically  =\r\n");
     mPc->printf("=    reboot with new firmware.                =\r\n");
     mPc->printf("===============================================\r\n");
@@ -222,7 +224,7 @@
         return;
     }
     switch (in) {
-    case 0x1B:
+    case 0x1B: // esc:
         mCurrScreen = mainScreenId;
         break;
     case 0x04:
@@ -305,11 +307,16 @@
 void SerialTermMgr::writeBootloaderCtrlPage(uint32_t nBytes)
 {
 	// This should always be less than 256 bytes
-	const unsigned int ctrlSize = sizeof(NEW_CODE)+sizeof(nBytes);
+
+	// Zero updates the bootloader version so that is cleared until the bootloader adds its back
+	const uint32_t zeroBootloaderVersion = 0;
+	const unsigned int ctrlSize = sizeof(NEW_CODE)+sizeof(nBytes)+sizeof(zeroBootloaderVersion);
 	char buf[ctrlSize];
 	std::memcpy(buf, NEW_CODE, sizeof(NEW_CODE));
 	std::memcpy(buf+sizeof(NEW_CODE), &nBytes, sizeof(nBytes));
-	// TODO add reprogram counter just for fun
+	std::memcpy(buf+sizeof(NEW_CODE)+sizeof(nBytes),
+				&zeroBootloaderVersion, sizeof(zeroBootloaderVersion));
+	// TODO add reprogram counter or other functions
 
 	// Copy to first page of flash
     mFlash->writeStream(0, buf, sizeof(buf));
--- a/xDotBridge/src/dot_util.cpp	Sat Nov 18 22:58:20 2017 +0000
+++ b/xDotBridge/src/dot_util.cpp	Sat Nov 18 18:01:43 2017 -0700
@@ -33,13 +33,17 @@
     logInfo("network join mode -------- %s", mDot::JoinModeStr(dot->getJoinMode()).c_str());
     if (dot->getJoinMode() == mDot::MANUAL || dot->getJoinMode() == mDot::PEER_TO_PEER) {
 	logInfo("network address ---------- %s", mts::Text::bin2hexString(dot->getNetworkAddress()).c_str());
+#if SHOW_SECRETS
 	logInfo("network session key------- %s", mts::Text::bin2hexString(dot->getNetworkSessionKey()).c_str());
 	logInfo("data session key---------- %s", mts::Text::bin2hexString(dot->getDataSessionKey()).c_str());
+#endif
     } else {
 	logInfo("network name ------------- %s", dot->getNetworkName().c_str());
 	logInfo("network phrase ----------- %s", dot->getNetworkPassphrase().c_str());
 	logInfo("network EUI -------------- %s", mts::Text::bin2hexString(dot->getNetworkId()).c_str());
+#if SHOW_SECRETS
 	logInfo("network KEY -------------- %s", mts::Text::bin2hexString(dot->getNetworkKey()).c_str());
+#endif
     }
     logInfo("========================");
     logInfo("communication parameters");
@@ -51,7 +55,7 @@
     }
     logInfo("TX datarate -------------- %s", mDot::DataRateStr(dot->getTxDataRate()).c_str());
     logInfo("TX power ----------------- %lu dBm", dot->getTxPower());
-    logInfo("atnenna gain ------------- %u dBm", dot->getAntennaGain());
+    logInfo("antenna gain ------------- %u dBm", dot->getAntennaGain());
 }
 
 void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack) {
@@ -115,7 +119,9 @@
     }
     
     if (current_network_key != network_key_vector) {
+#if SHOW_SECRETS
         logInfo("changing network KEY from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_key).c_str(), mts::Text::bin2hexString(network_key_vector).c_str());
+#endif
         if (dot->setNetworkKey(network_key_vector) != mDot::MDOT_OK) {
             logError("failed to set network KEY to \"%s\"", mts::Text::bin2hexString(network_key_vector).c_str());
         }
@@ -163,14 +169,18 @@
     }
     
     if (current_network_session_key != network_session_key_vector) {
+#if SHOW_SECRETS
         logInfo("changing network session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_session_key).c_str(), mts::Text::bin2hexString(network_session_key_vector).c_str());
+#endif
         if (dot->setNetworkSessionKey(network_session_key_vector) != mDot::MDOT_OK) {
             logError("failed to set network session key to \"%s\"", mts::Text::bin2hexString(network_session_key_vector).c_str());
         }
     }
     
     if (current_data_session_key != data_session_key_vector) {
+#if SHOW_SECRETS
         logInfo("changing data session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_data_session_key).c_str(), mts::Text::bin2hexString(data_session_key_vector).c_str());
+#endif
         if (dot->setDataSessionKey(data_session_key_vector) != mDot::MDOT_OK) {
             logError("failed to set data session key to \"%s\"", mts::Text::bin2hexString(data_session_key_vector).c_str());
         }
@@ -211,21 +221,27 @@
     std::vector<uint8_t> data_session_key_vector(data_session_key, data_session_key + 16);
 
     if (current_network_address != network_address_vector) {
+#if SHOW_SECRETS
         logInfo("changing network address from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_address).c_str(), mts::Text::bin2hexString(network_address_vector).c_str());
+#endif
         if (dot->setNetworkAddress(network_address_vector) != mDot::MDOT_OK) {
             logError("failed to set network address to \"%s\"", mts::Text::bin2hexString(network_address_vector).c_str());
         }
     }
     
     if (current_network_session_key != network_session_key_vector) {
+#if SHOW_SECRETS
         logInfo("changing network session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_session_key).c_str(), mts::Text::bin2hexString(network_session_key_vector).c_str());
+#endif
         if (dot->setNetworkSessionKey(network_session_key_vector) != mDot::MDOT_OK) {
             logError("failed to set network session key to \"%s\"", mts::Text::bin2hexString(network_session_key_vector).c_str());
         }
     }
     
     if (current_data_session_key != data_session_key_vector) {
+#if SHOW_SECRETS
         logInfo("changing data session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_data_session_key).c_str(), mts::Text::bin2hexString(data_session_key_vector).c_str());
+#endif
         if (dot->setDataSessionKey(data_session_key_vector) != mDot::MDOT_OK) {
             logError("failed to set data session key to \"%s\"", mts::Text::bin2hexString(data_session_key_vector).c_str());
         }
--- a/xDotBridge/src/main.cpp	Sat Nov 18 22:58:20 2017 +0000
+++ b/xDotBridge/src/main.cpp	Sat Nov 18 18:01:43 2017 -0700
@@ -1,7 +1,6 @@
 #include "mbed.h"
 #include <math.h>
 #include "config.h"
-#include "xdot_flash.h"
 #include "dot_util.h"
 #include "RadioEvent.h"
 #include "BufferedSerial.h"
@@ -19,7 +18,7 @@
 
 #define RX_SEQ_LOG 1
 
-const float BridgeVersion = 1.02; // Bumped 2017/11/18
+const float BridgeVersion = 1.99; // Bumped 2017/11/TODO
 
 // 232 Pins
 const PinName SER_TERM_TX = UART_TX;
@@ -49,11 +48,6 @@
     pairBtnIntFlag = true;
 }
 
-void testFunc() {
-	const uint32_t test=0xDEADBEEF;
-	printf("%d", test);
-}
-
 int main() {
     CommProtocolPeerBrute *protocol = new CommProtocolPeerBrute();
     BaseboardIO *bbio = new BaseboardIO();
--- a/xDotBridge/src/xdot_flash.cpp	Sat Nov 18 22:58:20 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,284 +0,0 @@
-/* mbed Microcontroller Library
- *******************************************************************************
- * Copyright (c) 2016, MultiTech Systems
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- * 3. Neither the name of MultiTech nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *******************************************************************************
- */
-
-#include "xdot_flash.h"
-
-#define XDOT_FLASH_START       0x08000000
-#define XDOT_FLASH_SIZE        0x00040000
-
-typedef union {
-    uint32_t* w;
-    uint8_t* b;
-} b2w;
-
-typedef union {
-    uint16_t* hw;
-    uint8_t* b;
-} b2hw;
-
-enum {
-    byte_write = 0,
-    hword_write,
-    word_write
-};
-
-static int xdot_flash_write_byte(uint32_t addr, uint8_t data) {
-    if (addr > XDOT_FLASH_SIZE - 1) {
-        return -1;
-    }
-
-    if (HAL_FLASH_Program(TYPEPROGRAMDATA_BYTE, XDOT_FLASH_START + addr, (uint32_t)data) != HAL_OK) {
-        return -1;
-    } else {
-        return 0;
-    }
-}
-
-static int xdot_flash_write_hword(uint32_t addr, uint16_t data) {
-    if (addr > XDOT_FLASH_SIZE - 2) {
-        return -1;
-    }
-
-    if (HAL_FLASH_Program(TYPEPROGRAMDATA_HALFWORD, XDOT_FLASH_START + addr, (uint32_t)data) != HAL_OK) {
-        return -1;
-    } else {
-        return 0;
-    }
-}
-
-static int xdot_flash_write_word(uint32_t addr, uint32_t data) {
-    if (addr > XDOT_FLASH_SIZE - 4) {
-        return -1;
-    }
-
-    if (HAL_FLASH_Program(TYPEPROGRAMDATA_WORD, XDOT_FLASH_START + addr, (uint32_t)data) != HAL_OK) {
-        return -1;
-    } else {
-        return 0;
-    }
-}
-
-static int xdot_flash_read_byte(uint32_t addr, uint8_t* data) {
-    if (addr > XDOT_FLASH_SIZE - 1) {
-        return -1;
-    }
-
-    *data = (*((uint8_t*)(XDOT_FLASH_START + addr)));
-
-    return 0;
-}
-
-
-int xdot_flash_write_buf(uint32_t addr, uint8_t* buf, uint32_t size) {
-    uint32_t bytes_written = 0;
-
-    if (addr + size > XDOT_FLASH_SIZE) {
-        return -1;
-    }
-
-    // TODO Erase sector
-
-    HAL_FLASH_Unlock();
-
-    while (bytes_written < size) {
-        uint32_t bytes_remaining = size - bytes_written;
-        uint32_t current_addr = addr + bytes_written;
-        uint8_t write_type = 0xFF;
-        uint8_t mismatch[4];
-        uint8_t match_byte = 0xFF;
-        b2w byte2word;
-        b2hw byte2hword;
-        //printf("0x%04X (%lu) bytes remaining\r\n", bytes_remaining, bytes_remaining);
-        //printf("addr 0x%04X\t%d\r\n", current_addr, current_addr % 4);
-
-        mismatch[0] = mismatch[1] = mismatch[2] = mismatch[3] = 0;
-
-        if ((current_addr % 4 == 0) && bytes_remaining >= 4) {
-            // aligned for word write
-            //printf("aligned for word write\r\n");
-            //printf("addr\tcurrent\t\tnew\r\n");
-            for (int i = 0; i < 4; i++) {
-                if (xdot_flash_read_byte(current_addr + i, &match_byte)) {
-                    HAL_FLASH_Lock();
-                    return -1;
-                }
-                //printf("0x%04X\t0x%08X\t0x%08X\t", current_addr + i, match_byte, buf[bytes_written + i]);
-                if (match_byte != buf[bytes_written + i]) {
-                    mismatch[i] = 1;
-                }
-                //printf("%smatch\r\n", mismatch[i] ? "mis" : "");
-            }
-            if (! (mismatch[0] || mismatch[1] || mismatch[2] || mismatch[3])) {
-                //printf("all match - no write necessary\r\n");
-                bytes_written += 4;
-                continue;
-            }
-            if ((mismatch[0] || mismatch[1]) && (mismatch[2] || mismatch[3])) {
-                // if at least one of byte 1 or byte 2 and one of byte 3 or byte 4 needs to be written, write a word
-                // this should also account for all 3 or 4 byte combinations as well
-                write_type = word_write;
-            } else if ((mismatch[0] && mismatch[1]) || (mismatch[2] && mismatch[3])) {
-                // if only bytes 1 and 2 or only bytes 3 and 4 need to be written, write a half-word
-                write_type = hword_write;
-                // increment bytes_written if we're skipping bytes that match
-                if (mismatch[2] && mismatch[3]) {
-                    bytes_written += 2;
-                    current_addr += 2;
-                }
-            } else if (mismatch[0] || mismatch[1] || mismatch[2] || mismatch[3]) {
-                // anything else is just a byte write
-                write_type = byte_write;
-                // increment bytes_written if we're skipping bytes that match
-                if (mismatch[1]) {
-                    bytes_written += 1;
-                    current_addr += 1;
-                } else if (mismatch[2]) {
-                    bytes_written += 2;
-                    current_addr += 2;
-                } else if (mismatch[3]) {
-                    bytes_written += 3;
-                    current_addr += 3;
-                }
-            }
-        } else if ((current_addr % 2 == 0) && bytes_remaining >= 2) {
-            // aligned for half word write
-            //printf("aligned for half word write\r\n");
-            //printf("addr\tcurrent\t\tnew\r\n");
-            for (int i = 0; i < 2; i++) {
-                if (xdot_flash_read_byte(current_addr + i, &match_byte)) {
-                    HAL_FLASH_Lock();
-                    return -1;
-                }
-                //printf("0x%04X\t0x%08X\t0x%08X\t", current_addr + i, match_byte, buf[bytes_written + i]);
-                if (match_byte != buf[bytes_written + i]) {
-                    mismatch[i] = 1;
-                }
-                //printf("%smatch\r\n", mismatch[i] ? "mis" : "");
-            }
-            if (! (mismatch[0] || mismatch[1])) {
-                //printf("all match - no write necessary\r\n");
-                bytes_written += 2;
-                continue;
-            }
-            if (mismatch[0] && mismatch[1]) {
-                // if bytes 1 and 2 need to be written, we truly want to write a half word
-                write_type = hword_write;
-            } else {
-                // anything else is just a byte write
-                write_type = byte_write;
-                // increment bytes_written if we're skipping bytes that match
-                if (mismatch[1]) {
-                    bytes_written += 1;
-                    current_addr += 1;
-                }
-            }
-        } else {
-            // aligned for byte write
-            //printf("aligned for byte write\r\n");
-            //printf("addr\tcurrent\t\tnew\r\n");
-            for (int i = 0; i < 1; i++) {
-                if (xdot_flash_read_byte(current_addr + i, &match_byte)) {
-                    HAL_FLASH_Lock();
-                    return -1;
-                }
-                //printf("0x%04X\t0x%08X\t0x%08X\t", current_addr + i, match_byte, buf[bytes_written + i]);
-                if (match_byte != buf[bytes_written + i]) {
-                    mismatch[i] = 1;
-                }
-                //printf("%smatch\r\n", mismatch[i] ? "mis" : "");
-            }
-            if (! mismatch[0]) {
-                //printf("all match - no write necessary\r\n");
-                bytes_written += 1;
-                continue;
-            }
-            write_type = byte_write;
-        }
-
-        switch (write_type) {
-            case word_write:
-                // we can write a word (32 bits)
-                //printf("word write\r\n");
-                byte2word.b = buf + bytes_written;
-                if (xdot_flash_write_word(current_addr, *byte2word.w)) {
-                    HAL_FLASH_Lock();
-                    return -1;
-                }
-                bytes_written += 4;
-                break;
-            case hword_write:
-                // we can write a half-word (16 bits)
-                //printf("half-word write\r\n");
-                byte2hword.b = buf + bytes_written;
-                if (xdot_flash_write_hword(current_addr, *byte2hword.hw)) {
-                    HAL_FLASH_Lock();
-                    return -1;
-                }
-                bytes_written += 2;
-                break;
-            case byte_write:
-                // we can write a byte (8 bits)
-                //printf("byte write\r\n");
-                if (xdot_flash_write_byte(current_addr, buf[bytes_written])) {
-                    HAL_FLASH_Lock();
-                    return -1;
-                }
-                bytes_written += 1;
-                break;
-            default:
-                //printf("no write needed\r\n");
-                break;
-        }
-    }
-
-    HAL_FLASH_Lock();
-
-    return 0;
-}
-
-int xdot_flash_read_buf(uint32_t addr, uint8_t* buf, uint32_t size) {
-    if (addr + size > XDOT_FLASH_SIZE) {
-        return -1;
-    }
-
-//    HAL_FLASHEx_DATAEEPROM_Unlock();
-
-    for (uint32_t i = 0; i < size; i++) {
-        if (xdot_flash_read_byte(addr + i, buf + i)) {
-//            HAL_FLASHEx_DATAEEPROM_Lock();
-            return -1;
-        }
-    }
-
-//    HAL_FLASHEx_DATAEEPROM_Lock();
-
-    return 0;
-}
-