我想在Intel Galileo板上编写一些“ hello world”裸机应用程序。当然,使用UEFI打印文本(到UART-1)效果很好,但是我想在没有UEFI任何帮助的情况下“手动”访问UART。
在QEMU中,我的代码运行良好:
#define COM1_PORT (0x03F8)
#define UART_PORT (COM1_PORT)
enum uart_port_offs_t
{ // DLAB RW
THR = 0, // 0 W Transmitter Holding Buffer
RBR = 0, // 0 R Receiver Buffer
DLL = 0, // 1 RW Divisor Latch Low Byte
IER = 1, // 0 RW Interrupt Enable Register
DLH = 1, // 1 RW Divisor Latch High Byte
IIR = 2, // - R Interrupt Identification Register
FCR = 2, // - RW FIFO Control Register
LCR = 3, // - RW Line Control Register
MCR = 4, // - RW Modem Control Register
LSR = 5, // - R Line Status Register
MSR = 6, // - R Modem Status Register
SR = 7, // - RW Scratch Register
};
void uart_init(void)
{
outb(UART_PORT + IER, 0x00); // Disable all interrupts
outb(UART_PORT + LCR, LCR_DLAB);
outb(UART_PORT + DLL, BAUD_LL); // Set divisor (lo byte)
outb(UART_PORT + DLH, BAUD_HL); // (hi byte)
outb(UART_PORT + LCR, LCR_WORD_BITS_8 | LCR_PAR_NONE | LCR_STOP_BITS_1);
outb(UART_PORT + FCR, FCR_ENABLE | FCR_CLR_RECV | FCR_CLR_SEND | FCR_TRIGGER_16);
outb(UART_PORT + MCR, MCR_DSR | MCR_RTS | MCR_AUX2);
}
ssize_t uart_write(const char *buf, size_t len)
{
size_t written = 0;
while (written < len) {
while (!is_output_empty()) {
asm volatile ("pause");
}
outb(UART_PORT + THR, buf[written]);
++written;
}
return written;
}
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Exiting EFI boot services ...\r\n");
SystemTable->BootServices->ExitBootServices(ImageHandle, map_key);
uart_init();
while (1) {
const char s[] = "UART\r\n";
uart_write(s, sizeof (s) - 1);
}
这些规范对我没有太大帮助。我想英特尔Galileo板上的UART不会使用/模拟正常/旧版COM端口3F8h,2F8h,3E8h或2E8h。
谁能告诉我我做错了什么,甚至发布了一个最小的裸机打招呼世界示例?
我假设您瞄准的是英特尔Galileo板上“类似于音频”连接器的串行端口。
这里有一些资源应该有所帮助:
关于此UART的注意事项:
由于第18章有很多内容可供阅读(约67页有用信息),因此在这里我不会重新键入所有内容,请阅读数据表并相应地配置寄存器。
一般说明:
对于裸机的做法首先确保你的启动程序是正确的,配置所有的时钟选项,GPIO默认模式和价值观,定时器如果有,等对于引导清单中读取章节4.12 X1000 UEFI固件作家指南(〜18个事做启动此芯片)。之后,我将通过GPIO上的简单“ LED闪烁”应用程序对其进行验证。
修补3F8h和类似的端口不会帮助解决此SoC的“裸机”问题。您需要直接处理寄存器,或者找到并使用适当的库或框架(也许是UEFI BIOS?)。
特定平台的编程源应该是一个很好的例子。例如,在“英特尔Quark的主板支持软件包源”中,归档文件Quark_EDKII_v1.0.0.tar.gz
是Quark / Galileo的UEFI源代码。在这里,Serial.c和Serial.h文件可能正是您要查找的内容:
Quark_EDKII_v1.0.0 / QuarkSocPkg / QuarkSouthCluster / Uart / Dxe / Serial。*
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句