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

pkg/tinyusb: add GD32VF103 support #19256

Merged
merged 20 commits into from Feb 21, 2023

Conversation

gschorcht
Copy link
Contributor

Contribution description

This PR provides the tinyUSB support for GD32VF103 and enables the tinyusb_device feature as well as stdio_tinyusb_cdc_acm for GD32VF103 boards.

Testing procedure

BOARD=sipeeed-longan-nano make -C tests/shell flash term

should work

Issues/PRs references

 This file contains the definitions for the DWC2 USB OTG FS IP Core from Synopsys as also defined in the CMSIS Device Peripheral Access Layer for each STM32 MCU and in the same way for ESP32x SoCs. GD32V MCUs use the same USB IP Core, but the vendor headers for these MCUs use a different register structure and different identifiers. To be able to use the same driver `usbdev_synopsys_dwc2`, the relevant USB IP core definitions have been extracted from `cmsis/f7/Include/stm32f767xx.h` which is under the copyright of STMicroelectronics, see below. This is the same file used by ESP32x SoCs but modified for GD32V MCUs.
@github-actions github-actions bot added Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports labels Feb 7, 2023
@gschorcht gschorcht added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Feb 7, 2023
@gschorcht gschorcht force-pushed the pkg/tinyusb/gd32v_support branch 2 times, most recently from 6134e0f to 7c31b80 Compare February 7, 2023 01:02
@riot-ci
Copy link

riot-ci commented Feb 7, 2023

Murdock results

✔️ PASSED

1026cb5 tests/xtimer_now64_continuity: blacklist GD32V boards

Success Failures Total Runtime
6865 0 6865 12m:25s

Artifacts

@benpicco
Copy link
Contributor

benpicco commented Feb 7, 2023

Hm, when I try this on my sipeed-longan-nano it just hangs with no output.
I do get the USB device though

[ 9187.759546] usb 1-1.6: New USB device found, idVendor=1209, idProduct=7d00, bcdDevice= 1.00
[ 9187.759556] usb 1-1.6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 9187.759560] usb 1-1.6: Product: sipeed-longan-nano
[ 9187.759562] usb 1-1.6: Manufacturer: RIOT-os.org
[ 9187.759565] usb 1-1.6: SerialNumber: 2323232323232323
[ 9187.761936] cdc_acm 1-1.6:1.0: ttyACM0: USB ACM device

@gschorcht
Copy link
Contributor Author

Hm, when I try this on my sipeed-longan-nano it just hangs with no output.

Hm, strange. It definitely works for me without any problems.

@benpicco
Copy link
Contributor

Ok my issue is unrelated to this PR. This happens when I use stdio_tinyusb_cdc_acm together with picolibc, I get the same results on weact-f411ce with FEATURES_REQUIRED=picolibc and tests/pkg_tinyusb_cdc_acm_stdio.

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash

Comment on lines +87 to +89
global_regs->GCCFG |= USB_OTG_GCCFG_PWRON |
USB_OTG_GCCFG_VBUSIG |
USB_OTG_GCCFG_VBUSBCEN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
global_regs->GCCFG |= USB_OTG_GCCFG_PWRON |
USB_OTG_GCCFG_VBUSIG |
USB_OTG_GCCFG_VBUSBCEN;
global_regs->GCCFG |= USB_OTG_GCCFG_PWRON
| USB_OTG_GCCFG_VBUSIG
| USB_OTG_GCCFG_VBUSBCEN;

I just like it pretty 😇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too, but isn't that a matter of taste?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It certainly is, this was just a suggestion.

@benpicco
Copy link
Contributor

still needs squashing 😉

@benpicco
Copy link
Contributor

bors merge

bors bot added a commit that referenced this pull request Feb 17, 2023
19027: sys/fmt: optimize scn_u32_dec scn_u32_hex r=benpicco a=kfessel

### Contribution description

Improves the compilation result for `scn_u32_dec` `scn_u32_hex` especially on `cortex-m` reducing either stack usage and or code size.

This makes use of unsigned int overflow (slightly less better without doing that `hexn`).

See godbolt (original versions got an `o` attached, modified versions got `k`s) all functions are  marked `_S_` defined to `static`

by assigning the global at end the compiled function can be changed (`deco deck  hexo hexk hexkk hexn`)

this PR is `hexkk` and `deck` 

### Testing procedure

run unit-test/test-fmt

```
<RIOT>/tests/unittests$ make tests-fmt
<RIOT>/tests/unittests$ make term
```

### Issues/PRs references

