B4R Question ESP32 error with WIFI and MCUFRIENDS_KBV [solved]

derez

Expert
Licensed User
Longtime User
Trying to compile an old application of a clock on TFT screen with esp32 I see a problem, it does not compile wifi and MCU together. I checked with a clean wifi test:
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    If wifi.Connect2("xxxxxx", "xxxxxxxxx") Then
        Log("Connected to network")
    Else
        Log("Failed to connect to network")
    End If
End Sub

It works with wifi lib but when I just add MCUFRIENDS_kbv and AdafruitGFX it fails:
"C:\\Users\\rdere\\AppData\\Local\\arduino\\sketches\\3CFB92164B6415131FD11C3F1508A0B3\\sketch\\rAdafruitGFX.cpp" -o "C:\\Users\\rdere\\AppData\\Local\\arduino\\sketches\\3CFB92164B6415131FD11C3F1508A0B3\\sketch\\rAdafruitGFX.cpp.o"
In file included from E:\B4ESP\wifi_tft_esp32_test\Objects\src\MCUFRIEND_kbv.cpp:35:
E:\B4ESP\wifi_tft_esp32_test\Objects\src\mcufriend_shield.h: In function 'void write_8(uint16_t)':
E:\B4ESP\wifi_tft_esp32_test\Objects\src\mcufriend_shield.h:1038:5: error: 'GPIO' was not declared in this scope
1038 | GPIo_Out_w1tc = map_8(0xFF); //could define once as DMASK
| ^~~~
E:\B4ESP\wifi_tft_esp32_test\Objects\src\mcufriend_shield.h: In function 'uint8_t read_8()':
E:\B4ESP\wifi_tft_esp32_test\Objects\src\mcufriend_shield.h:1044:19: error: 'GPIO' was not declared in this scope
1044 | return map_32(GPIO.in);
| ^~~~
Multiple libraries were found for "WiFi.h"
Used: C:\Users\rdere\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\libraries\WiFi
Not used: C:\Users\rdere\Documents\Arduino\libraries\WiFi
Using library WiFi at version 3.0.7 in folder: C:\Users\rdere\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\libraries\WiFi
Using library Networking at version 3.0.7 in folder: C:\Users\rdere\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\libraries\Network
Using library NetworkClientSecure at version 3.0.7 in folder: C:\Users\rdere\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\libraries\NetworkClientSecure
Error during build: exit status 1
[92mUsed library[0m [92mVersion[0m [90mPath[0m
[93mWiFi[0m 3.0.7 [90mC:\Users\rdere\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\libraries\WiFi[0m
[93mNetworking[0m 3.0.7 [90mC:\Users\rdere\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\libraries\Network[0m
[93mNetworkClientSecure[0m 3.0.7 [90mC:\Users\rdere\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\libraries\NetworkClientSecure[0m
[92mUsed platform[0m [92mVersion[0m [90mPath[0m
[93mesp32:esp32[0m 3.0.7 [90mC:\Users\rdere\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7[0m
It worked in the past, what went wrong ? Arduino version 2.3.3 , MCU lib version 3.0.0-Release.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
AdafruitGFX it fails: error: 'GPIO' was not declared in this scope
So, it was declared long ago, but was changed, and now it needs to declare. Look for updated lib version, or another lib.
Or add the declaration.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
B4X:
//################################### ESP32 ##############################
#elif defined(ESP32)       //regular UNO shield on TTGO D1 R32 (ESP32)
#define LCD_RD  2  //LED
#define LCD_WR  4
#define LCD_RS 15  //hard-wired to A2 (GPIO35)
#define LCD_CS 33  //hard-wired to A3 (GPIO34)
#define LCD_RST 32 //hard-wired to A4 (GPIO36)

#define LCD_D0 12
#define LCD_D1 13
#define LCD_D2 26
#define LCD_D3 25
#define LCD_D4 17
#define LCD_D5 16
#define LCD_D6 27
#define LCD_D7 14

#define RD_PORT GPIO.out
#define RD_PIN  LCD_RD
#define WR_PORT GPIO.out
#define WR_PIN  LCD_WR
#define CD_PORT GPIO.out
#define CD_PIN  LCD_RS
#define CS_PORT GPIO.out1.val
#define CS_PIN  LCD_CS
#define RESET_PORT GPIO.out1.val
#define RESET_PIN  LCD_RST

static inline uint32_t map_8(uint32_t d)
{
    return (
               0
               | ((d & (1 << 0)) << (LCD_D0 - 0))
               | ((d & (1 << 1)) << (LCD_D1 - 1))
               | ((d & (1 << 2)) << (LCD_D2 - 2))
               | ((d & (1 << 3)) << (LCD_D3 - 3))
               | ((d & (1 << 4)) << (LCD_D4 - 4))
               | ((d & (1 << 5)) << (LCD_D5 - 5))
               | ((d & (1 << 6)) << (LCD_D6 - 6))
               | ((d & (1 << 7)) << (LCD_D7 - 7))
           );
}

static inline uint8_t map_32(uint32_t d)
{
    return (
               0
               | ((d & (1 << LCD_D0)) >> (LCD_D0 - 0))
               | ((d & (1 << LCD_D1)) >> (LCD_D1 - 1))
               | ((d & (1 << LCD_D2)) >> (LCD_D2 - 2))
               | ((d & (1 << LCD_D3)) >> (LCD_D3 - 3))
               | ((d & (1 << LCD_D4)) >> (LCD_D4 - 4))
               | ((d & (1 << LCD_D5)) >> (LCD_D5 - 5))
               | ((d & (1 << LCD_D6)) >> (LCD_D6 - 6))
               | ((d & (1 << LCD_D7)) >> (LCD_D7 - 7))
           );
}


static inline void write_8(uint16_t data)
{
 [B]   GPIO.out_w1tc = map_8(0xFF);  //could define once as DMASK[/B]  *********** this is line1038
    GPIO.out_w1ts = map_8(data);
}

static inline uint8_t read_8()
{
   [B] return map_32(GPIO.in);[/B]  // *********** this is line1044
}

The files from old library and new library are the same. The above code is for the esp32 module the I use. I marked lines 1038 and 1044. Can you show me how to declare the missing GPIO ?
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
Found the answer here https://github.com/prenticedavid/MCUFRIEND_kbv/issues/255 and it works.

Add one line in mcufriend_shield.h :
B4X:
1024    //################################### ESP32 ##############################
1025    #elif defined(ESP32)       //regular UNO shield on TTGO D1 R32 (ESP32)
1026
1027    #include "hal/gpio_ll.h" // GPIO register functions
1028
1029    #define LCD_RD  2  //LED
1030    #define LCD_WR  4
 
Upvote 0
Top