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

U8G2 does not work on GD32 #92

Closed
flute2k3 opened this issue Jun 4, 2023 · 20 comments
Closed

U8G2 does not work on GD32 #92

flute2k3 opened this issue Jun 4, 2023 · 20 comments
Assignees
Labels
bug Something isn't working Component: I2C Regarding the I2C component waiting for feedback

Comments

@flute2k3
Copy link

flute2k3 commented Jun 4, 2023

I tried to port the I2C OLED code from STM32duino (which is working) to GD32 but failed, the HW I2C I'm using now with GD32 is SCL(PB8) and SDA(PB9), below is the STM32duino codes associated with OLED:

#include <U8x8lib.h>
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);

void setup() {
...
u8x8.begin();
u8x8.setPowerSave(0);
u8x8.setFont(u8x8_font_chroma48medium8_r);
}

void loop() {
...

u8x8.drawString(0,3,"ChipTmp = ");
u8x8.setCursor(10,3);
u8x8.print(In_Temp);

delay(1);
}

the screen is just totally black

@maxgerhardt
Copy link
Member

I tested a SSD1306 display with the "Adafruit SSD1306" library and that worked at the time.

Your pins are correct.

#define PIN_WIRE_SDA PB9
#define PIN_WIRE_SCL PB8

Can you run the https://playground.arduino.cc/Main/I2cScanner/ sketch to see if it detects an I2C device on the bus at all?

@maxgerhardt maxgerhardt self-assigned this Jun 4, 2023
@maxgerhardt maxgerhardt added bug Something isn't working Component: I2C Regarding the I2C component labels Jun 4, 2023
@maxgerhardt
Copy link
Member

maxgerhardt commented Jun 4, 2023

Hmm actually I just plugged in my SSD1306 and it worked fine with the library.

Using

#include <Arduino.h>
#include <SPI.h>
#include <U8x8lib.h>
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);

void setup(void) {
    u8x8.begin();
    u8x8.setPowerSave(0);
    u8x8.setFont(u8x8_font_chroma48medium8_r);
}

void loop(void) {
    u8x8.drawString(0,3,"ChipTmp = ");
    u8x8.setCursor(10,3);
    u8x8.print("Test");
    delay(1000);
}

with platformio.ini

[env]
platform = https://github.com/CommunityGD32Cores/platform-gd32.git
platform_packages = 
    framework-arduinogd32@https://github.com/CommunityGD32Cores/ArduinoCore-GD32.git
monitor_speed = 115200
lib_deps = olikraus/U8g2@^2.34.18

[env:genericGD32F303CC]
board = genericGD32F303CC
framework = arduino

And HW connections between my Bluepill (GD32F303CC chip):

  • GND -> GND
  • 3.3V -> 3.3V
  • PB8 -> SCL
  • PB9 -> SDA

The code runs first try.

What's your platformio.ini? Can you reproduce the problem with my minimal sketch above?

1685904761345

@maxgerhardt
Copy link
Member

We do seem to have some.. room for improvement though, performance-wise. I've noticed that when you do a display clear and redraw, it's visibly slow. Somewhere it's hitting a timeout in the I2C code. You can lower the default timeout (0xF0000U) a bit when you e.g. set build_flags = -DWIRE_I2C_FLAG_TIMEOUT=0x0F000 in the platformio.ini. But even at base settings, it's working for me.

@flute2k3
Copy link
Author

flute2k3 commented Jun 5, 2023

I tried your codes and changed another OLED, same black, hardware connection is the same with only Vcc to 5V (yours 3.3V). BTW, how to upload photo and video?

below is my platformio.ini

; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:genericGD32F303CC]
platform = gd32
board = genericGD32F303CC
framework = arduino
lib_deps = olikraus/U8g2@^2.34.18

@maxgerhardt
Copy link
Member

The SSD1306 OLED with 5V? Doesn't that kill it and would make all the I/O 5V?

@flute2k3
Copy link
Author

flute2k3 commented Jun 5, 2023

the spec says Vcc can accept 3.3V to 5V, there is a smt voltage regulator mounted on the board.

@maxgerhardt
Copy link
Member

What address does the I2C scanner report? #92 (comment)

@flute2k3
Copy link
Author

flute2k3 commented Jun 5, 2023

I got these two line under serial terminal.

I2C Scanner
Scanning...
No I2C devices found

Scanning...
No I2C devices found

Scanning...

@maxgerhardt
Copy link
Member

maxgerhardt commented Jun 5, 2023

Hm... Does my OLED maybe have 4.7K pullups to VCC on SCL and SDA? I haven't run the address scanner on my board yet, but given that the display reacts for me, I guess it should also be found. "No device" looks like either the device is not responding or there's an electrical problem on the I2C bus or the OLED.

