From e19611135a55ae00a62e12a622b9789a79bc30ac Mon Sep 17 00:00:00 2001 From: Maximilian Gerhardt Date: Wed, 12 Jul 2023 13:44:00 +0200 Subject: [PATCH 1/2] Add FSP and CMSIS framework, more examples (#7) * Add support for native FSP framework * Add support for CMSIS framework --- .github/workflows/examples.yml | 5 + .gitignore | 2 + boards/portenta_c33.json | 4 +- boards/uno_r4_minima.json | 4 +- boards/uno_r4_wifi.json | 4 +- builder/frameworks/cmsis.py | 55 +++++++ builder/frameworks/fsp.py | 115 ++++++++++++++ .../arduino-uno-r4-led-animation/.gitignore | 1 + .../arduino-uno-r4-led-animation/README.md | 21 +++ .../include/README | 39 +++++ .../arduino-uno-r4-led-animation/lib/README | 46 ++++++ .../platformio.ini | 16 ++ .../src/animation.h | 75 ++++++++++ .../arduino-uno-r4-led-animation/src/main.cpp | 20 +++ .../arduino-uno-r4-led-animation/test/README | 11 ++ examples/arduino-wifiscan/.gitignore | 1 + examples/arduino-wifiscan/README.md | 27 ++++ examples/arduino-wifiscan/include/README | 39 +++++ examples/arduino-wifiscan/lib/README | 46 ++++++ examples/arduino-wifiscan/platformio.ini | 23 +++ examples/arduino-wifiscan/src/main.cpp | 108 ++++++++++++++ examples/arduino-wifiscan/test/README | 11 ++ examples/cmsis-blink/.gitignore | 1 + examples/cmsis-blink/README.md | 26 ++++ examples/cmsis-blink/include/README | 39 +++++ examples/cmsis-blink/lib/README | 46 ++++++ examples/cmsis-blink/platformio.ini | 22 +++ examples/cmsis-blink/src/main.c | 37 +++++ examples/cmsis-blink/test/README | 11 ++ examples/fsp-blink/.gitignore | 1 + examples/fsp-blink/README.md | 26 ++++ examples/fsp-blink/include/README | 39 +++++ examples/fsp-blink/lib/README | 46 ++++++ examples/fsp-blink/platformio.ini | 22 +++ examples/fsp-blink/src/main.c | 50 +++++++ examples/fsp-blink/test/README | 11 ++ examples/fsp-button-isr/.gitignore | 1 + examples/fsp-button-isr/README.md | 26 ++++ examples/fsp-button-isr/include/README | 39 +++++ examples/fsp-button-isr/lib/README | 46 ++++++ examples/fsp-button-isr/platformio.ini | 22 +++ examples/fsp-button-isr/src/main.c | 140 ++++++++++++++++++ examples/fsp-button-isr/test/README | 11 ++ platform.json | 20 +++ platform.py | 16 +- 45 files changed, 1363 insertions(+), 8 deletions(-) create mode 100644 builder/frameworks/cmsis.py create mode 100644 builder/frameworks/fsp.py create mode 100644 examples/arduino-uno-r4-led-animation/.gitignore create mode 100644 examples/arduino-uno-r4-led-animation/README.md create mode 100644 examples/arduino-uno-r4-led-animation/include/README create mode 100644 examples/arduino-uno-r4-led-animation/lib/README create mode 100644 examples/arduino-uno-r4-led-animation/platformio.ini create mode 100644 examples/arduino-uno-r4-led-animation/src/animation.h create mode 100644 examples/arduino-uno-r4-led-animation/src/main.cpp create mode 100644 examples/arduino-uno-r4-led-animation/test/README create mode 100644 examples/arduino-wifiscan/.gitignore create mode 100644 examples/arduino-wifiscan/README.md create mode 100644 examples/arduino-wifiscan/include/README create mode 100644 examples/arduino-wifiscan/lib/README create mode 100644 examples/arduino-wifiscan/platformio.ini create mode 100644 examples/arduino-wifiscan/src/main.cpp create mode 100644 examples/arduino-wifiscan/test/README create mode 100644 examples/cmsis-blink/.gitignore create mode 100644 examples/cmsis-blink/README.md create mode 100644 examples/cmsis-blink/include/README create mode 100644 examples/cmsis-blink/lib/README create mode 100644 examples/cmsis-blink/platformio.ini create mode 100644 examples/cmsis-blink/src/main.c create mode 100644 examples/cmsis-blink/test/README create mode 100644 examples/fsp-blink/.gitignore create mode 100644 examples/fsp-blink/README.md create mode 100644 examples/fsp-blink/include/README create mode 100644 examples/fsp-blink/lib/README create mode 100644 examples/fsp-blink/platformio.ini create mode 100644 examples/fsp-blink/src/main.c create mode 100644 examples/fsp-blink/test/README create mode 100644 examples/fsp-button-isr/.gitignore create mode 100644 examples/fsp-button-isr/README.md create mode 100644 examples/fsp-button-isr/include/README create mode 100644 examples/fsp-button-isr/lib/README create mode 100644 examples/fsp-button-isr/platformio.ini create mode 100644 examples/fsp-button-isr/src/main.c create mode 100644 examples/fsp-button-isr/test/README diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 59f171f..da30d57 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -11,6 +11,11 @@ jobs: example: - "examples/arduino-blink" - "examples/arduino-internal-libs" + - "examples/arduino-uno-r4-led-animation" + - "examples/arduino-wifiscan" + - "examples/cmsis-blink" + - "examples/fsp-blink" + - "examples/fsp-button-isr" runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 96c40ed..32577bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.pyc .piolibdeps .pio +__pycache__ + diff --git a/boards/portenta_c33.json b/boards/portenta_c33.json index 73d2011..0a30869 100644 --- a/boards/portenta_c33.json +++ b/boards/portenta_c33.json @@ -30,7 +30,9 @@ "svd_path": "R7FA6M5BH.svd" }, "frameworks": [ - "arduino" + "arduino", + "fsp", + "cmsis" ], "name": "Arduino Portenta C33", "upload": { diff --git a/boards/uno_r4_minima.json b/boards/uno_r4_minima.json index 909ce15..40eba67 100644 --- a/boards/uno_r4_minima.json +++ b/boards/uno_r4_minima.json @@ -29,7 +29,9 @@ "svd_path": "R7FA4M1AB.svd" }, "frameworks": [ - "arduino" + "arduino", + "fsp", + "cmsis" ], "name": "Arduino Uno R4 Minima", "upload": { diff --git a/boards/uno_r4_wifi.json b/boards/uno_r4_wifi.json index 6c3ac16..1dfe997 100644 --- a/boards/uno_r4_wifi.json +++ b/boards/uno_r4_wifi.json @@ -36,7 +36,9 @@ "svd_path": "R7FA4M1AB.svd" }, "frameworks": [ - "arduino" + "arduino", + "fsp", + "cmsis" ], "name": "Arduino Uno R4 WiFi", "upload": { diff --git a/builder/frameworks/cmsis.py b/builder/frameworks/cmsis.py new file mode 100644 index 0000000..6d2cc44 --- /dev/null +++ b/builder/frameworks/cmsis.py @@ -0,0 +1,55 @@ +from os.path import isdir, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() +platform = env.PioPlatform() +board = env.BoardConfig() +variant = board.get("build.variant") + +env.SConscript("_bare.py") + +FRAMEWORK_DIR = platform.get_package_dir("framework-cmsis-renesas") +assert isdir(FRAMEWORK_DIR) + +env.Append( + CFLAGS=[ + "-std=gnu11" + ], + + CPPDEFINES=[ + "_RENESAS_RA_" + ], + + CXXFLAGS=[ + "-std=gnu++17", + "-fno-use-cxa-atexit" + ], + + CPPPATH=[ + join(FRAMEWORK_DIR, "CMSIS", "Core", "Include"), + join(FRAMEWORK_DIR, "Device", "RENESAS", "Include"), + join(FRAMEWORK_DIR, "Device", "RENESAS", "Source"), + ], + LINKFLAGS=[ + "--specs=nano.specs" + ], + LIBPATH=[ + join(FRAMEWORK_DIR, "variants", variant) + ], + LDSCRIPT_PATH=join(FRAMEWORK_DIR, "variants", variant, "fsp.ld") +) + +if board.id == "portenta_c33": + env.Append(CPPDEFINES=[("BSP_MCU_GROUP_RA6M5", 1)]) +else: + env.Append(CPPDEFINES=[("BSP_MCU_GROUP_RA4M1", 1)]) + +libs = [] + +libs.append(env.BuildLibrary( + join("$BUILD_DIR", "CMSISFramework"), + join(FRAMEWORK_DIR, "Device", "RENESAS", "Source")) +) + +env.Prepend(LIBS=libs) diff --git a/builder/frameworks/fsp.py b/builder/frameworks/fsp.py new file mode 100644 index 0000000..fff5f66 --- /dev/null +++ b/builder/frameworks/fsp.py @@ -0,0 +1,115 @@ +from os.path import isdir, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() +platform = env.PioPlatform() +board = env.BoardConfig() +variant = board.get("build.variant") + +env.SConscript("_bare.py") + +FRAMEWORK_DIR = platform.get_package_dir("framework-renesas-fsp") +assert isdir(FRAMEWORK_DIR) + +env.Append( + CFLAGS=[ + "-std=gnu11" + ], + + CPPDEFINES=[ + "_RENESAS_RA_" + ], + + CXXFLAGS=[ + "-std=gnu++17", + "-fno-use-cxa-atexit" + ], + + CPPPATH=[ + join(FRAMEWORK_DIR, "fsp", "inc"), + join(FRAMEWORK_DIR, "fsp", "inc", "api"), + join(FRAMEWORK_DIR, "fsp", "inc", "instances"), + join(FRAMEWORK_DIR, "fsp", "src"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce", "common"), + join(FRAMEWORK_DIR, "fsp", "inc", "arm", "CMSIS_5", "CMSIS", "Core", "Include"), + join(FRAMEWORK_DIR, "variants", variant), + join(FRAMEWORK_DIR, "variants", variant, "includes", "ra_gen"), + join(FRAMEWORK_DIR, "variants", variant, "includes", "ra_cfg", "fsp_cfg"), + join(FRAMEWORK_DIR, "variants", variant, "includes", "ra_cfg", "fsp_cfg", "bsp"), + join(FRAMEWORK_DIR, "variants", variant, "tmp_gen_c_files") + ], + LINKFLAGS=[ + "--specs=nano.specs" + ], + LIBPATH=[ + join(FRAMEWORK_DIR, "variants", variant) + ], + LDSCRIPT_PATH=join(FRAMEWORK_DIR, "variants", variant, "fsp.ld") +) + +libs = [] + +# Extracted from ArduinoCore-Renesas\extras\e2studioProjects\Santiago\configuration.xml "raComponentSelection" +sublibs_uno_r4_x = ["r_adc", "r_agt", "r_cgc", "r_dac", "r_doc", "r_dmac", "r_dtc", + "r_elc", "r_gpt", "r_icu", "r_iic_master", "r_iic_slave", "r_ioport", + "r_kint", "r_lpm", "r_rtc", "r_sce/crypto_procedures/src/sce5", "r_sce5_ra4", + "r_sci_i2c", "r_sci_spi", "r_sci_uart", "r_spi", "r_usb_basic", "r_usb_pcdc", + "r_wdt", "r_can", "r_flash_lp", "rm_vee_flash"] +# Extracted from ArduinoCore-Renesas\extras\e2studioProjects\portenta_h33_lib +sublibs_portenta_c33 = ["r_adc", "r_agt", "r_canfd", "r_cgc", "r_crc", "r_dac", "r_dmac", "r_dtc", + "r_elc", "r_ether_phy", "r_ether", "r_flash_hp", "r_gpt", "r_icu", "r_iic_master", + "r_iic_slave", "r_ioport", "r_lpm", "r_qspi", "r_rtc", + "r_sce_protected/crypto_procedures/src/sce9", "r_sci_i2c", "r_sci_spi", + "r_sci_uart", "r_spi", "r_ssi", "r_usb_basic", "r_usb_pcdc", "r_usb_composite", + "r_wdt", "rm_adpcm_decoder", "r_sdhi"] +# This is always built +src_filter = [ + "-<*>", + "+", + "+" +] +if board.get("build.mcu", "").lower().startswith("ra4m1"): + src_filter.append("+") # Uno R4 (Minima, WiFI) +else: + src_filter.append("+") # Portenta +if board.id in ("uno_r4_minima", "uno_r4_wifi"): + src_filter.extend(["+<" + sublib + ">" for sublib in sublibs_uno_r4_x]) + env.Append(CPPPATH=[ + join(FRAMEWORK_DIR, "fsp", "src", "bsp", "mcu", "ra4m1"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce", "crypto_procedures", "src", "sce5", "plainkey", "public", "inc"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce", "crypto_procedures", "src", "sce5", "plainkey", "private", "inc") + ]) + env.Append(CPPDEFINES=[ + ("_RA_CORE", "CM4") + ]) +elif board.id == "portenta_c33": + src_filter.extend(["+<" + sublib + ">" for sublib in sublibs_portenta_c33]) + env.Append(CPPPATH=[ + join(FRAMEWORK_DIR, "fsp", "src", "bsp", "mcu", "ra6m5"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce", "crypto_procedures", "src", "sce9", "plainkey", "public", "inc"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce", "crypto_procedures", "src", "sce9", "plainkey", "private", "inc"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce_protected", "crypto_procedures_protected", "src", "sce9", "inc", "api"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce_protected", "crypto_procedures_protected", "src", "sce9", "inc", "instances"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce_protected", "crypto_procedures_protected", "src", "sce9", "private", "inc"), + join(FRAMEWORK_DIR, "fsp", "src", "r_sce_protected", "crypto_procedures_protected", "src", "sce9", "public", "inc"), + join(FRAMEWORK_DIR, "variants", variant, "includes", "ra_cfg", "driver") + ]) + env.Append(CPPDEFINES=[ + ("_RA_CORE", "CM33") + ]) + +# Build the FSP framework +libs.append(env.BuildLibrary( + join("$BUILD_DIR", "FSPFramework"), + join(FRAMEWORK_DIR, "fsp", "src"), + src_filter + ) +) +# Build the glue files +libs.append(env.BuildLibrary( + join("$BUILD_DIR", "FSPFrameworkVariant"), + join(FRAMEWORK_DIR, "variants", variant, "tmp_gen_c_files"))) + +env.Prepend(LIBS=libs) diff --git a/examples/arduino-uno-r4-led-animation/.gitignore b/examples/arduino-uno-r4-led-animation/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/examples/arduino-uno-r4-led-animation/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/examples/arduino-uno-r4-led-animation/README.md b/examples/arduino-uno-r4-led-animation/README.md new file mode 100644 index 0000000..056cfb1 --- /dev/null +++ b/examples/arduino-uno-r4-led-animation/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-uno-r4-led-animation + +# Build project +$ pio run + +# Upload firmware +$ pio run --target upload + +# Clean build files +$ pio run --target clean +``` diff --git a/examples/arduino-uno-r4-led-animation/include/README b/examples/arduino-uno-r4-led-animation/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/arduino-uno-r4-led-animation/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-uno-r4-led-animation/lib/README b/examples/arduino-uno-r4-led-animation/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/arduino-uno-r4-led-animation/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-uno-r4-led-animation/platformio.ini b/examples/arduino-uno-r4-led-animation/platformio.ini new file mode 100644 index 0000000..77b3f89 --- /dev/null +++ b/examples/arduino-uno-r4-led-animation/platformio.ini @@ -0,0 +1,16 @@ +; 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 + +[env:uno_r4_wifi] +board = uno_r4_wifi + diff --git a/examples/arduino-uno-r4-led-animation/src/animation.h b/examples/arduino-uno-r4-led-animation/src/animation.h new file mode 100644 index 0000000..a359d41 --- /dev/null +++ b/examples/arduino-uno-r4-led-animation/src/animation.h @@ -0,0 +1,75 @@ +#include +const uint32_t animation[][4] = { + { + 0x30c20, + 0x43fc3fc2, + 0x430c000, + 66 + }, + { + 0x30c29, + 0x436c36c2, + 0x9430c000, + 66 + }, + { + 0x30c2f, + 0x430c30c2, + 0xf430c000, + 66 + }, + { + 0x36c29, + 0x41081082, + 0x9436c000, + 66 + }, + { + 0x3fc30, + 0xc1081083, + 0xc3fc000, + 66 + }, + { + 0x3fc20, + 0x42042042, + 0x43fc000, + 66 + }, + { + 0x3f, + 0xc2042043, + 0xfc000000, + 66 + }, + { + 0x0, + 0x3fc3fc0, + 0x0, + 66 + }, + { + 0x0, + 0x1f81f80, + 0x0, + 66 + }, + { + 0x0, + 0xf00f00, + 0x0, + 66 + }, + { + 0x0, + 0x600600, + 0x0, + 66 + }, + { + 0x0, + 0x0, + 0x0, + 66 + } +}; \ No newline at end of file diff --git a/examples/arduino-uno-r4-led-animation/src/main.cpp b/examples/arduino-uno-r4-led-animation/src/main.cpp new file mode 100644 index 0000000..50d90ca --- /dev/null +++ b/examples/arduino-uno-r4-led-animation/src/main.cpp @@ -0,0 +1,20 @@ +#include +#include "Arduino_LED_Matrix.h" +#include "animation.h" + +ArduinoLEDMatrix matrix; + +void setup() { + Serial.begin(115200); + // you can also load frames at runtime, without stopping the refresh + matrix.loadSequence(animation); + matrix.begin(); + // turn on autoscroll to avoid calling next() to show the next frame; the paramenter is in milliseconds + // matrix.autoscroll(300); + matrix.play(true); +} + +void loop() { + delay(500); + Serial.println(millis()); +} \ No newline at end of file diff --git a/examples/arduino-uno-r4-led-animation/test/README b/examples/arduino-uno-r4-led-animation/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/arduino-uno-r4-led-animation/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 diff --git a/examples/arduino-wifiscan/.gitignore b/examples/arduino-wifiscan/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/examples/arduino-wifiscan/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/examples/arduino-wifiscan/README.md b/examples/arduino-wifiscan/README.md new file mode 100644 index 0000000..73f465d --- /dev/null +++ b/examples/arduino-wifiscan/README.md @@ -0,0 +1,27 @@ +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-wifiscan + +# Build project +$ pio run + +# Upload firmware +$ pio run --target upload + +# Build specific environment +$ pio run -e uno_r4_wifi + +# Upload firmware for the specific environment +$ pio run -e uno_r4_wifi --target upload + +# Clean build files +$ pio run --target clean +``` diff --git a/examples/arduino-wifiscan/include/README b/examples/arduino-wifiscan/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/arduino-wifiscan/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-wifiscan/lib/README b/examples/arduino-wifiscan/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/arduino-wifiscan/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-wifiscan/platformio.ini b/examples/arduino-wifiscan/platformio.ini new file mode 100644 index 0000000..04303d4 --- /dev/null +++ b/examples/arduino-wifiscan/platformio.ini @@ -0,0 +1,23 @@ +; 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 +monitor_speed = 115200 +; needed for WiFi sublibraries to be found correctly +lib_ldf_mode = deep+ + +[env:uno_r4_wifi] +board = uno_r4_wifi + +[env:portenta_c33] +board = portenta_c33 + diff --git a/examples/arduino-wifiscan/src/main.cpp b/examples/arduino-wifiscan/src/main.cpp new file mode 100644 index 0000000..725c654 --- /dev/null +++ b/examples/arduino-wifiscan/src/main.cpp @@ -0,0 +1,108 @@ +#include +#if defined(ARDUINO_UNOR4_WIFI) +#include +#elif defined(ARDUINO_PORTENTA_C33) +#include +#else +#error "Unsupported board for this sketch!" +#endif + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.println("WEP"); + break; + case ENC_TYPE_WPA: + Serial.println("WPA"); + break; + case ENC_TYPE_WPA2: + Serial.println("WPA2"); + break; + case ENC_TYPE_WPA3: + Serial.print("WPA3"); + break; + case ENC_TYPE_NONE: + Serial.println("None"); + break; + case ENC_TYPE_AUTO: + Serial.println("Auto"); + break; + case ENC_TYPE_UNKNOWN: + default: + Serial.println("Unknown"); + break; + } +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} + + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) { + Serial.println("Couldn't get a WiFi connection"); + while (true); + } + + // print the list of networks seen: + Serial.print("number of available networks:"); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet); + Serial.print(") "); + Serial.print(WiFi.SSID(thisNet)); + Serial.print(" Signal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print(" Encryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + } +} + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } +} + +void loop() { + byte mac[6]; + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); + WiFi.macAddress(mac); + Serial.println(); + Serial.print("Your MAC Address is: "); + printMacAddress(mac); + delay(10000); +} \ No newline at end of file diff --git a/examples/arduino-wifiscan/test/README b/examples/arduino-wifiscan/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/arduino-wifiscan/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 diff --git a/examples/cmsis-blink/.gitignore b/examples/cmsis-blink/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/examples/cmsis-blink/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/examples/cmsis-blink/README.md b/examples/cmsis-blink/README.md new file mode 100644 index 0000000..ddbebf5 --- /dev/null +++ b/examples/cmsis-blink/README.md @@ -0,0 +1,26 @@ +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/cmsis-blink + +# Build project +$ pio run + +# Upload firmware +$ pio run --target upload + +# Clean build files +$ pio run --target clean +``` + +Note +---- + +Since this firmware does not include native USB functionality, on the Uno R4 Minima and Portenta C33, you will have to quickly double-press the reset button to enter bootloader mode again in order to upload a new firmware. The bootloader itself is **not** overwritten by this firmware. \ No newline at end of file diff --git a/examples/cmsis-blink/include/README b/examples/cmsis-blink/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/cmsis-blink/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/cmsis-blink/lib/README b/examples/cmsis-blink/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/cmsis-blink/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/cmsis-blink/platformio.ini b/examples/cmsis-blink/platformio.ini new file mode 100644 index 0000000..9592e17 --- /dev/null +++ b/examples/cmsis-blink/platformio.ini @@ -0,0 +1,22 @@ +; 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 = cmsis + +[env:portenta_c33] +board = portenta_c33 + +[env:uno_r4_minima] +board = uno_r4_minima + +[env:uno_r4_wifi] +board = uno_r4_wifi + diff --git a/examples/cmsis-blink/src/main.c b/examples/cmsis-blink/src/main.c new file mode 100644 index 0000000..b25d24a --- /dev/null +++ b/examples/cmsis-blink/src/main.c @@ -0,0 +1,37 @@ +#include +#include +#if defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA) +#include +#elif defined(ARDUINO_PORTENTA_C33) +#include +#endif + +// LED on Uno R4 Minima: P1.11 +// LED on Uno R4 WiFi: P1.02 +// Red LED on Portanta C33: P1.07 +#define LED_PORT_NUM 1 +#define LED_PIN_NUM 2 + +int main() { + // enable writing to the pin registers + R_PMISC->PWPR = 0; // Clear BOWI bit - writing to PFSWE bit enabled + R_PMISC->PWPR = 1U << 6; // Set PFSWE bit - writing to PFS register enabled + + // Set GPIO output mode + R_PFS->PORT[LED_PORT_NUM].PIN[LED_PIN_NUM].PmnPFS_b.PDR = 1; // "Output" + R_PFS->PORT[LED_PORT_NUM].PIN[LED_PIN_NUM].PmnPFS_b.DSCR = 1; // "Middle Drive capability" + R_PFS->PORT[LED_PORT_NUM].PIN[LED_PIN_NUM].PmnPFS_b.PMR = 0; // "Used as a general I/O pin" + while(1) { + // set pin HIGH + R_PFS->PORT[LED_PORT_NUM].PIN[LED_PIN_NUM].PmnPFS_b.PODR = 1; + // delay very crudely in a NOP loop, 1s delay at 8MHz reset clock + for(volatile int i=0; i < 8*1000*1000/2; i++) {} + // set LOW + R_PFS->PORT[LED_PORT_NUM].PIN[LED_PIN_NUM].PmnPFS_b.PODR = 0; + // delay + for(volatile int i=0; i < 8*1000*1000/2; i++) {} + } + return 0; +} + +void NMI_Handler (void) { while(1) { }} \ No newline at end of file diff --git a/examples/cmsis-blink/test/README b/examples/cmsis-blink/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/cmsis-blink/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 diff --git a/examples/fsp-blink/.gitignore b/examples/fsp-blink/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/examples/fsp-blink/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/examples/fsp-blink/README.md b/examples/fsp-blink/README.md new file mode 100644 index 0000000..8e6e0f0 --- /dev/null +++ b/examples/fsp-blink/README.md @@ -0,0 +1,26 @@ +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/fsp-blink + +# Build project +$ pio run + +# Upload firmware +$ pio run --target upload + +# Clean build files +$ pio run --target clean +``` + +Note +---- + +Since this firmware does not include native USB functionality, on the Uno R4 Minima and Portenta C33, you will have to quickly double-press the reset button to enter bootloader mode again in order to upload a new firmware. The bootloader itself is **not** overwritten by this firmware. \ No newline at end of file diff --git a/examples/fsp-blink/include/README b/examples/fsp-blink/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/fsp-blink/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/fsp-blink/lib/README b/examples/fsp-blink/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/fsp-blink/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/fsp-blink/platformio.ini b/examples/fsp-blink/platformio.ini new file mode 100644 index 0000000..8903a26 --- /dev/null +++ b/examples/fsp-blink/platformio.ini @@ -0,0 +1,22 @@ +; 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 = fsp + +[env:portenta_c33] +board = portenta_c33 + +[env:uno_r4_minima] +board = uno_r4_minima + +[env:uno_r4_wifi] +board = uno_r4_wifi + diff --git a/examples/fsp-blink/src/main.c b/examples/fsp-blink/src/main.c new file mode 100644 index 0000000..9ebbee4 --- /dev/null +++ b/examples/fsp-blink/src/main.c @@ -0,0 +1,50 @@ +#include "hal_data.h" +void R_BSP_WarmStart(bsp_warm_start_event_t event); + +/* Change LED as needed here */ +#if defined(ARDUINO_UNOR4_WIFI) +#define LED BSP_IO_PORT_01_PIN_02 // Yellow +#elif defined(ARDUINO_UNOR4_MINIMA) +#define LED BSP_IO_PORT_01_PIN_11 // Yellow +#elif defined(ARDUINO_PORTENTA_C33) +#define LED BSP_IO_PORT_01_PIN_07 // Red +#else +#error "Unknown board, please set LED" +#endif + +void hal_entry(void) +{ + R_BSP_PinAccessEnable(); + R_IOPORT_PinCfg(&g_ioport_ctrl, LED, IOPORT_CFG_PORT_DIRECTION_OUTPUT); + while(true) + { + R_IOPORT_PinWrite(&g_ioport_ctrl, LED, BSP_IO_LEVEL_HIGH); + R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS); + R_IOPORT_PinWrite(&g_ioport_ctrl, LED, BSP_IO_LEVEL_LOW); + R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS); + } +} + +/*******************************************************************************************************************//** + * This function is called at various points during the startup process. This implementation uses the event that is + * called right before main() to set up the pins. + * + * @param[in] event Where at in the start up process the code is currently at + **********************************************************************************************************************/ +void R_BSP_WarmStart(bsp_warm_start_event_t event) +{ + if (BSP_WARM_START_RESET == event) + { +#if BSP_FEATURE_FLASH_LP_VERSION != 0 + /* Enable reading from data flash. */ + R_FACI_LP->DFLCTL = 1U; + /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and + * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ +#endif + } + if (BSP_WARM_START_POST_C == event) + { + /* C runtime environment and system clocks are setup. */ + /* E.g., you can configure pins here. */ + } +} diff --git a/examples/fsp-blink/test/README b/examples/fsp-blink/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/fsp-blink/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 diff --git a/examples/fsp-button-isr/.gitignore b/examples/fsp-button-isr/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/examples/fsp-button-isr/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/examples/fsp-button-isr/README.md b/examples/fsp-button-isr/README.md new file mode 100644 index 0000000..895e23d --- /dev/null +++ b/examples/fsp-button-isr/README.md @@ -0,0 +1,26 @@ +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/fsp-button-isr + +# Build project +$ pio run + +# Upload firmware +$ pio run --target upload + +# Clean build files +$ pio run --target clean +``` + +Note +---- + +Since this firmware does not include native USB functionality, on the Uno R4 Minima and Portenta C33, you will have to quickly double-press the reset button to enter bootloader mode again in order to upload a new firmware. The bootloader itself is **not** overwritten by this firmware. \ No newline at end of file diff --git a/examples/fsp-button-isr/include/README b/examples/fsp-button-isr/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/fsp-button-isr/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/fsp-button-isr/lib/README b/examples/fsp-button-isr/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/fsp-button-isr/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/fsp-button-isr/platformio.ini b/examples/fsp-button-isr/platformio.ini new file mode 100644 index 0000000..8903a26 --- /dev/null +++ b/examples/fsp-button-isr/platformio.ini @@ -0,0 +1,22 @@ +; 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 = fsp + +[env:portenta_c33] +board = portenta_c33 + +[env:uno_r4_minima] +board = uno_r4_minima + +[env:uno_r4_wifi] +board = uno_r4_wifi + diff --git a/examples/fsp-button-isr/src/main.c b/examples/fsp-button-isr/src/main.c new file mode 100644 index 0000000..12e40a3 --- /dev/null +++ b/examples/fsp-button-isr/src/main.c @@ -0,0 +1,140 @@ +#include "hal_data.h" +#include +void R_BSP_WarmStart(bsp_warm_start_event_t event); + +/* Change pins as needed here */ +#define ICU_CHANNEL 0 // freely choosable from 0 to 15 +#define NVIC_ICU_IRQ 0 // freely choosable position in the vector table (0 to 31) +#if defined(ARDUINO_UNOR4_WIFI) +#define LED BSP_IO_PORT_01_PIN_02 // Yellow +#define BUTTON BSP_IO_PORT_01_PIN_04 // "D2" +// must match "Renesas RA4M1 Group - User's Manual: Hardware" +// "Register settings for input/output pin function", "ISEL bit" +// NOT ALL PINS ARE INTERRUPT CAPABLE!! +// P105 has "IRQ1" +#define ELC_EVENT_TO_LINK ELC_EVENT_ICU_IRQ1 /* ICU IRQ1 (External pin interrupt 1) */ +#elif defined(ARDUINO_UNOR4_MINIMA) +#define LED BSP_IO_PORT_01_PIN_11 // Yellow +#define BUTTON BSP_IO_PORT_01_PIN_05 // "D2" +// P105 has "IRQ0" +#define ELC_EVENT_TO_LINK ELC_EVENT_ICU_IRQ0 /* ICU IRQ0 (External pin interrupt 0) */ +#elif defined(ARDUINO_PORTENTA_C33) +#define LED BSP_IO_PORT_01_PIN_07 // Red +#define BUTTON BSP_IO_PORT_01_PIN_11 // "D2" +// P111 has "IRQ4" +#define ELC_EVENT_TO_LINK ELC_EVENT_ICU_IRQ4 /* ICU IRQ4 (External pin interrupt 4) */ +#else +#error "Unknown board, please set LED and Button pin" +#endif + +// linker script and CMSIS symbols +extern const uint32_t __StackTop; +const uint32_t *APPLICATION_VECTOR_TABLE_ADDRESS_RAM = (uint32_t *)&__StackTop; +extern uint32_t __ROM_Start; +extern const fsp_vector_t __VECTOR_TABLE[BSP_CORTEX_VECTOR_TABLE_ENTRIES]; + +BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BSP_PLACE_IN_SECTION(BSP_SECTION_APPLICATION_VECTORS) = { + // you can add interrupt functions here as needed or set them later using NVIC_SetVector() + // see e.g. ArduinoCore-Renesas vector_table + [(int)NVIC_ICU_IRQ] = r_icu_isr, +}; +/* Needed to link the NVIC IRQ number to an ICU (interrupt controll unit) event */ +/* sets R_ICU->IELSR registers */ +const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = { + [(int)NVIC_ICU_IRQ] = ELC_EVENT_TO_LINK, +}; + +// akin to ArduinoCore-Renesas main.cpp +void copy_vectors_to_ram() { + __disable_irq(); + // reserved space in RAM via linkerscript + volatile uint32_t *irq_vector_table = (volatile uint32_t *)APPLICATION_VECTOR_TABLE_ADDRESS_RAM; + size_t _i; + // copy the Cortex-M4's vectors (ResetHandler, NMI, SysTick, ..) + for (_i = 0; _i < BSP_CORTEX_VECTOR_TABLE_ENTRIES; _i++) { + *(irq_vector_table + _i) = (uint32_t)__VECTOR_TABLE[_i]; + } + // copy the device-specific vectors for this microcontroller (Port interrupts, UART, I2C, ...) + for (_i = 0; _i < BSP_ICU_VECTOR_MAX_ENTRIES; _i++) { + *(irq_vector_table + _i + BSP_CORTEX_VECTOR_TABLE_ENTRIES) = (uint32_t)g_vector_table[_i]; + } + // set vector table offset register to point at our RAM copy + SCB->VTOR = (uint32_t)irq_vector_table; + // data sync barrier, renable IRQ + __DSB(); + __enable_irq(); +} + +static uint8_t ledState = 0; +static volatile uint8_t interrupt_occurred = 0; +/* Called from icu_irq_isr */ +void button_pressed_isr (external_irq_callback_args_t * p_args) +{ + // only flag that interrupt occurred, we can handle debouncing in the main loop + interrupt_occurred = 1; +} + +void hal_entry(void) +{ + // needed when we are invoked from the Arduino bootloader to use our own vector table + copy_vectors_to_ram(); + + // output on LED + R_IOPORT_PinCfg(&g_ioport_ctrl, LED, IOPORT_CFG_PORT_DIRECTION_OUTPUT); + // IRQ input + pullup on button (will trigger when touched with GND) + R_IOPORT_PinCfg(&g_ioport_ctrl, BUTTON, IOPORT_CFG_IRQ_ENABLE | IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE); + + external_irq_cfg_t icu_cfg = + { + .channel = ICU_CHANNEL, + .trigger = EXTERNAL_IRQ_TRIG_FALLING, + .filter_enable = false, /* must be 0 for port IRQs */ + .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, + .p_callback = &button_pressed_isr, + .p_context = NULL, + .ipl = 0, + .irq = (IRQn_Type) NVIC_ICU_IRQ, + }; + + /* Open and enable the external interrupt. */ + icu_instance_ctrl_t irq_ctrl; + memset(&irq_ctrl, 0, sizeof(irq_ctrl)); + fsp_err_t err = R_ICU_ExternalIrqOpen(&irq_ctrl, &icu_cfg); + assert(FSP_SUCCESS == err); + + err = R_ICU_ExternalIrqEnable(&irq_ctrl); + assert(FSP_SUCCESS == err); + + // start with turned on LED + ledState = 1; + R_IOPORT_PinWrite(&g_ioport_ctrl, LED, ledState ? BSP_IO_LEVEL_HIGH : BSP_IO_LEVEL_LOW); + + while(true) + { + if(interrupt_occurred) { + ledState ^= 1; // toggle + R_IOPORT_PinWrite(&g_ioport_ctrl, LED, ledState ? BSP_IO_LEVEL_HIGH : BSP_IO_LEVEL_LOW); + // debounce in software + R_BSP_SoftwareDelay(200, BSP_DELAY_UNITS_MILLISECONDS); + interrupt_occurred = 0; + } + } +} + +void R_BSP_WarmStart(bsp_warm_start_event_t event) +{ + if (BSP_WARM_START_RESET == event) + { +#if BSP_FEATURE_FLASH_LP_VERSION != 0 + /* Enable reading from data flash. */ + R_FACI_LP->DFLCTL = 1U; + /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and + * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ +#endif + } + if (BSP_WARM_START_POST_C == event) + { + /* C runtime environment and system clocks are setup. */ + /* E.g., you can configure pins here. */ + } +} diff --git a/examples/fsp-button-isr/test/README b/examples/fsp-button-isr/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/fsp-button-isr/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 diff --git a/platform.json b/platform.json index 8fe103c..ea02777 100644 --- a/platform.json +++ b/platform.json @@ -26,6 +26,14 @@ "arduino": { "package": "framework-arduinorenesas-uno", "script": "builder/frameworks/arduino.py" + }, + "fsp": { + "package": "framework-renesas-fsp", + "script": "builder/frameworks/fsp.py" + }, + "cmsis": { + "package": "framework-cmsis-renesas", + "script": "builder/frameworks/cmsis.py" } }, "packages": { @@ -46,6 +54,18 @@ "owner": "platformio", "version": "~1.0.1" }, + "framework-renesas-fsp": { + "type": "framework", + "optional": true, + "owner": "platformio", + "version": "1.40000.0" + }, + "framework-cmsis-renesas": { + "type": "framework", + "optional": true, + "owner": "platformio", + "version": "1.40500.0" + }, "tool-dfuutil-arduino": { "type": "uploader", "optional": true, diff --git a/platform.py b/platform.py index 0526ccf..2742421 100644 --- a/platform.py +++ b/platform.py @@ -49,11 +49,17 @@ def _configure_uploader_packages(package_name, interface_name): ): _configure_uploader_packages(package, interface) - if variables.get("board") == "portenta_c33": - self.frameworks["arduino"]["package"] = "framework-arduinorenesas-portenta" - self.packages["framework-arduinorenesas-portenta"]["optional"] = False - else: - self.packages["framework-arduinorenesas-uno"]["optional"] = False + frameworks = variables.get("pioframework", []) + if "arduino" in frameworks: + if variables.get("board") == "portenta_c33": + self.frameworks["arduino"]["package"] = "framework-arduinorenesas-portenta" + self.packages["framework-arduinorenesas-portenta"]["optional"] = False + else: + self.packages["framework-arduinorenesas-uno"]["optional"] = False + if "fsp" in frameworks: + self.packages["framework-renesas-fsp"]["optional"] = False + if "cmsis" in frameworks: + self.packages["framework-cmsis-renesas"]["optional"] = False return super().configure_default_packages(variables, targets) From 7fdde2301dd8729a7549b66b47d94dc107df5387 Mon Sep 17 00:00:00 2001 From: valeros Date: Fri, 28 Jul 2023 12:52:53 +0300 Subject: [PATCH 2/2] Bump version to 1.0.0 --- platform.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.json b/platform.json index ea02777..dd0394a 100644 --- a/platform.json +++ b/platform.json @@ -21,7 +21,7 @@ "type": "git", "url": "https://github.com/platformio/platform-renesas-ra.git" }, - "version": "0.0.2", + "version": "1.0.0", "frameworks": { "arduino": { "package": "framework-arduinorenesas-uno",