Giter Club home page Giter Club logo

arduinocore-gd32-keyboardio's Introduction

GD32 Arduino Core (New)

Lint Code Base GitHub pull-requests GitHub issues GitHub issues-closed

This is a Arduino core is based off of the original GigaDevice core that was provided by the company in early June 2021 (see https://github.com/CommunityGD32Cores/GD32Core/)

It is currently a work in progress, but believed to be functional on GigaDevice's mBed boards.

The intention is to further develop that original core in an open-source, community-driven manner.

Collaborating

Interested in collaborating? Join our dedicated Discord channel for this at https://discord.gg/59kf4JxsRM.

Media

A GD32F303CC chip (placed on a bluepill PCB) runs its first blinky code with the new Arduino core!

first_blinky_gd32f303cc_1080p.mp4

The same board reading out a DHT11 temperature & humidity sensor and displaying it on an SSD1306 OLED via the Adafruit GFX libraries

dht11_oled_preview

The board runs the Adafruit SSD1306 test sketch

i2c_oled.mp4

And here it is using analogRead() to read the voltage over a potentiomeneter as a 12-bit value.

ADC_OLED_preview

Using this core with PlatformIO

Currently, development of this core is being done using PlatformIO. It uses the custom PlatformIO platform https://github.com/CommunityGD32Cores/platform-gd32.

Using PlatformIO is already possible to very easily edit code in the IDE and even live-debug a chip (with e.g. an ST-Link)

Various example projects for this platform for the SPL framework and this Arduino core are currently hosted at https://github.com/CommunityGD32Cores/gd32-pio-projects.

Using this core with the Arduino IDE

To compile for this core with the Arduino IDE, add the following URL to the boards manager.

https://raw.githubusercontent.com/CommunityGD32Cores/GD32Core-New/main/package_gd32_index.json

This will install the core and compiler toolchain against the 'main' git branch.

grafik

Current state

The gd32-arduino-blinky project compiles for the gd32f307_mbed board and the genericGD32F303CC board and works (see video above).

Multiple more complicated demos work, like an SSD1306 OLED, analog input, Serial, etc. See issue CommunityGD32Cores#8 for the latest state of tested components.

Library compatibility list

Legend:

  • ✔️ = working
  • ❌ = not working at all
  • ⚠️ = some features not working
  • ⁉️ = untested
Name Works? Notes
Adafruit GFX ✔️ Tested in conjunction with SSD1306 OLED, CP437 symbols works
Adafruit SSD1306 ✔️ Tested on SSD1306 I2C 128x64 OLED, entire extensive demo works
SimpleDHT ✔️ Works with DHT11 (Temp & Humidity) and OLED, demo above

Updates / History

31.05.2021:

Initial contact and thoughts about an Arduino core implementation from scratch for GD32 devices with @kemotz via Email.

02.06.2021:

Creation of the Github project https://github.com/maxgerhardt/gd32-arduino-core/ and a discord channel.

10.06.2021:

A custom dev board has been designed and is in production. The repo with the files for it is at https://github.com/kemotz/GD32F1x0-dev-brd.

board_preview

@obra and @algernon join the project.

GigaDevices is contact with a request for information on a potentially existing in-house developed Arduino core and code licensing questions.

16.06.2021:

GigaDeviecs confirms that there is a internally developed Arduino core, sends it over to use and approves of publishing it. The code is also BSD 3-clause licensed.

The original files for this are found at https://github.com/CommunityGD32Cores/GD32Core.

The focus shifts from creating a new Arduino core from scratch to getting the retrieved one working and expanding upon it.

18.06.2021:

Arduino core:

  • Add package.json for PlatformIO compatibility
  • Add tools\platformio\platformio-build.py PlatformIO builder script
  • gives a successful build for the gd32f307_mbed board
  • gives a successful build for the genericGD32F303CC board (and gives a working blinky!)

19.06.2021:

24.07.2021:

  • moved all relevant projects into the Github org instead of personal accounts, adapted URLs
  • build fixes for Linux
  • added CI to projects repository, now builds 15 projects fully automatically
  • Jesse worked on merging new-style Arduino APIs (https://github.com/arduino/ArduinoCore-API/) to this core
  • Jesse started working on USB support (and USB bootloaders)
  • later that day, the new ArduinoCore-API adoption was successfully merged and tested

ToDo / thoughts

ToDos are now all moved to issues.

Supported boards

Everything is WIP now and no full support can be expected yet.

Planned support:

GD32F303CC based boards

bluepill_f303cc

custom GD32F190 board seen above

the boards previously supported by this core, so GD32F303ZE-EVAL and GD32F307VG-MBED

.. more?

arduinocore-gd32-keyboardio's People

Contributors

algernon avatar bjc avatar djix123 avatar maxgerhardt avatar obra avatar tlyu avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

tlyu

arduinocore-gd32-keyboardio's Issues

race condition in `usbd_ep_send`

usbd_ep_send in the vendor firmware has a race condition where it can enable transmission on the endpoint before updating the usb_transc object that the ISR will update. This might be safe within the ISR, but the function can be called from outside the ISR.

avoid EPxCS update race conditions

Even with interrupts disabled, the USBD peripheral runs asynchronously from the CPU core, and can change registers in ways that conflict with the firmware's modifications. This can lead to race conditions.

We should use "invariant" values for unchanged values when modifying EPxCS registers: zeroes for toggle bits, and ones for clear-only bits.

race condition in control request handling

This is a little difficult to describe. The vendor USBD firmware has a bug where if an IN transaction completes on an endpoint as an OUT transaction completion is being handled, and is followed in quick succession by another OUT or SETUP transaction, the OUT or SETUP transaction will take priority over the IN transaction. This is mostly relevant for control transfers. This means that multiple Status IN completions can shadow each other, so that the handler executes only once.

This might cause missed notification of completion events, and corruption of some control transfers. It's definitely visible with trace logging turned on, because logging with reasonable UART speeds adds enough delay to exhibit the problem.

I2C erratum causing data corruption

I've been running into what appears to be an instance of a documented hardware erratum in the I2C peripheral. Interrupts that delay the reading of I2C_DATA can cause invalid data to be read. See Device Limitations of GD32F30x, Version 1.0, 2022-06-20.

The erratum note says that "I2C will read an additional data", implying that the controller will clock in an additional byte from the target. That doesn't appear to happen, as far as I can tell. What appears to happen instead is data corruption: the controller will erroneously duplicate the previously-read byte instead of reading in the next byte.

Observed effects: with USB trace logging active to the hardware serial port, I sometimes got random activations of the Consumer Control volume keys when pressing arrow keys. (These parts of my keymap are the default.) Also, when pressing keys on the right half, Num Lock would spuriously activate. I couldn't make this happen reproducibly, but when it did happen, there tended to be bursts of the corruption. Notably, the Consumer Control key that activated seemed to correspond to the arrow key immediately above it in the same column, which makes sense given the hardware key map. The spurious Num Lock activation seemed to be caused by duplication of the 0x05 length prefix byte.

I was unable to reliably reproduce the problem by making the trace logging emit more characters. I did eventually add a delay directly in the I2C receive function, which did replicate the symptoms that I previously observed.

I have a fix in progress that appears to work so far.

add USB timeouts

USB_Send currently blocks forever if there's nothing polling the endpoint. We should fix this. AVR has a 250ms timeout, though it's not clear that's the best choice for us.

vendor firmware clears `RX_ST` too early

The vendor firmware has a bug where it clears the RX_ST flag too early. An undocumented feature of this flag (though partially documented in the documentation of the STM32F1 peripheral that the GD32 one seems to be trying to emulate) is to "freeze" the SETUP flag in USBD_EPxCS so that incoming tokens won't change it. If RX_ST is clear, then an OUT token not associated with a SETUP transaction can still clear the SETUP flag, even if the transaction is NAKed by the peripheral.

The result is that an incoming SETUP transaction is processed as an OUT transaction, which can lead to all kinds of chaos.

enable/disable interrupts at NVIC not by USBD_CTL

There are a few flags in USBD_CTL that can be changed asynchronously by hardware. To avoid race conditions, we should enable and disable interrupts at the NVIC instead of by read-modify-write operations on USBD_CTL.

emulate USB double buffering

The AVR core uses double buffering for the non-default endpoints. GD32 only supports double buffering for isochronous and bulk endpoints, so we can't use it for interrupt endpoints. (The GD32 also has only 512 bytes of USB packet RAM, less than the AVR.)

We should emulate double buffering, given that we're already maintaining a buffer for each endpoint, to accumulate multiple writes for some situations, etc.

One scenario that could cause problems is a user pressing and releasing a key to resume from suspend. On AVR, this enqueues two HID reports (one key down, one key up) on the peripheral, and nothing blocks or times out until the next transmission attempt on that endpoint. On GD32, the key up event blocks (or times out, if patched to implement timeouts).

Another scenario is the null reports sent at startup. This causes the M100 to lock up when talking to a UEFI or BIOS that only talks to boot devices, because the multi-report endpoint send multiple null reports.

In the longer term, GD32 should implement timeouts, and KeyboardioHID should be more aware of timeouts. For now, emulating double buffering on GD32 might mitigate some of the existing problems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.