summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyke van Laethem <aykevanlaethem@gmail.com>2018-03-26 13:40:18 +0200
committerDamien George <damien.p.george@gmail.com>2018-07-18 17:12:26 +1000
commit57ca1ecf0107a680af9ac896d53d5399266947cd (patch)
treed73f06c6899c931bccae41f1f5aaf1451738a278
parent002f7d1ad7463b579422eb07fc47084e75e70659 (diff)
nrf: Fix NUS console when using boot.py or main.py.
-rw-r--r--ports/nrf/drivers/bluetooth/ble_uart.c9
-rw-r--r--ports/nrf/main.c23
2 files changed, 19 insertions, 13 deletions
diff --git a/ports/nrf/drivers/bluetooth/ble_uart.c b/ports/nrf/drivers/bluetooth/ble_uart.c
index 0c53ec1dc..9bfb2ee4b 100644
--- a/ports/nrf/drivers/bluetooth/ble_uart.c
+++ b/ports/nrf/drivers/bluetooth/ble_uart.c
@@ -93,6 +93,9 @@ static ubluepy_advertise_data_t m_adv_data_eddystone_url;
#endif // BLUETOOTH_WEBBLUETOOTH_REPL
int mp_hal_stdin_rx_chr(void) {
+ while (!ble_uart_enabled()) {
+ // wait for connection
+ }
while (isBufferEmpty(mp_rx_ring_buffer)) {
;
}
@@ -103,6 +106,9 @@ int mp_hal_stdin_rx_chr(void) {
}
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
+ // Not connected: drop output
+ if (!ble_uart_enabled()) return;
+
uint8_t *buf = (uint8_t *)str;
size_t send_len;
@@ -138,6 +144,7 @@ STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn
} else if (event_id == 17) { // disconnect event
self->conn_handle = 0xFFFF; // invalid connection handle
m_connected = false;
+ m_cccd_enabled = false;
ble_uart_advertise();
}
}
@@ -154,6 +161,8 @@ STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t at
#if MICROPY_KBD_EXCEPTION
if (data[i] == mp_interrupt_char) {
mp_keyboard_interrupt();
+ m_rx_ring_buffer.start = 0;
+ m_rx_ring_buffer.end = 0;
} else
#endif
{
diff --git a/ports/nrf/main.c b/ports/nrf/main.c
index ec1638e0f..f058e0bb4 100644
--- a/ports/nrf/main.c
+++ b/ports/nrf/main.c
@@ -200,25 +200,12 @@ pin_init0();
MP_PARSE_FILE_INPUT);
#endif
-#if MICROPY_VFS || MICROPY_HW_HAS_BUILTIN_FLASH
- // run boot.py and main.py if they exist.
- if (mp_import_stat("boot.py") == MP_IMPORT_STAT_FILE) {
- pyexec_file("boot.py");
- }
- if (mp_import_stat("main.py") == MP_IMPORT_STAT_FILE) {
- pyexec_file("main.py");
- }
-#endif
-
// Main script is finished, so now go into REPL mode.
// The REPL mode can change, or it can request a soft reset.
int ret_code = 0;
#if MICROPY_PY_BLE_NUS
ble_uart_init0();
- while (!ble_uart_enabled()) {
- ;
- }
#endif
#if MICROPY_PY_MACHINE_SOFT_PWM
@@ -238,6 +225,16 @@ pin_init0();
pwm_start();
#endif
+#if MICROPY_VFS || MICROPY_HW_HAS_BUILTIN_FLASH
+ // run boot.py and main.py if they exist.
+ if (mp_import_stat("boot.py") == MP_IMPORT_STAT_FILE) {
+ pyexec_file("boot.py");
+ }
+ if (mp_import_stat("main.py") == MP_IMPORT_STAT_FILE) {
+ pyexec_file("main.py");
+ }
+#endif
+
for (;;) {
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
if (pyexec_raw_repl() != 0) {