CommunityGD32Cores / platform-gd32

PlatformIO platform for ARM-based GD32{F,E,L,W} chips. Work in Progress!
67 stars 28 forks source link

Add GD32F10x to known datasheets #49

Open dmlambo opened 1 year ago

dmlambo commented 1 year ago

Hello @maxgerhardt ! I've made some changes to add support for f103, but with only moderate success.

I hope this doesn't go against the grain for you, it's a new codebase for me. :) If you want to grab the relavent parts and merge it yourself, by all means!

What's not in the change, obviously, are all the additions to ArduinoCore-GD32 to make it compile. There wasn't too much to be done to get it going, just adding the startup files, variants, and the GD32F10x_firmware (cmsis/spl).

I got to a point where it was compiling and I could upload firmware, but I don't have an external debugger, so I can't say where it stops, other than it stops in the bootloader. I tried changing the FLASH offset with no luck. I'm not going to look into it any further without a way of actually debugging it.

maxgerhardt commented 1 year ago

First of all, I'm amazed that someone was able to look through this mess of a script and pin system I made and still make sensible additions to it. Woah. The changes do look good.

What's not in the change, obviously, are all the additions to ArduinoCore-GD32 to make it compile. There wasn't too much to be done to get it going, just adding the startup files, variants, and the GD32F10x_firmware (cmsis/spl).

Could you still PR that in at https://github.com/CommunityGD32Cores/ArduinoCore-GD32/ for reference, so I can have your reference state? I do have a ST-Link debuger and should also have a F103 board somewhere, so I am able to debug if it stops somewhere for whatever reason.

dmlambo commented 1 year ago

No problem! It's interesting work! 😄

Here's a draft PR with the changes to the arduino core.

I went a little crazy after staring at the code for about 12 hours straight and had to stop cold, so it's in a bit of a dangling state. But that's the gist of the changes.

dmlambo commented 1 year ago

Ah, found the problem. The startup .S didn't match the linker script in /variants... the section name and stack pointer name were wrong, so the isr vector table wasn't being placed at 0x0. I can now get an LED to blink. Hooray!

I also made a very expensive STLink by hooking up an RPi with OpenOCD to my f103 board (someone made an SWD bit blaster interface) and using remote GDB in vscode to debug the bootloader. I spent maybe 3 hours saving the $7 it'd cost from Amazon. At least I can debug my code now! 😃

dmlambo commented 1 year ago

Hmm, were the build failures my fault?

maxgerhardt commented 1 year ago

No, they were broken with a SPL update in the Arduino core in which they just removed support for gd32f170,190 chips (but fixed bugs for other f1x0 series chips). That is still an open issue to fix.

dmlambo commented 1 year ago

Incoming. 😄

This is a doozie, I know. I went ahead and added pin remapping logic for A family boards. It's not fully tested, but it builds with additional changes to the package which I haven't pushed yet.

So basically I had to hand-code a structure to describe the remappings, and it's all laid out quite clearly in the user manual. There are too many gotchas to make tabula worth it, in this case. It took about 3 hours to write it all out, but that was including figuring out the best layout for the remapping structure.

The main differences are:

I don't guarantee I didn't break the other family of boards. I think there's opportunity to separate them a bit more, and I may tackle that a bit next. I'll do some testing on my board locally as well to make sure it does mostly what it's supposed to. It also got a bit ugly with the pin gather and adding ALT decorations, so I may try to clean that up a little bit, or maybe just add some comments to justify the ugliness. 😆

I'll push my changes to ArduinoCore as well so you can see the whole context.

Let me know what you think!

dmlambo commented 1 year ago

Just noticed a problem in the variant.h generator, it doesn't create all the ALT pins. Whoops.