From e5228822b1870e7ca373e38b50c266a9b25ba617 Mon Sep 17 00:00:00 2001 From: Valerii Koval Date: Wed, 20 Dec 2023 12:09:13 +0200 Subject: [PATCH 1/5] Fix J-Link device names Resolves #19 --- boards/portenta_c33.json | 2 +- boards/uno_r4_minima.json | 2 +- boards/uno_r4_wifi.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/boards/portenta_c33.json b/boards/portenta_c33.json index 3acccce..75eee07 100644 --- a/boards/portenta_c33.json +++ b/boards/portenta_c33.json @@ -26,7 +26,7 @@ "variant": "PORTENTA_C33" }, "debug": { - "jlink_device": "R7FA6M5", + "jlink_device": "R7FA6M5BH", "svd_path": "R7FA6M5BH.svd" }, "frameworks": [ diff --git a/boards/uno_r4_minima.json b/boards/uno_r4_minima.json index 45df704..1e7eefa 100644 --- a/boards/uno_r4_minima.json +++ b/boards/uno_r4_minima.json @@ -26,7 +26,7 @@ "variant": "MINIMA" }, "debug": { - "jlink_device": "ra4m1", + "jlink_device": "R7FA4M1AB", "svd_path": "R7FA4M1AB.svd" }, "frameworks": [ diff --git a/boards/uno_r4_wifi.json b/boards/uno_r4_wifi.json index d425799..592c588 100644 --- a/boards/uno_r4_wifi.json +++ b/boards/uno_r4_wifi.json @@ -32,7 +32,7 @@ "onboard_tools": [ "cmsis-dap" ], - "jlink_device": "ra4m1", + "jlink_device": "R7FA4M1AB", "openocd_config": "openocd.cfg", "svd_path": "R7FA4M1AB.svd" }, From f4aeaf5e22c924cdbb97bc348fc7d445926b2849 Mon Sep 17 00:00:00 2001 From: valeros Date: Thu, 21 Dec 2023 14:26:11 +0200 Subject: [PATCH 2/5] Fix linker flags // Resolves #20 --- builder/frameworks/arduino.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index 9248196..7b841ed 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -79,9 +79,7 @@ def load_flags(filename): "-mcpu=%s" % board.get("build.cpu"), "-mthumb", "-Wl,--gc-sections", - "--specs=nano.specs", "--specs=nosys.specs", - "-nostdlib", '-Wl,-Map="%s"' % os.path.join("${BUILD_DIR}", "${PROGNAME}.map") ], @@ -149,6 +147,13 @@ def load_flags(filename): ] ) +if board.id != "portenta_c33": + env.Append( + LINKFLAGS=[ + "--specs=nano.specs", + ] + ) + # # Add Linker scripts # From 222d97d93acd5d1f9e09cd41a5a610613a763685 Mon Sep 17 00:00:00 2001 From: valeros Date: Thu, 21 Dec 2023 14:26:46 +0200 Subject: [PATCH 3/5] Add basic Arduino IoT Cloud example --- examples/arduino-iot-cloud-basic/.gitignore | 1 + examples/arduino-iot-cloud-basic/README.md | 21 +++++++ .../arduino-iot-cloud-basic/include/README | 39 +++++++++++++ examples/arduino-iot-cloud-basic/lib/README | 46 ++++++++++++++++ .../arduino-iot-cloud-basic/platformio.ini | 21 +++++++ .../src/ArduinoIoTCloud-Basic.ino | 55 +++++++++++++++++++ .../src/arduino_secrets.h | 37 +++++++++++++ .../src/thingProperties.h | 47 ++++++++++++++++ examples/arduino-iot-cloud-basic/test/README | 11 ++++ 9 files changed, 278 insertions(+) create mode 100644 examples/arduino-iot-cloud-basic/.gitignore create mode 100644 examples/arduino-iot-cloud-basic/README.md create mode 100644 examples/arduino-iot-cloud-basic/include/README create mode 100644 examples/arduino-iot-cloud-basic/lib/README create mode 100644 examples/arduino-iot-cloud-basic/platformio.ini create mode 100644 examples/arduino-iot-cloud-basic/src/ArduinoIoTCloud-Basic.ino create mode 100644 examples/arduino-iot-cloud-basic/src/arduino_secrets.h create mode 100644 examples/arduino-iot-cloud-basic/src/thingProperties.h create mode 100644 examples/arduino-iot-cloud-basic/test/README diff --git a/examples/arduino-iot-cloud-basic/.gitignore b/examples/arduino-iot-cloud-basic/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/examples/arduino-iot-cloud-basic/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/examples/arduino-iot-cloud-basic/README.md b/examples/arduino-iot-cloud-basic/README.md new file mode 100644 index 0000000..e4f950e --- /dev/null +++ b/examples/arduino-iot-cloud-basic/README.md @@ -0,0 +1,21 @@ +How to build PlatformIO based project +===================================== + +1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) +2. Download [development platform with examples](https://github.com/platformio/platform-renesas-ra/archive/develop.zip) +3. Extract ZIP archive +4. Run these commands: + +```shell +# Change directory to example +$ cd platform-renesas-ra/examples/arduino-iot-cloud-basic + +# Build project +$ pio run + +# Upload firmware +$ pio run --target upload + +# Clean build files +$ pio run --target clean +``` diff --git a/examples/arduino-iot-cloud-basic/include/README b/examples/arduino-iot-cloud-basic/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/arduino-iot-cloud-basic/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/arduino-iot-cloud-basic/lib/README b/examples/arduino-iot-cloud-basic/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/arduino-iot-cloud-basic/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/arduino-iot-cloud-basic/platformio.ini b/examples/arduino-iot-cloud-basic/platformio.ini new file mode 100644 index 0000000..648abc5 --- /dev/null +++ b/examples/arduino-iot-cloud-basic/platformio.ini @@ -0,0 +1,21 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env] +platform = renesas-ra +framework = arduino +lib_ldf_mode = deep+ +lib_deps = + arduino-libraries/ArduinoIoTCloud@^1.13.0 + +[env:portenta_c33] +board = portenta_c33 + +[env:uno_r4_wifi] +board = uno_r4_wifi diff --git a/examples/arduino-iot-cloud-basic/src/ArduinoIoTCloud-Basic.ino b/examples/arduino-iot-cloud-basic/src/ArduinoIoTCloud-Basic.ino new file mode 100644 index 0000000..ba4162b --- /dev/null +++ b/examples/arduino-iot-cloud-basic/src/ArduinoIoTCloud-Basic.ino @@ -0,0 +1,55 @@ +/* + This sketch demonstrates how to exchange data between your board and the Arduino IoT Cloud. + + * Connect a potentiometer (or other analog sensor) to A0. + * When the potentiometer (or sensor) value changes the data is sent to the Cloud. + * When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF. + + IMPORTANT: + This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud. + On a LoRa board, if it is configured as a class A device (default and preferred option), values from Cloud dashboard are received + only after a value is sent to Cloud. + + The full list of compatible boards can be found here: + - https://github.com/arduino-libraries/ArduinoIoTCloud#what +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32) +static int const LED_BUILTIN = 2; +#endif + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { } + + /* Configure LED pin as an output */ + pinMode(LED_BUILTIN, OUTPUT); + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); + potentiometer = analogRead(A0); + seconds = millis() / 1000; +} + +/* + * 'onLedChange' is called when the "led" property of your Thing changes + */ +void onLedChange() { + Serial.print("LED set to "); + Serial.println(led); + digitalWrite(LED_BUILTIN, led); +} diff --git a/examples/arduino-iot-cloud-basic/src/arduino_secrets.h b/examples/arduino-iot-cloud-basic/src/arduino_secrets.h new file mode 100644 index 0000000..fc43514 --- /dev/null +++ b/examples/arduino-iot-cloud-basic/src/arduino_secrets.h @@ -0,0 +1,37 @@ +#include +#include + +/* A complete list of supported boards with WiFi is available here: + * https://github.com/arduino-libraries/ArduinoIoTCloud/#what + */ +#if defined(BOARD_HAS_WIFI) + #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" + #define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 ESP32*/ +#if defined(BOARD_HAS_SECRET_KEY) + #define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */ +#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_CATM1_NBIOT) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) + #define SECRET_APP_EUI "" + #define SECRET_APP_KEY "" +#endif + +/* Portenta H7 + Ethernet shield */ +#if defined(BOARD_HAS_ETHERNET) + #define SECRET_OPTIONAL_IP "" + #define SECRET_OPTIONAL_DNS "" + #define SECRET_OPTIONAL_GATEWAY "" + #define SECRET_OPTIONAL_NETMASK "" +#endif diff --git a/examples/arduino-iot-cloud-basic/src/thingProperties.h b/examples/arduino-iot-cloud-basic/src/thingProperties.h new file mode 100644 index 0000000..31d49b6 --- /dev/null +++ b/examples/arduino-iot-cloud-basic/src/thingProperties.h @@ -0,0 +1,47 @@ +#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \ + defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)) + #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" +#endif + +#if defined(BOARD_HAS_SECRET_KEY) + #define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#endif + +void onLedChange(); + +bool led; +int potentiometer; +int seconds; + +void initProperties() { +#if defined(BOARD_HAS_SECRET_KEY) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) + ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange); + ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10); + ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange); + ArduinoCloud.addProperty(potentiometer, 2, READ, ON_CHANGE); + ArduinoCloud.addProperty(seconds, 3, READ, 5 * MINUTES); +#endif +} + +#if defined(BOARD_HAS_ETHERNET) + /* DHCP mode */ + //EthernetConnectionHandler ArduinoIoTPreferredConnection; + /* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */ + EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK); +#elif defined(BOARD_HAS_WIFI) + WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) + GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) + LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) + NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_CATM1_NBIOT) + CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/examples/arduino-iot-cloud-basic/test/README b/examples/arduino-iot-cloud-basic/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/arduino-iot-cloud-basic/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html From 7e1a2b53e3d648341b4309aaa8db31b10523093d Mon Sep 17 00:00:00 2001 From: Valerii Koval Date: Thu, 21 Dec 2023 14:27:01 +0200 Subject: [PATCH 4/5] Add new example to CI --- .github/workflows/examples.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index da30d57..2b618c1 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -13,6 +13,7 @@ jobs: - "examples/arduino-internal-libs" - "examples/arduino-uno-r4-led-animation" - "examples/arduino-wifiscan" + - "examples/arduino-iot-cloud-basic" - "examples/cmsis-blink" - "examples/fsp-blink" - "examples/fsp-button-isr" From 5cced3cf0f94e8d5ccec6ddf4a077ae241bb1234 Mon Sep 17 00:00:00 2001 From: valeros Date: Wed, 27 Dec 2023 13:57:32 +0200 Subject: [PATCH 5/5] Bump version to 1.3.1 --- platform.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.json b/platform.json index 9c226b8..4ca7580 100644 --- a/platform.json +++ b/platform.json @@ -21,7 +21,7 @@ "type": "git", "url": "https://github.com/platformio/platform-renesas-ra.git" }, - "version": "1.3.0", + "version": "1.3.1", "frameworks": { "arduino": { "package": "framework-arduinorenesas-uno",