[godbolt](https://godbolt.org/z/MzT1zh4q1)

19256: pkg/tinyusb: add GD32VF103 support r=benpicco a=gschorcht

### Contribution description

This PR provides the tinyUSB support for GD32VF103 and enables the `tinyusb_device` feature as well as `stdio_tinyusb_cdc_acm` for GD32VF103 boards.

### Testing procedure

```
BOARD=sipeeed-longan-nano make -C tests/shell flash term
```
should work

### Issues/PRs references


19269: cpu/gd32v/periph_i2c: interrupt based driver r=benpicco a=gschorcht

### Contribution description

This PR provides an interrupt-driven version of the I2C low-level driver.

The existing I2C low-level driver for GDVF103 uses a busy-waiting approach where the status register is continuously polled while waiting for a certain status when sending or receiving. The MCU is thus occupied the whole time during a send or receive operation.

The driver provided with this PR uses an interrupt-driven approach. This is, while waiting for a certain status when sending or receiving, the calling thread is suspended and woken up by interrupts.

Since the I2C controller allows to receive up to two bytes before the application has to react, receiving a single byte, two bytes or more than two bytes needs a different handling for correct receiption. This requires a tricky implementation which distinguish a number of different case. There the driver requires 860 byte more ROM and 8 byte more RAM.

### Testing procedure

The driver should work with any I2C sensor/actuator. It was tested with
- `tests/driver_bmp180`
   <details>
  
   ```
    main(): This is RIOT! (Version: 2023.04-devel-355-g940c7-cpu/gd32v/periph_i2c_interrupt_driven)
    BMP180 test application
    
    +------------Initializing------------+
    Initialization successful
    
    +------------Calibration------------+
    AC1: 8448
    AC2: -1208
    AC3: -14907
    AC4: 33310
    AC5: 24774
    AC6: 19213
    B1: 6515
    B2: 49
    MB: -32768
    MC: -11786
    MD: 2958
    
    +--------Starting Measurements--------+
    Temperature [°C]: 22.0
    Pressure [hPa]: 1006.49
    Pressure at see level [hPa]: 1025.55
    Altitude [m]: 157
    
    +-------------------------------------+
    Temperature [°C]: 22.0
    Pressure [hPa]: 1006.56
    Pressure at see level [hPa]: 1025.58
    Altitude [m]: 157
    
    +-------------------------------------+
   ```
   
   </details>
- `tests/driver_ccs811`
   <details>
  
   ```
    main(): This is RIOT! (Version: 2023.04-devel-355-g940c7-cpu/gd32v/periph_i2c_interrupt_driven)
    CCS811 test application
    
    +------------Initializing------------+
    
    +--------Starting Measurements--------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 0
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 0
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 0
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 400
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 400
    +-------------------------------------+
    TVOC [ppb]: 0
    eCO2 [ppm]: 400
    +-------------------------------------+
    TVOC [ppb]: 7
    eCO2 [ppm]: 446
    +-------------------------------------+
    TVOC [ppb]: 7
    eCO2 [ppm]: 446
    +-------------------------------------+
    TVOC [ppb]: 7
    eCO2 [ppm]: 446
    +-------------------------------------+
    TVOC [ppb]: 7
    eCO2 [ppm]: 446
    +-------------------------------------+
    ```
   
   </details>
- `tests/driver_sht3x`
   <details>
  
    ```
    main(): This is RIOT! (Version: 2023.04-devel-355-g940c7-cpu/gd32v/periph_i2c_interrupt_driven)
    SHT3X test application
    
    +------------Initializing------------+
    Initialization successful
    
    
    +--------Starting Measurements--------+
    Temperature [°C]: 21.46
    Relative Humidity [%]: 54.50
    +-------------------------------------+
    Temperature [°C]: 21.47
    Relative Humidity [%]: 54.53
    +-------------------------------------+
    Temperature [°C]: 21.46
    Relative Humidity [%]: 54.48
    +-------------------------------------+
    Temperature [°C]: 21.46
    Relative Humidity [%]: 54.47
    +-------------------------------------+
    ```
   
   </details>
- `tests/driver_l3gxxxx`
   <details>
  
    ```
    main(): This is RIOT! (Version: 2023.04-devel-375-g75547-cpu/gd32v/periph_i2c_interrupt_driven)
    L3GXXXX gyroscope driver test application
    
    Initializing L3GXXXX sensor
    [OK]
    
    gyro [dps] x:    +0, y:    -1, z:    -2
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    +0, y:    +0, z:    +0
    gyro [dps] x:    -1, y:    +0, z:    +4
    gyro [dps] x:    +0, y:    +0, z:   -21
    gyro [dps] x:    +0, y:    +0, z:    +6
    gyro [dps] x:   -43, y:    +0, z:   -13
    gyro [dps] x:   -21, y:    -2, z:    +0
    gyro [dps] x:    +0, y:    +1, z:    +3
    gyro [dps] x:   +25, y:    +0, z:    +0
    ```
   
   </details>
- `tests/driver_hd44780` with `pcf8574a` I2C interface

### Issues/PRs references



19286: cpu/esp_common: use generic WIFI_SSID/WIFI_PASS defines r=benpicco a=benpicco



Co-authored-by: Karl Fessel <karl.fessel@ovgu.de>
Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Co-authored-by: Benjamin Valentin <benpicco@beuth-hochschule.de>
@bors
Copy link
Contributor

bors bot commented Feb 17, 2023

Build failed (retrying...):

bors bot added a commit that referenced this pull request Feb 17, 2023
19027: sys/fmt: optimize scn_u32_dec scn_u32_hex r=benpicco a=kfessel

### Contribution description

Improves the compilation result for `scn_u32_dec` `scn_u32_hex` especially on `cortex-m` reducing either stack usage and or code size.

This makes use of unsigned int overflow (slightly less better without doing that `hexn`).

See godbolt (original versions got an `o` attached, modified versions got `k`s) all functions are  marked `_S_` defined to `static`

by assigning the global at end the compiled function can be changed (`deco deck  hexo hexk hexkk hexn`)

this PR is `hexkk` and `deck` 

### Testing procedure

run unit-test/test-fmt

```
<RIOT>/tests/unittests$ make tests-fmt
<RIOT>/tests/unittests$ make term
```

### Issues/PRs references

[godbolt](https://godbolt.org/z/MzT1zh4q1)

19256: pkg/tinyusb: add GD32VF103 support r=benpicco a=gschorcht

### Contribution description

This PR provides the tinyUSB support for GD32VF103 and enables the `tinyusb_device` feature as well as `stdio_tinyusb_cdc_acm` for GD32VF103 boards.

### Testing procedure

```
BOARD=sipeeed-longan-nano make -C tests/shell flash term
```
should work

### Issues/PRs references


Co-authored-by: Karl Fessel <karl.fessel@ovgu.de>
Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
@benpicco
Copy link
Contributor

Kconfig strikes again

bors cancel

@bors
Copy link
Contributor

bors bot commented Feb 17, 2023

Canceled.

@github-actions github-actions bot added the Area: tests Area: tests and testing framework label Feb 21, 2023
@gschorcht
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Feb 21, 2023
@benpicco
Copy link
Contributor

bors merge

bors bot added a commit that referenced this pull request Feb 21, 2023
19256: pkg/tinyusb: add GD32VF103 support r=benpicco a=gschorcht

### Contribution description

This PR provides the tinyUSB support for GD32VF103 and enables the `tinyusb_device` feature as well as `stdio_tinyusb_cdc_acm` for GD32VF103 boards.

### Testing procedure

```
BOARD=sipeeed-longan-nano make -C tests/shell flash term
```
should work

### Issues/PRs references


Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
@gschorcht
Copy link
Contributor Author

bors merge

Hm, I don't think that it will work. I had a problem with tests/xtimer_now32_overflow and tests/xtimer_now64_overflow for which I don't have an idea yet:

make RIOT_CI_BUILD=1 CC_NOCOLOR=1 --no-print-directory -C ./tests/xtimer_now32_overflow clean all --jobs 8
rm -rf /home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/bin/sipeed-longan-nano/pkg-build/nmsis_sdk
rm -rf /home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/bin/sipeed-longan-nano/pkg-build/tinyusb
Building application "tests_xtimer_now32_overflow" for "sipeed-longan-nano" with MCU "gd32v".

/home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/main.c: In function 'main':
/home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/main.c:37:5: error: '_xtimer_current_time' undeclared (first use in this function)
   37 |     _xtimer_current_time = (1LLU << 32U);
      |     ^~~~~~~~~~~~~~~~~~~~
/home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/main.c:37:5: note: each undeclared identifier is reported only once for each function it appears in
/home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/main.c:51:11: error: 'xtimer_t' {aka 'ztimer_t'} has no member named 'long_start_time'
   51 |     if (t2.long_start_time == 1) {
      |           ^
/home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/Makefile.base:146: recipe for target '/home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/bin/sipeed-longan-nano/application_tests_xtimer_now32_overflow/main.o' failed
make[1]: *** [/home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/bin/sipeed-longan-nano/application_tests_xtimer_now32_overflow/main.o] Error 1
make[1]: *** Auf noch nicht beendete Prozesse wird gewartet …
/home/gs/tmp/RIOT-Xtensa-ESP.esp-idf-4.4/tests/xtimer_now32_overflow/../../Makefile.include:749: recipe for target 'application_tests_xtimer_now32_overflow.module' failed
make: *** [application_tests_xtimer_now32_overflow.module] Error 2

@gschorcht
Copy link
Contributor Author

Ah ok, I just have to blacklist them.

@benpicco
Copy link
Contributor

Ah just blacklist the board - those tests rely on xtimer being used (not the ztimer compat API) and ztimer is used by USB.

We should just drop those tests along with the legacy xtimer code already.

@bors
Copy link
Contributor

bors bot commented Feb 21, 2023

Canceled.

@gschorcht
Copy link
Contributor Author

bors merge

@bors
Copy link
Contributor

bors bot commented Feb 21, 2023

Build succeeded:

@bors bors bot merged commit 37b6491 into RIOT-OS:master Feb 21, 2023
@bors
Copy link
Contributor

bors bot commented Feb 22, 2023

try

Timed out.

1 similar comment
@bors
Copy link
Contributor

bors bot commented Feb 22, 2023

try

Timed out.

@gschorcht
Copy link
Contributor Author

Thanks.

@gschorcht gschorcht deleted the pkg/tinyusb/gd32v_support branch February 23, 2023 17:05
@MrKevinWeiss MrKevinWeiss added this to the Release 2023.04 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: tests Area: tests and testing framework CI: no fast fail don't abort PR build after first error CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants