This is my ninth week in AESTE. Continue working on PIC32 and Harmony with storing data into internal flash (using NVM) and improving my network transport layer by adding CORS protocol and HOTP.

😀😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏😐😑😒😓😔😕😖😗😛
PIC32 with NVM Driver

For storing data into internal flash I plan to use NVM driver, but not DEE Emulation which I used for PIC18. The main reason is because NVM method could store faster and much more data with a single write command. The only disadvantage would be, the write and erase is fixed. For DEE Emulation, I can write Byte by Byte data, but for NVM is Word by Word or bigger. To use NVM on PIC32, there is already an example project in ‘Harmony > Apps > Drivers > Nvm’. After studying the example code, there are basically 2 method to write into internal flash:

1. DRV_NVM_Write
2. DRV_NVM_EraseWrite

After reading the Harmony help pdf, and trying out the example code, I decided to use EraseWrite function to store my data into internal flash. This is so that I do not need to erase the whole page when I need to update a Row of data for a page. For internal flash programming, 3 things must be taken into account

1. Write/Row Size
2. Erase/Page Size

This is because for every Write using NVM driver, one can decide the Row size which indirectly control the Write size. Whereas for Page size will determine the number of bytes that will be Erase when an erase command was initiated.

PIC32 with HOTP

After successfully storing data into internal flash, I proceed with CORS protocol and HOTP for PIC32. Both this protocol I had done it before for PIC18, therefore most of the code I just port it over. The only minor adjustment I made was to use wolfssl library to generate a HOTP value.

Hmac hmac;
byte Digest[20] = {0};
wc_HmacSetKey(hmac, SHA, Key, sizeof(Key)); //SHA or MD5
wc_HmacUpdate(hmac, Text, sizeof(Text));
wc_HmacFinal(hmac, Digest);

Then just truncate Digest array to produce a 6digit HOTP value.

PIC32 with CORS protocol

While for CORS protocol, from Harmony NET_PRES_SKT_Read(...) will read all data from Client. So I just use “string.h” functions like strncpy() and strchr() to search/identify the data from Client eg:Headers and Body, so that I could send the correct respond based on the message from Client. While for PIC18 uses “TCP.h” consist of function likes TCPFind to process the message from Client. I did not use the same function because the current Wolfssl TCP Server project, I included an addition Harmony Network Layer which does not use TCPFind function, therefore I used functions from “string.h” for my PIC32.


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.