diff --git a/examples/blinky/CMakeLists.txt b/examples/blinky/CMakeLists.txt new file mode 100644 index 0000000..b711afd --- /dev/null +++ b/examples/blinky/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.19.2) + +project(Blinky C) + +find_package(Harmony REQUIRED) +find_package(SAMV71-DFP COMPONENTS SAMV71Q21B REQUIRED) + +add_harmony_config( + MCU_MODEL ATSAMV71Q21B + YAML_FILES + ./mcu-config/core.yml + ./mcu-config/dfp.yml + ./mcu-config/efc.yml +) + +add_executable(Blinky) +target_include_directories(Blinky PRIVATE include/) +target_sources(Blinky PRIVATE src/main.c) +target_link_libraries(Blinky PRIVATE samv71-dfp::SAMV71Q21B::Startup samv71-dfp::SAMV71Q21B::Linker::Flash Harmony::SysInit Harmony::PeripheralDrivers) diff --git a/examples/blinky/README.md b/examples/blinky/README.md new file mode 100644 index 0000000..7f56d31 --- /dev/null +++ b/examples/blinky/README.md @@ -0,0 +1,26 @@ +# SAMV71 blinky example + +This example blinks the User LED on a SAMV71 Xplained Ultra board +with a 1 sec interval. + +## Building + +To build this, run the following (assuming you have installed the +Conan packages) +- `conan build . -pr=baremetal-samv71-armv7 -s build_type=Debug` + +If for some reason you want to run the build manually, these are +the steps: +- `conan install . -pr=baremetal-samv71-armv7` +- `cmake . -Bbuild/Debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=./build/Debug/generators/conan_toolchain.cmake -GNinja` +- `cd build/Debug/` +- `ninja` + +The produced `Blinky.elf` file can be found under `./build/Debug/`. +For a release build, change `Debug` to `Release` in all the commands above. + +## Uploading + +Use your favorite debug/flash tool for uploading. Refer to your tool's documentation +or to the main `README.md` file for a basic procedure using [OpenOCD](https://openocd.org/) + diff --git a/examples/blinky/atmel_samv71_xplained_ultra.cfg b/examples/blinky/atmel_samv71_xplained_ultra.cfg new file mode 100644 index 0000000..c7f559b --- /dev/null +++ b/examples/blinky/atmel_samv71_xplained_ultra.cfg @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +# +# Atmel SAMV71 Xplained Ultra evaluation kit. +# http://www.atmel.com/tools/ATSAMV71-XULT.aspx +# +# To connect using the EDBG chip on the dev kit over USB, you will +# first need to source [find interface/cmsis-dap.cfg] +# however, since this board also has a SWD+ETM connector, we don't +# automatically source that file here. + +set CHIPNAME samv71 + +source [find interface/cmsis-dap.cfg] +source [find target/atsamv.cfg] diff --git a/examples/blinky/conanfile.py b/examples/blinky/conanfile.py new file mode 100644 index 0000000..0ebe803 --- /dev/null +++ b/examples/blinky/conanfile.py @@ -0,0 +1,36 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout + + +class BlinkyRecipe(ConanFile): + name = "BlinkyExample" + version = "1.0" + package_type = "application" + + # Authorship metadata + license = "MIT" + author = "Grigoris Pavlakis " + url = "https://github.com/PeakSat/minimal_dev_setup" + description = "Blinky example for Atmel SAMV71 Xplained Ultra" + + settings = "build_type", "arch" + generators = "CMakeToolchain", "CMakeDeps" + + # Dependencies + requires = "samv71-dfp/4.9.117", "harmony/3.0" + + # Sources are located in the same place as this recipe, copy them to the recipe + exports_sources = "CMakeLists.txt", "src/*" + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + cmake = CMake(self) + cmake.install() + diff --git a/examples/blinky/mcu-config/core.yml b/examples/blinky/mcu-config/core.yml new file mode 100644 index 0000000..e3991a8 --- /dev/null +++ b/examples/blinky/mcu-config/core.yml @@ -0,0 +1,393 @@ +format_version: v1.0 +type: UniqueComponent +attributes: {id: core} +children: +- type: Symbols + children: + - type: KeyValueSet + attributes: {id: COMPILER_CHOICE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: Menu + attributes: {id: CoreIARMenu} + children: + - type: Attributes + children: + - type: Boolean + attributes: {id: visible} + children: + - {type: Value, value: 'false'} + - type: Menu + attributes: {id: CoreKEILMenu} + children: + - type: Attributes + children: + - type: Boolean + attributes: {id: visible} + children: + - {type: Value, value: 'false'} + - type: KeyValueSet + attributes: {id: DEVICE_BOOT} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '1'} + - type: KeyValueSet + attributes: {id: DEVICE_SECURITY} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: KeyValueSet + attributes: {id: DEVICE_TCM_SIZE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: String + attributes: {id: KEIL_STACK_HEAP_SIZE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0x1200'} + - type: Boolean + attributes: {id: NVIC_-1_0_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Boolean + attributes: {id: NVIC_-1_0_HANDLER_LOCK} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Boolean + attributes: {id: NVIC_4_0_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: String + attributes: {id: NVIC_4_0_HANDLER} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: WDT_Handler} + - type: Boolean + attributes: {id: NVIC_4_0_HANDLER_LOCK} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: Boolean + attributes: {id: NVIC_63_0_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: String + attributes: {id: NVIC_63_0_HANDLER} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: RSWDT_Handler} + - type: Boolean + attributes: {id: NVIC_63_0_HANDLER_LOCK} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: String + attributes: {id: PIN_46_DIR} + children: + - type: Values + children: + - type: User + attributes: {value: Out} + - type: String + attributes: {id: PIN_46_FUNCTION_NAME} + children: + - type: Values + children: + - type: User + attributes: {value: GPIO_PA23} + - type: String + attributes: {id: PIN_46_FUNCTION_TYPE} + children: + - type: Values + children: + - type: User + attributes: {value: GPIO} + - type: String + attributes: {id: PIN_46_LAT} + children: + - type: Values + children: + - type: User + attributes: {value: ''} + - type: String + attributes: {id: PIN_46_PERIPHERAL_FUNCTION} + children: + - type: Values + children: + - type: User + attributes: {value: GPIO} + - type: Hex + attributes: {id: PIOA_ABCDSR1_VALUE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: Hex + attributes: {id: PIOA_ABCDSR2_VALUE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: Boolean + attributes: {id: PIOA_CLOCK_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Hex + attributes: {id: PIOA_OER_VALUE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '8388608'} + - type: Hex + attributes: {id: PIOA_PDR_VALUE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: Hex + attributes: {id: PIOA_SODR_VALUE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: Boolean + attributes: {id: PIOB_CLOCK_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Boolean + attributes: {id: PIOC_CLOCK_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Boolean + attributes: {id: PIOD_CLOCK_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Boolean + attributes: {id: PIOE_CLOCK_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Hex + attributes: {id: PMC_PCER0} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '203776'} + - type: KeyValueSet + attributes: {id: PMC_PCR_GCLK0CSS} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: KeyValueSet + attributes: {id: PMC_PCR_GCLK1CSS} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: '0'} + - type: Boolean + attributes: {id: RSWDT_INTERRUPT_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: Boolean + attributes: {id: RSWDT_INTERRUPT_ENABLE_UPDATE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: String + attributes: {id: RSWDT_INTERRUPT_HANDLER} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: RSWDT_Handler} + - type: Boolean + attributes: {id: RSWDT_INTERRUPT_HANDLER_LOCK} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: File + attributes: {id: SYSTICK_FILE_0} + children: + - type: Attributes + children: + - type: Boolean + attributes: {id: enabled} + children: + - {type: Value, value: 'true'} + - type: File + attributes: {id: SYSTICK_FILE_1} + children: + - type: Attributes + children: + - type: Boolean + attributes: {id: enabled} + children: + - {type: Value, value: 'true'} + - type: File + attributes: {id: SYSTICK_FILE_2} + children: + - type: Attributes + children: + - type: Boolean + attributes: {id: enabled} + children: + - {type: Value, value: 'true'} + - type: Menu + attributes: {id: SYSTICK_MENU_0} + children: + - type: Attributes + children: + - type: Boolean + attributes: {id: visible} + children: + - {type: Value, value: 'true'} + - type: Boolean + attributes: {id: SysTick_INTERRUPT_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Boolean + attributes: {id: SysTick_INTERRUPT_ENABLE_UPDATE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: Boolean + attributes: {id: SysTick_INTERRUPT_HANDLER_LOCK} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: Boolean + attributes: {id: TCM_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: String + attributes: {id: TCM_SIZE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 0 KB} + - type: Boolean + attributes: {id: USE_SYSTICK_INTERRUPT} + children: + - type: Values + children: + - type: User + attributes: {value: 'true'} + - type: Boolean + attributes: {id: WDT_INTERRUPT_ENABLE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: Boolean + attributes: {id: WDT_INTERRUPT_ENABLE_UPDATE} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'true'} + - type: String + attributes: {id: WDT_INTERRUPT_HANDLER} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: WDT_Handler} + - type: Boolean + attributes: {id: WDT_INTERRUPT_HANDLER_LOCK} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: core, value: 'false'} + - type: Boolean + attributes: {id: systickEnable} + children: + - type: Values + children: + - type: User + attributes: {value: 'true'} + - type: File + attributes: {id: systickSystemInitFile} + children: + - type: Attributes + children: + - type: Boolean + attributes: {id: enabled} + children: + - {type: Value, value: 'true'} +- type: ElementPosition + attributes: {x: '240', y: '20', id: core} diff --git a/examples/blinky/mcu-config/dfp.yml b/examples/blinky/mcu-config/dfp.yml new file mode 100644 index 0000000..eff2f08 --- /dev/null +++ b/examples/blinky/mcu-config/dfp.yml @@ -0,0 +1,6 @@ +format_version: v1.0 +type: UniqueComponent +attributes: {id: dfp} +children: +- type: ElementPosition + attributes: {x: '20', y: '20', id: dfp} diff --git a/examples/blinky/mcu-config/efc.yml b/examples/blinky/mcu-config/efc.yml new file mode 100644 index 0000000..ed3a8c3 --- /dev/null +++ b/examples/blinky/mcu-config/efc.yml @@ -0,0 +1,15 @@ +format_version: v1.0 +type: UniqueComponent +attributes: {id: efc} +children: +- type: Symbols + children: + - type: Integer + attributes: {id: NVM_RWS} + children: + - type: Values + children: + - type: Dynamic + attributes: {id: efc, value: '6'} +- type: ElementPosition + attributes: {x: '30', y: '60', id: efc} diff --git a/examples/blinky/src/main.c b/examples/blinky/src/main.c new file mode 100644 index 0000000..90b4a84 --- /dev/null +++ b/examples/blinky/src/main.c @@ -0,0 +1,35 @@ +/* + * main.c - Blinky for SAMV71 Xplained Ultra + * + * Created: 24 July 2024 + * Author : Grigoris Pavlakis + */ + +/* + * Although SYS_Initialize() is declared for us in 'definitions.h', + * this header will transitively include all the peripheral + * libraries, which is a bad practice since it makes for + * 'spooky-action-at-a-distance' wrt. missing errors. + * + * Prefer directly including the peripheral headers you need. It's + * more verbose but the gain in explicitness helps when debugging. + */ + +#include "pio/plib_pio.h" +#include "systick/plib_systick.h" + +void SYS_Initialize ( void* data ); + +int main(void) +{ + SYS_Initialize(NULL); + SYSTICK_TimerStart(); + + while (1) + { + SYSTICK_DelayMs(1000); + PIO_PinClear(PIO_PIN_PA23); + SYSTICK_DelayMs(1000); + PIO_PinSet(PIO_PIN_PA23); + } +}