define CIRCUITPY_BOOT_OUTPUT_FILE will cause mp_hal_stdout_tx_strn() to
invoke before serial_init() is called. Solution is skipped output to
serial if it is not inited.
This commit is contained in:
hathach 2018-05-15 18:40:49 +07:00
parent d655e2194c
commit 53593d1315
5 changed files with 24 additions and 5 deletions

View File

@ -31,7 +31,7 @@ __check_defined = \
.PHONY: dfu-gen dfu-flash boot-flash .PHONY: dfu-gen dfu-flash boot-flash
dfu-gen: dfu-gen:
$(NRFUTIL) dfu genpkg --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip $(NRFUTIL) dfu genpkg --sd-req 0xFFFE --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip
dfu-flash: dfu-flash:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0) @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)

View File

@ -156,6 +156,10 @@ void hal_uart_init(NRF_UART_Type * p_instance, hal_uart_init_t const * p_uart_in
NVIC_EnableIRQ(p_uart_init->irq_num); NVIC_EnableIRQ(p_uart_init->irq_num);
} }
bool hal_uart_inited(NRF_UART_Type * p_instance)
{
return !(p_instance->PSELTXD & (1 << 31)) && !(p_instance->PSELRXD & (1 << 31));
}
void UARTE0_UART0_IRQHandler(void) void UARTE0_UART0_IRQHandler(void)
{ {

View File

@ -117,6 +117,7 @@ typedef struct
typedef void (*uart_complete_cb)(void); typedef void (*uart_complete_cb)(void);
void hal_uart_init(NRF_UART_Type * p_instance, hal_uart_init_t const * p_uart_init); void hal_uart_init(NRF_UART_Type * p_instance, hal_uart_init_t const * p_uart_init);
bool hal_uart_inited(NRF_UART_Type * p_instance);
hal_uart_error_t hal_uart_char_write(NRF_UART_Type * p_instance, uint8_t ch); hal_uart_error_t hal_uart_char_write(NRF_UART_Type * p_instance, uint8_t ch);

View File

@ -330,6 +330,6 @@ extern const struct _mp_obj_module_t ble_module;
#include <alloca.h> #include <alloca.h>
#define MICROPY_PIN_DEFS_PORT_H "pin_defs_nrf5.h" #define MICROPY_PIN_DEFS_PORT_H "pin_defs_nrf5.h"
//#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt" #define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt"
#endif #endif

View File

@ -65,9 +65,23 @@ bool mp_hal_stdin_any(void) {
} }
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
// #ifdef MICROPY_HW_LED_TX
// gpio_toggle_pin_level(MICROPY_HW_LED_TX);
// #endif
//
// #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
// if (boot_output_file != NULL) {
// UINT bytes_written = 0;
// f_write(boot_output_file, str, len, &bytes_written);
// }
// #endif
if ( hal_uart_inited(UART_INSTANCE) ) {
while(len--) { while(len--) {
hal_uart_char_write(UART_INSTANCE, *str++); hal_uart_char_write(UART_INSTANCE, *str++);
} }
}
} }
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) { void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {