Skip to content

Commit 3c7eec9

Browse files
committed
Hackjob attempt at changing from USB to UART1
1 parent 1e225d4 commit 3c7eec9

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

include/marlin/Configuration_A3ides_2209_MINI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
*
105105
* :[-1, 0, 1, 2, 3, 4, 5, 6, 7]
106106
*/
107-
#define SERIAL_PORT -1
107+
#define SERIAL_PORT 1
108108

109109
/**
110110
* Select a secondary serial port on the board to use for communication with the host.

lib/Arduino_Core_A3ides/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ target_compile_definitions(
3333
ARDUINO=187
3434
$<$<STREQUAL:${ARDUINO_CORE_TARGET},STM32F4xx>:STM32F4xx>
3535
HAVE_HWSERIAL2
36+
HAVE_HWSERIAL1
3637
USBD_USE_CDC
3738
USBCON
3839
)

lib/Arduino_Core_A3ides/cores/arduino/HardwareSerial.h

+17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ class HardwareSerial : public Stream {
1919
operator bool();
2020
};
2121

22+
23+
// ultra-mega-terrible-hack.
24+
class HardwareSerial2 : public Stream {
25+
public:
26+
HardwareSerial2(void *p){};
27+
void begin(unsigned long baud);
28+
virtual int available(void);
29+
virtual int peek(void) { return -1; };
30+
virtual int read(void);
31+
virtual void flush(void);
32+
virtual size_t write(uint8_t);
33+
virtual size_t write(uint8_t *buffer, size_t size);
34+
operator bool() { return true;};
35+
};
36+
2237
extern HardwareSerial Serial3;
38+
extern HardwareSerial2 SerialUART1;
39+
2340

2441
#endif //_HARDWARESERIAL_H

src/common/hardware_serial.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ void HardwareSerial::begin(unsigned long baud) {
1313
BufferedSerial::uart2.Open();
1414
}
1515

16+
17+
1618
void HardwareSerial::begin(unsigned long baud, byte config) {
1719
}
1820

@@ -47,4 +49,56 @@ HardwareSerial::operator bool() {
4749
return true;
4850
}
4951

52+
extern "C" {
53+
extern UART_HandleTypeDef huart1;
54+
extern uartrxbuff_t uart1rxbuff;
55+
}
56+
57+
void HardwareSerial2::begin(unsigned long baud) {
58+
// Do nothing, the MX_UART_Init() function takes care of this.
59+
}
60+
61+
int HardwareSerial2::read(void)
62+
{
63+
//return uartrxbuff_getchar(&uart1rxbuff);
64+
if (huart1.Instance->SR & UART_FLAG_RXNE)
65+
return huart1.Instance->DR;
66+
else
67+
return -1;
68+
69+
}
70+
71+
int HardwareSerial2::available()
72+
{
73+
return (huart1.Instance->SR & UART_FLAG_RXNE)>0;
74+
}
75+
76+
void HardwareSerial2::flush() {
77+
// Nothing to do here, the TX is blocking.
78+
}
79+
80+
size_t HardwareSerial2::write(uint8_t c) {
81+
if (HAL_UART_Transmit(&huart1, &c, 1, HAL_MAX_DELAY) == HAL_OK)
82+
{
83+
return 1;
84+
}
85+
else
86+
{
87+
return 0;
88+
}
89+
}
90+
91+
size_t HardwareSerial2::write(uint8_t *buffer, size_t size) {
92+
if (HAL_UART_Transmit(&huart1, buffer, size, HAL_MAX_DELAY) == HAL_OK)
93+
{
94+
return size;
95+
}
96+
else
97+
{
98+
return 0;
99+
}
100+
}
101+
50102
HardwareSerial Serial3(USART3);
103+
104+
HardwareSerial2 SerialUART1(USART1);

src/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ TIM_HandleTypeDef htim2;
9797
TIM_HandleTypeDef htim3;
9898
TIM_HandleTypeDef htim14;
9999

100-
static UART_HandleTypeDef huart1;
100+
UART_HandleTypeDef huart1;
101101
UART_HandleTypeDef huart2;
102102
UART_HandleTypeDef huart6;
103103
DMA_HandleTypeDef hdma_usart1_rx;
@@ -228,9 +228,9 @@ int main(void) {
228228

229229
buddy::hw::BufferedSerial::uart2.Open();
230230

231-
uartrxbuff_init(&uart1rxbuff, &huart1, &hdma_usart1_rx, sizeof(uart1rx_data), uart1rx_data);
232-
HAL_UART_Receive_DMA(&huart1, uart1rxbuff.buffer, uart1rxbuff.buffer_size);
233-
uartrxbuff_reset(&uart1rxbuff);
231+
// uartrxbuff_init(&uart1rxbuff, &huart1, &hdma_usart1_rx, sizeof(uart1rx_data), uart1rx_data);
232+
// HAL_UART_Receive_DMA(&huart1, uart1rxbuff.buffer, uart1rxbuff.buffer_size);
233+
// uartrxbuff_reset(&uart1rxbuff);
234234

235235
uartrxbuff_init(&uart6rxbuff, &huart6, &hdma_usart6_rx, sizeof(uart6rx_data), uart6rx_data);
236236
HAL_UART_Receive_DMA(&huart6, uart6rxbuff.buffer, uart6rxbuff.buffer_size);

0 commit comments

Comments
 (0)