Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB_Host_Shield_Library_2.0 SPI issue in combination with TFT_eSPI #802

Open
Paulsburg opened this issue Jan 29, 2024 · 4 comments
Open

Comments

@Paulsburg
Copy link

Paulsburg commented Jan 29, 2024

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.

  • With <with_tft = true> I initialize the TFT and can draw some retangles on the TFT. But afterwards I can't receive serial data from the USB interface.
  • If I switch the init/drawing of the TFT off <with_tft = false> I can receive my serial test data from the USB interface without any problem.

Info:

  • The serial buffer to realize the scrolling on the TFT is not part of this test setup.
  • The TFT SPI-chipselect is connected to GPIO4 and the HostShield SPI-chipselect is connected to GPIO5 on my esp32 testboard.

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
Copy link
Author

Paulsburg commented Jan 29, 2024

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

#include <cdcacm.h>
#include <usbhub.h>

#include "pgmstrings.h"

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif

#include <SPI.h>

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<uint8_t>(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<uint8_t>(PSTR("SetLineCoding"), rcode);

return rcode;
}

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

// ----------------------------- TFT ---------------------------------------------
#include <SPI.h>
#include <TFT_eSPI.h> // 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<uint8_t>(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
Copy link
Author

Paulsburg commented Feb 1, 2024

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)

  • USB-HostShield => VSPI
  • TFT_eSPI => HSPI-Bus
    the issue is still persisting.
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Info from the TFT_eSPI-Lib:
    #define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)
    This problem couldn't be the reason for my problems, because my TFT-MISO is unconnected.
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

@Paulsburg
Copy link
Author

Paulsburg commented Feb 2, 2024

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.

Bodmer/TFT_eSPI#3151

@Paulsburg
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant