CommunityGD32Cores / ArduinoCore-GD32

Arduino core for GD32 devices, community developed, based on original GigaDevice's core
Other
89 stars 33 forks source link

U8G2 does not work on GD32 #92

Closed flute2k3 closed 1 year ago

flute2k3 commented 1 year ago

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

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 commented 1 year ago

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

Your pins are correct.

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/blob/a178ad6ef661aff6b0b91245163ba4791f279a09/variants/GD32F303CC_GENERIC/variant.h#L96-L97

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 commented 1 year ago

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):

The code runs first try.

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

1685904761345

maxgerhardt commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

flute2k3 commented 1 year ago

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

maxgerhardt commented 1 year ago

What address does the I2C scanner report? https://github.com/CommunityGD32Cores/ArduinoCore-GD32/issues/92#issuecomment-1575668600

flute2k3 commented 1 year ago

I got these two line under serial terminal.

I2C Scanner Scanning... No I2C devices found

Scanning... No I2C devices found

Scanning...

maxgerhardt commented 1 year ago

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 commented 1 year ago

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

maxgerhardt commented 1 year ago

And when using only 3.3V?

flute2k3 commented 1 year ago

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

flute2k3 commented 1 year ago

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:

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 commented 1 year ago

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 commented 1 year ago

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

maxgerhardt commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Then let's have this tracked in https://github.com/CommunityGD32Cores/ArduinoCore-GD32/issues/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.