From dc237b8294c153962d5608584011707f0772c533 Mon Sep 17 00:00:00 2001 From: Bengt Ragnemalm <bengt.ragnemalm@liu.se> Date: Thu, 4 Nov 2021 14:16:07 +0100 Subject: [PATCH] Moved I/O macros to separate file --- ArduinoZeroTemplate.cproj | 6 ++++- src/ArduinoZeroTemplate.c | 1 + src/ArduinoZeroTemplate.h | 35 -------------------------- src/config/ArduinoZeroTemplateClocks.h | 1 + 4 files changed, 7 insertions(+), 36 deletions(-) diff --git a/ArduinoZeroTemplate.cproj b/ArduinoZeroTemplate.cproj index 4e36db0..1e0c0d5 100644 --- a/ArduinoZeroTemplate.cproj +++ b/ArduinoZeroTemplate.cproj @@ -412,7 +412,7 @@ <Value>../src/ASF/sam0/drivers/rtc/rtc_sam_d_r_h</Value> </ListValues> </armgcc.compiler.directories.IncludePaths> - <armgcc.compiler.optimization.level>Optimize (-O1)</armgcc.compiler.optimization.level> + <armgcc.compiler.optimization.level>Optimize debugging experience (-Og)</armgcc.compiler.optimization.level> <armgcc.compiler.optimization.OtherFlags>-fdata-sections</armgcc.compiler.optimization.OtherFlags> <armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection> <armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel> @@ -431,6 +431,7 @@ </ListValues> </armgcc.linker.libraries.LibrarySearchPaths> <armgcc.linker.optimization.GarbageCollectUnusedSections>True</armgcc.linker.optimization.GarbageCollectUnusedSections> + <armgcc.linker.memorysettings.ExternalRAM /> <armgcc.linker.miscellaneous.LinkerFlags>-Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam0/utils/linker_scripts/samd21/gcc/samd21g18a_flash.ld</armgcc.linker.miscellaneous.LinkerFlags> <armgcc.assembler.general.IncludePaths> <ListValues> @@ -1124,6 +1125,9 @@ <Compile Include="src\config\asf.h"> <SubType>compile</SubType> </Compile> + <Compile Include="src\macros.h"> + <SubType>compile</SubType> + </Compile> <Compile Include="src\main.c"> <SubType>compile</SubType> </Compile> diff --git a/src/ArduinoZeroTemplate.c b/src/ArduinoZeroTemplate.c index 0b0dfc6..8ea2afe 100644 --- a/src/ArduinoZeroTemplate.c +++ b/src/ArduinoZeroTemplate.c @@ -7,6 +7,7 @@ #include <asf.h> #include "ArduinoZeroTemplate.h" +#include "macros.h" // Globala variabler diff --git a/src/ArduinoZeroTemplate.h b/src/ArduinoZeroTemplate.h index 3e14f99..1bc1e9b 100644 --- a/src/ArduinoZeroTemplate.h +++ b/src/ArduinoZeroTemplate.h @@ -98,41 +98,6 @@ Available for user (J4-14) PB11 - TCC0-W5 */ -// Macros for writing to I/O: - // There are many ways to write to PORT registers. - // Method 1. Simples PORT method. Example for setting PA20 on PORTA. Note PORT_PA20 and not PIN_PA20 - // PORTA.OUTSET.reg = PORT_PA20 - // Method 2. Quicker method of PORT. Not sure if it is much faster than method 1 but it is more "compatible" with method nr 3. - // port_nr is in this case 0 for PORTA, 1 for PORTB and so on. - // PORT->Group[port_nr].OUTSET.reg = PORT_PA20 - // Method nr 3. Much quicker method that uses the direct access IOBUS. (If any optimization is enabled, otherwise difference is smaller). - // PORT_IOBUS->Group[port_nr].OUTSET.reg = PORT_PA20 - // Drawback is that for using IOBUS the constant sampling of used pins (in groups of 8) must be enabled. - // This consumes some power. - // Recommendation: Use method nr 2 and 3. Nr 2 if need to use minimum of power and 3 if need for maximal speed. - // Note: Data sheet says that only Data Output Value, Data Input Value and Pin Direction registers can be accessed through IOBUS operation. - // But practically test has shown that all PORT register can be accessed. For example PINCFG. - // Read more here about writing to ports: - // https://electronics.stackexchange.com/questions/139117/atmels-arm-programming-without-asf - // https://community.atmel.com/forum/getting-started-arm-3 - // https://www.avrfreaks.net/forum/considerations-using-iobus-port-access - - #define PORT_SET_PIN(port_nr,port_pin) PORT_IOBUS->Group[port_nr].OUTSET.reg = port_pin // Set to 1; Time with 40MHz is 190nsec - #define PORT_CLR_PIN(port_nr,port_pin) PORT_IOBUS->Group[port_nr].OUTCLR.reg = port_pin // Set to 0 - #define PORT_TOGGLE_PIN(port_nr,port_pin) PORT_IOBUS->Group[port_nr].OUTTGL.reg = port_pin // Toggle pin - #define PORT_OUTPUT_PIN(port_nr,port_pin) PORT_IOBUS->Group[port_nr].DIRSET.reg = port_pin // Set pin to output - #define PORT_INPUT_PIN(port_nr,port_pin) PORT_IOBUS->Group[port_nr].DIRCLR.reg = port_pin // port.DIRCLR.reg = pin // Set pin to input - #define PORT_INPUT_PIN_EN(port_nr,port_pin) PORT->Group[port_nr].PINCFG[port_pin].bit.INEN = 1 // Enable input buffer (needed to be able to read a pin) - #define PORT_READ_PIN(port_nr,port_pin) PORT_IOBUS->Group[port_nr].IN[port_pin] // Read a pin - #define PORT_READ(port_nr) PORT->Group[port_nr].IN.reg // Read a port - #define PORT_SET_CTRLSAMPLING(port_nr,port_pin) PORT->Group[port_nr].CTRL.reg |= port_pin; // Enable continuous sampling of a pin group (always in groups of 8) - #define PORT_CLR_CTRLSAMPLING(port_nr,port_pin) PORT->Group[port_nr].CTRL.reg &= ~port_pin; // Remove continuous sampling of a pin group - #define PORT_PULL_PIN_EN(port_nr,port_pin) PORT->Group[port_nr].PINCFG[port_pin].PULLEN=1 // Enable pull on a pin (Typ 40 kohm). Data value defines pull-up (1) or pull-down (0). Not on PA24 and PA25 - #define PORT_PULL_PIN_DIS(port_nr,port_pin) PORT->Group[port_nr].PINCFG[port_pin].PULLEN=0 // Disable pull on a pin - #define PORT_PULL_PIN_DRIVE_STRONG(port_nr,port_pin) PORT->Group[port_nr].PINCFG[port_pin].DRVSTR=1 // Enable strong drive strength on a pin. (~3mA, twice for VCC=3.6V). Not on PA24 and PA25 - #define PORT_PULL_PIN_DRIVE_WEAK(port_nr,port_pin) PORT->Group[port_nr].PINCFG[port_pin].DRVSTR=1 // Disable strong drive strength on a pin. (~1mA, twice for VCC=3.6V) - - // Tip: Example of other register or variable fiddling: SYSCTRL->VREG.bit.RUNSTDBY = 1 // Definitions diff --git a/src/config/ArduinoZeroTemplateClocks.h b/src/config/ArduinoZeroTemplateClocks.h index 4fcd785..3f51799 100644 --- a/src/config/ArduinoZeroTemplateClocks.h +++ b/src/config/ArduinoZeroTemplateClocks.h @@ -5,6 +5,7 @@ * Author: ilosz01 */ +// ArduinoZeroTemplate: configured for maximum speed using DFLL (48 MHz) // System clock bus configuration # define CONF_CLOCK_CPU_CLOCK_FAILURE_DETECT false -- GitLab