An Introduction to the AG32

The AG32 is a family of 32-bit RISC-V microcontrollers with a built-in ~2k-logic-element FPGA/CPLD block, aimed at “MCU + small FPGA in one chip” use cases. Documentation for this family of microcontrollers is sparse, especially on the English-speaking side of the Internet. These chips are also rare. Dev boards are available on Taobao, and limited quantities of bare chips are available on LCSC. Despite these problems, this is an extremely interesting chip. This page will introduce the AG32 series of microcontrollers and serve as a ‘zero to blinky LED’ guide for this family of microcontrollers.

This page is a condensed version of what I could find available on the Internet. It’s all the datasheets, forum posts, Taobao listings, and pin mappings I could find, washed through Google Translate and various LLMs, and condensed into a single document. This is not an SDK, although I am working on it. This is what AGM Micro should have produced if they wanted to sell more chips. 公开 does translate, even if some meaning is lost.

For purely selfish reasons, this document focuses solely on the AG32VF303KCU6, the QFN-32 part. There are other, larger packages, and even some with an integrated PSRAM. I’ll leave that for someone else.

What Is The AG32

The AG32 is RV32IMAFC RISC-V CPU (integer, mul/div, atomics, single-precision FPU, compressed instructions) running up to about 248 MHz, with up to 1 MB of on-chip flash and 128 KB SRAM depending on the part. The VF303KCU6 has 256k Flash, 128k SRAM, and no PSRAM. It features a fairly normal suite of peripherals: five UARTs, CAN, I²C, SPI, USB FS+OTG, Ethernet MAC, timers, three 12-bit 3 MSPS ADCs (up to 16 channels), DACs, comparators, RTC, watchdog, etc.

Every AG32 has an embedded AGRV2K FPGA fabric, wired into the MCU over the internal AHB bus. It’s a small non-volatile FPGA bolted to a reasonably beefy MCU, but in one package, with very fast internal connectivity. Some AG32 parts also include some amount of PSRAM or SDRAM, supporting up to 64MB of on-chip RAM. The combination of a small FPGA along with a lot of RAM and a fast microcontroller core in a single chip is extremely interesting for some use cases, but I am not using one of the parts with extra RAM.

The FPGA fabric sits between the MCU peripherals and the physical pins. This means any internal peripheral can be routed to any external pin. UART0 doesn’t have to be on PA9/PA10, or whatever the default is. You’re not limited to assigning UART0 to just a few pairs of pins. If your board layout doesn’t match the default pinout, you just change the configuration file.

The AG32 is available for eighty cents on LCSC in quantity 1000. One of these chips costs a buck fifty. Can you beat that? No, you can’t.

block diagram of the AG32

AGM Micro documentation offers a ‘comparison table’, and Chinese language blogs compare the AG32 to chips made by ST and GigaDevice (the GigaDevice GD32F103 is itself essentially a clone of the STM32F103):

Of course the AG32 is a RISC-V device, and the STM32 is an Arm Cortex device.

These aren’t direct drop-in replacements; there are quirks with the clocks and some different behavior with the peripherals between the STM32, GD32, and AG32. But the overall contour of the landscape is that the AG32 micros are STM32s with a 2k FPGA bolted on.

As far as the FPGA fabric of the AG32 is concerned, official documentation and Chinese language blogs (here’s a page on Scribd) say they integrate AGM’s AGRV2K fabric. This has 2000 LUT4+FF slices, four ‘M9K’-style embedded RAM blocks, and on-chip Flash configuration for instant-on behavior.

The AGM AGRV2K is sometimes mentioned in the same breath as the Altera Cyclone IV; The larger AG10K is commonly described as a drop-in replacement for the Cyclone IV EP4CE10. Capacity-wise, AGRV2K is much smaller than any Cyclone IV (even EP4CE6 is 6,272 LEs), so think “small FPGA/CPLD-class fabric glued onto an MCU”. It’s kinda like the iCE40 LP2K, although you’re not going to be using the open source iCE40 toolchain with the AG32. These aren’t exact comparisons, but it’s a good mental anchor and we’re in the ballpark of what the AG32 actually is.

That’s the AG32. It’s kinda like an STM32 clone, but all the pins are routed through something like an iCE40. But it’s not really that. It’s just like that. Simulacra and simulation, now available in silicon.

Programming Model

The programming model of the AG32 is weird, especially on the FPGA side. The RISC-V half of the chip is programmed a lot like the CH32, over a serial UART with the included bootloader. The FPGA half is also programmed via the UART bootloader. The FPGA can be programmed independently from the RISC-V, and in fact most of the peripherals for the RISC-V are FPGA bitstreams.

There are two IDEs for this chip: VS Code with a Platform IO extension for the RISC-V part of the chip, and Supra for the FPGA half. The following is a linkdump:

Steal all this and put it on the archive.

Compiling code for this chip produces two binaries, code.bin for the MCU and logic.bin for the FPGA. Both binaries need to be flashed for the chip to function, with some caveats. Assume you already have all the peripherals you need and the wiring from the core to the pins is correct. Here, you might only upload code to the MCU. Now assume all your microcontroller code is correct, you only want to change the pin mapping. Here, you only upload code to the FPGA.

Code, both for the MCU and FPGA, is uploaded via a serial bootloader. You may note that this requires a specific UART have dedicated pins, for the AG32VF303KCU6, Pin 20 is IO_UART0_TX, Pin 21 is IO_UART0_RX. Boot0 is Pin 30, and NRST is pin 4.

This thing is fuckin’ weird. This thing is two kids in a trenchcoat. But you start to wonder why you haven’t seen anything like this before.

Linkdump: https://www.aliexpress.us/item/3256808776276288.html https://www.agm-micro.com/upload/userfiles/files/AG32%20MCU%20Reference%20Manual(20250930%e4%bf%ae%e8%ae%a2%e7%89%88%ef%bc%89.pdf https://www.agmcn.com/product/2670.html https://blog.csdn.net/HIZYUAN/article/details/143896318 https://gitcode.com/GitHub_Trending/vscode6/vscode?utm_source=highlight_word_gitcode&word=vscode&isLogin=9&from_link=3a4abfcad0f54dfa73cff43c903b34a8 https://blog.csdn.net/HIZYUAN/article/details/143089245 https://blog.csdn.net/fpcc/article/details/142635533 https://www.scribd.com/document/808084197/MANUAL-Supra-6-2%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8 https://www.agm-micro.com/solutions.aspx?lang=&id=3096&p=2078

back