@flute2k3
Copy link
Author

flute2k3 commented Jun 5, 2023

no lucky with 4.7k resistor pullup to 5V on both SCL and SDA.

@maxgerhardt
Copy link
Member

And when using only 3.3V?

@flute2k3
Copy link
Author

flute2k3 commented Jun 5, 2023

I think it is my problem, let me try it on breadboard again

@flute2k3
Copy link
Author

flute2k3 commented Jun 5, 2023

ok, I tried on breadboard, with same wiring, one works one does not. the one does not work is a GD32F303CG, and the one I just tested good as exactly what you did, is GD32F303CC. when I try to modify the platformio.ini from CC to CG, it comes with this compile error:

Processing genericGD32F303CG (board: genericGD32F303CG; framework: arduino; platform: https://github.com/CommunityGD32Cores/platform-gd32.git)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/gd32/genericGD32F303CG.html
PLATFORM: GD GD32 (1.0.0+sha.3424e66) > GD32F303CG (96k RAM, 1024k Flash)
HARDWARE: GD32F303CGT6 120MHz, 96KB RAM, 1MB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, sipeed-rv-debugger, stlink)
PACKAGES:

  • framework-arduinogd32 @ 4.20000.210603+sha.a178ad6
  • tool-dfuutil @ 1.9.200310
  • tool-gdlinkcli @ 2.40611.220807+sha.74386ec
  • tool-openocd-gd32 @ 2.1100.211207 (11.0)
    Error: This board doesn't support arduino framework!
  • tool-stm32duino @ 1.0.2
  • toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)

now it comes with another question, how to make the CG work with Arduino-GD32?
on the other hand, the previous DAC1 and PB3 tested were all based on this CG board (platformio.ini claimed as CC), it comes with an issue only for OLED/I2C, it is quite weird to me.

@maxgerhardt
Copy link
Member

maxgerhardt commented Jun 5, 2023

The GD32F303CC variant definition was inherited, while practically all other variant definitions were auto-generated. We don't yet have auto-generation of the Arduino variants for GD32F30x series, which would give is the CG definition.

The problem may be that the CG chip belongs to the "XD" (extra-density) class while the CC chip is "HD" (high-density). This actually changes some very low level register and interrupt definitions.

Could you please do the following as "hat trick": Use the platformio.ini.

[env:genericGD32F303CG]
platform = gd32
; use CC as a base board
board = genericGD32F303CC
; but make it seem like it's a XD chip (as the CG chip actually is)
build_unflags = -DGD32F30X_HD
build_flags= -DGD32F30X_XD
board_build.spl_sub_series = XD
; correct flash and RAM sizes to the bigger ones (of the CG)
board_upload.maximum_size = 1048576
board_upload.maximum_ram_size= 98304
framework = arduino
lib_deps = olikraus/U8g2@^2.34.18

@flute2k3
Copy link
Author

flute2k3 commented Jun 5, 2023

use the provided platformio.ini does pass the compile, but does not solve the issue :-(

@maxgerhardt
Copy link
Member

Can you attach the debugger using the VSCode Debug -> Start Debugging menu, let the firmware run with the play button, and then pause it after some time? Does the call stack show that it's crashed in some exception handler?

@flute2k3
Copy link
Author

flute2k3 commented Jun 5, 2023

I'm not good at debugging, I tried to step into/step out/step over, it keeps going I do not see any crash (lose control?) happen.

@maxgerhardt
Copy link
Member

Let me create a dedicated Arduino variant for the CG chip and verify that it atleast looks and compiles good. Unfortunately I don't have a GD32F303CG chip or board to test with :(

@flute2k3
Copy link
Author

flute2k3 commented Jun 6, 2023

if you have a hot gun, you can replace the stm32F103C8T6 on bluepill by GD32F303CGT6, it is pin to pin replacement. the GD32F303CG itself is quite cheap, wildly available https://www.aliexpress.com/w/wholesale-gd32f303cgt6.html?catId=0&initiative_id=AS_20230606040937&origin=y&SearchText=gd32f303cgt6&spm=a2g0o.detail.1000002.0

but anway I give up the CG chip, the platformio delicately support CC chip with Arduino, and I do not actually need that much money to play with :-) let's focus our energy on CC chips first.

@maxgerhardt
Copy link
Member

Then let's have this tracked in #94 instead since it does work on the out-of-the-box supported CC chip as of now and CG is not yet officially supported herer.

I just ordered a few of these CG chips (really cheap) and I should have a LQFP breakout board to solder them to and hook them up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Component: I2C Regarding the I2C component waiting for feedback
Projects
None yet
Development

No branches or pull requests

2 participants