Skip to content

Commit c880072

Browse files
committed
added bridge example
1 parent 64621cc commit c880072

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
This file is part of the Arduino_Alvik library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
12+
13+
/*
14+
You can use this sketch to make your Arduino Nano ESP32 an USB-to-serial adapter.
15+
This allows to flash firmware into the Arduino Alvik Carrier via Arduino Nano ESP32.
16+
17+
Please refer to Arduino_AlvikCarrier library available at https://github.com/arduino-libraries/Arduino_AlvikCarrier
18+
*/
19+
20+
21+
22+
23+
#include "Arduino_Alvik.h"
24+
25+
unsigned long baud = 115200;
26+
27+
int rts = -1;
28+
int dtr = -1;
29+
30+
31+
static void onLineChange(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
32+
if (event_base == ARDUINO_USB_CDC_EVENTS) {
33+
arduino_usb_cdc_event_data_t * data = (arduino_usb_cdc_event_data_t*)event_data;
34+
switch (event_id) {
35+
case ARDUINO_USB_CDC_LINE_CODING_EVENT:
36+
auto baud = data->line_coding.bit_rate;
37+
Serial0.updateBaudRate(baud);
38+
while (Serial0.available()) {
39+
Serial0.read();
40+
}
41+
break;
42+
}
43+
}
44+
}
45+
46+
void setup() {
47+
Serial.onEvent(onLineChange);
48+
Serial.enableReboot(false);
49+
Serial.begin(baud);
50+
Serial.setRxBufferSize(0);
51+
Serial.setRxBufferSize(2048);
52+
Serial0.setRxBufferSize(8192);
53+
Serial0.setTxBufferSize(8192);
54+
Serial0.begin(baud, SERIAL_8E1);
55+
Serial0.flush();
56+
pinMode(BOOT_STM32, OUTPUT);
57+
pinMode(RESET_STM32, OUTPUT);
58+
digitalWrite(BOOT_STM32,HIGH);
59+
delay(1000);
60+
digitalWrite(RESET_STM32,LOW);
61+
delay(1000);
62+
digitalWrite(RESET_STM32,HIGH);
63+
64+
65+
66+
}
67+
68+
void loop() {
69+
int len = 0;
70+
uint8_t auc_buffer[488];
71+
while (Serial.available() && len < sizeof(auc_buffer)) {
72+
auc_buffer[len++] = Serial.read();
73+
}
74+
if (len) {
75+
Serial0.write(auc_buffer, len);
76+
}
77+
78+
len = 0;
79+
while (Serial0.available() && len < sizeof(auc_buffer)) {
80+
auc_buffer[len++] = Serial0.read();
81+
}
82+
if (len) {
83+
Serial.write(auc_buffer, len);
84+
}
85+
}

0 commit comments

Comments
 (0)