felis / UHS30

For information about the project see README below
GNU General Public License v2.0
133 stars 39 forks source link

Help to move data between SD Card & USB flash Drive with UHS30 or UHS20 #32

Closed shadeyinka closed 6 years ago

shadeyinka commented 7 years ago

I am building a datalogger whose primary memory is the SD card and the secondary storage is the USB flash drive. The data in the SD card is downloaded into the USB flash drive like once a week. I am using Arduino Mega ADK with Max3421 USB host chip.

  1. How can I use both SD card and Flash Drive together. The excellent UHS30 library seems to conflict with SD.h, SdFat.h and Fatfs.h(to a limited extent).

Any example code will do, especially to be able to initialize and mount the SD card and write/read text files. CS on my SD card shield is on digital pin 8 (cs_pin=8) of my Arduino board.

  1. I have some success with the SD card datalogger separately and UHS20 separately. UHS30 compiles on Arduino 1.6.9, AVR board 1.6.11, Windows 7 but it wouldn't execute any function (blank). Only UHS20 works for now.
shadeyinka commented 7 years ago

The new code still get stuck when executing the line

while(KINETIS_Usb.Init(1000) != 0);

I have put the jumper between pin9 and pin3 between pin53 and pin3 with no jumper

xxxajk commented 7 years ago

Should be no jumpers needed with new code.

xxxajk commented 7 years ago

Also compile with board as the MEGA ADK

shadeyinka commented 7 years ago

Even with no jumper. It prints Start. on the serial monitor and then waits indefinitly

xxxajk commented 7 years ago

Try this with the board_qc example.

shadeyinka commented 7 years ago

Yes. I did compile it as

  1. Mega ADK
  2. Mega 2560
  3. Changed Board in case it is faulty Nothing seem to work
xxxajk commented 7 years ago

Please try board_qc as Mega ADK, no jumpers, and it should print something out, after you pull this new patch.

shadeyinka commented 7 years ago

What do you mean by board_qc? Did you upload a new patch?

xxxajk commented 7 years ago

https://github.com/felis/UHS30/blob/master/libraries/UHS_host/USB_HOST_SHIELD/examples/board_qc/board_qc.ino It is under the examples for USB Host Shield. Yes I uploaded a new patch. :-)

shadeyinka commented 7 years ago

This is the Result from the Serial Display

Circuits At Home 2011 USB Host Shield Quality Control RoutineInitial reset failed. Unrecoverable error - test halted!! 0x55 pattern is transmitted via SPI Press RESET to restart test

xxxajk commented 7 years ago

Please see if you have +5v on pin 12 on the MAX3421E. I will send you a picture of where to test to your private email.

xxxajk commented 7 years ago

Sorry, 3.3v

shadeyinka commented 7 years ago

There is 0.85V between Pin12 and GND

shadeyinka commented 7 years ago

Sorry my error. Pin12 on the MAX3421E chip you mean?

xxxajk commented 7 years ago

Yes.

xxxajk commented 7 years ago

Sent you the pin to check to your email.

shadeyinka commented 7 years ago

I am on it. The pins are so tiny I want to activate my usb microscope to see where i am probing

xxxajk commented 7 years ago

No problem, I am probing here as well on the ATMega, using mine.

xxxajk commented 7 years ago

Pushed a new patch, pull, try board_qc again.

shadeyinka commented 7 years ago

Just Did that. The same Result on Serial Port

Circuits At Home 2011 USB Host Shield Quality Control RoutineInitial reset failed. Unrecoverable error - test halted!! 0x55 pattern is transmitted via SPI Press RESET to restart test

xxxajk commented 7 years ago

Unsure what the exact issue is, the port/pins should be correct now. I probed them on my regular Arduino Mega2560 at the actual MCU.

Try this short sketch, it will toggle the reset and int pins.

#define PULSE_DELAY 100 

void setup() {
        DDRJ |= 0x04; // output
        PORTJ |= 0x04; // HIGH
        DDRE &= 0x40; // outputput
        PORTE |= 0x40; // HIGH
        pinMode(LED_BUILTIN, OUTPUT);
        digitalWrite(LED_BUILTIN,HIGH);
}

