MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface

Dependencies:   USBDevice

Fork of HSP_Release by Jerry Bradshaw

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.

Revision:
1:9490836294ea
Parent:
0:e4a10ed6eb92
--- a/HSP/RpcServer/StringInOut.cpp	Tue Oct 25 15:22:11 2016 +0000
+++ b/HSP/RpcServer/StringInOut.cpp	Fri Apr 21 12:12:30 2017 -0500
@@ -43,13 +43,15 @@
 /// a flag that keeps track of the state of accumulating a string
 static int getLine_State = GETLINE_WAITING;
 
+extern USBSerial *usbSerialPtr;
+
 /**
 * @brief Place incoming USB characters into a fifo
 * @param data_IN buffer of characters
 * @param len length of data
 */
 int fifoIncomingChars(uint8_t data_IN[], unsigned int len) {
-  int i;
+  unsigned int i;
   for (i = 0; i < len; i++) {
     fifo_put8(GetUSBIncomingFifo(), data_IN[i]);
   }
@@ -94,12 +96,12 @@
 int getLine(char *lineBuffer, int bufferLength) {
   uint8_t ch;
 
-  USBSerial *serial = Peripherals::usbSerial();
+  //USBSerial *serial = Peripherals::usbSerial();
   if (getLine_State == GETLINE_DONE) {
     getLine_State = GETLINE_WAITING;
   }
-  if (serial->available() != 0) {
-    ch = serial->_getc();
+  if (usbSerialPtr->available() != 0) {
+    ch = usbSerialPtr->_getc();
     if (ch != 0x0A && ch != 0x0D) {
       lineBuffer[lineBuffer_index++] = ch;
     }
@@ -135,61 +137,44 @@
 }
 
 /**
-* @brief Output a string out the USB serial port
-* @param str output this str the USB channel
-*/
-int putStr(const char *str) {
-  Peripherals::usbSerial()->printf("%s", str); // fflush(stdout);
-  // uint8_t *ptr;
-  // uint8_t buffer[256];
-  // int index = 0;
-  /*	int length;
-          ptr = (uint8_t *)str;
-          length = strlen(str);
-
-          Peripherals::usbSerial()->writeBlock(ptr,length);	*/
-  return 0;
-}
-
-/**
 * @brief Outut an array of bytes out the USB serial port
 * @param data buffer to output
 * @param length length of buffer
 */
 int putBytes(uint8_t *data, uint32_t length) {
-  int sendThis = 64;
-  int sent = 0;
-  int thisLeft;
-  uint8_t *ptr = data;
-  if (length < 64)
-    sendThis = length;
-  do {
-    Peripherals::usbSerial()->writeBlock(ptr, sendThis);
-    sent += sendThis;
-    ptr += sendThis;
-    thisLeft = length - sent;
-    sendThis = 64;
-    if (thisLeft < 64)
-      sendThis = thisLeft;
-  } while (sent != length);
+  int sent;
+  int send;
+  bool status;
+  uint8_t *ptr;
+  ptr = data;
+  //
+  // break up the string into chunks
+  //
+  sent = 0;
+  do { 
+    send = MAX_PACKET_SIZE_EPBULK;
+    if ((sent + MAX_PACKET_SIZE_EPBULK) > (int)length) {
+      send = length - sent;
+    }
+    status = usbSerialPtr->writeBlock(ptr,send);
+    if (status != true) {
+      while (1) ;
+    }
+    sent += send;
+    ptr += send;
+  } while (sent < (int)length);
   return 0;
 }
 
 /**
-* @brief Outut 256 byte blocks out the USB serial using writeBlock bulk
-* transfers
-* @param data buffer of blocks to output
-* @param length length of 256-byte blocks
+* @brief Output a string out the USB serial port
+* @param str to output
 */
-int putBytes256Block(uint8_t *data, int numberBlocks) {
-  int i;
+int putStr(const char *str) {
+  int length;
   uint8_t *ptr;
-  ptr = data;
-  const int BLOCK_SIZE = 32;
-  const int FLASH_PAGE_SIZE = 256;
-  for (i = 0; i < numberBlocks * (FLASH_PAGE_SIZE / BLOCK_SIZE); i++) {
-    Peripherals::usbSerial()->writeBlock(ptr, BLOCK_SIZE);
-    ptr += BLOCK_SIZE;
-  }
+  ptr = (uint8_t *)str;
+  length = strlen(str);
+  putBytes(ptr, length);
   return 0;
 }