在qemu-stm32运行stm32_p103_demos后,如何模拟按键按下?
Got it, let's work through how to simulate button presses when running the stm32_p103_demos on qemu-stm32. I’ve tinkered with this setup before, so here’s a straightforward way to get it working:
Step 1: Identify the Button’s GPIO Pin
First, check your button demo code to find which GPIO pin the button is mapped to. For most stm32_p103 button examples, this is typically PA0—but double-check the code’s pin definition to be sure (look for lines like GPIO_PIN_0 or similar).
Step 2: Access the QEMU Monitor
When you launch qemu-stm32, you can switch to its built-in monitor to send hardware control commands:
- Press
Ctrl+Alt+2to switch from the serial console (where you see "Led ON") to the QEMU monitor window. - To switch back to the console later, press
Ctrl+Alt+1.
Step 3: Simulate Button Press/Release
Use monitor commands to toggle the GPIO pin state (since buttons usually trigger on a level change, like low for pressed, high for released):
- Simulate button press: Run this command (replace
PA0with your actual pin if different, and adjust the syscon prefix for your STM32 model—stm32f103-sysconis common for stm32_p103):
Thestm32f103-syscon set-gpio-in PA0 00sets the pin to low voltage, mimicking a pressed button. - Simulate button release: Run this to set the pin back to high:
stm32f103-syscon set-gpio-in PA0 1
Quick Troubleshooting Tip
If you’re unsure about the correct syscon command for your STM32 variant, type help in the QEMU monitor—look for entries starting with stm32*-syscon to find the right prefix for your board.
After sending the press command, switch back to the serial console (Ctrl+Alt+1) and you should see the demo’s response to the button input!
内容的提问来源于stack exchange,提问作者exebook