void loop() {
        PORTJ |= 0x04; // HIGH
        PORTE |= 0x40; // HIGH
        digitalWrite(LED_BUILTIN,HIGH);
        delay(PULSE_DELAY);
        PORTJ &= ~0x04; // LOW
        PORTE &= ~0x40; // LOW
        digitalWrite(LED_BUILTIN,LOW);
        delay(PULSE_DELAY);
}

Do you have an oscilloscope or multimeter with the ability to sense frequency? If so, the RESET and INT pins should be pulsing in the above test.

shadeyinka commented 7 years ago

I do not have the Oscilloscope around, but I was able to do a work around by slowing down the oscillation (delay 2000) and viewing the Output with LED.

My observations:

  1. Pin7 and Pin8 Toggles ON/OFF
  2. The Oscillations on Pin7 and Pin8 are in Phase
  3. I am not sure which one of them is INT and which is RST
  4. Pin9 is permanently ON

Was this your intention?

shadeyinka commented 7 years ago

of course Pin13 goes in sync with Pin8 and Pin7. Same phase and Same Frequency

xxxajk commented 7 years ago

All right, in that case, the creators of this board tied pin 7 an 8 to the "hidden" pins. That's pretty interesting, and not really how the official ADK works, but should not pose a problem as long as you don't use pins 7 and 8.

This is actually progress :-)

Are you certain it is pins 7 and 8 and not 7 and 9?

shadeyinka commented 7 years ago

I am certain. Pin 7 and Pin 8 Oscillates Pin 9 is permanently ON

shadeyinka commented 7 years ago

Hi, I noticed an important difference in the port assignment between the Standard ADK and the Robotdyn ADK Except if the supplied schematic is wrong.

RobotDyn ADK__MAX3421E__Arduino ADK(Standard) PH4/PJ2_RST3V3____PH4/PJ2 PB1 (Pin52)__SCK_3V3PB1_SCK (Pin 52) PB0 (Pin 53)_SS_3V3__PB0_SS/PH7 Pin (53) PB3 (Pin 50)_PB3_MISO___PB3_MISO (Pin 50) PB2 (Pin 51)_____MISO_3V3___PB2_MOSI (Pin 51) PH5/PJ3_____GPX_MAXPJ3 PH6/PE6_____INT_MAX___PJ6/PE6 FROM: http://download.arduino.org/products/MEGAADK/arduino-mega-adk-schematic.pdf and the RobotDyn Supplied Schematic The major problem seems to be that PH6/PE6_____INT_MAX___PJ6/PE6 INT_MAX is connected in addition to PE6 differently: Robotdyn allowed a connection to PH6 while the Standard Arduino ADK allowed connection to PJ6 the non critical difference is the connection PB0 (Pin 53)_SS_3V3__PB0_SS/PH7 Pin (53) where the standard connected SS_3V3 to PH7, whereas PH7 was unconnected in Robotdyns board.

What do you think? It is even possible that bot schematics have been reviewed since published.

shadeyinka commented 7 years ago

From Robodyns Schematic,(if it is correct), Pin_PORT____MAX3421E Pin 6= PH3 Pin 7= PH4/Pj2---->RST_3V3 Pin 8= PH5/PJ3--->GPX_3V3 Pin 9= PH6/PE6--->INT_3V3 Pin10= PB4 Pin13= PB7 Pin53=PB0--------->SS_3V3 Pin50=PB3--------->MISO_3V3 Pin52=PB1--------->SCK_3V3 Pin51=PB2--------->MOSI_3V3

Seems all the connections to the MAX3421E chip were made accessible

xxxajk commented 7 years ago

I made a spreadsheet, and should be able to run some kind of test to determine what kind of "ADK", official, or quirky clone.

Part of the difference should actually not matter, however it is wired differently for /INT.

uhs

shadeyinka commented 7 years ago

Whao! So much difference between the Official and Robotdyn ADK. I am sure except for their own library as in https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Libraries/_06_Microduino_USBHOST_MAX3421E , No other library would work with the MAX3421E chip.

