MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface
Dependencies: USBDevice
Fork of HSP_Release by
This is an example program for the MAX32620HSP (MAXREFDES100 Health Sensor Platform). It demonstrates all the features of the platform and works with a companion graphical user interface (GUI) to help evaluate/configure/monitor the board. Go to the MAXREFDES100 product page and click on "design resources" to download the companion software. The GUI connects to the board through an RPC interface on a virtual serial port over the USB interface.
The RPC interface provides access to all the features of the board and is available to interface with other development environments such Matlab. This firmware provides realtime data streaming through the RPC interface over USB, and also provides the ability to log the data to flash for untethered battery operation. The data logging settings are configured through the GUI, and the GUI also provides the interface to download logged data.
Details on the RPC interface can be found here: HSP RPC Interface Documentation
Windows
With this program loaded, the MAX32620HSP will appear on your computer as a serial port. On Mac and Linux, this will happen by default. For Windows, you need to install a driver: HSP serial port windows driver
For more details about this platform and how to use it, see the MAXREFDES100 product page.
Diff: HSP/LoggingService/Logging_RPC.cpp
- Revision:
- 3:8e9b9f5818aa
- Parent:
- 2:d483f896c7a9
--- a/HSP/LoggingService/Logging_RPC.cpp Fri Apr 21 18:10:37 2017 -0500 +++ b/HSP/LoggingService/Logging_RPC.cpp Tue Apr 25 10:47:10 2017 -0500 @@ -37,6 +37,7 @@ #include "DataLoggingService.h" #include "Peripherals.h" #include "Logging.h" +#include "S25FS512.h" extern char loggingMissionCmds[4096]; uint32_t missionCmdIndex; @@ -161,31 +162,89 @@ return 0; } -#define SECTOR_SIZE_256K 0x10000 -#define PAGE_INC_256K 0x400 -#define SECTOR_SIZE_4K 0x1000 -#define PAGE_INC_4K 0x10 -#define TOTAL_SECTOR_NUMBER 263 - - -#define ADDRESS_INC_4K 0x1000 -#define ADDRESS_INC_32K 0x8000 -#define ADDRESS_INC_64K 0x10000 +// +// small helper function to determine if the X number of a page are FF (empty) +// +static bool isPartialPageEmpty(uint8_t *ptr, int count) { + int i; + for (i = 0; i < count; i++) { + if (ptr[i] != 0xFF) return false; + } + return true; +} -#define ADDRESS_4K_START 0x0 -#define ADDRESS_4K_END 0x8000 - -#define ADDRESS_32K_START 0x8000 -#define ADDRESS_32k_END 0x10000 - -#define ADDRESS_64K_START 0x10000 -#define ADDRESS_64k_END 0x2000000 - -#define SIZE_OF_EXTERNAL_FLASH 0x2000000 // 33,554,432 Bytes +// +// define the different sector sizes in flash +// +typedef enum { + e4K, + e32K, + e64K +} loggingFlashArea_t; //****************************************************************************** int Logging_EraseWrittenSectors(char argStrs[32][32], char replyStrs[32][32]) { - Peripherals::s25FS512()->bulkErase_Helper(); + uint32_t i; + uint8_t data[512]; + uint32_t address; + uint32_t pageNumber; + bool pageEmpty; + uint32_t pagesToScan; + loggingFlashArea_t currentArea; + uint32_t currentAreaSize; + //Peripherals::s25FS512()->bulkErase_Helper(); + + // + // quickly scan through the first few bytes of a page and continue this through a sector + // this will determine if the sector needs to be erased or can be skipped + // + currentArea = e4K; + address = 0; + // interate through the entire flash + while (address < SIZE_OF_EXTERNAL_FLASH) { + // determine the size of the current area + switch (currentArea) { + case e4K: + currentAreaSize = ADDRESS_INC_4K; + break; + case e32K: + currentAreaSize = ADDRESS_INC_32K; + break; + default: + currentAreaSize = ADDRESS_INC_64K; + break; + } + pagesToScan = currentAreaSize / SIZE_OF_PAGE; + pageNumber = address >> 8; + pageEmpty = true; + // scan the first few bytes in each page for this area + for (i = 0; i < pagesToScan; i++) { + Peripherals::s25FS512()->readPartialPage_Helper(pageNumber + i, data, 4); + pageEmpty = isPartialPageEmpty(data, 4); + if (pageEmpty == false) break; + } + // if we detected data then erase this sector + if (pageEmpty == false) { + switch (currentArea) { + case e4K: + Peripherals::s25FS512()->parameterSectorErase_Helper(address); + break; + default: + Peripherals::s25FS512()->sectorErase_Helper(address); + break; + } + } + // update the address with the current area size + address += currentAreaSize; + // determine the new area in flash + if (address < ADDRESS_4K_END) { + currentArea = e4K; + } else if (address == ADDRESS_32K_START) { + currentArea = e32K; + } else { + currentArea = e64K; + } + } return 0; }