Ok, I think I found the bug. If you can test it again as before it should work now.
A11 to GND, A10 to 3.3v
A0: 2.58. A1: 2.15. A2: 1.92. A3: 1.94. A4: 1.79. A5: 1.64. A6: 2.20. A7: 2.03. A8: 2.14. A9: 2.26. A10: 3.30. A11: 0.01. A12: 1.44. A13: 1.53. A14: 2.87. A15: 2.42. A16: 2.36. A17: 2.16. A18: 2.08. A19: 2.11. A20: 2.33. A21: 2.45. A22: 1.81.
Differential pairs: 0: 3.30.
A0: 2.59. A1: 2.15. A2: 1.93. A3: 1.95. A4: 1.81. A5: 1.73. A6: 2.16. A7: 1.89. A8: 2.14. A9: 2.26. A10: 3.30. A11: 0.01. A12: 1.38. A13: 1.50. A14: 2.87. A15: 2.43. A16: 2.41. A17: 2.24. A18: 2.16. A19: 2.10. A20: 2.33. A21: 2.43. A22: 1.82.
Differential pairs: 0: 3.30.
A10 to GND, A11 to 3.3v
A0: 1.73. A1: 2.03. A2: 1.98. A3: 1.82. A4: 1.86. A5: 1.73. A6: 2.29. A7: 2.17. A8: 2.06. A9: 2.21. A10: 0.01. A11: 3.30. A12: 2.61. A13: 2.01. A14: 1.64. A15: 1.94. A16: 2.47. A17: 2.15. A18: 2.02. A19: 2.04. A20: 2.21. A21: 2.17. A22: 1.76.
Differential pairs: 0: -3.30.
A0: 1.73. A1: 2.14. A2: 2.08. A3: 2.03. A4: 1.98. A5: 1.75. A6: 2.33. A7: 2.24. A8: 2.11. A9: 2.29. A10: 0.01. A11: 3.30. A12: 2.67. A13: 1.90. A14: 1.64. A15: 1.89. A16: 2.47. A17: 2.17. A18: 2.02. A19: 2.03. A20: 2.21. A21: 2.24. A22: 1.76.
Differential pairs: 0: -3.30.
A0: 1.79. A1: 1.58. A2: 1.60. A3: 1.13. A4: 1.19. A5: 1.26. A6: 1.79. A7: 1.64. A8: 1.54. A9: 1.45. A10: 1.64. A11: 2.25. A12: 2.39. A13: 1.99. A14: 1.60. A15: 1.40. A16: 2.14. A17: 1.89. A18: 1.80. A19: 1.81. A20: 1.90. A21: 1.19. A22: 1.55.
Differential pairs: 0: -0.54.
I ported ELM-CHaN's FATFS to K66 as Teensy library
https://github.com/WMXZ-EU/uSDFS
original is from http://elm-chan.org/fsw/ff/00index_e.html
But needs still some work!
But I'm on it.
I was thinking along the same line (that is why I printed SDHC_BLKATTR after read)
Will continue with your single assignment version
Edit: sdhc-test and uSDFS are corrected to use multi-sector operations correctly
EDIT: removed shdc_test from GitHub as functionality is in uSDFS
I ran the example (you need Serial.printf for printf in die()), commented out write/read, and got directory listing OK. then tried to read my RAW.DAT, but sketch hung on
rc=f_read(&fil,(void *)sector,sizeof(sector),<h);
Maybe file structure that wrote RAW.DAT different from uSDFS?? further study required...
EDIT: I can read TST.C with f_gets() -- is my semantics for f_read() wrong ??
#if (I2C_BUS_NUM >= 2) && (defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)) // 3.1-3.2/3.4/3.5
,{&I2C1_A1, &I2C1_F, &I2C1_C1, &I2C1_S, &I2C1_D, &I2C1_C2,
&I2C1_FLT, &I2C1_RA, &I2C1_SMB, &I2C1_A2, &I2C1_SLTH, &I2C1_SLTL,
{}, 0, 0, {}, 0, 0, I2C_OP_MODE_ISR, I2C_MASTER, I2C_PINS_29_30, I2C_PULLUP_EXT, I2C_RATE_100, I2C_STOP, I2C_WAITING,
0, 0, 0, 0, I2C_DMA_OFF, nullptr, nullptr, nullptr, 0}
#if I2C_BUS_NUM >= 2
if(bus == 1)
{
#if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)// 3.1
if(pins == I2C_PINS_26_31)
Oooops, pilot error, f_read() works just fine (one shouldn't use "()" to define a vector, DUH. I must have had a FORTRAN-moment.)
295us (13.9mbs) for one-sector (512 byte) read from file (bout same as underlying 1-sector read time)
Reading 4*512 bytes in a single f_read() takes 396us (41.4 mbs)
Paul, Do you have sort of a prioritized list of things you would like tested or converted or extended?
Have SPI and I believe working SPI1, although I don't believe my changes have been merged in yet. The merge also added the defines for SPI2 in the main header file. Have not gone beyond that yet, waiting until we know if SPI2 pads will be exposed.
Suggestions?
It looks like it is off to me, like it needs to be fixed: it should be special cased like the LC for pins 37 and 38 and it should be for ALT2 not ALT6.On K66 I got a working I2C Adafruit_SSD1306 on I2C_0 == SCL0/SDA0. { SSD1306_128_64 }
Looking at getting it working on I2C_1 == SCL1/SDA1 I got as far as i2c_t3.h for Wire1. But looking at that it doesn't have altered definitions from T_3.1 using I2C1== i2c_pins == I2C_PINS_29_30 where T_3.5 needs:: I2C_PINS_37_38 [ and perhaps I2C_PINS_4_3 ].
I hacked the Adafruit_SSD1306 to use Wire1 with "#define Wire Wire1" and have my K66 look alike T_3.1 running on those pins 29_30
This special case was modified for T_3.4/T_3.5 but specifies unusable pins - am I missing something is there another way around - or finding an area needing to be fixed?:
And this that ties the T_3.5 to those pins in pinConfigure_:
Adafruit 2.2" SPI TFT Test!
Benchmark Time (microseconds)
Screen fill 1472608
Text 91341
Lines 898389
Horiz/Vert Lines 121168
Rectangles (outline) 77853
Rectangles (filled) 3057596
Circles (filled) 470819
Circles (outline) 392656
Triangles (outline) 284926
Triangles (filled) 1016970
Rounded rects (outline) 171763
Rounded rects (filled) 3340025
Done!
Benchmark Time (microseconds)
Screen fill 435229
Text 20885
Lines 196627
Horiz/Vert Lines 35525
Rectangles (outline) 22592
Rectangles (filled) 903562
Circles (filled) 124462
Circles (outline) 86013
Triangles (outline) 62362
Triangles (filled) 292699
Rounded rects (outline) 41672
Rounded rects (filled) 982471
Done!
-#if defined(__MK20DX128__) || defined(__MK20DX256__)
+#if defined(KINETISK)
f_write seems to work only if there are single cluster writes (buffer sizes up to 2*512-1)
e.g: buffersize = 7*128 is fine, but buffersize=8*128 crashes
NOTE crashes seems to mean USB crashes (loose COM port, need to disconnect USB hub for new upload, button press is not sufficient)
Filesystem my corrupt USB, or vice versa
Still investigating
Tried TFT_ILI9340 library (Sumotoy) - Does not compile (I am using the latest stuff off of github)...
Edited #if defined statements in library now compiles and runs
Code:Benchmark Time (microseconds) Screen fill 435229 Text 20885 Lines 196627 Horiz/Vert Lines 35525 Rectangles (outline) 22592 Rectangles (filled) 903562 Circles (filled) 124462 Circles (outline) 86013 Triangles (outline) 62362 Triangles (filled) 292699 Rounded rects (outline) 41672 Rounded rects (filled) 982471 Done!
It looks like it is off to me, like it needs to be fixed: it should be special cased like the LC for pins 37 and 38 and it should be for ALT2 not ALT6.
If you want I can take a look at it. ...
pinConfigAlt2 = (pullup == I2C_PULLUP_EXT) ? (PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE)
: (PORT_PCR_MUX(2)|PORT_PCR_PE|PORT_PCR_PS);
Adding code to allow pin 26 as CS pin, but wonder:Edit: I may want to do another edit of the main spi.cpp as I believe pin #26 is a valid CS pin (CS0) for SPI... Would need to add it both as a valid pin and also in the two pin test, that you are not using it with either 2 or 10...
bool SPIClass::pinIsChipSelect(uint8_t pin)
{
if (pin == 10 || pin == 9 || pin == 6 || pin == 2 || pin == 15) return true;
if (pin >= 20 && pin <= 23) return true;
return false;
}
bool SPIClass::pinIsChipSelect(uint8_t pin1, uint8_t pin2)
{
if (!pinIsChipSelect(pin1) || !pinIsChipSelect(pin2)) return false;
if ((pin1 == 2 && pin2 == 10) || (pin1 == 10 && pin2 == 2)) return false;
if ((pin1 == 6 && pin2 == 9) || (pin1 == 9 && pin2 == 6)) return false;
if ((pin1 == 20 && pin2 == 23) || (pin1 == 23 && pin2 == 20)) return false;
if ((pin1 == 21 && pin2 == 22) || (pin1 == 22 && pin2 == 21)) return false;
return true;
}
bool SPIClass::pinIsChipSelect(uint8_t pin)
{
switch (pin) {
case 10: return 0x01; // PTC4
case 2: return 0x01; // PTD0
case 9: return 0x02; // PTC3
case 6: return 0x02; // PTD4
case 20: return 0x04; // PTD5
case 23: return 0x04; // PTC2
case 21: return 0x08; // PTD6
case 22: return 0x08; // PTC1
case 15: return 0x10; // PTC0
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
case 26: return 0x01;
#endif
}
return 0;
}
bool SPIClass::pinIsChipSelect(uint8_t pin1, uint8_t pin2)
{
uint8_t pin1_mask, pin2_mask;
if ((pin1_mask = pinIsChipSelect(pin1)) == 0) return false;
if ((pin2_mask = pinIsChipSelect(pin2)) == 0) return false;
if ((pin1 & pin2) != 0) return false;
return true;
}
Yep...Thanks KurtE Looks like you saw what I saw with Wire2 == I2C_PINS_4_3 and Wire1 == I2C_PINS_37_38.
Which Alt will which pins, from my Excel document:Kurt(Paul/?): Am I inferring correctly that all three K66 I2C ports will be MUX(2) when you say "not ALT6"? That is the part I won't see without some RTFM or guidance.
The other thing I took note of was that the K66/K64 seems to have LC interrupt detect, unlike T_3.1 : "//TODO: 3.4 & 3.5 have stop detect interrupt", so those special LC cases will be modelled instead of the T_3.1 workaround.Code:pinConfigAlt2 = (pullup == I2C_PULLUP_EXT) ? (PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE) : (PORT_PCR_MUX(2)|PORT_PCR_PE|PORT_PCR_PS);
This library is old, I have abandoned it. New one il called TFT_ILI93XX and it's ready for K64/K66Wonder how that compares to a Teensy 3.2
Adding code to allow pin 26 as CS pin, but wonder:
To add pin 26 to this, I would need to add tests for 2/26, 26/2, 10/26, 26/10, which is all doable, but wonder if it would make sense, to change both functions like:Code:bool SPIClass::pinIsChipSelect(uint8_t pin) { if (pin == 10 || pin == 9 || pin == 6 || pin == 2 || pin == 15) return true; if (pin >= 20 && pin <= 23) return true; return false; } bool SPIClass::pinIsChipSelect(uint8_t pin1, uint8_t pin2) { if (!pinIsChipSelect(pin1) || !pinIsChipSelect(pin2)) return false; if ((pin1 == 2 && pin2 == 10) || (pin1 == 10 && pin2 == 2)) return false; if ((pin1 == 6 && pin2 == 9) || (pin1 == 9 && pin2 == 6)) return false; if ((pin1 == 20 && pin2 == 23) || (pin1 == 23 && pin2 == 20)) return false; if ((pin1 == 21 && pin2 == 22) || (pin1 == 22 && pin2 == 21)) return false; return true; }
Code:bool SPIClass::pinIsChipSelect(uint8_t pin) { switch (pin) { case 10: return 0x01; // PTC4 case 2: return 0x01; // PTD0 case 9: return 0x02; // PTC3 case 6: return 0x02; // PTD4 case 20: return 0x04; // PTD5 case 23: return 0x04; // PTC2 case 21: return 0x08; // PTD6 case 22: return 0x08; // PTC1 case 15: return 0x10; // PTC0 #if defined(__MK64FX512__) || defined(__MK66FX1M0__) case 26: return 0x01; #endif } return 0; } bool SPIClass::pinIsChipSelect(uint8_t pin1, uint8_t pin2) { uint8_t pin1_mask, pin2_mask; if ((pin1_mask = pinIsChipSelect(pin1)) == 0) return false; if ((pin2_mask = pinIsChipSelect(pin2)) == 0) return false; if ((pin1 & pin2) != 0) return false; return true; }
... Which Alt will which pins, from my Excel document:
. . .
ALT6 >> I2C1_SDA / I2C1_SCL
ALT2 >> I2C3_SDA / I2C3_SCL
ALT5 >> I2C0_SCL / I2C0_SDA
ALT4 >> I2C3_SDA / I2C3_SCL
ALT5 >> I2C2_SDA / I2C2_SCL
ALT2 >> I2C0_SCL / I2C0_SDA
. . .