I guess this is the problem with Chinese clones: with almost no documentation. I am surprised you were able to get the Table above. The schematic supplied by the seller to me actually seems not the same that was implemented.

I guess I have learnt a lesson. "Never use a Chinese Clone for prototyping: to avoid endless Headaches and Time waste".

Thanks so much for spending so much time on this.

  1. From your earlier Port Test Sketch,

_#define PULSE_DELAY 100 void setup() { DDRJ |= 0x04; // output PORTJ |= 0x04; // HIGH DDRE &= 0x40; // outputput PORTE |= 0x40; // HIGH pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN,HIGH); } void loop() { PORTJ |= 0x04; // HIGH PORTE |= 0x40; // HIGH digitalWrite(LED_BUILTIN,HIGH); delay(PULSE_DELAY); PORTJ &= ~0x04; // LOW PORTE &= ~0x40; // LOW digitalWrite(LED_BUILTIN,LOW); delay(PULSEDELAY); }

I assumed you did intended to toggle PJ2(RST ) and PE6(INT), and by the Table, it should correspond to Pin7(PH4) and Pin9(PH6) but Pin7(PH4) and Pin8(PH5) Toggles ON/OFF while Pin9(PH6) is permanently ON.

This would mean that INT on Robotdyn ADK is actually PH5/PE6 and not PH6/PE6 as the table suggests.

  1. How critical is the connection to PH6 which seems to be missing in Robotdyn ADK? Thanks
xxxajk commented 7 years ago

Yup, that's where even sometimes it is actually even better to build your own boards too. Considering that the code was tweaked to use PE6, it should actually work. One huge difference also is that on the official Arduino ADK, the alternate pins are not connected, and are optional connections. This difference could possibly be part of the issue as well. One possible solution would be to locate where on the board the junction is made, and disconnect the secondary connections. Another possible problem with this board (judging by the schematics) is that there are no buffer chips to convert the signal levels from the MAX chip to the ATMega. While typically this shouldn't be an issue, it could actually be, since the waveform characteristics would be very different. Another problem with doing it the way they did is that if the INT/MISO/GPX lines are set to PULL_UP, the backwash of +5v to the +3.3V signal may damage the MAX3421E. Furthermore, MISO should be gated via the buffer IC so as when /SS is not low, that MISO is tristated, and not visible on the SPI BUS. Even if the MAX3421E DOES tristate alone, this is not enough, because anything ELSE connected to the SPI BUS is goping to be talking at +5V, and fry the MAX3421E that way too.

shadeyinka commented 7 years ago

My only consolation now is that their own library seems to work. Start

_Current UsbDEBUGlvl 81 '+' and '-' increase/decrease by 0x01 '.' and ',' increase/decrease by 0x10 't' will run a 10MB write/read test and print out the time it took. 'e' will toggle vbus off for a few moments.

Long filename support: Enabled Total EXT RAM banks 0 Available heap: 7132 Bytes SP 21ef Available heap: 7105 Bytes VBUS on USB state = 20 USB state = 40 USB state = 50 USB state = 51 USB state = 90 LUN: 0 Total Sectors: 00772c80 7810176 Sector Size: 0200 512 Partition 0 type 0xb

Open an existing file (message.txt). Error 4, message.txt not found.

Create a new file (hello.txt).

Write a text data. (Hello world!) 14 bytes written.

Close the file.

Open root directory.

Directory listing... Available heap: 5982 Bytes -rw--a 14 HELLO.TXT (Hello.TxT)

Test completed. Available heap: 5984 Bytes_

An easy solution will be to purchase the Standard Arduino ADK and get on with the project, but that will take approximately 3 weeks of waiting for the shipment. It is sometimes impossible to trust the schematics you get from China. They could have done 21 revisions after the publication for their own consumption.

It looks like they have buffer chips to convert the signal levels from the MAX chip to the ATMega

I have tried to compare what they did (they heavily modified your code) with your USB_Host_Shield_2.0 with a view of noting the important difference to no avail. ...my coding skill isn't that strong.

Can you please help with the easiest solution that you think while I try to get a Standard Arduino ADK? I will surely appreciate this.

shadeyinka commented 7 years ago

