File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 28
28
#include "py/mphal.h"
29
29
#include <string.h>
30
30
#include "supervisor/serial.h"
31
+ #if CPY_STM32F4
31
32
#include "stm32f4xx_hal.h"
32
33
#include "stm32f4/gpio.h"
33
-
34
34
// TODO: Switch this to using DEBUG_UART.
35
35
36
36
UART_HandleTypeDef huart2 ;
37
+ #endif
37
38
38
39
void port_serial_init (void ) {
40
+ #if CPY_STM32F4
39
41
huart2 .Instance = USART2 ;
40
42
huart2 .Init .BaudRate = 115200 ;
41
43
huart2 .Init .WordLength = UART_WORDLENGTH_8B ;
@@ -47,25 +49,33 @@ void port_serial_init(void) {
47
49
if (HAL_UART_Init (& huart2 ) == HAL_OK ) {
48
50
stm32f4_peripherals_status_led (1 ,1 );
49
51
}
52
+ #endif
50
53
}
51
54
52
55
bool port_serial_connected (void ) {
53
56
return true;
54
57
}
55
58
56
59
char port_serial_read (void ) {
60
+ #if CPY_STM32F4
57
61
uint8_t data ;
58
62
HAL_UART_Receive (& huart2 , & data , 1 ,500 );
59
63
return data ;
64
+ #else
65
+ return -1 ;
66
+ #endif
60
67
}
61
68
62
69
bool port_serial_bytes_available (void ) {
70
+ #if CPY_STM32F4
63
71
return __HAL_UART_GET_FLAG (& huart2 , UART_FLAG_RXNE );
72
+ #else
73
+ return false;
74
+ #endif
64
75
}
65
76
66
77
void port_serial_write_substring (const char * text , uint32_t len ) {
67
- if (len == 0 ) {
68
- return ;
69
- }
78
+ #if CPY_STM32F4
70
79
HAL_UART_Transmit (& huart2 , (uint8_t * )text , len , 5000 );
80
+ #endif
71
81
}
You can’t perform that action at this time.
0 commit comments