I am a very beginner of QEMU and mcu programming, recently practicing uart control on QEMU. What I’m trying to do is virtually connect QEMU with host PC through USART2.
I have learned that option -serial
is probably able to do so and tried adding
-serial mon:stdio
=> nothing happened
-serial stdio
=> error, but nothing shown in console.
Processor: STM32F407VG
Board: STM32F4-Discovery
IDE: Eclipse IDE
Host device os: macOS Catalina 10.15.7
Following are my codes and run configuration
#include "stm32f4xx.h"
void UART2_Init(void);
void UART2_Write(int ch);
void delayMs(int delay);
int main(void){
UART2_Init();
while(1){
UART2_Write('H');
delayMs(500);
UART2_Write('i');
delayMs(500);
}
}
void UART2_Init(void){
RCC -> APB1ENR |= 0x20000; // Enable usart2 clock
RCC -> AHB1ENR |= 0x8; // Enable PD5 clock
GPIOD -> AFR[0] = 0x700000; // access PD5 AF7
GPIOD -> MODER |= 0x800;
USART2 -> BRR = 0x0683; // Set buad rate to 9600
USART2 -> CR1 = 0x8; // Tx enable
USART2 -> CR1 = 0x2000; // USART enable
}
void UART2_Write(int ch){
// wait until Tx buffer is empty
while(!(USART2 -> SR & 0x80)){
USART2 -> DR = (ch & 0xff);
}
}