Hello My Arduino MEGA ADK (original and direct from https://store.arduino.cc/arduino-mega-adk-rev3 ) finally arrived yesterday

The Good News: Board is OK. Compiles and executes your UHS20 example testusbhostFAT The Bad News:

  1. UHS_FS/UHS_KINETIS_FS_HOST/UHS_FS_NEW_DEMO Give a Compile Error C:\Users\HP\Documents\Arduino\libraries\UHS_host/UHS_KINETIS_FSHOST /UHS_KINETIS_FS_HOST.h:24:2: error: #error include dyn_swi.h first

    error include dynswi.h first

  2. UHS_FS/UHS_HOST_SHIELD/UHS_FS_NEW_DEMO Compiles OK Execution gets stuck at _while(KINETISUsb.Init(1000) != 0);
  3. UHS_host/UHS_BULK_STORAGE/UHS_KINETIS_FS_HOST/TEST_BULK_K Give a Compile Error _In file included from C:\Users\HP\Documents\Arduino\libraries\UHS_host/UHS_host.h:54:0, from C:\Users\HP\Documents\Arduino\libraries\UHS_host\UHS_BULK_STORAGE\examples\UHS_KINETIS_FS_HOST\TEST_BULK_K\TEST_BULK_K.ino:40: C:\Users\HP\Documents\Arduino\libraries\UHS_host/UHS_KINETIS_FS_HOST/UHS_KINETIS_FS_HOST.h:24:2: error: #error include dyn_swi.h first

    error include dynswi.h first

  4. UHS_host/UHS_BULK_STORAGE/USB_HOST_SHIELD/TEST_BULK Compiles OK Execution gets stuck at _while(KINETISUsb.Init(1000) != 0);

Is there a setting specifically for Arduino Mega ADK? Thanks for your understanding Arduino IDE 1.8.3 Arduino AVR Board manager 1.6.11

shadeyinka commented 7 years ago

Display from board_qc

Circuits At Home 2011 USB Host Shield Quality Control RoutineInitial reset failed. Unrecoverable error - test halted!! 0x55 pattern is transmitted via SPI Press RESET to restart test

xxxajk commented 7 years ago

You may need to reroute the int line to pin 3, plus some other stuff, possibly. Quite busy with work currently. As far as what board to compile for/what demos, use only the demos for the host shield, and select mega ADK. Again, I do not actually have this board, so I can't really tell you why it doesn't work. If you can send me one, then I could probabbly get it running in a couple minutes, and tell you what to modify.

shadeyinka commented 7 years ago

I did a checkup for Arduino Mega ADK from their site https://store.arduino.cc/arduino-mega-adk-rev3 the board seem to be out of stock. Is there a local site near you where I can purchase it online?

I can pay for it once I know your shipping address. Pls use my private mail to ensure confidentiality.

Thanks so much.

xxxajk commented 7 years ago

Click my avatar, you'll get my email address and I'll give details. No, there is no local stores that carry any such items.

xxxajk commented 7 years ago

Test 1 board_qc


Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register... Die revision 03
SPI long test. Transfers 1MB of data. Each dot is 64K 
................
SPI long test passed
PLL test. 100 chip resets will be performed
Reset oscillator test.
Reset number 1  Time to stabilize, about 2748 microseconds
<SNIP!>
Reset number 99 Time to stabilize, about 2740 microseconds
Reset number 100    Time to stabilize, about 2744 microseconds
Checking USB device communication.

Device connected. Resetting...
USB Device detected.
Performing a bus reset... 
Got device pointer at 0
Getting device descriptor

Descriptor Length:  0x12
Descriptor type:    0x01
USB version:    0x0200
Device class:   0x00
Device Subclass:    0x00
Device Protocol:    0x00
Max.packet size:    0x40
Vendor  ID: 0x0457
Product ID: 0x0151
Revision ID:    0x0100
Mfg.string index:   0x00
Prod.string index:  0x02
Serial number index:    0x03
Number of conf.:    0x01

All tests passed. Press RESET to restart test

Test 2 UHS_FS_NEW_DEMO

Start.

USB HOST READY.
USB HOST state 1d
No media. Waiting to mount /
USB HOST state 02
USB HOST state 0a
USB HOST state 03
USB HOST state 0c
USB HOST state 0d
USB HOST state 60
/ mounted.
Removing '/HeLlO.tXt' file... completed with 4

Starting Write test...
File opened OK, fd = 1
Wrote 19 bytes, File closed result = 0.

Starting Read test...
File opened OK, fd = 1, displaying contents...
]-[ello \/\/orld!

Read completed, last read result = -1 (20), file close result = 0.
Testing rename
file rename result = 0.

Removing '/1MB.bin' file... completed with 0
1MB write timing test  2048 writes, (0), (0),  9485 ms (9 sec)
completed with 0
1MB read timing test 2048 reads, (20),  10413 ms (10 sec)
completed with 0
Directory of '/'
-rw--a      1048576 2017-10-16 20:16:30 1MB.bin
-rw--a           19 2017-10-16 20:16:20 newtest.txt
265003008 bytes available on disk.

Flushing caches...
Remove and insert media...

Let me know here if it also works for you, it should. I shall be pushing the patch very soon.

shadeyinka commented 7 years ago

Hi, Your patch works like a charm on both my ADk clone Robotdyn Arduino Mega ADK and the Official Arduino Mega ADK. I gues the patch can now be made public. Thanks so much for the effort you have put.

Unfortunately, it doesnt support the SD card all the SD card libraries i know. I have tried SD.h, SdFat.h, SdFs.h and SduFat.h.

'Sorry to ask, What does UHS_KINETIS_FS_HOST Do? The two examples do not compile on the ADK. You might want to check them out.

I am happy the code works but will prefer both the SD and the USB card shields work together.

The Output of the UHS3 I paste Here Below: Thanks so much.

_**Start.

USB HOST READY. USB HOST state 1d No media. Waiting to mount / USB HOST state 02 USB HOST state 0a USB HOST state 03 USB HOST state 0c USB HOST state 0d USB HOST state 60 / mounted. Removing '/HeLlO.tXt' file... completed with 4

Starting Write test... File opened OK, fd = 1 Wrote 19 bytes, File closed result = 0.

Starting Read test... File opened OK, fd = 1, displaying contents... ]-[ello \/\/orld!

Read completed, last read result = -1 (20), file close result = 0. Testing rename file rename result = 0.

Removing '/1MB.bin' file... completed with 0 1MB write timing test 2048 writes, (0), (0), 15134 ms (15 sec) completed with 0 1MB read timing test 2048 reads, (20), 14176 ms (14 sec) completed with 0 Directory of '/' -rw--a 1048576 2017-10-17 16:24:04 1MB.bin -rw--a 19 2017-10-17 16:23:48 newtest.txt -rw--- 5000000 2000-01-01 01:00:00 bench.dat -rw--- 11 2000-01-01 01:00:00 TESTFI~1.TXT (test file.txt) -rw--- 53 2000-01-01 01:00:00 DATA00.CSV (Data00.csv) drwhs- 0 2017-09-06 09:34:08 SYSTEM~1 (System Volume Information) -rw--- 54 2000-01-01 01:00:00 DATA01.CSV (Data01.csv) -rw--- 54 2000-01-01 01:00:00 DATA02.CSV (Data02.csv)

-rw--a 376971 2017-09-14 11:49:56 TINYFA~1.ZIP (tinyFAT(1).zip) -rw--a 18261 2017-09-14 11:51:38 ARDUIN~2.ZIP (Arduino_SDuFAT_Library.zip) 3774201856 bytes available on disk.

Flushing caches... Remove and insert media...

shadeyinka commented 7 years ago

Since the UHS30 and the SD card FAT system seem to share a lot in common, wouldn't it be nice if the UHS30 can also handle SD card functions?

shadeyinka commented 7 years ago

I guess the easiest solution by which to resolve the namespace conflicts is to modify an SD card library specifically for the UHS30.

xxxajk commented 6 years ago

Closing, problems assumed resolved.

xxxajk commented 5 years ago

Heads-up... SD card on SPI is now supported. You must have the SDcard detect pin connecting to a real interrupt pin or ARM MCU with built-in pin interrupts for it to work.