File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828#include "py/mphal.h"
2929#include <string.h>
3030#include "supervisor/serial.h"
31+ #if CPY_STM32F4
3132#include "stm32f4xx_hal.h"
3233#include "stm32f4/gpio.h"
33-
3434// TODO: Switch this to using DEBUG_UART.
3535
3636UART_HandleTypeDef huart2 ;
37+ #endif
3738
3839void port_serial_init (void ) {
40+ #if CPY_STM32F4
3941 huart2 .Instance = USART2 ;
4042 huart2 .Init .BaudRate = 115200 ;
4143 huart2 .Init .WordLength = UART_WORDLENGTH_8B ;
@@ -47,25 +49,33 @@ void port_serial_init(void) {
4749 if (HAL_UART_Init (& huart2 ) == HAL_OK ) {
4850 stm32f4_peripherals_status_led (1 ,1 );
4951 }
52+ #endif
5053}
5154
5255bool port_serial_connected (void ) {
5356 return true;
5457}
5558
5659char port_serial_read (void ) {
60+ #if CPY_STM32F4
5761 uint8_t data ;
5862 HAL_UART_Receive (& huart2 , & data , 1 ,500 );
5963 return data ;
64+ #else
65+ return -1 ;
66+ #endif
6067}
6168
6269bool port_serial_bytes_available (void ) {
70+ #if CPY_STM32F4
6371 return __HAL_UART_GET_FLAG (& huart2 , UART_FLAG_RXNE );
72+ #else
73+ return false;
74+ #endif
6475}
6576
6677void port_serial_write_substring (const char * text , uint32_t len ) {
67- if (len == 0 ) {
68- return ;
69- }
78+ #if CPY_STM32F4
7079 HAL_UART_Transmit (& huart2 , (uint8_t * )text , len , 5000 );
80+ #endif
7181}
You can’t perform that action at this time.
0 commit comments