felis / USB_Host_Shield_2.0

Revision 2.0 of USB Host Library for Arduino.
https://chome.nerpa.tech
1.76k stars 781 forks source link

USB_Host_Shield_Library_2.0 SPI issue in combination with TFT_eSPI #802

Open Paulsburg opened 5 months ago

Paulsburg commented 5 months ago

Hardware: esp32 dev kit Compiler: Arduino IDE 2.2.1

The acm_terminal example doesn't run together with the TFT_eSPI library.

If added some software lines to the example, to test the HostShield-Lib running together with the TFT_eSPI-Lib. Goal is to program a smart USB-terminal to observe the output of all of my esp32 applications without using my laptop. Only displaying the serial datastream, no inputs, no further controls as inputs.

Info:

What might be the problem? I am really helpless.

The used arduino sketch ist added to this issue as ZIP-file. At the end of the sketch I added the serial output for the two described cases. The other esp32 is producing incrementing textlines to test the behavior of the USB_Host_Shield_Lib. You can see them at the end of the serial output.

TEST_GitHub_acm_terminal_to_Display_V0_1_0_iA.zip

Paulsburg commented 5 months ago

// basing on the of the <\USB_Host_Shield_Library_2.0>

include

include

include "pgmstrings.h"

// Satisfy the IDE, which needs to see the include statment in the ino too.

ifdef dobogusinclude

include

endif

include

class ACMAsyncOper : public CDCAsyncOper { public: uint8_t OnInit(ACM *pacm); };

uint8_t ACMAsyncOper::OnInit(ACM *pacm) { uint8_t rcode; // Set DTR = 1 RTS=1 rcode = pacm->SetControlLineState(3);

if (rcode) { ErrorMessage(PSTR("SetControlLineState"), rcode); return rcode; }

LINE_CODING lc; lc.dwDTERate = 115200; lc.bCharFormat = 0; lc.bParityType = 0; lc.bDataBits = 8;

rcode = pacm->SetLineCoding(&lc);

if (rcode) ErrorMessage(PSTR("SetLineCoding"), rcode);

return rcode; }

USB Usb; //USBHub Hub(&Usb); ACMAsyncOper AsyncOper; ACM Acm(&Usb, &AsyncOper);

// ----------------------------- TFT ---------------------------------------------

include

include // Hardware-specific library

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

define TFT_GREY 0x5AEB // New colour

unsigned long testRects(uint16_t color); // -----------------------------------------------------------------------------------

// ############################################# SETUP ###################################### void setup() { // ######################################################################################## Serial.begin(115200);

if !defined(MIPSEL)

while (!Serial) ; // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection

endif

Serial.println("Start");

if (Usb.Init() == -1) Serial.println("OSCOKIRQ failed to assert");

delay(200);

// ----------------- Init_display -------------------

define with_tft true

// if (with_tft) { Serial.println("TESTAUSGABE: TFT_CS: " + String(TFT_CS)); tft.init(); testRects(TFT_WHITE); delay(200); } }

// ############################################### LOOP ###################### void loop() { // ########################################################################### Usb.Task();

if (Acm.isReady()) { uint8_t rcode; // ------------------------------------------------------- // reading the keyboard if (Serial.available()) { uint8_t data = Serial.read(); // sending to the phone rcode = Acm.SndData(1, &data); if (rcode) ErrorMessage(PSTR("SndData"), rcode); } //if(Serial.available()... // -------------------------------------------------------

/* reading the serial interface */
/* buffer size must be greater or equal to max.packet size */
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
    for particular endpoint */
uint8_t buf[64];
uint16_t rcvd = 64;
rcode = Acm.RcvData(&rcvd, buf);
if (rcode && rcode != hrNAK)
  ErrorMessage<uint8_t>(PSTR("Ret"), rcode);

if (rcvd) {  //more than zero bytes received
  for (uint16_t i = 0; i < rcvd; i++) {
    Serial.print((char)buf[i]);  //printing on the screen
  }
}

} //if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. }

