Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
8a3842eb
Commit
8a3842eb
authored
Aug 12, 2024
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
qemu-arm/uart: Implement uart_rx_chr.
Signed-off-by:
Damien George
<
damien@micropython.org
>
parent
e8863e44
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
5 deletions
+56
-5
ports/qemu-arm/uart.c
ports/qemu-arm/uart.c
+52
-5
ports/qemu-arm/uart.h
ports/qemu-arm/uart.h
+4
-0
No files found.
ports/qemu-arm/uart.c
View file @
8a3842eb
...
...
@@ -31,14 +31,29 @@
#if defined(QEMU_SOC_STM32)
#define UART_SR_RXNE (1 << 5)
#define UART_CR1_UE (1 << 13)
#define UART_CR1_TE (1 << 3)
#define UART_CR1_RE (1 << 2)
typedef
struct
_UART_t
{
volatile
uint32_t
SR
;
volatile
uint32_t
DR
;
volatile
uint32_t
BRR
;
volatile
uint32_t
CR1
;
}
UART_t
;
#define UART0 ((UART_t *)(0x40011000))
void
uart_init
(
void
)
{
UART0
->
CR1
=
UART_CR1_UE
|
UART_CR1_TE
|
UART_CR1_RE
;
}
int
uart_rx_chr
(
void
)
{
if
(
!
(
UART0
->
SR
&
UART_SR_RXNE
))
{
return
UART_RX_NO_CHAR
;
}
return
UART0
->
DR
;
}
void
uart_tx_strn
(
const
char
*
buf
,
size_t
len
)
{
...
...
@@ -50,11 +65,15 @@ void uart_tx_strn(const char *buf, size_t len) {
#elif defined(QEMU_SOC_NRF51)
typedef
struct
_UART_t
{
volatile
uint32_t
r0
[
2
];
volatile
uint32_t
STARTRX
;
// 0x000
volatile
uint32_t
STOPRX
;
// 0x004
volatile
uint32_t
STARTTX
;
// 0x008
volatile
uint32_t
r1
[(
0x500
-
0x008
)
/
4
-
1
];
volatile
uint32_t
r0
[(
0x108
-
0x008
)
/
4
-
1
];
volatile
uint32_t
RXDRDY
;
// 0x108
volatile
uint32_t
r1
[(
0x500
-
0x108
)
/
4
-
1
];
volatile
uint32_t
ENABLE
;
// 0x500
volatile
uint32_t
r2
[(
0x51c
-
0x500
)
/
4
-
1
];
volatile
uint32_t
r2
[(
0x518
-
0x500
)
/
4
-
1
];
volatile
uint32_t
RXD
;
// 0x518
volatile
uint32_t
TXD
;
// 0x51c
}
UART_t
;
...
...
@@ -62,9 +81,18 @@ typedef struct _UART_t {
void
uart_init
(
void
)
{
UART0
->
ENABLE
=
4
;
UART0
->
STARTRX
=
1
;
UART0
->
STARTTX
=
1
;
}
int
uart_rx_chr
(
void
)
{
if
(
!
UART0
->
RXDRDY
)
{
return
UART_RX_NO_CHAR
;
}
UART0
->
RXDRDY
=
0
;
return
UART0
->
RXD
;
}
void
uart_tx_strn
(
const
char
*
buf
,
size_t
len
)
{
for
(
size_t
i
=
0
;
i
<
len
;
++
i
)
{
UART0
->
TXD
=
buf
[
i
];
...
...
@@ -74,6 +102,7 @@ void uart_tx_strn(const char *buf, size_t len) {
#elif defined(QEMU_SOC_MPS2)
#define UART_STATE_TXFULL (1 << 0)
#define UART_STATE_RXFULL (1 << 1)
#define UART_CTRL_TX_EN (1 << 0)
#define UART_CTRL_RX_EN (1 << 1)
...
...
@@ -90,7 +119,14 @@ typedef struct _UART_t {
void
uart_init
(
void
)
{
UART0
->
BAUDDIV
=
16
;
UART0
->
CTRL
=
UART_CTRL_TX_EN
;
UART0
->
CTRL
=
UART_CTRL_TX_EN
|
UART_CTRL_RX_EN
;
}
int
uart_rx_chr
(
void
)
{
if
(
!
(
UART0
->
STATE
&
UART_STATE_RXFULL
))
{
return
UART_RX_NO_CHAR
;
}
return
UART0
->
DATA
;
}
void
uart_tx_strn
(
const
char
*
buf
,
size_t
len
)
{
...
...
@@ -104,7 +140,9 @@ void uart_tx_strn(const char *buf, size_t len) {
#elif defined(QEMU_SOC_IMX6)
#define UART_UCR1_UARTEN (1 << 0)
#define UART_UCR2_RXEN (1 << 1)
#define UART_UCR2_TXEN (1 << 2)
#define UART_UTS1_RXEMPTY (1 << 5)
typedef
struct
_UART_t
{
volatile
uint32_t
URXD
;
// 0x00
...
...
@@ -113,13 +151,22 @@ typedef struct _UART_t {
volatile
uint32_t
r1
[
15
];
volatile
uint32_t
UCR1
;
// 0x80
volatile
uint32_t
UCR2
;
// 0x84
volatile
uint32_t
r2
[
11
];
volatile
uint32_t
UTS1
;
// 0xb4
}
UART_t
;
#define UART1 ((UART_t *)(0x02020000))
void
uart_init
(
void
)
{
UART1
->
UCR1
=
UART_UCR1_UARTEN
;
UART1
->
UCR2
=
UART_UCR2_TXEN
;
UART1
->
UCR2
=
UART_UCR2_TXEN
|
UART_UCR2_RXEN
;
}
int
uart_rx_chr
(
void
)
{
if
(
UART1
->
UTS1
&
UART_UTS1_RXEMPTY
)
{
return
UART_RX_NO_CHAR
;
}
return
UART1
->
URXD
&
0xff
;
}
void
uart_tx_strn
(
const
char
*
buf
,
size_t
len
)
{
...
...
ports/qemu-arm/uart.h
View file @
8a3842eb
...
...
@@ -28,7 +28,11 @@
#include <stddef.h>
// Returned from uart_rx_chr when there are no chars available.
#define UART_RX_NO_CHAR (-1)
void
uart_init
(
void
);
int
uart_rx_chr
(
void
);
void
uart_tx_strn
(
const
char
*
buf
,
size_t
len
);
#endif // MICROPY_INCLUDED_QEMU_ARM_UART_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment