diff options
| author | Damien George | 2016-01-07 17:43:07 +0000 |
|---|---|---|
| committer | Damien George | 2016-01-07 17:43:07 +0000 |
| commit | 54729247e11eac1c86a2e0b1778b8c4406a53445 (patch) | |
| tree | c692b561a6b37e64d8e44a342b9f275b8a63a335 /minimal/uart_core.c | |
| parent | dd0a0f79d777684aba7986d44fae1a6eff176151 (diff) | |
minimal: Add enough code to run minimal build on STM32F4xx hardware.
Minimal support code for a Cortex-M CPU is added, along with set-up
code for an STM32F4xx MCU, including a UART for a REPL. Tested on
a pyboard. Code size is 77592 bytes.
Diffstat (limited to 'minimal/uart_core.c')
| -rw-r--r-- | minimal/uart_core.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/minimal/uart_core.c b/minimal/uart_core.c index 48cc27d6d..d2d17b4d1 100644 --- a/minimal/uart_core.c +++ b/minimal/uart_core.c @@ -5,12 +5,25 @@ * Core UART functions to implement for a port */ +#if MICROPY_MIN_USE_STM32_MCU +typedef struct { + volatile uint32_t SR; + volatile uint32_t DR; +} periph_uart_t; +#define USART1 ((periph_uart_t*)0x40011000) +#endif + // Receive single character int mp_hal_stdin_rx_chr(void) { unsigned char c = 0; #if MICROPY_MIN_USE_STDOUT int r = read(0, &c, 1); (void)r; +#elif MICROPY_MIN_USE_STM32_MCU + // wait for RXNE + while ((USART1->SR & (1 << 5)) == 0) { + } + c = USART1->DR; #endif return c; } @@ -20,5 +33,12 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { #if MICROPY_MIN_USE_STDOUT int r = write(1, str, len); (void)r; +#elif MICROPY_MIN_USE_STM32_MCU + while (len--) { + // wait for TXE + while ((USART1->SR & (1 << 7)) == 0) { + } + USART1->DR = *str++; + } #endif } |
