CommunityGD32Cores / gd32-pio-projects

PlatformIO test projects for the new GD32 platform and arduino core
44 stars 10 forks source link

Is there a howto for utlizing reference firmware examples? #4

Closed crosswick closed 2 years ago

crosswick commented 2 years ago

Hi again - this time I'd like to try out an I2S example project for the GD32E103, and I thought I'd try to use the factory firmware examples first. A bit of a primer on how to make a PlatformIO project out of that would be very welcome.

crosswick commented 2 years ago

Ah in the mean time I've found these two to study:

https://github.com/CommunityGD32Cores/gigadevice-firmware-and-docs/blob/main/GD32F30x/GD32F30x_Firmware_Library_V2.1.2/Examples/ADC/ADC0_temperature_Vref/main.c

and

https://github.com/CommunityGD32Cores/gd32-pio-projects/blob/main/gd32-spl-adc-core-temp-gd32f30x/src/main.c

maxgerhardt commented 2 years ago

Sorry, I'll add a proper tutorial for this in the README.

The TL;DR is, if your project doesn't need any complicated libraries (like the USB stack or whatever), you create a new SPL project for your target chip, that gives you the base folder structure and platformio.ini. Now copy all files from the example (like this one) into the src/ folder of the PlatformIO project, but don't copy the x_libopt.h file, since this is included in our SPL package. Then it should compile right away with no further configuration.

crosswick commented 2 years ago

Alright, thank you - and when you say "create a new SPL project for your target chip", do you mean starting with this project for example?

https://github.com/CommunityGD32Cores/gd32-pio-projects/tree/main/gd32-spl-blinky

maxgerhardt commented 2 years ago

That can be used as a starting project but its platformio.ini is filled with a lot of boards, if you just have one target board you'd have to delete all the [env:...] and create a new env with the board you have. What I meant is that you can create one in the regular PlatformIO new project wizard though. In the board searchbox you can start typing your chip name (GD32...) and select "SPL" as framework, give the project a name and click finish.

crosswick commented 2 years ago

Thanks, that worked - although I did need to change the GPIO pin in gd32e10x_eval.h because I am using a different board.

Also for some reason in the E103 I2S example the LED behavior seems inverted from the description, but that's beyond the scope of this issue, and it could be I'm simply overlooking something.

maxgerhardt commented 2 years ago

If the GD32-E103 board has an inverted-LED logic, i.e., drive pin LOW to make LED light up, and your board has a regular-logic with drive HIGH -> light (or vice-versa), the app will have the inverted behavior, so that is well possible.

crosswick commented 2 years ago

Right - I just verified that is indeed the case by commenting out the existing LED logic; using

gd_eval_led_off(LED2);

turns the LED on.