English | 中文
Arduino for Keil is a lightweight implementation of the Arduino framework, enabling AT32 / STM32 series MCUs to support Arduino syntax with compilation and debugging in the Keil MDK environment.
- Leverage the Arduino Ecosystem — Directly reuse thousands of Arduino libraries (Adafruit, Arduboy, SdFat, etc.), significantly reducing development effort.
- Optimized Hardware Access — Uses register + macro optimization to minimize function call overhead, achieving near bare-metal performance.
- Minimal Footprint — Compared to stm32duino and HAL, this project delivers smaller code size and faster compilation.
- Flexible Development — Freely mix Arduino API, Standard Peripheral Library, and direct register access in the same project.
| Vendor | MCU Family | Platform Directory |
|---|---|---|
| ST | STM32F0xx | Platform/STM32F0xx |
| ST | STM32F10x | Platform/STM32F10x |
| ST | STM32F4xx | Platform/STM32F4xx |
| Artery | AT32F4xx | Platform/AT32F4xx |
| Artery | AT32F421 | Platform/AT32F421 |
| Artery | AT32F43x | Platform/AT32F43x |
graph TB
APP["<b>Application</b><br/>User Code · Third-Party Libraries<br/><sub>setup() / loop() · Adafruit · Arduboy · SdFat ...</sub>"]
API["<b>Arduino API</b><br/>pinMode · digitalWrite · analogRead · Serial · SPI · Wire · Servo · Tone · String"]
CORE["<b>Core HAL</b><br/>GPIO · PWM · ADC · DMA · Timer · EXTI · USART · Delay · WDG · RTC"]
HW["<b>Hardware</b>"]
APP --> API --> CORE --> HW
CORE -. "Register + Macro" .-> HW
CORE -. "StdPeriph API" .-> HW
HW --- STM32["STM32<br/><sub>F0xx · F10x · F4xx</sub>"]
HW --- AT32["AT32<br/><sub>F4xx · F421 · F43x</sub>"]
classDef app fill:#f0f0f0,stroke:#aaa,color:#333
classDef api fill:#dce9f5,stroke:#7a9cc6,color:#333
classDef core fill:#d5ecd4,stroke:#7ab87a,color:#333
classDef hw fill:#e0d4ee,stroke:#9a82b5,color:#333
class APP app
class API api
class CORE core
class HW,STM32,AT32 hw
-
Install the firmware pack for your target platform (see Packs).
⚠️ If a newer version of the pack is already installed, uninstall (Remove) it first using Keil's built-in Pack Manager. -
Open Keilduino/Platform and select the directory matching your MCU.
-
Open the Keil project file (
.uvprojx) inside theMDK-ARMfolder. -
Write your code in
main.cppusingsetup()andloop():
#include <Arduino.h>
static void setup()
{
Serial.begin(115200);
pinMode(PA0, OUTPUT);
}
static void loop()
{
digitalWrite(PA0, HIGH);
delay(1000);
digitalWrite(PA0, LOW);
delay(1000);
}Arduino API, Standard Peripheral Library functions, and direct register operations can be used together:
void setup()
{
pinMode(PA0, OUTPUT); // Arduino API
}
void loop()
{
GPIOA->BSRR = GPIO_Pin_0; // Direct register access
delay(1000);
GPIO_ResetBits(GPIOA, GPIO_Pin_0); // Standard Peripheral Library
delay(1000);
}Keilduino/
├── Application/ # User code (main.cpp)
├── ArduinoAPI/ # Arduino-compatible API layer
│ ├── Arduino.h/c # Core API (pinMode, digitalWrite, analogRead ...)
│ ├── HardwareSerial → Platform-specific
│ ├── SPI → Platform-specific
│ ├── Wire.h/cpp # Software I2C
│ ├── Print / Stream # Base I/O classes
│ ├── WString # Arduino String class
│ ├── Tone # Tone generation
│ └── WMath # Math utilities
├── Libraries/ # Built-in libraries (Servo, etc.)
└── Platform/ # MCU-specific implementations
├── STM32F0xx/
├── STM32F10x/
├── STM32F4xx/
├── AT32F4xx/
├── AT32F421/
└── AT32F43x/
├── Config/ # mcu_config.h (peripheral enable/disable, pin mapping)
├── Core/ # HAL drivers (GPIO, ADC, PWM, Timer, EXTI, USART ...)
└── MDK-ARM/ # Keil project file
Example code is available in the Example directory:
| Example | Description |
|---|---|
| Basic.cpp | GPIO, PWM, ADC, Serial |
| PWM.cpp | PWM initialization and duty cycle control |
| Timer.cpp | Timer interrupt callbacks |
| USART.cpp | Serial communication with interrupt |
| ADC_DMA.cpp | Multi-channel ADC with DMA |
| EXTI.cpp | External interrupt (button press) |
| GPIO_Fast.cpp | Fast GPIO macros for high-speed I/O |
See the Arduino Library Porting Guide for a step-by-step walkthrough.
- Do not remove the
mainfunction inmain.cpp. - When adding third-party libraries, provide the full include path and add all
.cppsource files to the Keil project. - Some libraries may require minor modifications for platform compatibility. Check compiler error messages or open an issue.
MIT License — Copyright (c) 2017 - 2025 _VIFEXTech