My first serious work with STM processors as powerful ARM-based Arduinos started with ST32L071 and is documented here. As part of that article, I found a way to integrate a custom board into the Arduino environment and how to use the ST-Link to upload a sketch from the Arduino IDE. Satisfied as I am with that work, I realize that no one is likely to build any of my L071 based Arduinos, even if they can be itsy-bitsy, low power, etc. However, my work may still be very useful!
Let's talk about the WeAct Duino. As discussed in the Description section above, the STM32G431 on the WeAct Mini Core Board offers a lot of power along with many peripherals. WeAct offers this unit at a very affordable price - less than three bucks! (Even in quantity, the G431 chip from Digikey costs more than the cost of the system from WeAct. How can they make it so cheap? Who knows! But we can all benefit!) While the G4xx draws more power than the L0xx, it is an M4 core with floating point hardware, runs over 4 times faster, and has additional resources. The version from WeAct is in a 48 pin package, so more of the resources are accessible. ST Nucleo versions of the G431 are available from Digikey (and others). The 32 pin version costs $12 and the 64 pin version is $16. Both are significantly larger than the WeAct board, but not any more powerful (same chip).
As a useful bonus, WeAct also offers a clone of the ST-LINK_2.1 programmer. Not only does it cost half what the cheapest ST version costs, it also provides a serial interface. The usual sort of Serial.print() debug can be easily used for program debug; for harder problems, gdb (g-debugger) can be invoked as described here (but it might be broken also - not sure)??
So lots of reasons to love the G431, but how do we use it as an Arduino?? That brings us back to my work on the L071! As mentioned above, that project is currently broken. It will be fixed soon and the documentation will be directly applicable to the G431. In the paragraphs to follow, I will explain how to make the G431 into an Arduino: WeAct Duino!
Let's have a look at the hardware side. WeAct supplies dual rows of square pins to be soldered into the holes in the board, but I wanted something that could plug into a breadboard. I used Arduino connectors on the inside rows and standard square pins on the outer rows as shown.
Now I can plug the WeAct Duino into a breadboard if I want and still have a row or two of connections available for each pin.
WeAct kindly provides pdf versions of the schematics and the board layout. These are very helpful in understanding the design and how to use it effectively. I've included these in the Files section.
The files that actually define a board to the Arduino IDE are those in the variant directories. This is all (or soon will be) explained in the revisions to the tDuino prject referenced above. For now, know that the necessary files (which you will put in place in a few paragraphs) have been suitably modified for the WeAct Duino. The external 8MHz clock crystal on the WeAct board is implemented as the system clock source. The WeAct Duino board runs at 170MHz.
To assist in understanding and using the resources of the WeAct Duino, I created a map of the pin functions. This is WeAct_Pin_Map.png in the Files section, and will be used as a guide to experiments in the Project Logs to follow.
Final hardware note: There are still a few details of the WeAct board that are not clear to me. I am still investigating and will report as I learn.
Hardware ready, let's look at software. Although I will explain all the steps I went through to add the WeAct Duino to the Arduino IDE (as part of the update to the tDuino project), I've provided the necessary files so you can just copy them and go. I'm now running Ubuntu 18.04, but this should work with other recent versions and operating systems. My Arduino version is 1.8.15, but more recent versions should work also. (However, I haven't tried Arduino 2.0 or later.)
To begin, install the STM32 MCU Based Boards version 2.6.0. This isn't quite as clean as it might be and can't be done from the Arduino Boards manager as might be expected. ST provides simple instructions. Follow these, restart Arduino, and verify that the ST processors show up in the boards menu as shown in the instructions. (I'm not sure if you need to install STM32CubeProgrammer or not. If you try uploading to the WeAct Duino from Arduino and it doesn't work, then install the STM32CubeProgrammer per the instructions.) I'm don't know exactly how to test this on my system.
Next, you'll need a place to put the WeAct Duino variant. Find your Arduino Sketchbook location from the Arduino IDE using File > Preferences. The Sketchbook location is the first entry in the window. In that location, create a new directory named "hardware" (without the quotes).
Then copy WeActDuino.zip from the Files area of this project. Unzip it into the hardware directory you just created. Verify that you have the correct structure, then restart Arduino. You should see an entry in the Tools -> Board menu named "WeActDuino Boads (in sketchbook)" with a single item: "weActDuinoG431".
Each Project Log will show how to implement a feature or one of the interfaces for the G431. I'll start with a couple of obvious ones, and build. If there are any specific requests, please post them to the Comments. I'll try to respond to them. Don't expect everything to be revealed at once!
First Log: Getting Started and Blinky. Blinky, of course! But this really explains how to download a program using the ST-Link. Coming soon:
Second Log: Using a serial port (USART), along with the ST-Link as a serial-to-usb interface for Arduino.
Things left to do (partial list):
I2C interface - OLED Display Must add pullups.
SPI interface - TFT Display Must be sure interfacing is correct (as discussed by pjrc LINK)
Additional serial interfaces - GPS read out.
External interrupt capability. All GPIO pins should have interrupt capability. Need to test and verify.
Using the ADC inputs.
Using PWM. Note that PWM may work on more pins than currently indicated, I just haven't tested it.
Using the DAC outputs.
Timer functions including input capture.
Sleep and low power modes (maybe someday).
And more ...