Skip to content

Commit 3aae5cf

Browse files
authored
Merge pull request #9 from 107-systems/renesas
Add support for ArduinoCore-renesas.
2 parents 2ed7969 + 013d9b0 commit 3aae5cf

File tree

7 files changed

+119
-11
lines changed

7 files changed

+119
-11
lines changed

.github/workflows/compile-examples.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ jobs:
3838
platforms: |
3939
- name: rp2040:rp2040
4040
source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
41+
- fqbn: arduino:renesas_portenta:portenta_c33
42+
platforms: |
43+
- name: arduino:renesas_portenta
44+
- fqbn: arduino:renesas_uno:minima
45+
platforms: |
46+
- name: arduino:renesas_uno
4147
4248
steps:
4349
- name: Checkout

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This library provides support functionality for building a complete [Cyphal](htt
1818

1919
This library works for
2020
* [arduino-pico](https://github.com/earlephilhower/arduino-pico): [`Raspberry Pi Pico`](https://www.raspberrypi.org/products/raspberry-pi-pico), `Adafruit Feather RP2040`, ... :heavy_check_mark:
21+
* [ArduinoCore-renesas](https://github.com/arduino/ArduinoCore-renesas): [`Portenta C33`](https://store.arduino.cc/products/portenta-c33), [`Uno R4 WiFi`](https://store.arduino.cc/products/uno-r4-wifi), [`Uno R4 Minima`](https://store.arduino.cc/products/uno-r4-minima), ... :heavy_check_mark:
2122

2223
**Features:**
2324
* API for obtaining a **unique 64-bit ID**.

examples/AsyncReset/AsyncReset.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ void setup()
2727
while (!Serial) { }
2828

2929
Serial.println("Trigger async reset in 5 seconds ...");
30-
cyphal::support::platform::reset_async(std::chrono::milliseconds(5000));
30+
auto const rc = cyphal::support::platform::reset_async(std::chrono::milliseconds(5000));
31+
if (rc.has_value()) {
32+
Serial.print("reset_async failed with error code ");
33+
Serial.println(static_cast<int>(rc.value()));
34+
}
35+
3136
start = millis();
3237
}
3338

examples/SyncReset/SyncReset.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ void setup()
2121
while (!Serial) { }
2222

2323
Serial.println("Trigger sync reset in 5 seconds ...");
24-
cyphal::support::platform::reset_sync(std::chrono::milliseconds(5000));
24+
auto const rc = cyphal::support::platform::reset_sync(std::chrono::milliseconds(5000));
25+
if (rc.has_value()) {
26+
Serial.print("reset_sync failed with error code ");
27+
Serial.println(static_cast<int>(rc.value()));
28+
}
2529
}
2630

2731
void loop()

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ sentence=Arduino library for providing a various support functions for building
66
paragraph=Examples for such support functionality is an API for obtaining a unique 64-bit ID as well as an API for permanent register storage and retrieval.
77
category=Other
88
url=https://github.com/107-systems/107-Arduino-Cyphal-Support
9-
architectures=rp2040
9+
architectures=rp2040,renesas_portenta,renesas_uno
1010
includes=107-Arduino-Cyphal-Support.h
1111
depends=107-Arduino-UniqueId,107-Arduino-Cyphal,107-Arduino-littlefs

src/reset/reset-renesas.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* This software is distributed under the terms of the MIT License.
3+
* Copyright (c) 2023 LXRobotics.
4+
* Author: Alexander Entinger <[email protected]>
5+
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal-Support/graphs/contributors.
6+
*/
7+
8+
/**************************************************************************************
9+
* INCLUDE
10+
**************************************************************************************/
11+
12+
#include "reset.h"
13+
14+
#if defined(ARDUINO_ARCH_RENESAS)
15+
16+
#include <WDT.h>
17+
18+
/* Provide prototype for Arduino's delay function. */
19+
extern "C" void delay(unsigned long);
20+
21+
/**************************************************************************************
22+
* NAMESPACE
23+
**************************************************************************************/
24+
25+
namespace cyphal::support::platform
26+
{
27+
28+
/**************************************************************************************
29+
* GLOBAL CONSTANTS
30+
**************************************************************************************/
31+
32+
#if defined(ARDUINO_MINIMA) || defined(ARDUINO_UNOWIFIR4)
33+
static uint32_t const WATCHDOG_MAX_DELAY_ms = 5592;
34+
#elif defined(ARDUINO_PORTENTA_C33)
35+
static uint32_t const WATCHDOG_MAX_DELAY_ms = 2684;
36+
#else
37+
# error "Your selected Renesas MCU is not supported"
38+
#endif
39+
40+
/**************************************************************************************
41+
* GLOBAL VARIABLES
42+
**************************************************************************************/
43+
44+
static bool is_async_reset_pending_flag = false;
45+
46+
/**************************************************************************************
47+
* FUNCTION DEFINITION
48+
**************************************************************************************/
49+
50+
std::optional<Error> reset()
51+
{
52+
WDT.begin(1); /* Minimum delay is 1 ms. */
53+
return std::nullopt;
54+
}
55+
56+
std::optional<Error> reset_sync(std::chrono::milliseconds const ms)
57+
{
58+
if (ms.count() > WATCHDOG_MAX_DELAY_ms)
59+
return Error::InvalidParam;
60+
61+
WDT.begin(ms.count());
62+
for(;;) { delay(100); } /* Wait for the watchdog to bite. */
63+
return std::nullopt;
64+
}
65+
66+
std::optional<Error> reset_async(std::chrono::milliseconds const ms)
67+
{
68+
if (ms.count() > WATCHDOG_MAX_DELAY_ms)
69+
return Error::InvalidParam;
70+
71+
WDT.begin(ms.count());
72+
73+
is_async_reset_pending_flag = true;
74+
75+
return std::nullopt;
76+
}
77+
78+
bool is_async_reset_pending()
79+
{
80+
return is_async_reset_pending_flag;
81+
}
82+
83+
/**************************************************************************************
84+
* NAMESPACE
85+
**************************************************************************************/
86+
87+
} /* cyphal::support::platform */
88+
89+
#endif /* defined(ARDUINO_ARCH_RENESAS) */

src/reset/reset.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* INCLUDE
1212
**************************************************************************************/
1313

14+
#ifdef ARDUINO_ARCH_RENESAS
15+
# undef abs
16+
#endif
1417
#include <chrono>
1518
#include <optional>
1619

@@ -36,26 +39,26 @@ enum class Error
3639

3740
/* Immediately after calling this method a reset is performed. */
3841
std::optional<Error> reset()
39-
#if !defined(ARDUINO_ARCH_RP2040)
40-
__attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040.")))
42+
#if !defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_RENESAS)
43+
__attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040 and ARDUINO_ARCH_RENESAS.")))
4144
#endif
4245
;
4346

4447
/* This method performs a reset in 'ms' milliseconds after its invocation,
4548
* blocking while waiting for the time to expire.
4649
*/
4750
std::optional<Error> reset_sync(std::chrono::milliseconds const ms)
48-
#if !defined(ARDUINO_ARCH_RP2040)
49-
__attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040.")))
51+
#if !defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_RENESAS)
52+
__attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040 and ARDUINO_ARCH_RENESAS.")))
5053
#endif
5154
;
5255

5356
/* This method performs a reset in 'ms' milliseconds after its invocation,
5457
* but returns immediately after its invocation.
5558
*/
5659
std::optional<Error> reset_async(std::chrono::milliseconds const ms)
57-
#if !defined(ARDUINO_ARCH_RP2040)
58-
__attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040.")))
60+
#if !defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_RENESAS)
61+
__attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040 and ARDUINO_ARCH_RENESAS.")))
5962
#endif
6063
;
6164

@@ -64,8 +67,8 @@ __attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040
6467
* regular watchdog feeding i.e. in the main loop.
6568
*/
6669
bool is_async_reset_pending()
67-
#if !defined(ARDUINO_ARCH_RP2040)
68-
__attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040.")))
70+
#if !defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_RENESAS)
71+
__attribute__ ((error("Currently the reset API only supports ARDUINO_ARCH_RP2040 and ARDUINO_ARCH_RENESAS.")))
6972
#endif
7073
;
7174

0 commit comments

Comments
 (0)