Skip to content

Commit af1a452

Browse files
Merge branch 'main' into main
2 parents a382728 + 99b3454 commit af1a452

File tree

30 files changed

+1377
-339
lines changed

30 files changed

+1377
-339
lines changed

boards.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ portenta_c33.build.fpu=-mfpu=fpv5-sp-d16
1212
portenta_c33.build.float-abi=-mfloat-abi=hard
1313

1414
portenta_c33.build.board=PORTENTA_C33
15-
portenta_c33.build.defines=-DF_CPU=200000000
15+
portenta_c33.build.defines=-DF_CPU=200000000 -DPROVIDE_FREERTOS_HOOK
1616
portenta_c33.vid.0=0x2341
1717
portenta_c33.pid.0=0x0068
1818
portenta_c33.vid.1=0x2341

cores/arduino/Serial.cpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ void UART::WrapperCallback(uart_callback_args_t *p_args) {
5858
{
5959
break;
6060
}
61-
case UART_EVENT_TX_COMPLETE:
62-
case UART_EVENT_TX_DATA_EMPTY:
61+
case UART_EVENT_TX_COMPLETE: // This is call when the transmission is complete
6362
{
64-
//uint8_t to_enqueue = uart_ptr->txBuffer.available() < uart_ptr->uart_ctrl.fifo_depth ? uart_ptr->txBuffer.available() : uart_ptr->uart_ctrl.fifo_depth;
65-
//while (to_enqueue) {
66-
uart_ptr->tx_done = true;
63+
uart_ptr->tx_complete = true;
64+
break;
65+
}
66+
case UART_EVENT_TX_DATA_EMPTY: // This is called when the buffer is empty
67+
{ // Last byte is transmitting, but ready for more data
68+
uart_ptr->tx_empty = true;
6769
break;
6870
}
6971
case UART_EVENT_RX_CHAR:
@@ -87,6 +89,8 @@ UART::UART(int _pin_tx, int _pin_rx, int _pin_rts, int _pin_cts):
8789
rx_pin(_pin_rx),
8890
rts_pin(_pin_rts),
8991
cts_pin(_pin_cts),
92+
tx_empty(true),
93+
tx_complete(true),
9094
init_ok(false) {
9195
/* -------------------------------------------------------------------------- */
9296
uart_cfg.txi_irq = FSP_INVALID_VECTOR;
@@ -109,9 +113,10 @@ bool UART::setUpUartIrqs(uart_cfg_t &cfg) {
109113
size_t UART::write(uint8_t c) {
110114
/* -------------------------------------------------------------------------- */
111115
if(init_ok) {
112-
tx_done = false;
116+
tx_empty = false;
117+
tx_complete = false;
113118
R_SCI_UART_Write(&uart_ctrl, &c, 1);
114-
while (!tx_done) {}
119+
while (!tx_empty) {}
115120
return 1;
116121
}
117122
else {
@@ -121,9 +126,10 @@ size_t UART::write(uint8_t c) {
121126

122127
size_t UART::write(uint8_t* c, size_t len) {
123128
if(init_ok) {
124-
tx_done = false;
129+
tx_empty = false;
130+
tx_complete = false;
125131
R_SCI_UART_Write(&uart_ctrl, c, len);
126-
while (!tx_done) {}
132+
while (!tx_empty) {}
127133
return len;
128134
}
129135
else {
@@ -322,7 +328,7 @@ int UART::read() {
322328
/* -------------------------------------------------------------------------- */
323329
void UART::flush() {
324330
/* -------------------------------------------------------------------------- */
325-
while(txBuffer.available());
331+
while(!tx_complete);
326332
}
327333

328334
/* -------------------------------------------------------------------------- */
@@ -335,4 +341,4 @@ size_t UART::write_raw(uint8_t* c, size_t len) {
335341
i++;
336342
}
337343
return len;
338-
}
344+
}

cores/arduino/Serial.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class UART : public arduino::HardwareSerial {
7878
arduino::SafeRingBufferN<SERIAL_BUFFER_SIZE> rxBuffer;
7979
arduino::SafeRingBufferN<SERIAL_BUFFER_SIZE> txBuffer;
8080

81-
volatile bool tx_done;
81+
volatile bool tx_empty;
82+
volatile bool tx_complete;
8283

8384
sci_uart_instance_ctrl_t uart_ctrl;
8485
uart_cfg_t uart_cfg;

cores/arduino/main.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void unsecure_registers() {
6464
#define str(s) #s
6565

6666
extern "C" void Stacktrace_Handler(void);
67+
extern "C" __attribute__((weak)) void start_freertos_on_header_inclusion() {}
6768

6869
void arduino_main(void)
6970
{
@@ -112,6 +113,9 @@ void arduino_main(void)
112113
#endif
113114
startAgt();
114115
setup();
116+
#ifdef PROVIDE_FREERTOS_HOOK
117+
start_freertos_on_header_inclusion();
118+
#endif
115119
while (1)
116120
{
117121
loop();

libraries/Arduino_FreeRTOS/src/portable/FSP/port.c

+23
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,29 @@ static void prvTaskExitError(void);
225225

226226
#endif
227227

228+
#ifdef PROVIDE_FREERTOS_HOOK
229+
void loop_thread_func(void* arg) {
230+
while (1)
231+
{
232+
loop();
233+
}
234+
}
235+
236+
static TaskHandle_t loop_task;
237+
void start_freertos_on_header_inclusion() {
238+
xTaskCreate(
239+
(TaskFunction_t)loop_thread_func,
240+
"Loop Thread",
241+
4096 / 4, /* usStackDepth in words */
242+
NULL, /* pvParameters */
243+
4, /* uxPriority */
244+
&loop_task /* pxCreatedTask */
245+
);
246+
247+
vTaskStartScheduler();
248+
}
249+
#endif
250+
228251
/* Arduino specific overrides */
229252
void delay(uint32_t ms) {
230253
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {

libraries/Arduino_LED_Matrix/examples/TextWithArduinoGraphics/TextWithArduinoGraphics.ino

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TextAnimation works only when ArduinoGraphics is installed and used.
2+
// ArduinoGraphics is an external library and needs to be installed using
3+
// Library Manager.
14
// To use ArduinoGraphics APIs, please include BEFORE Arduino_LED_Matrix
25
#include "ArduinoGraphics.h"
36
#include "Arduino_LED_Matrix.h"

libraries/Arduino_LED_Matrix/examples/TextWithArduinoGraphicsAsynchronous/TextWithArduinoGraphicsAsynchronous.ino

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TextAnimation works only when ArduinoGraphics is installed and used.
2+
// ArduinoGraphics is an external library and needs to be installed using
3+
// Library Manager.
14
// To use ArduinoGraphics APIs, please include BEFORE Arduino_LED_Matrix and TextAnimation
25
#include "ArduinoGraphics.h"
36
#include "Arduino_LED_Matrix.h"

libraries/ESPhost/examples/ESP32_TEST/ESP32_TEST.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void connectAccessPoint() {
297297
int i = stoi(ap_str);
298298

299299
Serial.println(">>> [APP]: Connecting to Access Point");
300-
WifiApCfg_t ap;
300+
WifiApCfg_t ap{};
301301
memcpy(ap.ssid,access_point_list[i].ssid,SSID_LENGTH);
302302
memcpy(ap.pwd,pwd.c_str(),pwd.size());
303303
memcpy(ap.bssid,access_point_list[i].bssid,BSSID_LENGTH);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
OTANonBlocking
3+
4+
This sketch demonstrates how to make an OTA Update on the UNO R4 WiFi.
5+
Upload the sketch and wait for the invasion!
6+
7+
It requires at least version 0.5.0 of USB Wifi bridge firmware
8+
9+
*/
10+
11+
12+
#include "WiFiS3.h"
13+
#include "OTAUpdate.h"
14+
#include "root_ca.h"
15+
#include "arduino_secrets.h"
16+
17+
char ssid[] = SECRET_SSID; // your network SSID (name)
18+
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
19+
20+
int status = WL_IDLE_STATUS;
21+
22+
OTAUpdate ota;
23+
static char const OTA_FILE_LOCATION[] = "https://downloads.arduino.cc/ota/UNOR4WIFI_Animation.ota";
24+
25+
/* -------------------------------------------------------------------------- */
26+
void setup() {
27+
/* -------------------------------------------------------------------------- */
28+
//Initialize serial and wait for port to open:
29+
Serial.begin(115200);
30+
while (!Serial) {
31+
; // wait for serial port to connect. Needed for native USB port only
32+
}
33+
34+
// check for the Wi-Fi module:
35+
if (WiFi.status() == WL_NO_MODULE) {
36+
Serial.println("Communication with Wi-Fi module failed!");
37+
// don't continue
38+
while (true);
39+
}
40+
41+
String fv = WiFi.firmwareVersion();
42+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
43+
Serial.println("Please upgrade the firmware");
44+
}
45+
46+
// attempt to connect to Wi-Fi network:
47+
while (status != WL_CONNECTED) {
48+
Serial.print("Attempting to connect to SSID: ");
49+
Serial.println(ssid);
50+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
51+
status = WiFi.begin(ssid, pass);
52+
53+
// wait 1 seconds for connection:
54+
delay(1000);
55+
}
56+
57+
printWiFiStatus();
58+
59+
Serial.println("ota.begin()");
60+
int ret = ota.begin("/update.bin");
61+
if(ret != OTAUpdate::OTA_ERROR_NONE) {
62+
Serial.println("ota.begin() error: ");
63+
Serial.println((int)ret);
64+
return;
65+
}
66+
67+
Serial.println("ota.setCACert()");
68+
ret = ota.setCACert(root_ca);
69+
if(ret != OTAUpdate::OTA_ERROR_NONE) {
70+
Serial.println("ota.setCACert() error: ");
71+
Serial.println((int)ret);
72+
return;
73+
}
74+
75+
Serial.println("ota.startDownload()");
76+
int ota_size = ota.startDownload(OTA_FILE_LOCATION, "/update.bin");
77+
if(ota_size <= 0) {
78+
Serial.println("ota.startDownload() error: ");
79+
Serial.println(ota_size);
80+
Serial.println("Make sure your WiFi firmware version is at least 0.5.0");
81+
return;
82+
}
83+
84+
Serial.println("ota.downloadProgress()");
85+
while((ret = ota.downloadProgress()) < ota_size) {
86+
Serial.print("Progress ");
87+
Serial.print(ret);
88+
Serial.print("/");
89+
Serial.println(ota_size);
90+
delay(100);
91+
}
92+
93+
if(ret < 0){
94+
Serial.println("ota.downloadProgress() error: ");
95+
Serial.println((int)ret);
96+
return;
97+
}
98+
99+
Serial.println("ota.verify()");
100+
ret = ota.verify();
101+
if(ret != OTAUpdate::OTA_ERROR_NONE) {
102+
Serial.println("ota.verify() error: ");
103+
Serial.println((int)ret);
104+
return;
105+
}
106+
\
107+
Serial.println("ota.update()");
108+
ret = ota.update("/update.bin");
109+
if(ret != OTAUpdate::OTA_ERROR_NONE) {
110+
Serial.println("ota.update() error: ");
111+
Serial.println((int)ret);
112+
return;
113+
}
114+
}
115+
116+
/* -------------------------------------------------------------------------- */
117+
void loop() {
118+
/* -------------------------------------------------------------------------- */
119+
delay(1000);
120+
}
121+
122+
/* -------------------------------------------------------------------------- */
123+
void printWiFiStatus() {
124+
/* -------------------------------------------------------------------------- */
125+
// print the SSID of the network you're attached to:
126+
Serial.print("SSID: ");
127+
Serial.println(WiFi.SSID());
128+
129+
// print your board's IP address:
130+
IPAddress ip = WiFi.localIP();
131+
Serial.print("IP Address: ");
132+
Serial.println(ip);
133+
134+
// print the received signal strength:
135+
long rssi = WiFi.RSSI();
136+
Serial.print("signal strength (RSSI):");
137+
Serial.print(rssi);
138+
Serial.println(" dBm");
139+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define SECRET_SSID ""
2+
#define SECRET_PASS ""

0 commit comments

Comments
 (0)