How to run microcontroller program in Keil?

To run a microcontroller program in Keil µVision, you usually do one of two things:
Run on real hardware (flash + debug via ST-LINK/J-LINK/ULINK)
Run in the simulator (only for some MCUs, with limitations)
Here’s the practical workflow.
A) Run on real hardware (recommended)
1) Create / open the project
Open µVision → Project → Open Project… (
.uvprojx)Or Project → New µVision Project… and select your MCU.
2) Add startup + CMSIS + device packs (if needed)
Pack Installer (left side) → install the pack for your MCU (e.g., STM32F4xx).
Make sure you have:
Startup file (startup_*.s)
System file (system_*.c)
CMSIS headers
(Keil packs usually provide these.)
3) Build the program
Click Build (hammer icon) or press F7
Fix any errors until you get 0 Errors.
4) Configure the debug adapter
Go to Project → Options for Target…
Debug tab
Select your debugger:
ST-Link Debugger (common for STM32)
J-LINK / ULINK if you have them
Click Settings…
Choose interface: SWD (recommended) or JTAG
Set SWD clock (start lower like 1 MHz if connection is flaky)
Utilities tab
Check Use Target Driver for Flash Programming
Select the correct flash algorithm for your chip (Keil usually auto-adds it from the pack)
5) Start debugging (“run”)
Click Start/Stop Debug Session (or Debug → Start/Stop Debug Session)
Keil will:
connect to the target
download (flash) the program
halt at
main()(depending on settings)
6) Run / step
While in debug mode:
Run: F5
Step: F11 (step into), F10 (step over)
Reset: Ctrl+F5
Set breakpoints by clicking left margin.
B) Run in Keil Simulator (if supported)
Some MCUs/cores are supported by the built-in simulator, but most STM32 peripheral behavior is limited.
Options for Target → Debug
Select Use Simulator
Start debug session
Use Run/Step as above
Good for:
basic C logic
CPU register inspection
Not great for:real UART/I2C/SPI, clocks, DMA, etc.
Common gotchas (and fixes)
“Cannot connect to target”
Make sure SWDIO/SWCLK/GND are connected (and NRST helps a lot)
Lower SWD clock in Debug settings
Use “Connect under reset” if available
Ensure board is powered and grounds are common
Program downloads but doesn’t “run”
Check clock setup (bad PLL config can lock up)
Verify you’re not stuck in HardFault (use call stack)
Ensure your
main()is reached (breakpoint)
Flash programming fails
Wrong flash algorithm selected (Utilities tab)
Read-out protection enabled on some chips (need mass erase)



