You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
909 B
45 lines
909 B
10 years ago
|
#include <unistd.h>
|
||
|
#include "py/mpconfig.h"
|
||
|
|
||
|
/*
|
||
|
* Core UART functions to implement for a port
|
||
|
*/
|
||
|
|
||
9 years ago
|
#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
|
||
|
|
||
10 years ago
|
// Receive single character
|
||
10 years ago
|
int mp_hal_stdin_rx_chr(void) {
|
||
10 years ago
|
unsigned char c = 0;
|
||
|
#if MICROPY_MIN_USE_STDOUT
|
||
|
int r = read(0, &c, 1);
|
||
|
(void)r;
|
||
9 years ago
|
#elif MICROPY_MIN_USE_STM32_MCU
|
||
|
// wait for RXNE
|
||
|
while ((USART1->SR & (1 << 5)) == 0) {
|
||
|
}
|
||
|
c = USART1->DR;
|
||
10 years ago
|
#endif
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
// Send string of given length
|
||
10 years ago
|
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
||
10 years ago
|
#if MICROPY_MIN_USE_STDOUT
|
||
|
int r = write(1, str, len);
|
||
|
(void)r;
|
||
9 years ago
|
#elif MICROPY_MIN_USE_STM32_MCU
|
||
|
while (len--) {
|
||
|
// wait for TXE
|
||
|
while ((USART1->SR & (1 << 7)) == 0) {
|
||
|
}
|
||
|
USART1->DR = *str++;
|
||
|
}
|
||
10 years ago
|
#endif
|
||
|
}
|