I am developing a test kernel for Raspberry Pi devices. In this case, I need to configure UART so that we can write data to the device and receive data that should be processed by the kernel. I want the test core to work on multiple Raspberry Pi devices. However, there is a small problem:
UART addresses Difference between versions. For example, the address for the RPi 1 UART GPIO line:
0x20200000
But the address for the GPIO URI on the RPi 2 and RPi 3 lines is:
0x3F200000
Naturally, this means that there must be two separate functions UART_INIT: 1 for devices of the line RPi 1 and 1 for RPi 2 and higher.
Here is an example UART processing code. This code is modified from the code provided by osdev:
void uart_init_rpi1()
{
mmio_write(PD_UART_INTERNAL_VALUES_RPI1->UART0_CR, 0x00000000);
mmio_write(PD_GPPUD_RPI1, 0x00000000);
delay(150);
mmio_write(PD_GPPUDCLK0_RPI1, (1 << 14) | (1 << 15));
delay(150);
mmio_write(PD_GPPUDCLK0_RPI1, 0x00000000);
mmio_write(PD_UART_INTERNAL_VALUES_RPI1->UART0_ICR, 0x7FF);
mmio_write(PD_UART_INTERNAL_VALUES_RPI1->UART0_IBRD, 1);
mmio_write(PD_UART_INTERNAL_VALUES_RPI1->UART0_FBRD, 40);
mmio_write(PD_UART_INTERNAL_VALUES_RPI1->UART0_LCRH, (1 << 4) | (1 << 5) | (1 << 6));
mmio_write(PD_UART_INTERNAL_VALUES_RPI1->UART0_IMSC, (1 << 1) | (1 << 4) | (1 << 5) | (1 << 6) |
(1 << 7) | (1 << 8) | (1 << 9) | (1 << 10));
mmio_write(PD_UART_INTERNAL_VALUES_RPI1->UART0_CR, (1 << 0) | (1 << 8) | (1 << 9));
}
UART INIT RPi 2 RPi 3. UART INIT , . , . , . , , RPi 1, RPi 2-3 RPi, ODROID OC-2, . - , UART , , . , , - , RPi Revision . x86 _RTDSC, , NON-x86/x86-64.
, , , : , , C, , /? , C, C volatile assembly.