Logger to USB stick running on KL25Z

Dependencies:   F401RE-USBHost FastAnalogIn RTC mbed tsi_sensor2 mbed-rtos2

Fork of ReadSendData by Stuart Scott

Homepage for kXX_logger(was kl25x_usb_logger)

2014Nov12 - Added TSI - only works for kl25z, and fails after 4287seconds

Tests sequences for freezing 4287seconds 4287 4287 - Changed to USB write update every two seconds and lasted 4283seconds. Added mbed TSI_sensor - kudos to mbed as it turns out to be complex to do capacitive touch sensing. Kinetis L series Cortex-M0 (kl25z) has simpler capacitive sensing hardware which mbed/TSI_sensor lib uses, but doesn't support Cortex-M4 versions. K20D is older more complex interface. TSS hasn't had an open source support by Freescale in the past however that has changed. Currently I found KDS1.1.1 has a Processor Expert TSSlib that can be imported - but I'm getting a weird compile/include error - and not found any examples of how to make it work.

2014Oct05 - Published simple kl25z_usb_logger

Testing: Version (2:f06fbf86887e) has run over 28days starting 2014Sept07, reading a sensor data every seconds and then on the USB stick open file, write record, close file

This is over 2,419,200seconds ( 28days*24hrs*3600seconds) The stick data reflected 2,447,633 seconds, but only had 1,776,366 data records. After 407,650 data records started missing updates - analysis: the file could not be opened and read to the end in the allocated 1 second, and therefore missed the next ADC deadline.

By the end of the test period with 1,776,366 records on the USB Stick, ever read then write was causing it to miss two/three ADC updates - ie taking longer than two seconds.

Analysis: this was an aggressive test, and normally would not be opening, writing, closing every 1 second. However big plus the file mechanism held up and the program continued to operate, with a graceful failure of a missed ADC readings. The output used JSON, which reads nicely but turns out not to be supported by Excel (2014?) I was using.

Conclusion: Overall the USB Mechanisms and file read is stable. However the USB stack used doesn't have an event based management for stick insertion and removal, or OTG power management . This KL25Z has been a very useful test to prove the configuration of clocks for USB Stack is possible and stable. The target processor being looked at is the MK20 and is similar in clocks, but slightly more comprehensive USB OTG Next step is to investigate the full Freescale Kinetis USB OTG Stack with power management on a custom K20 board, using Kinetis Design Studio, and very low power capability.

Example https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/FRDM-K20D50M/FRDM-K20_MSD_Host http://mcuoneclipse.com/2014/10/25/usb-cdc-with-the-frdm-k64f-finally/#comment-37727 - Commentary on Freescale USB versions

Committer:
sas37
Date:
Wed Jul 23 16:46:41 2014 +0000
Revision:
0:eb0dc2b5bc51
Child:
2:f06fbf86887e
Version now running;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sas37 0:eb0dc2b5bc51 1 #include "mbed.h"
sas37 0:eb0dc2b5bc51 2 #include "FastAnalogIn.h"
sas37 0:eb0dc2b5bc51 3
sas37 0:eb0dc2b5bc51 4 /*
sas37 0:eb0dc2b5bc51 5 Simple program which uses a ticker object to record and analoge value and store it in a cicular buffer.
sas37 0:eb0dc2b5bc51 6 The ticker delay sets the sampling rate.
sas37 0:eb0dc2b5bc51 7
sas37 0:eb0dc2b5bc51 8 The FastAnalogIn Library is used (http://mbed.org/users/Sissors/code/FastAnalogIn/) to rapidly sample
sas37 0:eb0dc2b5bc51 9 a single channel.
sas37 0:eb0dc2b5bc51 10
sas37 0:eb0dc2b5bc51 11 In the main loop a busy loop is used to send read the data from the cicular buffer and send down the serial line
sas37 0:eb0dc2b5bc51 12
sas37 0:eb0dc2b5bc51 13
sas37 0:eb0dc2b5bc51 14 */
sas37 0:eb0dc2b5bc51 15
sas37 0:eb0dc2b5bc51 16 //size of cicular buffer
sas37 0:eb0dc2b5bc51 17 #define BuffSize 255
sas37 0:eb0dc2b5bc51 18
sas37 0:eb0dc2b5bc51 19 using namespace mbed;
sas37 0:eb0dc2b5bc51 20
sas37 0:eb0dc2b5bc51 21 FastAnalogIn Ain(PTC2);
sas37 0:eb0dc2b5bc51 22
sas37 0:eb0dc2b5bc51 23 Serial pc(USBTX, USBRX);
sas37 0:eb0dc2b5bc51 24 Timer t;
sas37 0:eb0dc2b5bc51 25 Ticker tock;
sas37 0:eb0dc2b5bc51 26
sas37 0:eb0dc2b5bc51 27 //set the delay used by the ticker
sas37 0:eb0dc2b5bc51 28 float delay = 0.01;
sas37 0:eb0dc2b5bc51 29
sas37 0:eb0dc2b5bc51 30 //some circular buffers
sas37 0:eb0dc2b5bc51 31
sas37 0:eb0dc2b5bc51 32 float data[BuffSize];
sas37 0:eb0dc2b5bc51 33 float time_[BuffSize];
sas37 0:eb0dc2b5bc51 34 long i =0;
sas37 0:eb0dc2b5bc51 35 int j=0;
sas37 0:eb0dc2b5bc51 36 long k =0;
sas37 0:eb0dc2b5bc51 37
sas37 0:eb0dc2b5bc51 38 void ana()
sas37 0:eb0dc2b5bc51 39 {
sas37 0:eb0dc2b5bc51 40 if(i<k+BuffSize)
sas37 0:eb0dc2b5bc51 41 {j = i%BuffSize;
sas37 0:eb0dc2b5bc51 42 //time_[j]=t.read();
sas37 0:eb0dc2b5bc51 43 data[j]=Ain.read();
sas37 0:eb0dc2b5bc51 44 time_[j]=t.read();
sas37 0:eb0dc2b5bc51 45 i++;
sas37 0:eb0dc2b5bc51 46 }
sas37 0:eb0dc2b5bc51 47 }
sas37 0:eb0dc2b5bc51 48
sas37 0:eb0dc2b5bc51 49
sas37 0:eb0dc2b5bc51 50 int main()
sas37 0:eb0dc2b5bc51 51 {
sas37 0:eb0dc2b5bc51 52 pc.baud(57600);
sas37 0:eb0dc2b5bc51 53 t.start();
sas37 0:eb0dc2b5bc51 54 tock.attach(&ana,delay);
sas37 0:eb0dc2b5bc51 55 while (true) {
sas37 0:eb0dc2b5bc51 56 if(k<i)
sas37 0:eb0dc2b5bc51 57 {
sas37 0:eb0dc2b5bc51 58 pc.printf("%f,%f\n",time_[k%BuffSize],data[k%BuffSize]);
sas37 0:eb0dc2b5bc51 59 k++;
sas37 0:eb0dc2b5bc51 60 }
sas37 0:eb0dc2b5bc51 61
sas37 0:eb0dc2b5bc51 62
sas37 0:eb0dc2b5bc51 63 }
sas37 0:eb0dc2b5bc51 64 }