Skip to content

Commit 1ac8280

Browse files
Merge branch 'arduino:main' into main
2 parents a994343 + 8a0bbaa commit 1ac8280

40 files changed

+3486
-201
lines changed

.github/workflows/compile-examples.yml

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
- libraries/RTC/examples/RTC_NTPSync
7777
- libraries/RTC/examples/RTC_Alarm
7878
- libraries/SFU
79+
- libraries/KVStore/examples/StartCounter
7980
- board:
8081
fqbn: "arduino-git:renesas:portenta_c33"
8182
additional-sketch-paths: |
@@ -91,6 +92,7 @@ jobs:
9192
- libraries/RTC/examples/RTC_NTPSync
9293
- libraries/RTC/examples/RTC_Alarm
9394
- libraries/SFU
95+
- libraries/KVStore/examples/StartCounter
9496
- board:
9597
fqbn: "arduino:renesas_uno:unor4wifi"
9698
additional-sketch-paths: |

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 -DPROVIDE_FREERTOS_HOOK
15+
portenta_c33.build.defines=-DF_CPU=200000000
1616
portenta_c33.vid.0=0x2341
1717
portenta_c33.pid.0=0x0068
1818
portenta_c33.vid.1=0x2341

cores/arduino/analog.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,10 @@ void analogReference(uint8_t mode) {
558558
R_ADC_Open(&adc1.ctrl, &adc1.cfg);
559559
}
560560

