Skip to content

Commit a021a9e

Browse files
committed
update uart to remove dependency on machine uart module
1 parent 1789256 commit a021a9e

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

ports/nrf/hal/hal_uart.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,6 @@ hal_uart_error_t hal_uart_char_write(NRF_UART_Type * p_instance, uint8_t ch) {
6969
}
7070

7171
hal_uart_error_t hal_uart_char_read(NRF_UART_Type * p_instance, uint8_t * ch) {
72-
// p_instance->ERRORSRC = 0;
73-
// while (p_instance->EVENTS_RXDRDY != 1) {
74-
// // Wait for RXD data.
75-
// }
76-
//
77-
// p_instance->EVENTS_RXDRDY = 0;
78-
// *ch = p_instance->RXD;
79-
//
80-
// return p_instance->ERRORSRC;
81-
8272
while ( !fifo_read(_ff_uart, ch) ) {
8373
// wait for fifo data
8474
}

ports/nrf/mphalport.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
#include "py/mpstate.h"
3131
#include "py/mphal.h"
3232
#include "py/mperrno.h"
33-
#include "uart.h"
33+
#include "hal_uart.h"
3434

35+
#define UART_INSTANCE UART_BASE(0)
3536
FIL* boot_output_file;
3637

3738
// this table converts from HAL_StatusTypeDef to POSIX errno
@@ -46,36 +47,36 @@ NORETURN void mp_hal_raise(HAL_StatusTypeDef status) {
4647
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(mp_hal_status_to_errno_table[status])));
4748
}
4849

49-
void mp_hal_set_interrupt_char(int c) {
50-
51-
}
52-
5350
#if (MICROPY_PY_BLE_NUS == 0)
5451
int mp_hal_stdin_rx_chr(void) {
5552
for (;;) {
56-
if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
57-
return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
53+
if ( hal_uart_available(UART_INSTANCE) ) {
54+
uint8_t ch;
55+
hal_uart_char_read(UART_INSTANCE, &ch);
56+
return (int) ch;
5857
}
5958
}
6059

6160
return 0;
6261
}
6362

64-
bool mp_hal_stdin_any(void)
65-
{
66-
return uart_rx_any(MP_STATE_PORT(pyb_stdio_uart));
63+
bool mp_hal_stdin_any(void) {
64+
return hal_uart_available(UART_INSTANCE);
6765
}
6866

6967
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
70-
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
71-
uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
72-
}
68+
while(len--) {
69+
hal_uart_char_write(UART_INSTANCE, *str++);
70+
}
7371
}
7472

7573
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
76-
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
77-
uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
74+
while(len--){
75+
if (*str == '\n') {
76+
hal_uart_char_write(UART_INSTANCE, '\r');
7877
}
78+
hal_uart_char_write(UART_INSTANCE, *str++);
79+
}
7980
}
8081
#endif
8182

ports/nrf/supervisor/serial.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,36 @@
2929
#include "py/obj.h"
3030
#include "py/runtime.h"
3131
#include "mphalport.h"
32-
#include "uart.h"
32+
#include "pins.h"
33+
#include "hal_uart.h"
3334

3435
void serial_init(void) {
35-
uart_init0();
36+
// uart_init0();
37+
//
38+
// mp_obj_t args[2] = {
39+
// MP_OBJ_NEW_SMALL_INT(0),
40+
// MP_OBJ_NEW_SMALL_INT(115200),
41+
// };
42+
// MP_STATE_PORT(pyb_stdio_uart) = machine_hard_uart_type.make_new((mp_obj_t)&machine_hard_uart_type, MP_ARRAY_SIZE(args), 0, args);
3643

37-
mp_obj_t args[2] = {
38-
MP_OBJ_NEW_SMALL_INT(0),
39-
MP_OBJ_NEW_SMALL_INT(115200),
44+
hal_uart_init_t param =
45+
{
46+
.id = 0,
47+
.rx_pin = &MICROPY_HW_UART1_RX,
48+
.tx_pin = &MICROPY_HW_UART1_TX,
49+
.rts_pin = NULL,
50+
.cts_pin = NULL,
51+
.flow_control = MICROPY_HW_UART1_HWFC ? true : false,
52+
.use_parity = false,
53+
.baud_rate = HAL_UART_BAUD_115K2,
54+
.irq_priority = 6,
55+
.irq_num = UARTE0_UART0_IRQn
4056
};
41-
MP_STATE_PORT(pyb_stdio_uart) = machine_hard_uart_type.make_new((mp_obj_t)&machine_hard_uart_type, MP_ARRAY_SIZE(args), 0, args);
57+
58+
hal_uart_init( UART_BASE(0), &param);
4259
}
4360

61+
4462
bool serial_connected(void) {
4563
return true;
4664
}

0 commit comments

Comments
 (0)