unsigned long testRects(uint16_t color) { unsigned long start; int n, i, i2, cx = tft.width() / 2, cy = tft.height() / 2;

tft.fillScreen(TFT_BLACK); n = min(tft.width(), tft.height()); start = micros(); for (i = 2; i < n; i += 6) { i2 = i / 2; tft.drawRect(cx - i2, cy - i2, i, i, color); }

return micros() - start; } / -------------------- #define with_tft true ---------------------------- 15:11:34.353 -> ets Jun 8 2016 00:22:57 15:11:34.353 -> 15:11:34.353 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) 15:11:34.353 -> configsip: 0, SPIWP:0xee 15:11:34.353 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 15:11:34.353 -> mode:DIO, clock div:1 15:11:34.353 -> load:0x3fff0030,len:1344 15:11:34.353 -> load:0x40078000,len:13964 15:11:34.353 -> load:0x40080400,len:3600 15:11:34.353 -> entry 0x400805f0 15:11:34.556 -> Start 15:11:34.556 -> TESTAUSGABE: USB HOST SetDirWrite() pinMode(5, OUTPUT) 15:11:34.556 -> TESTAUSGABE: USB HOST SetDirWrite() pinMode(5, OUTPUT) 15:11:34.556 -> TESTAUSGABE: USB HOST SetDirRead() pinMode(17, INPUT) 15:11:34.715 -> TESTAUSGABE: TFT_CS: 4 /

/ -------------------- #define with_tft false ---------------------------- 14:41:04.363 -> ets Jun 8 2016 00:22:57 14:41:04.363 -> 14:41:04.363 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) 14:41:04.363 -> configsip: 0, SPIWP:0xee 14:41:04.363 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 14:41:04.363 -> mode:DIO, clock div:1 14:41:04.363 -> load:0x3fff0030,len:1344 14:41:04.363 -> load:0x40078000,len:13964 14:41:04.400 -> load:0x40080400,len:3600 14:41:04.400 -> entry 0x400805f0 14:41:04.583 -> Start 14:41:04.583 -> TESTAUSGABE: USB HOST SetDirWrite() pinMode(5, OUTPUT) 14:41:04.583 -> TESTAUSGABE: USB HOST SetDirWrite() pinMode(5, OUTPUT) 14:41:04.583 -> TESTAUSGABE: USB HOST SetDirRead() pinMode(17, INPUT) 14:41:08.410 -> {13}1234567890<0>|| 14:41:08.510 -> {26}1234567890<0>1234567890<1>|| 14:41:08.653 -> {39}1234567890<0>1234567890<1>1234567890<2>|| 14:41:08.740 -> {52}1234567890<0>1234567890<1>1234567890<2>1234567890<3>|| 14:41:08.812 -> {65}1234567890<0>1234567890<1>1234567890<2>1234567890<3>1234567890<4>|| 14:41:08.912 -> {78}1234567890<0>1234567890<1>1234567890<2>1234567890<3>1234567890<4>1234567890<5>|| 14:41:09.054 -> {91}1234567890<0>1234567890<1>1234567890<2>1234567890<3>1234567890<4>1234567890<5>1234567890<6>|| 14:41:09.141 -> {104}1234567890<0>1234567890<1>1234567890<2>1234567890<3>1234567890<4>1234567890<5>1234567890<6>1234567890<7>|| 14:41:09.212 -> {117}1234567890<0>1234567890<1>1234567890<2>1234567890<3>1234567890<4>1234567890<5>1234567890<6>1234567890<7>1234567890<8>|| /

Paulsburg commented 5 months ago

Here are some results of additional investigations on this issue: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Even if I separate the two SPI-members (no more both connected to the VSPI-bus)

Paulsburg commented 5 months ago

I am now asking the same question in Bodmers TFT_eSPI chat. To connect the two issues, Soon I will display here a link to Bodmers chat.

https://github.com/Bodmer/TFT_eSPI/issues/3151

Paulsburg commented 5 months ago

Solution found, see the issue #3151 on TFT_eSPI. Just uncomment the use of the HSPI interface in the user_setup.h