561+
#if defined(AVCC_MEASURE_PIN)
561562
static float aref = 0;
563+
#endif
564+
562565
float analogReference() {
563566
switch (adc.cfg_extend.adc_vref_control) {
564567
case ADC_VREF_CONTROL_1_5V_OUTPUT:
@@ -817,4 +820,4 @@ void analogWrite(pin_size_t pinNumber, int value)
817820

818821
FspTimer* __get_timer_for_channel(int channel) {
819822
return pwms.get_from_channel(channel)->get_timer();
820-
}
823+
}

cores/arduino/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void unsecure_registers() {
6565

6666
extern "C" void Stacktrace_Handler(void);
6767
extern "C" __attribute__((weak)) void start_freertos_on_header_inclusion() {}
68+
extern "C" __attribute__((weak)) void early_start_freertos_on_header_inclusion() {}
6869

6970
void arduino_main(void)
7071
{
@@ -112,10 +113,9 @@ void arduino_main(void)
112113
Serial.begin(115200);
113114
#endif
114115
startAgt();
116+
early_start_freertos_on_header_inclusion();
115117
setup();
116-
#ifdef PROVIDE_FREERTOS_HOOK
117118
start_freertos_on_header_inclusion();
118-
#endif
119119
while (1)
120120
{
121121
loop();

libraries/Arduino_FreeRTOS/src/Arduino_FreeRTOS.h

+21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ extern "C" {
2727
#include "lib/FreeRTOS-Kernel-v10.5.1/semphr.h"
2828
#include "lib/FreeRTOS-Kernel-v10.5.1/task.h"
2929
#include "lib/FreeRTOS-Kernel-v10.5.1/timers.h"
30+
#include <stdbool.h>
31+
32+
33+
// If you need to automatically start FREERTOS, declare either EARLY_AUTOSTART_FREERTOS or
34+
// AUTOSTART_FREERTOS in your library or sketch code (.ino or .cpp file)
35+
//
36+
// EARLY_AUTOSTART_FREERTOS -> if you need the scheduler to be already running in setup()
37+
// AUTOSTART_FREERTOS -> if you only declare the threads in setup() and use them in loop()
38+
39+
void _start_freertos_on_header_inclusion_impl(bool early_start);
40+
void early_start_freertos_on_header_inclusion();
41+
void start_freertos_on_header_inclusion();
42+
#define EARLY_AUTOSTART_FREERTOS \
43+
void early_start_freertos_on_header_inclusion() { \
44+
_start_freertos_on_header_inclusion_impl(true); \
45+
}
46+
#define AUTOSTART_FREERTOS \
47+
void start_freertos_on_header_inclusion() { \
48+
_start_freertos_on_header_inclusion_impl(false); \
49+
}
50+
3051

3152
#ifdef __cplusplus
3253
}

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

+22-15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "FreeRTOSConfig.h"
3333
#include "../../lib/FreeRTOS-Kernel-v10.5.1/FreeRTOS.h"
3434
#include "../../lib/FreeRTOS-Kernel-v10.5.1/task.h"
35+
#include "portmacro.h"
3536

3637
#if BSP_TZ_NONSECURE_BUILD
3738
#include "tz_context.h"
@@ -225,28 +226,34 @@ static void prvTaskExitError(void);
225226

226227
#endif
227228

228-
#ifdef PROVIDE_FREERTOS_HOOK
229-
void loop_thread_func(void* arg) {
229+
extern void setup(void);
230+
extern void loop(void);
231+
232+
static void sketch_thread_func(void* arg) {
233+
bool early_start = (bool)arg;
234+
if (early_start) {
235+
setup();
236+
}
230237
while (1)
231238
{
232239
loop();
233240
}
234241
}
235242

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();
243+
void _start_freertos_on_header_inclusion_impl(bool early_start) {
244+
static TaskHandle_t sketch_task;
245+
if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) {
246+
xTaskCreate(
247+
(TaskFunction_t)sketch_thread_func,
248+
"Sketch Thread",
249+
4096 / 4, /* usStackDepth in words */
250+
(void*)early_start, /* pvParameters */
251+
4, /* uxPriority */
252+
&sketch_task /* pxCreatedTask */
253+
);
254+
vTaskStartScheduler();
255+
}
248256
}
249-
#endif
250257

251258
/* Arduino specific overrides */
252259
void delay(uint32_t ms) {

libraries/BlockDevices/QSPIFlashBlockDevice.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ int QSPIFlashBlockDevice::write(const void *buffer, bd_addr_t add, bd_size_t _si
287287
R_QSPI_BankSet(&ctrl, bank);
288288
rv = R_QSPI_Write(&ctrl, (uint8_t *)(buffer), (uint8_t*)address, chunk);
289289
address += chunk;
290-
buffer += chunk;
290+
buffer = (uint8_t *)(buffer) + chunk;
291291

292292
if(rv == FSP_SUCCESS) {
293293
rv = get_flash_status();
@@ -328,7 +328,7 @@ int QSPIFlashBlockDevice::erase(bd_addr_t add, bd_size_t _size) {
328328

329329
uint32_t num_of_blocks = (_size / erase_block_size);
330330

331-
for(int i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
331+
for(uint32_t i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
332332
/* set bank */
333333
uint32_t bank = add / READ_PAGE_SIZE;
334334
uint32_t address = base_address + ((add + i * erase_block_size) % READ_PAGE_SIZE);

libraries/BlockDevices/QSPIFlashBlockDevice.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,27 @@
7070

7171
class QSPIFlashBlockDevice : public BlockDevice {
7272
private:
73-
bool opened;
74-
73+
74+
pin_t ck;
75+
pin_t cs;
76+
pin_t io0;
77+
pin_t io1;
78+
pin_t io2;
79+
pin_t io3;
80+
7581
bd_addr_t base_address;
7682
bd_size_t total_size;
7783
bd_size_t read_block_size;
7884
bd_size_t erase_block_size;
7985
bd_size_t write_block_size;
8086

87+
bool opened;
88+
8189
bool is_address_correct(bd_addr_t add);
8290

8391
qspi_instance_ctrl_t ctrl;
8492
spi_flash_cfg_t cfg;
8593
qspi_extended_cfg_t ext_cfg;
86-
pin_t ck;
87-
pin_t cs;
88-
pin_t io0;
89-
pin_t io1;
90-
pin_t io2;
91-
pin_t io3;
9294

9395
fsp_err_t get_flash_status();
9496

libraries/BlockDevices/SDCardBlockDevice.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ SDCardBlockDevice::~SDCardBlockDevice() {
166166
/* CALLBACK */
167167
/* -------------------------------------------------------------------------- */
168168
void SDCardBlockDevice::SDCardBlockDeviceCbk(sdmmc_callback_args_t *arg) {
169-
int open_status = -1;
170169
if(arg != nullptr) {
171170
sdmmc_event_t event = arg->event;
172171

@@ -368,8 +367,9 @@ int SDCardBlockDevice::read(void *buffer, bd_addr_t add, bd_size_t _size) {
368367
uint32_t num_of_blocks = (_size / read_block_size);
369368
uint32_t start_add_of_block = (add / read_block_size);
370369
rv = FSP_SUCCESS;
371-
for(int i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
372-
rv = R_SDHI_Read (&ctrl, (uint8_t *)(buffer + (i * read_block_size)), start_add_of_block + i, 1);
370+
for(uint32_t i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
371+
uint8_t *buf = (uint8_t *)buffer;
372+
rv = R_SDHI_Read (&ctrl, buf + (i * read_block_size), start_add_of_block + i, 1);
373373
if(rv == FSP_SUCCESS) {
374374
rv = wait_for_completition();
375375
}
@@ -404,8 +404,9 @@ int SDCardBlockDevice::write(const void *buffer, bd_addr_t add, bd_size_t _size)
404404
uint32_t num_of_blocks = (_size / write_block_size);
405405
uint32_t start_block_number = (add / write_block_size);
406406
rv = FSP_SUCCESS;
407-
for(int i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
408-
rv = R_SDHI_Write (&ctrl, (uint8_t *)(buffer + (i * write_block_size)), start_block_number + i, 1);
407+
for(uint32_t i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
408+
uint8_t *buf = (uint8_t *)buffer;
409+
rv = R_SDHI_Write (&ctrl, buf + (i * write_block_size), start_block_number + i, 1);
409410
if(rv == FSP_SUCCESS) {
410411
rv = wait_for_completition();
411412
}
@@ -439,7 +440,7 @@ int SDCardBlockDevice::erase(bd_addr_t add, bd_size_t _size) {
439440
uint32_t num_of_blocks = (_size / erase_block_size);
440441
uint32_t start_block_number = (add / erase_block_size);
441442
rv = FSP_SUCCESS;
442-
for(int i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
443+
for(uint32_t i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
443444
rv = R_SDHI_Erase (&ctrl, start_block_number + i, 1);
444445
if(rv == FSP_SUCCESS) {
445446
rv = wait_for_completition();

libraries/BlockDevices/SDCardBlockDevice.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,22 @@ enum class CmdStatus {
6060

6161
class SDCardBlockDevice : public BlockDevice {
6262
private:
63-
sdmmc_device_t sd_card_info;
63+
pin_t ck;
64+
pin_t cmd;
65+
pin_t d0;
66+
pin_t d1;
67+
pin_t d2;
68+
pin_t d3;
69+
pin_t cd;
70+
pin_t wp;
6471
bd_addr_t base_address;
6572
bd_size_t total_size;
6673
bd_size_t read_block_size;
6774
bd_size_t erase_block_size;
6875
bd_size_t write_block_size;
76+
bool opened;
6977
sdhi_instance_ctrl_t ctrl;
78+
sdmmc_device_t sd_card_info;
7079
sdmmc_cfg_t cfg;
7180

7281
#ifdef USE_DMAC
@@ -84,22 +93,15 @@ class SDCardBlockDevice : public BlockDevice {
8493
transfer_cfg_t dtc_cfg;
8594
transfer_instance_t dtc_instance;
8695
#endif
87-
pin_t ck;
88-
pin_t cmd;
89-
pin_t d0;
90-
pin_t d1;
91-
pin_t d2;
92-
pin_t d3;
93-
pin_t cd;
94-
pin_t wp;
96+
9597
static volatile bool initialized;
9698
static volatile bool card_inserted;
9799
static volatile CmdStatus st;
98100
static void SDCardBlockDeviceCbk(sdmmc_callback_args_t *);
99101
virtual int write(const void *buffer, bd_addr_t addr, bd_size_t size) override;
100102
virtual int open() override;
101103
virtual int close() override;
102-
bool opened;
104+
103105
fsp_err_t wait_for_completition();
104106
public:
105107

libraries/ESPhost/src/CMsg.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ void CMsg::reset_without_delete() {
8585

8686

8787
/* -------------------------------------------------------------------------- */
88-
CMsg::CMsg() : buf{nullptr}, dim{0}, payload_header{nullptr}, proto_dim{0}, tlv_size(esp_tlv_header_size) {
88+
CMsg::CMsg() : buf{nullptr}, dim{0}, proto_dim{0}, payload_header{nullptr}, tlv_size(esp_tlv_header_size) {
8989

9090
}
9191
/* -------------------------------------------------------------------------- */
9292

9393
/* -------------------------------------------------------------------------- */
94-
CMsg::CMsg(uint16_t proto_size, bool use_tlv /*= true*/) : buf{nullptr},
95-
dim{0},
96-
payload_header{nullptr},
97-
proto_dim{proto_size} {
94+
CMsg::CMsg(uint16_t proto_size, bool use_tlv /*= true*/) : buf{nullptr},
95+
dim{0},
96+
proto_dim{proto_size},
97+
payload_header{nullptr} {
9898
/* -------------------------------------------------------------------------- */
9999
uint16_t request_size = 0;
100100
if(use_tlv) {
@@ -204,6 +204,7 @@ CMsg& CMsg::operator=(CMsg&& m) {
204204
Serial.println(" bad!");
205205
#endif
206206
}
207+
return *this;
207208
}
208209

209210

@@ -442,6 +443,7 @@ void CMsg::debug_print(const char* title) {
442443
/* -------------------------------------------------------------------------- */
443444
bool CMsg::store_rx_buffer(const uint8_t *buffer, uint32_t d) {
444445
/* -------------------------------------------------------------------------- */
446+
(void)d;
445447
/* rx_payload_len is TLV + PROTO (tlv can be present or not) */
446448
uint16_t rx_payload_len = verify_payload_header(buffer);
447449

@@ -498,6 +500,7 @@ bool CMsg::add_msg(CMsg &msg) {
498500
return false;
499501
}
500502
}
503+
return true;
501504
}
502505

503506
/* -------------------------------------------------------------------------- */

libraries/ESPhost/src/EspSpiDriver.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ static spi_event_t _spi_cb_status = SPI_EVENT_TRANSFER_ABORTED;
124124
* ############################# */
125125

126126
static void spi_callback(spi_callback_args_t *p_args);
127-
static void ext_irq_callback(void);
128127

129128

130129
/* execute SPI communication, send the content of tx_buffer to ESP32, put the
@@ -534,9 +533,3 @@ static void spi_callback(spi_callback_args_t *p_args) {
534533
_spi_cb_status = SPI_EVENT_TRANSFER_ABORTED;
535534
}
536535
}
537-
538-
/* -------------------------------------------------------------------------- */
539-
static void ext_irq_callback(void) {
540-
/* -------------------------------------------------------------------------- */
541-
542-
}

libraries/Ethernet/src/Ethernet.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_ser
123123
/* -------------------------------------------------------------------------- */
124124
int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
125125
/* -------------------------------------------------------------------------- */
126+
(void)responseTimeout;
127+
(void)timeout;
126128
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
127129
return begin(local_ip, dns_server, gateway, subnet);
128130
}

libraries/Ethernet/src/EthernetClock.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,14 @@ fsp_err_t EthernetClock::stop() {
4949
fsp_err_t err = R_AGT_Stop(&this->TIMER_ETHERNET_ctrl);
5050
if (err != FSP_SUCCESS) {
5151
return err;
52-
} else {
53-
err = R_AGT_Close(&this->TIMER_ETHERNET_ctrl);
54-
if (err != FSP_SUCCESS) {
55-
return err;
56-
} else {
57-
err = R_AGT_Disable(&this->TIMER_ETHERNET_ctrl);
58-
if (err != FSP_SUCCESS) {
59-
return err;
60-
}
61-
}
6252
}
53+
54+
err = R_AGT_Close(&this->TIMER_ETHERNET_ctrl);
55+
if (err != FSP_SUCCESS) {
56+
return err;
57+
}
58+
59+
return R_AGT_Disable(&this->TIMER_ETHERNET_ctrl);
6360
}
6461

6562
#else

0 commit comments

Comments
 (0)