From db5755250e894356872b02e28bc4bee54aa988f6 Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Mon, 11 Nov 2019 19:02:29 +0100 Subject: [PATCH 01/15] fix atstart import script --- library.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/library.py b/library.py index 9738cb7..ebcc178 100644 --- a/library.py +++ b/library.py @@ -14,23 +14,23 @@ import requests import zipfile +global_env = DefaultEnvironment() + +print('Start') try: import yaml except ImportError: env.Execute("$PYTHONEXE -m pip install pyyaml") import yaml -from yaml import CLoader as Loader +from yaml import Loader try: import configparser except ImportError: import ConfigParser as configparser -global_env = DefaultEnvironment() -Import('env') - output_filename = "output.json" -DOWNLOAD_DIR = os.path.join(env['PROJECTWORKSPACE_DIR'], ".downloads") +DOWNLOAD_DIR = os.path.join(env['PROJECT_WORKSPACE_DIR'], ".downloads") PACKAGES_DIR = "packages" config = configparser.ConfigParser() @@ -177,7 +177,7 @@ def adjust_linker_offset(script_name, ldscript): r"\1+%s\2-%s" % (offset_address, offset_address), content, flags=re.MULTILINE) - offset_script = os.path.join(env.subst('$PROJECTBUILD_DIR'), + offset_script = os.path.join(env.subst('$PROJECT_BUILD_DIR'), "%s_flash_%s.ld" % (script_name, offset_address)) with open(offset_script, "w") as fp: @@ -185,7 +185,8 @@ def adjust_linker_offset(script_name, ldscript): return offset_script -linker_script = adjust_linker_offset(env.subst('$PIOENV'), linker_script) +# following function does not work with custom board due to platformio bug +# linker_script = adjust_linker_offset(env.subst('$PIOENV'), linker_script) global_env.Append(CPPPATH=[os.path.realpath(p) for p in include_paths]) env.Append( @@ -204,5 +205,5 @@ def src_dir(*x): SRC_FILTER=sources ) -global_env.Replace( - LDSCRIPT_PATH=linker_script) +env.Append( + LINKFLAGS=['-T',linker_script]) From fb294f2a4ec3d8819d3b913c56e320aa7f93423d Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Mon, 11 Nov 2019 19:18:06 +0100 Subject: [PATCH 02/15] move atStart file project dir --- library.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.py b/library.py index ebcc178..0e90666 100644 --- a/library.py +++ b/library.py @@ -15,7 +15,7 @@ import zipfile global_env = DefaultEnvironment() - +Import('env') print('Start') try: import yaml @@ -39,7 +39,7 @@ if atstart_file is None: sys.stderr.write("Error: Please specify property `atstart_file = myproject.atstart`.\nThe file is expected to be in the project source directory.\n") env.Exit(1) -input_filename = os.path.join(env['PROJECTSRC_DIR'], atstart_file) +input_filename = os.path.join(env['PROJECT_DIR'], atstart_file) if not os.path.isfile(input_filename): sys.stderr.write("Error: atstart_file specifies a non-existent or invalid file: {}\n".format(input_filename)) env.Exit(1) From a248a7ddcdd5621f6881763173860d01643e7dde Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Mon, 11 Nov 2019 22:33:47 +0100 Subject: [PATCH 03/15] clean up --- library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.py b/library.py index 0e90666..37cd2fc 100644 --- a/library.py +++ b/library.py @@ -16,7 +16,7 @@ global_env = DefaultEnvironment() Import('env') -print('Start') + try: import yaml except ImportError: From 2d7d8c5c528b79d0d43d80fc5a2a6c21583dc8ab Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Mon, 11 Nov 2019 23:40:59 +0100 Subject: [PATCH 04/15] add a readme --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..193b784 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Using platform io as an IDE for ASF4 projects +ASF4 is a collection of software components such as peripheral drivers, middleware, and software applications provided by Microchip. The framework supports the Microchip's SAM family of microcontrollers. + +Atmel START - https://start.atmel.com/ - is a web-based software configuration tool, for various software frameworks, which helps you get started with MCU development. Starting from either a new project or an example project, Atmel START allows you to select and configure software components (from ASF4 and AVR Code), such as drivers and middleware to tailor your embedded application in a usable and optimized manner. Once an optimized software configuration is done, you can download the generated code project and open it in the IDE of your choice, including Studio 7, IAR Embedded Workbench®, Keil® μVision®, or simply generate a makefile. + +This tutorial explains how to open an Atmel START project in platformIO. + +## Start a new project +1. Go to [Atmel START](https://start.atmel.com/) amd create a new project. Choose your mcu and configure all the software libraries you need. +2. Save and Download the configuration file as a [project name].atstart in a new project folder. +3. Start a new platformio projectin that project folder with `platformio init` +4. Create a custom board like explained [here](https://docs.platformio.org/en/latest/platforms/creating_board.html). You can start from the myboard.json file in the examples folder. It is important to not have a "ldscript" tag defined in the "build" section. The atmel start project will contain a new linker script. +5. Define an [environment](https://docs.platformio.org/en/latest/projectconf.html) in platformio.ini file that contains the following settings: +``` +[env:myEnvironment] +platform = atmelsam +board = myboard ; custom board as created in step 4 +atstart_file = myAtStartProject.atstart ; name of the downloaded atstart file from step 3 +lib_deps = https://github.com/JelleRoets/AtmelStart_PlatformIO ; library that will download and include all ASF libraries as configured in the atstart file +``` +7. From the moment you save the ini file (or run `platformio run` for the first time) it will download the package in `.pio/libdeps/[env]/AtmelStart_PlatformIO/packages/[someHash]` +8. Go find a main.c file in that package and copy it to the project src folder as `main.cpp` and start editing. + +Now you should be all set to further extend your project, compile, upload and debug your project with all features from platformIO. + +## Some background info +The magic happens by an extra script in the AtmelStart_PlatformIO. This script will download the package according to the given atstart file. It will include all headers and compile all library files when compiling the project. Everytime the .atstart file changes (when you updated your config in the web based atmel START tool) it will download a new package and use the (converted) .atstart file as a hash. + +## TODO +- automatically update the custom board file when chosing a different mcu. It should not only update the mcu name but also the openocd name and target, find the corresponding svd file (e.g. downloading it from: http://packs.download.atmel.com/ ) and update the ram size +- a bootloader offset is currently not taken into account, due to a bug (https://github.com/platformio/platformio-core/issues/3264) that prevents using custom board definitions in library scripts. +- add a custom task / command to easily go to the online Atmel START tool with the current .atstart file preloaded (not sure if there is an atmel start rest api for this...) + +## Credits: +- [Frank Leon Rose](https://github.com/frankleonrose) +- [Jelle Roets](https://github.com/JelleRoets) \ No newline at end of file From 9c2aa0ddc58ee72450119177614d2a060d6d2d74 Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Mon, 11 Nov 2019 23:46:49 +0100 Subject: [PATCH 05/15] add example --- README.md | 3 + examples/ArduinoZeroASF/.travis.yml | 67 +++ examples/ArduinoZeroASF/arduinoZero.atstart | 529 ++++++++++++++++++++ examples/ArduinoZeroASF/boards/myboard.json | 30 ++ examples/ArduinoZeroASF/include/README | 39 ++ examples/ArduinoZeroASF/lib/README | 46 ++ examples/ArduinoZeroASF/platformio.ini | 18 + examples/ArduinoZeroASF/src/main.cpp | 13 + examples/ArduinoZeroASF/test/README | 11 + 9 files changed, 756 insertions(+) create mode 100644 examples/ArduinoZeroASF/.travis.yml create mode 100644 examples/ArduinoZeroASF/arduinoZero.atstart create mode 100644 examples/ArduinoZeroASF/boards/myboard.json create mode 100644 examples/ArduinoZeroASF/include/README create mode 100644 examples/ArduinoZeroASF/lib/README create mode 100644 examples/ArduinoZeroASF/platformio.ini create mode 100644 examples/ArduinoZeroASF/src/main.cpp create mode 100644 examples/ArduinoZeroASF/test/README diff --git a/README.md b/README.md index 193b784..fce3066 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ lib_deps = https://github.com/JelleRoets/AtmelStart_PlatformIO ; library that wi Now you should be all set to further extend your project, compile, upload and debug your project with all features from platformIO. +## Examples +You can find an example in `examples\ArduinoZeroASF`, where I use Atmel Start and ASF4 libraries to create and debug a blink example project for the Arduino Zero. You simply do `platformio run` and / or ` platformio run --target upload ` (Note that uploading the binary with a debugger to the arduino zero will remove the existing bootloader). + ## Some background info The magic happens by an extra script in the AtmelStart_PlatformIO. This script will download the package according to the given atstart file. It will include all headers and compile all library files when compiling the project. Everytime the .atstart file changes (when you updated your config in the web based atmel START tool) it will download a new package and use the (converted) .atstart file as a hash. diff --git a/examples/ArduinoZeroASF/.travis.yml b/examples/ArduinoZeroASF/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/examples/ArduinoZeroASF/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/ArduinoZeroASF/arduinoZero.atstart b/examples/ArduinoZeroASF/arduinoZero.atstart new file mode 100644 index 0000000..1ec81ce --- /dev/null +++ b/examples/ArduinoZeroASF/arduinoZero.atstart @@ -0,0 +1,529 @@ +format_version: '2' +name: My Project +versions: + api: '1.0' + backend: 1.6.148 + commit: 605f106ab95776472e3febf2fac2471441fb1816 + content: 1.0.1635 + content_pack_name: acme-packs-all + format: '2' + frontend: 1.6.1884 +board: + identifier: CustomBoard + device: SAMD21G18A-AF +details: null +application: null +middlewares: {} +drivers: + GCLK: + user_label: GCLK + definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21G18A-AF::GCLK::driver_config_definition::GCLK::HAL:HPL:GCLK + functionality: System + api: HAL:HPL:GCLK + configuration: + enable_gclk_gen_0: true + enable_gclk_gen_1: false + enable_gclk_gen_2: false + enable_gclk_gen_3: false + enable_gclk_gen_4: false + enable_gclk_gen_5: false + enable_gclk_gen_6: false + enable_gclk_gen_7: false + gclk_arch_gen_0_RUNSTDBY: false + gclk_arch_gen_0_enable: true + gclk_arch_gen_0_idc: false + gclk_arch_gen_0_oe: false + gclk_arch_gen_0_oov: false + gclk_arch_gen_1_RUNSTDBY: false + gclk_arch_gen_1_enable: false + gclk_arch_gen_1_idc: false + gclk_arch_gen_1_oe: false + gclk_arch_gen_1_oov: false + gclk_arch_gen_2_RUNSTDBY: false + gclk_arch_gen_2_enable: false + gclk_arch_gen_2_idc: false + gclk_arch_gen_2_oe: false + gclk_arch_gen_2_oov: false + gclk_arch_gen_3_RUNSTDBY: false + gclk_arch_gen_3_enable: false + gclk_arch_gen_3_idc: false + gclk_arch_gen_3_oe: false + gclk_arch_gen_3_oov: false + gclk_arch_gen_4_RUNSTDBY: false + gclk_arch_gen_4_enable: false + gclk_arch_gen_4_idc: false + gclk_arch_gen_4_oe: false + gclk_arch_gen_4_oov: false + gclk_arch_gen_5_RUNSTDBY: false + gclk_arch_gen_5_enable: false + gclk_arch_gen_5_idc: false + gclk_arch_gen_5_oe: false + gclk_arch_gen_5_oov: false + gclk_arch_gen_6_RUNSTDBY: false + gclk_arch_gen_6_enable: false + gclk_arch_gen_6_idc: false + gclk_arch_gen_6_oe: false + gclk_arch_gen_6_oov: false + gclk_arch_gen_7_RUNSTDBY: false + gclk_arch_gen_7_enable: false + gclk_arch_gen_7_idc: false + gclk_arch_gen_7_oe: false + gclk_arch_gen_7_oov: false + gclk_gen_0_div: 1 + gclk_gen_0_div_sel: false + gclk_gen_0_oscillator: 8MHz Internal Oscillator (OSC8M) + gclk_gen_1_div: 1 + gclk_gen_1_div_sel: false + gclk_gen_1_oscillator: External Crystal Oscillator 0.4-32MHz (XOSC) + gclk_gen_2_div: 1 + gclk_gen_2_div_sel: false + gclk_gen_2_oscillator: External Crystal Oscillator 0.4-32MHz (XOSC) + gclk_gen_3_div: 1 + gclk_gen_3_div_sel: false + gclk_gen_3_oscillator: External Crystal Oscillator 0.4-32MHz (XOSC) + gclk_gen_4_div: 1 + gclk_gen_4_div_sel: false + gclk_gen_4_oscillator: External Crystal Oscillator 0.4-32MHz (XOSC) + gclk_gen_5_div: 1 + gclk_gen_5_div_sel: false + gclk_gen_5_oscillator: External Crystal Oscillator 0.4-32MHz (XOSC) + gclk_gen_6_div: 1 + gclk_gen_6_div_sel: false + gclk_gen_6_oscillator: External Crystal Oscillator 0.4-32MHz (XOSC) + gclk_gen_7_div: 1 + gclk_gen_7_div_sel: false + gclk_gen_7_oscillator: External Crystal Oscillator 0.4-32MHz (XOSC) + optional_signals: [] + variant: null + clocks: + domain_group: null + PM: + user_label: PM + definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21G18A-AF::PM::driver_config_definition::PM::HAL:HPL:PM + functionality: System + api: HAL:HPL:PM + configuration: + apba_div: '1' + apbb_div: '1' + apbc_div: '1' + cpu_clock_source: Generic clock generator 0 + cpu_div: '1' + enable_cpu_clock: true + nvm_wait_states: '0' + optional_signals: [] + variant: null + clocks: + domain_group: + nodes: + - name: CPU + input: CPU + external: false + external_frequency: 0 + configuration: {} + DELAY_0: + user_label: DELAY_0 + definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21G18A-AF::SysTick::driver_config_definition::Delay::HAL:Driver:Delay + functionality: Delay + api: HAL:Driver:Delay + configuration: + systick_arch_tickint: false + optional_signals: [] + variant: null + clocks: + domain_group: null + TIMER_0: + user_label: TIMER_0 + definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21G18A-AF::TC3::driver_config_definition::Timer::HAL:Driver:Timer + functionality: Timer + api: HAL:Driver:Timer + configuration: + tc_arch_dbgrun: false + tc_arch_evact: Event action disabled + tc_arch_mceo0: false + tc_arch_mceo1: false + tc_arch_ovfeo: false + tc_arch_presync: Reload or reset counter on next GCLK + tc_arch_runstdby: false + tc_arch_tcei: false + tc_arch_tceinv: false + timer_advanced_configuration: false + timer_event_control: false + timer_prescaler: Divide by 1024 + timer_tick: 500 + optional_signals: [] + variant: null + clocks: + domain_group: + nodes: + - name: TC + input: Generic clock generator 0 + external: false + external_frequency: 0 + configuration: + tc_gclk_selection: Generic clock generator 0 + DMAC: + user_label: DMAC + definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21G18A-AF::DMAC::driver_config_definition::DMAC::HAL:HPL:DMAC + functionality: System + api: HAL:HPL:DMAC + configuration: + dmac_beatsize_0: 8-bit bus transfer + dmac_beatsize_1: 8-bit bus transfer + dmac_beatsize_10: 8-bit bus transfer + dmac_beatsize_11: 8-bit bus transfer + dmac_beatsize_12: 8-bit bus transfer + dmac_beatsize_13: 8-bit bus transfer + dmac_beatsize_14: 8-bit bus transfer + dmac_beatsize_15: 8-bit bus transfer + dmac_beatsize_2: 8-bit bus transfer + dmac_beatsize_3: 8-bit bus transfer + dmac_beatsize_4: 8-bit bus transfer + dmac_beatsize_5: 8-bit bus transfer + dmac_beatsize_6: 8-bit bus transfer + dmac_beatsize_7: 8-bit bus transfer + dmac_beatsize_8: 8-bit bus transfer + dmac_beatsize_9: 8-bit bus transfer + dmac_blockact_0: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_1: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_10: Channel will be disabled if it is the last block transfer + in the transaction + dmac_blockact_11: Channel will be disabled if it is the last block transfer + in the transaction + dmac_blockact_12: Channel will be disabled if it is the last block transfer + in the transaction + dmac_blockact_13: Channel will be disabled if it is the last block transfer + in the transaction + dmac_blockact_14: Channel will be disabled if it is the last block transfer + in the transaction + dmac_blockact_15: Channel will be disabled if it is the last block transfer + in the transaction + dmac_blockact_2: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_3: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_4: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_5: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_6: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_7: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_8: Channel will be disabled if it is the last block transfer in + the transaction + dmac_blockact_9: Channel will be disabled if it is the last block transfer in + the transaction + dmac_channel_0_settings: false + dmac_channel_10_settings: false + dmac_channel_11_settings: false + dmac_channel_12_settings: false + dmac_channel_13_settings: false + dmac_channel_14_settings: false + dmac_channel_15_settings: false + dmac_channel_1_settings: false + dmac_channel_2_settings: false + dmac_channel_3_settings: false + dmac_channel_4_settings: false + dmac_channel_5_settings: false + dmac_channel_6_settings: false + dmac_channel_7_settings: false + dmac_channel_8_settings: false + dmac_channel_9_settings: false + dmac_dbgrun: false + dmac_dstinc_0: false + dmac_dstinc_1: false + dmac_dstinc_10: false + dmac_dstinc_11: false + dmac_dstinc_12: false + dmac_dstinc_13: false + dmac_dstinc_14: false + dmac_dstinc_15: false + dmac_dstinc_2: false + dmac_dstinc_3: false + dmac_dstinc_4: false + dmac_dstinc_5: false + dmac_dstinc_6: false + dmac_dstinc_7: false + dmac_dstinc_8: false + dmac_dstinc_9: false + dmac_enable: false + dmac_enable_0: false + dmac_enable_1: false + dmac_enable_10: false + dmac_enable_11: false + dmac_enable_12: false + dmac_enable_13: false + dmac_enable_14: false + dmac_enable_15: false + dmac_enable_2: false + dmac_enable_3: false + dmac_enable_4: false + dmac_enable_5: false + dmac_enable_6: false + dmac_enable_7: false + dmac_enable_8: false + dmac_enable_9: false + dmac_evact_0: No action + dmac_evact_1: No action + dmac_evact_10: No action + dmac_evact_11: No action + dmac_evact_12: No action + dmac_evact_13: No action + dmac_evact_14: No action + dmac_evact_15: No action + dmac_evact_2: No action + dmac_evact_3: No action + dmac_evact_4: No action + dmac_evact_5: No action + dmac_evact_6: No action + dmac_evact_7: No action + dmac_evact_8: No action + dmac_evact_9: No action + dmac_evie_0: false + dmac_evie_1: false + dmac_evie_10: false + dmac_evie_11: false + dmac_evie_12: false + dmac_evie_13: false + dmac_evie_14: false + dmac_evie_15: false + dmac_evie_2: false + dmac_evie_3: false + dmac_evie_4: false + dmac_evie_5: false + dmac_evie_6: false + dmac_evie_7: false + dmac_evie_8: false + dmac_evie_9: false + dmac_evoe_0: false + dmac_evoe_1: false + dmac_evoe_10: false + dmac_evoe_11: false + dmac_evoe_12: false + dmac_evoe_13: false + dmac_evoe_14: false + dmac_evoe_15: false + dmac_evoe_2: false + dmac_evoe_3: false + dmac_evoe_4: false + dmac_evoe_5: false + dmac_evoe_6: false + dmac_evoe_7: false + dmac_evoe_8: false + dmac_evoe_9: false + dmac_evosel_0: Event generation disabled + dmac_evosel_1: Event generation disabled + dmac_evosel_10: Event generation disabled + dmac_evosel_11: Event generation disabled + dmac_evosel_12: Event generation disabled + dmac_evosel_13: Event generation disabled + dmac_evosel_14: Event generation disabled + dmac_evosel_15: Event generation disabled + dmac_evosel_2: Event generation disabled + dmac_evosel_3: Event generation disabled + dmac_evosel_4: Event generation disabled + dmac_evosel_5: Event generation disabled + dmac_evosel_6: Event generation disabled + dmac_evosel_7: Event generation disabled + dmac_evosel_8: Event generation disabled + dmac_evosel_9: Event generation disabled + dmac_lvl_0: Channel priority 0 + dmac_lvl_1: Channel priority 0 + dmac_lvl_10: Channel priority 0 + dmac_lvl_11: Channel priority 0 + dmac_lvl_12: Channel priority 0 + dmac_lvl_13: Channel priority 0 + dmac_lvl_14: Channel priority 0 + dmac_lvl_15: Channel priority 0 + dmac_lvl_2: Channel priority 0 + dmac_lvl_3: Channel priority 0 + dmac_lvl_4: Channel priority 0 + dmac_lvl_5: Channel priority 0 + dmac_lvl_6: Channel priority 0 + dmac_lvl_7: Channel priority 0 + dmac_lvl_8: Channel priority 0 + dmac_lvl_9: Channel priority 0 + dmac_lvlen0: false + dmac_lvlen1: false + dmac_lvlen2: false + dmac_lvlen3: false + dmac_lvlpri0: 0 + dmac_lvlpri1: 0 + dmac_lvlpri2: 0 + dmac_lvlpri3: 0 + dmac_rrlvlen0: Static arbitration scheme for channel with priority 0 + dmac_rrlvlen1: Static arbitration scheme for channel with priority 1 + dmac_rrlvlen2: Static arbitration scheme for channel with priority 2 + dmac_rrlvlen3: Static arbitration scheme for channel with priority 3 + dmac_srcinc_0: false + dmac_srcinc_1: false + dmac_srcinc_10: false + dmac_srcinc_11: false + dmac_srcinc_12: false + dmac_srcinc_13: false + dmac_srcinc_14: false + dmac_srcinc_15: false + dmac_srcinc_2: false + dmac_srcinc_3: false + dmac_srcinc_4: false + dmac_srcinc_5: false + dmac_srcinc_6: false + dmac_srcinc_7: false + dmac_srcinc_8: false + dmac_srcinc_9: false + dmac_stepsel_0: Step size settings apply to the destination address + dmac_stepsel_1: Step size settings apply to the destination address + dmac_stepsel_10: Step size settings apply to the destination address + dmac_stepsel_11: Step size settings apply to the destination address + dmac_stepsel_12: Step size settings apply to the destination address + dmac_stepsel_13: Step size settings apply to the destination address + dmac_stepsel_14: Step size settings apply to the destination address + dmac_stepsel_15: Step size settings apply to the destination address + dmac_stepsel_2: Step size settings apply to the destination address + dmac_stepsel_3: Step size settings apply to the destination address + dmac_stepsel_4: Step size settings apply to the destination address + dmac_stepsel_5: Step size settings apply to the destination address + dmac_stepsel_6: Step size settings apply to the destination address + dmac_stepsel_7: Step size settings apply to the destination address + dmac_stepsel_8: Step size settings apply to the destination address + dmac_stepsel_9: Step size settings apply to the destination address + dmac_stepsize_0: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_1: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_10: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_11: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_12: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_13: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_14: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_15: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_2: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_3: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_4: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_5: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_6: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_7: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_8: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_stepsize_9: Next ADDR = ADDR + (BEATSIZE + 1) * 1 + dmac_trifsrc_0: Only software/event triggers + dmac_trifsrc_1: Only software/event triggers + dmac_trifsrc_10: Only software/event triggers + dmac_trifsrc_11: Only software/event triggers + dmac_trifsrc_12: Only software/event triggers + dmac_trifsrc_13: Only software/event triggers + dmac_trifsrc_14: Only software/event triggers + dmac_trifsrc_15: Only software/event triggers + dmac_trifsrc_2: Only software/event triggers + dmac_trifsrc_3: Only software/event triggers + dmac_trifsrc_4: Only software/event triggers + dmac_trifsrc_5: Only software/event triggers + dmac_trifsrc_6: Only software/event triggers + dmac_trifsrc_7: Only software/event triggers + dmac_trifsrc_8: Only software/event triggers + dmac_trifsrc_9: Only software/event triggers + dmac_trigact_0: One trigger required for each block transfer + dmac_trigact_1: One trigger required for each block transfer + dmac_trigact_10: One trigger required for each block transfer + dmac_trigact_11: One trigger required for each block transfer + dmac_trigact_12: One trigger required for each block transfer + dmac_trigact_13: One trigger required for each block transfer + dmac_trigact_14: One trigger required for each block transfer + dmac_trigact_15: One trigger required for each block transfer + dmac_trigact_2: One trigger required for each block transfer + dmac_trigact_3: One trigger required for each block transfer + dmac_trigact_4: One trigger required for each block transfer + dmac_trigact_5: One trigger required for each block transfer + dmac_trigact_6: One trigger required for each block transfer + dmac_trigact_7: One trigger required for each block transfer + dmac_trigact_8: One trigger required for each block transfer + dmac_trigact_9: One trigger required for each block transfer + optional_signals: [] + variant: null + clocks: + domain_group: null + SYSCTRL: + user_label: SYSCTRL + definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21G18A-AF::SYSCTRL::driver_config_definition::SYSCTRL::HAL:HPL:SYSCTRL + functionality: System + api: HAL:HPL:SYSCTRL + configuration: + dfll48m_arch_bplckc: false + dfll48m_arch_calibration: false + dfll48m_arch_ccdis: false + dfll48m_arch_coarse: 31 + dfll48m_arch_enable: false + dfll48m_arch_fine: 512 + dfll48m_arch_llaw: false + dfll48m_arch_ondemand: true + dfll48m_arch_qldis: false + dfll48m_arch_runstdby: false + dfll48m_arch_stable: false + dfll48m_arch_usbcrm: false + dfll48m_arch_waitlock: false + dfll48m_mode: Open Loop Mode + dfll48m_mul: 0 + dfll48m_ref_clock: Generic clock generator 3 + dfll_arch_cstep: 1 + dfll_arch_fstep: 1 + enable_dfll48m: false + enable_fdpll96m: false + enable_osc32k: false + enable_osc8m: true + enable_osculp32k: true + enable_xosc: false + enable_xosc32k: false + fdpll96m_arch_enable: false + fdpll96m_arch_lbypass: false + fdpll96m_arch_ondemand: true + fdpll96m_arch_runstdby: false + fdpll96m_clock_div: 0 + fdpll96m_ldr: 1463 + fdpll96m_ldrfrac: 13 + fdpll96m_ref_clock: Generic clock generator 3 + osc32k_arch_calib: 0 + osc32k_arch_en1k: false + osc32k_arch_en32k: false + osc32k_arch_enable: false + osc32k_arch_ondemand: true + osc32k_arch_overwrite_calibration: false + osc32k_arch_runstdby: false + osc32k_arch_startup: 3 Clock Cycles (92us) + osc32k_arch_wrtlock: false + osc8m_arch_calib: 0 + osc8m_arch_enable: true + osc8m_arch_ondemand: true + osc8m_arch_overwrite_calibration: false + osc8m_arch_runstdby: false + osc8m_presc: '8' + osculp32k_arch_calib: 0 + osculp32k_arch_overwrite_calibration: false + osculp32k_arch_wrtlock: false + xosc32k_arch_aampen: false + xosc32k_arch_en1k: false + xosc32k_arch_en32k: false + xosc32k_arch_enable: false + xosc32k_arch_ondemand: true + xosc32k_arch_runstdby: false + xosc32k_arch_startup: 122 us + xosc32k_arch_wrtlock: false + xosc32k_arch_xtalen: false + xosc_arch_ampgc: false + xosc_arch_enable: false + xosc_arch_gain: 2Mhz + xosc_arch_ondemand: true + xosc_arch_runstdby: false + xosc_arch_startup: 31 us + xosc_arch_xtalen: false + xosc_frequency: 400000 + optional_signals: [] + variant: null + clocks: + domain_group: null +pads: + LED1: + name: PA17 + definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21G18A-AF::pad::PA17 + mode: Digital output + user_label: LED1 + configuration: null +toolchain_options: [] diff --git a/examples/ArduinoZeroASF/boards/myboard.json b/examples/ArduinoZeroASF/boards/myboard.json new file mode 100644 index 0000000..6fd8db8 --- /dev/null +++ b/examples/ArduinoZeroASF/boards/myboard.json @@ -0,0 +1,30 @@ +{ + "build": { + "cpu": "cortex-m0plus", + "extra_flags": "-DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__", + "f_cpu": "48000000L", + "mcu": "samd21g18a" + }, + "debug": { + "jlink_device": "ATSAMD21G18", + "openocd_chipname": "at91samd21g18", + "openocd_target": "at91samdXX", + "svd_path": "ATSAMD21G18A.svd" + }, + "frameworks": [], + "name": "Arduino Zero ASF", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 262144, + "protocol": "jlink", + "protocols": [ + "sam-ba", + "blackmagic", + "jlink", + "atmel-ice" + ] + }, + "url": "https://www.arduino.cc/en/Main/ArduinoBoardZero", + "vendor": "Arduino" +} \ No newline at end of file diff --git a/examples/ArduinoZeroASF/include/README b/examples/ArduinoZeroASF/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/ArduinoZeroASF/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/ArduinoZeroASF/lib/README b/examples/ArduinoZeroASF/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/ArduinoZeroASF/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/ArduinoZeroASF/platformio.ini b/examples/ArduinoZeroASF/platformio.ini new file mode 100644 index 0000000..7249d26 --- /dev/null +++ b/examples/ArduinoZeroASF/platformio.ini @@ -0,0 +1,18 @@ +;PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:zeroASF] +platform = atmelsam +board = myboard +atstart_file = arduinoZero.atstart +build_flags = +lib_deps = file:///Users/jelle/github/AtmelStart_PlatformIO +debug_tool = jlink +upload_protocol = jlink \ No newline at end of file diff --git a/examples/ArduinoZeroASF/src/main.cpp b/examples/ArduinoZeroASF/src/main.cpp new file mode 100644 index 0000000..1b688fd --- /dev/null +++ b/examples/ArduinoZeroASF/src/main.cpp @@ -0,0 +1,13 @@ +#include + +int main(void) +{ + /* Initializes MCU, drivers and middleware */ + atmel_start_init(); + + /* Replace with your application code */ + while (1) { + gpio_toggle_pin_level(LED1); + delay_ms(500); + } +} diff --git a/examples/ArduinoZeroASF/test/README b/examples/ArduinoZeroASF/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/ArduinoZeroASF/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 42c044afdd8c0904f7c44602f50009888766482d Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Mon, 11 Nov 2019 23:47:38 +0100 Subject: [PATCH 06/15] update lib_deps --- examples/ArduinoZeroASF/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ArduinoZeroASF/platformio.ini b/examples/ArduinoZeroASF/platformio.ini index 7249d26..09677bf 100644 --- a/examples/ArduinoZeroASF/platformio.ini +++ b/examples/ArduinoZeroASF/platformio.ini @@ -13,6 +13,6 @@ platform = atmelsam board = myboard atstart_file = arduinoZero.atstart build_flags = -lib_deps = file:///Users/jelle/github/AtmelStart_PlatformIO +lib_deps = https://github.com/JelleRoets/AtmelStart_PlatformIO debug_tool = jlink upload_protocol = jlink \ No newline at end of file From 32712c7c8c8ec64518a6201fac9e4b2575307b26 Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Mon, 11 Nov 2019 23:50:33 +0100 Subject: [PATCH 07/15] update library.json --- library.json | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/library.json b/library.json index 7404ce4..37cc84e 100644 --- a/library.json +++ b/library.json @@ -2,15 +2,21 @@ "name": "AtmelStart_PlatformIO", "description": "Automatic download and build as PlatformIO dependency given atstart configuration file.", "keywords": "atmel,start,atstart", - "authors": { + "authors": [ + { "name": "Frank Leon Rose", "email": "frankleonrose@gmail.com" - }, + }, + { + "name": "Jelle Roets", + "email": "jelleroets@outlook.be" + } + ], "repository": { "type": "git", - "url": "https://github.com/frankleonrose/AtmelStart_PlatformIO.git" + "url": "https://github.com/JelleRoets/AtmelStart_PlatformIO.git" }, - "version": "1.0.0", + "version": "1.1.0", "frameworks": "", "platforms": "atmelsam", "build": { From f304c00a7adc8c4383596c7a72cb8e62bfe3f9cd Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Tue, 12 Nov 2019 00:00:53 +0100 Subject: [PATCH 08/15] update readme --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fce3066..250fbe0 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # Using platform io as an IDE for ASF4 projects -ASF4 is a collection of software components such as peripheral drivers, middleware, and software applications provided by Microchip. The framework supports the Microchip's SAM family of microcontrollers. +[ASF4](https://www.microchip.com/mplab/avr-support/advanced-software-framework) is a collection of software components such as peripheral drivers, middleware, and software applications provided by Microchip. The framework supports the Microchip's SAM family of microcontrollers. -Atmel START - https://start.atmel.com/ - is a web-based software configuration tool, for various software frameworks, which helps you get started with MCU development. Starting from either a new project or an example project, Atmel START allows you to select and configure software components (from ASF4 and AVR Code), such as drivers and middleware to tailor your embedded application in a usable and optimized manner. Once an optimized software configuration is done, you can download the generated code project and open it in the IDE of your choice, including Studio 7, IAR Embedded Workbench®, Keil® μVision®, or simply generate a makefile. +[Atmel START](https://start.atmel.com/) is a web-based software configuration tool, which helps you get started with MCU development. Atmel START allows you to select and configure software components (from ASF4 and AVR Code), such as drivers and middleware to tailor your embedded application in a usable and optimized manner. Once an optimized software configuration is done, you can download the generated code project and open it in the IDE of your choice, including Studio 7, IAR Embedded Workbench®, Keil® μVision®, or simply generate a makefile. -This tutorial explains how to open an Atmel START project in platformIO. +This tutorial explains how to open an Atmel START project in platformIO IDE. ## Start a new project -1. Go to [Atmel START](https://start.atmel.com/) amd create a new project. Choose your mcu and configure all the software libraries you need. -2. Save and Download the configuration file as a [project name].atstart in a new project folder. -3. Start a new platformio projectin that project folder with `platformio init` -4. Create a custom board like explained [here](https://docs.platformio.org/en/latest/platforms/creating_board.html). You can start from the myboard.json file in the examples folder. It is important to not have a "ldscript" tag defined in the "build" section. The atmel start project will contain a new linker script. -5. Define an [environment](https://docs.platformio.org/en/latest/projectconf.html) in platformio.ini file that contains the following settings: +1. Go to [Atmel START](https://start.atmel.com/) and create a new project. Choose your mcu and configure all the software libraries you need. +2. Save and Download the configuration file as a `[project name].atstart` in a new project folder. +3. Start a new platformio project in that project folder with `platformio init` +4. Create a custom board like explained [here](https://docs.platformio.org/en/latest/platforms/creating_board.html). You can start from the myboard.json file in the examples folder or another existing board. It is important to not have a "ldscript" tag defined in the "build" section. The atmel start project will contain a new linker script. +5. Define an [environment](https://docs.platformio.org/en/latest/projectconf.html) in platformio.ini file that contains at least the following settings: ``` [env:myEnvironment] platform = atmelsam @@ -18,13 +18,13 @@ board = myboard ; custom board as created in step 4 atstart_file = myAtStartProject.atstart ; name of the downloaded atstart file from step 3 lib_deps = https://github.com/JelleRoets/AtmelStart_PlatformIO ; library that will download and include all ASF libraries as configured in the atstart file ``` -7. From the moment you save the ini file (or run `platformio run` for the first time) it will download the package in `.pio/libdeps/[env]/AtmelStart_PlatformIO/packages/[someHash]` -8. Go find a main.c file in that package and copy it to the project src folder as `main.cpp` and start editing. +6. From the moment you save the ini file (or run `platformio run` for the first time) it will download the package in `.pio/libdeps/[env]/AtmelStart_PlatformIO/packages/[someHash]` +7. Go find a main.c file in that package and copy it to the project src folder as `main.cpp` and start editing. Now you should be all set to further extend your project, compile, upload and debug your project with all features from platformIO. ## Examples -You can find an example in `examples\ArduinoZeroASF`, where I use Atmel Start and ASF4 libraries to create and debug a blink example project for the Arduino Zero. You simply do `platformio run` and / or ` platformio run --target upload ` (Note that uploading the binary with a debugger to the arduino zero will remove the existing bootloader). +You can find an [ArduinoZeroASF](./examples/ArduinoZeroASF) example, where I use Atmel Start and ASF4 libraries to create and debug a blink example project for the Arduino Zero. You can simply do `platformio run` and / or ` platformio run --target upload ` (Note that uploading the binary with a debugger to the arduino zero will remove the existing bootloader). ## Some background info The magic happens by an extra script in the AtmelStart_PlatformIO. This script will download the package according to the given atstart file. It will include all headers and compile all library files when compiling the project. Everytime the .atstart file changes (when you updated your config in the web based atmel START tool) it will download a new package and use the (converted) .atstart file as a hash. From ba4b3f0fa520466f27841f5a5d1a8dcc6ecdc5d5 Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Tue, 12 Nov 2019 00:29:23 +0100 Subject: [PATCH 09/15] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 250fbe0..e9f118c 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ The magic happens by an extra script in the AtmelStart_PlatformIO. This script w - automatically update the custom board file when chosing a different mcu. It should not only update the mcu name but also the openocd name and target, find the corresponding svd file (e.g. downloading it from: http://packs.download.atmel.com/ ) and update the ram size - a bootloader offset is currently not taken into account, due to a bug (https://github.com/platformio/platformio-core/issues/3264) that prevents using custom board definitions in library scripts. - add a custom task / command to easily go to the online Atmel START tool with the current .atstart file preloaded (not sure if there is an atmel start rest api for this...) +- atmel start rest api contains a bug that sets all clock frequencies in the peripheral_clk_config.h file to 0. This results in incorrect configuration of the components. When you download the atstart package directly from the atmel start web tool peripheral_clk_config.h is correctly populated. ## Credits: - [Frank Leon Rose](https://github.com/frankleonrose) From 2f3c7c32e95c7eeaf3cbaea52ef4170b2e4a62a4 Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Tue, 12 Nov 2019 21:58:04 +0100 Subject: [PATCH 10/15] move atstart file to the root project dir --- examples/AdafruitFeatherM0/{src => }/AdafruitFeatherM0.atstart | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/AdafruitFeatherM0/{src => }/AdafruitFeatherM0.atstart (100%) diff --git a/examples/AdafruitFeatherM0/src/AdafruitFeatherM0.atstart b/examples/AdafruitFeatherM0/AdafruitFeatherM0.atstart similarity index 100% rename from examples/AdafruitFeatherM0/src/AdafruitFeatherM0.atstart rename to examples/AdafruitFeatherM0/AdafruitFeatherM0.atstart From 7d6bf13f01452156be9894ff47d3bb4d7256fe36 Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Tue, 12 Nov 2019 21:58:46 +0100 Subject: [PATCH 11/15] use original repo dir --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 37cc84e..328d556 100644 --- a/library.json +++ b/library.json @@ -14,7 +14,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/JelleRoets/AtmelStart_PlatformIO.git" + "url": "https://github.com/frankleonrose/AtmelStart_PlatformIO.git" }, "version": "1.1.0", "frameworks": "", From 13c9487310371f01c23103c708bff532a6fb63e1 Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Tue, 12 Nov 2019 22:22:28 +0100 Subject: [PATCH 12/15] enable linker script again --- library.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library.py b/library.py index 37cd2fc..07c4556 100644 --- a/library.py +++ b/library.py @@ -185,8 +185,7 @@ def adjust_linker_offset(script_name, ldscript): return offset_script -# following function does not work with custom board due to platformio bug -# linker_script = adjust_linker_offset(env.subst('$PIOENV'), linker_script) +linker_script = adjust_linker_offset(env.subst('$PIOENV'), linker_script) global_env.Append(CPPPATH=[os.path.realpath(p) for p in include_paths]) env.Append( From 6d95a8ee0893a3b40d153af033b87f902c1ad453 Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Thu, 5 Mar 2020 17:48:13 +0100 Subject: [PATCH 13/15] fix archive script --- library.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library.py b/library.py index 07c4556..3e8a774 100644 --- a/library.py +++ b/library.py @@ -141,7 +141,7 @@ def download_package(config_file, download_dir, packages_dir): package_dir = download_package(output_filename, DOWNLOAD_DIR, PACKAGES_DIR) def valid_source(p): - return "armcc" not in p and "IAR" not in p and "RVDS" not in p + return "armcc" not in p and "IAR" not in p and "RVDS" not in p and "examples" not in p include_paths = [] source_paths = [] @@ -198,6 +198,10 @@ def src_dir(*x): sources = ["-<*>"] sources.extend(["+<{}>".format(src_dir(sp, '*.c')) for sp in source_paths]) sources.append("-<{}>".format(src_dir(package_dir, 'main.c'))) +# avoid including startup script in library archive +sources.append("-<{}>".format(src_dir(package_dir, '*/gcc/gcc/startup_*.c'))) +# IMPORTANT: copy this startup_ file to the source dir! +# TODO: How to automate this? env.Append( srcDir=package_dir, @@ -205,4 +209,4 @@ def src_dir(*x): ) env.Append( - LINKFLAGS=['-T',linker_script]) + LINKFLAGS=['-T',linker_script]) \ No newline at end of file From 1e95ac4e935bb55b2d137cbe4f4b51a939507dab Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Thu, 5 Mar 2020 17:52:05 +0100 Subject: [PATCH 14/15] update readme --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e9f118c..17bc0d0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Using platform io as an IDE for ASF4 projects + [ASF4](https://www.microchip.com/mplab/avr-support/advanced-software-framework) is a collection of software components such as peripheral drivers, middleware, and software applications provided by Microchip. The framework supports the Microchip's SAM family of microcontrollers. [Atmel START](https://start.atmel.com/) is a web-based software configuration tool, which helps you get started with MCU development. Atmel START allows you to select and configure software components (from ASF4 and AVR Code), such as drivers and middleware to tailor your embedded application in a usable and optimized manner. Once an optimized software configuration is done, you can download the generated code project and open it in the IDE of your choice, including Studio 7, IAR Embedded Workbench®, Keil® μVision®, or simply generate a makefile. @@ -6,11 +7,13 @@ This tutorial explains how to open an Atmel START project in platformIO IDE. ## Start a new project + 1. Go to [Atmel START](https://start.atmel.com/) and create a new project. Choose your mcu and configure all the software libraries you need. 2. Save and Download the configuration file as a `[project name].atstart` in a new project folder. 3. Start a new platformio project in that project folder with `platformio init` 4. Create a custom board like explained [here](https://docs.platformio.org/en/latest/platforms/creating_board.html). You can start from the myboard.json file in the examples folder or another existing board. It is important to not have a "ldscript" tag defined in the "build" section. The atmel start project will contain a new linker script. 5. Define an [environment](https://docs.platformio.org/en/latest/projectconf.html) in platformio.ini file that contains at least the following settings: + ``` [env:myEnvironment] platform = atmelsam @@ -18,23 +21,29 @@ board = myboard ; custom board as created in step 4 atstart_file = myAtStartProject.atstart ; name of the downloaded atstart file from step 3 lib_deps = https://github.com/JelleRoets/AtmelStart_PlatformIO ; library that will download and include all ASF libraries as configured in the atstart file ``` + 6. From the moment you save the ini file (or run `platformio run` for the first time) it will download the package in `.pio/libdeps/[env]/AtmelStart_PlatformIO/packages/[someHash]` 7. Go find a main.c file in that package and copy it to the project src folder as `main.cpp` and start editing. Now you should be all set to further extend your project, compile, upload and debug your project with all features from platformIO. ## Examples -You can find an [ArduinoZeroASF](./examples/ArduinoZeroASF) example, where I use Atmel Start and ASF4 libraries to create and debug a blink example project for the Arduino Zero. You can simply do `platformio run` and / or ` platformio run --target upload ` (Note that uploading the binary with a debugger to the arduino zero will remove the existing bootloader). + +You can find an [ArduinoZeroASF](./examples/ArduinoZeroASF) example, where I use Atmel Start and ASF4 libraries to create and debug a blink example project for the Arduino Zero. You can simply do `platformio run` and / or `platformio run --target upload` (Note that uploading the binary with a debugger to the arduino zero will remove the existing bootloader). ## Some background info + The magic happens by an extra script in the AtmelStart_PlatformIO. This script will download the package according to the given atstart file. It will include all headers and compile all library files when compiling the project. Everytime the .atstart file changes (when you updated your config in the web based atmel START tool) it will download a new package and use the (converted) .atstart file as a hash. ## TODO -- automatically update the custom board file when chosing a different mcu. It should not only update the mcu name but also the openocd name and target, find the corresponding svd file (e.g. downloading it from: http://packs.download.atmel.com/ ) and update the ram size + +- automatically update the custom board file when chosing a different mcu. It should not only update the mcu name but also the openocd name and target, find the corresponding svd file (e.g. downloading it from: http://packs.download.atmel.com/ ) and update the ram size - a bootloader offset is currently not taken into account, due to a bug (https://github.com/platformio/platformio-core/issues/3264) that prevents using custom board definitions in library scripts. - add a custom task / command to easily go to the online Atmel START tool with the current .atstart file preloaded (not sure if there is an atmel start rest api for this...) - atmel start rest api contains a bug that sets all clock frequencies in the peripheral_clk_config.h file to 0. This results in incorrect configuration of the components. When you download the atstart package directly from the atmel start web tool peripheral_clk_config.h is correctly populated. +- Before you can correctly compile the program you must copy the `'*/gcc/gcc/startup_*.c` file from the downloaded and extracted atstart package folder to the project source dir. ## Credits: + - [Frank Leon Rose](https://github.com/frankleonrose) -- [Jelle Roets](https://github.com/JelleRoets) \ No newline at end of file +- [Jelle Roets](https://github.com/JelleRoets) From fb2b335059c0b7a01d8ba569216b5de4818b679f Mon Sep 17 00:00:00 2001 From: Jelle Roets Date: Thu, 5 Mar 2020 18:49:47 +0100 Subject: [PATCH 15/15] disable archiving via platformio --- README.md | 4 ++-- examples/ArduinoZeroASF/platformio.ini | 3 ++- library.py | 4 ---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 17bc0d0..600c596 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ platform = atmelsam board = myboard ; custom board as created in step 4 atstart_file = myAtStartProject.atstart ; name of the downloaded atstart file from step 3 lib_deps = https://github.com/JelleRoets/AtmelStart_PlatformIO ; library that will download and include all ASF libraries as configured in the atstart file +lib_archive = no ; prevents archiving ASF library to avoid linking problems ``` 6. From the moment you save the ini file (or run `platformio run` for the first time) it will download the package in `.pio/libdeps/[env]/AtmelStart_PlatformIO/packages/[someHash]` @@ -38,10 +39,9 @@ The magic happens by an extra script in the AtmelStart_PlatformIO. This script w ## TODO - automatically update the custom board file when chosing a different mcu. It should not only update the mcu name but also the openocd name and target, find the corresponding svd file (e.g. downloading it from: http://packs.download.atmel.com/ ) and update the ram size -- a bootloader offset is currently not taken into account, due to a bug (https://github.com/platformio/platformio-core/issues/3264) that prevents using custom board definitions in library scripts. - add a custom task / command to easily go to the online Atmel START tool with the current .atstart file preloaded (not sure if there is an atmel start rest api for this...) - atmel start rest api contains a bug that sets all clock frequencies in the peripheral_clk_config.h file to 0. This results in incorrect configuration of the components. When you download the atstart package directly from the atmel start web tool peripheral_clk_config.h is correctly populated. -- Before you can correctly compile the program you must copy the `'*/gcc/gcc/startup_*.c` file from the downloaded and extracted atstart package folder to the project source dir. +- Althoug the `build.libArchive` flag is set to false in the `library.json` file, it does seems to archive the ASF code due to a bug in platform IO, which breaks the linking. So make sure to set the `lib_archive = no` in the `platformio.ini` instead ## Credits: diff --git a/examples/ArduinoZeroASF/platformio.ini b/examples/ArduinoZeroASF/platformio.ini index 09677bf..6eac531 100644 --- a/examples/ArduinoZeroASF/platformio.ini +++ b/examples/ArduinoZeroASF/platformio.ini @@ -15,4 +15,5 @@ atstart_file = arduinoZero.atstart build_flags = lib_deps = https://github.com/JelleRoets/AtmelStart_PlatformIO debug_tool = jlink -upload_protocol = jlink \ No newline at end of file +upload_protocol = jlink +lib_archive = no \ No newline at end of file diff --git a/library.py b/library.py index 3e8a774..134abc4 100644 --- a/library.py +++ b/library.py @@ -198,10 +198,6 @@ def src_dir(*x): sources = ["-<*>"] sources.extend(["+<{}>".format(src_dir(sp, '*.c')) for sp in source_paths]) sources.append("-<{}>".format(src_dir(package_dir, 'main.c'))) -# avoid including startup script in library archive -sources.append("-<{}>".format(src_dir(package_dir, '*/gcc/gcc/startup_*.c'))) -# IMPORTANT: copy this startup_ file to the source dir! -# TODO: How to automate this? env.Append( srcDir=package_dir,