Skip to content

Commit f03d030

Browse files
shenkidpgeorge
authored andcommitted
powerpc/uart: Choose which UART to use at build time, not runtime.
Microwatt may have firmware that places data in r3, which was used to detect microwatt vs powernv. This breaks the existing probing of the UART type in this powerpc port. Instead build only the appropriate UART into the firmware, selected by passing the option UART=potato or UART=lpc_serial to the Makefile. A future enhancement would be to parse the device tree and configure MicroPython based on the settings.
1 parent 50a7ba2 commit f03d030

File tree

6 files changed

+38
-96
lines changed

6 files changed

+38
-96
lines changed

ports/powerpc/Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ QSTR_DEFS = qstrdefsport.h
66
# include py core make definitions
77
include $(TOP)/py/py.mk
88

9+
# potato or lpc_serial
10+
UART ?= potato
11+
912
ARCH = $(shell uname -m)
1013
ifneq ("$(ARCH)", "ppc64")
1114
ifneq ("$(ARCH)", "ppc64le")
@@ -30,9 +33,7 @@ LIBS =
3033

3134
SRC_C = \
3235
main.c \
33-
uart_core.c \
34-
uart_potato.c \
35-
uart_lpc_serial.c \
36+
uart_$(UART).c \
3637
lib/utils/printf.c \
3738
lib/utils/stdout_helpers.c \
3839
lib/utils/pyexec.c \

ports/powerpc/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ potato UART.
66

77
## Building
88

9-
By default the port will be built for the host machine:
9+
By default the port will be built with the potato uart for microwatt:
1010

1111
$ make
1212

13+
To instead build for a machine with LPC serial, such as QEMU powernv:
14+
15+
$ make UART=lpc_serial
16+
1317
## Cross compilation for POWERPC
1418

1519
If you need to cross compilers you'll want to grab a powerpc64le

ports/powerpc/main.c

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ int main(int argc, char **argv) {
6565
int stack_dummy;
6666
stack_top = (char *)&stack_dummy;
6767

68-
// microwatt has argc/r3 = 0 whereas QEMU has r3 set in head.S
6968
uart_init_ppc(argc);
7069

7170
#if MICROPY_ENABLE_PYSTACK

ports/powerpc/uart_core.c

-73
This file was deleted.

ports/powerpc/uart_lpc_serial.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,24 @@ static int lpc_uart_rx_empty(void) {
9696
return !(lpc_uart_reg_read(REG_LSR) & LSR_DR);
9797
}
9898

99-
void lpc_uart_init(void) {
99+
void uart_init_ppc(void) {
100100
lpc_uart_base = LPC_UART_BASE;
101101
}
102102

103-
char lpc_uart_read(void) {
103+
int mp_hal_stdin_rx_chr(void) {
104104
while (lpc_uart_rx_empty()) {
105105
;
106106
}
107107
return lpc_uart_reg_read(REG_THR);
108108
}
109109

110-
void lpc_uart_write(char c) {
111-
while (lpc_uart_tx_full()) {
112-
;
110+
111+
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
112+
int i;
113+
for (i = 0; i < len; i++) {
114+
while (lpc_uart_tx_full()) {
115+
;
116+
}
117+
lpc_uart_reg_write(REG_RBR, str[i]);
113118
}
114-
lpc_uart_reg_write(REG_RBR, c);
115119
}

ports/powerpc/uart_potato.c

+19-12
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
#include <stdbool.h>
3535
#include "py/mpconfig.h"
3636

37-
#define PROC_FREQ 50000000
37+
#define SYSCON_BASE 0xc0000000 /* System control regs */
38+
#define SYS_REG_CLKINFO 0x20
39+
3840
#define UART_FREQ 115200
3941
#define POTATO_UART_BASE 0xc0002000
40-
uint64_t potato_uart_base;
42+
static uint64_t potato_uart_base;
4143

4244
#define POTATO_CONSOLE_TX 0x00
4345
#define POTATO_CONSOLE_RX 0x08
@@ -60,7 +62,7 @@ static uint64_t potato_uart_reg_read(int offset) {
6062
return val;
6163
}
6264

63-
void potato_uart_reg_write(int offset, uint64_t val) {
65+
static void potato_uart_reg_write(int offset, uint64_t val) {
6466
uint64_t addr;
6567

6668
addr = potato_uart_base + offset;
@@ -96,13 +98,16 @@ static unsigned long potato_uart_divisor(unsigned long proc_freq, unsigned long
9698
return proc_freq / (uart_freq * 16) - 1;
9799
}
98100

99-
void potato_uart_init(void) {
101+
void uart_init_ppc(void) {
102+
uint64_t proc_freq;
103+
100104
potato_uart_base = POTATO_UART_BASE;
101-
potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV, potato_uart_divisor(PROC_FREQ, UART_FREQ));
105+
proc_freq = *(volatile uint64_t *)(SYSCON_BASE + SYS_REG_CLKINFO);
106+
potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV, potato_uart_divisor(proc_freq, UART_FREQ));
102107

103108
}
104109

105-
char potato_uart_read(void) {
110+
int mp_hal_stdin_rx_chr(void) {
106111
uint64_t val;
107112

108113
while (potato_uart_rx_empty()) {
@@ -113,13 +118,15 @@ char potato_uart_read(void) {
113118
return (char)(val & 0x000000ff);
114119
}
115120

116-
void potato_uart_write(char c) {
117-
uint64_t val;
121+
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
122+
int i;
118123

119-
val = c;
124+
for (i = 0; i < len; i++) {
125+
uint64_t val = str[i];
120126

121-
while (potato_uart_tx_full()) {
122-
;
127+
while (potato_uart_tx_full()) {
128+
;
129+
}
130+
potato_uart_reg_write(POTATO_CONSOLE_TX, val);
123131
}
124-
potato_uart_reg_write(POTATO_CONSOLE_TX, val);
125132
}

0 commit comments

Comments
 (0)