Fix STM non-F4 builds

This commit is contained in:
Scott Shawcroft 2022-03-22 23:07:38 -07:00
parent f5d90fc84f
commit 2fa182147b
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
1 changed files with 14 additions and 4 deletions

View File

@ -28,14 +28,16 @@
#include "py/mphal.h"
#include <string.h>
#include "supervisor/serial.h"
#if CPY_STM32F4
#include "stm32f4xx_hal.h"
#include "stm32f4/gpio.h"
// TODO: Switch this to using DEBUG_UART.
UART_HandleTypeDef huart2;
#endif
void port_serial_init(void) {
#if CPY_STM32F4
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
@ -47,6 +49,7 @@ void port_serial_init(void) {
if (HAL_UART_Init(&huart2) == HAL_OK) {
stm32f4_peripherals_status_led(1,1);
}
#endif
}
bool port_serial_connected(void) {
@ -54,18 +57,25 @@ bool port_serial_connected(void) {
}
char port_serial_read(void) {
#if CPY_STM32F4
uint8_t data;
HAL_UART_Receive(&huart2, &data, 1,500);
return data;
#else
return -1;
#endif
}
bool port_serial_bytes_available(void) {
#if CPY_STM32F4
return __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE);
#else
return false;
#endif
}
void port_serial_write_substring(const char *text, uint32_t len) {
if (len == 0) {
return;
}
#if CPY_STM32F4
HAL_UART_Transmit(&huart2, (uint8_t *)text, len, 5000);
#endif
}