Commit 5dc47c4e authored by Jake Read's avatar Jake Read

add stmf4 chip and try xmega event system ring

parent 221f06eb
Pipeline #2310 passed with stage
in 3 seconds
<!DOCTYPE html>
<html>
<title>Ring Test - STM32F407</title><!DOCTYPE html>
<html>
<xmp theme="united" style="display:none;">
# STM32F407
I used the STMF4 'Discovery' dev board to test this out.
The chip runs at 168MHz at the core, with a 42MHz peripheral clock.
To build code for it, I used the [OpenSTM32 Workbench](http://www.openstm32.org/HomePage) - an IDE based on Eclipse. Here's a [small register structure primer](stm32-register-help.pdf). I watched [this video](https://www.youtube.com/watch?v=FPfTxNS9NvQ) and, while the HAL libraries I was using were not identical, poking around in those .h files and listening to this person helped me figure out the clock setup.
The chip runs a 3.1MHz ring.
![scope](scope.jpg)
![setup](setup.jpg)
![ide](ide.jpg)
Here's the code,
```C
#include "stm32f4xx.h"
#include "stm32f4_discovery.h"
#include "stm32f4xx_hal_rcc.h"
#include "stm32f4xx_hal_rcc_ex.h"
#include "stm32f4xx_hal_gpio.h"
int main(void)
{
// boilerplate from STM HAL
SystemInit();
// shutdown RCC
HAL_RCC_DeInit();
// enable the external clock
__HAL_RCC_HSE_CONFIG(RCC_HSE_ON);
while(!(RCC_FLAG_HSERDY));
RCC_OscInitTypeDef oscinit;
oscinit.OscillatorType = RCC_OSCILLATORTYPE_HSE;
oscinit.HSEState = RCC_HSE_ON;
RCC_PLLInitTypeDef pllinit;
pllinit.PLLState = RCC_PLL_ON;
pllinit.PLLSource = RCC_PLLSOURCE_HSE;
// div source by 4, crystal is 8M, so input to pll will be 2M
pllinit.PLLM = 8;
// then mult to 386
pllinit.PLLN = 336;
// div into sysclk
pllinit.PLLP = RCC_PLLP_DIV2;
// div into usb clk etc..
pllinit.PLLQ = 7;
oscinit.PLL = pllinit;
HAL_RCC_OscConfig(&oscinit);
while(!(RCC_FLAG_PLLRDY));
RCC_ClkInitTypeDef clkinit;
clkinit.AHBCLKDivider = RCC_SYSCLK_DIV1;
clkinit.APB1CLKDivider = RCC_SYSCLK_DIV4;
clkinit.APB2CLKDivider = RCC_SYSCLK_DIV2;
clkinit.ClockType = RCC_CLOCKTYPE_SYSCLK;
clkinit.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; //RCC_SYSCLKSOURCE_HSE
// 2nd item is 'flash latency' - see AN3988 and pg 9
HAL_RCC_ClockConfig(&clkinit, FLASH_LATENCY_5);
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOE_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitTypeDef GPIO_InitStructInput;
GPIO_InitStructInput.Pin = GPIO_PIN_14;
GPIO_InitStructInput.Mode = GPIO_MODE_INPUT;
GPIO_InitStructInput.Speed = GPIO_SPEED_MEDIUM;
HAL_GPIO_Init(GPIOE, &GPIO_InitStructInput);
while(1){
(GPIOE -> IDR & GPIO_PIN_14) ? (GPIOE -> ODR &= ~GPIO_PIN_13) : (GPIOE -> ODR |= GPIO_PIN_13);
}
}
```
</xmp>
<script src="http://strapdownjs.com/v/0.2/strapdown.js"></script>
</html>
\ No newline at end of file
......@@ -73,6 +73,16 @@
"ic_sales_link":"",
"ring_period":0.17
},
{
"name":"STM32F407",
"serial_number":"",
"subdirectory_path":"gpio/stm32f407",
"dev_board_price":21.00,
"dev_board_sales link":"",
"ic_price":9.55,
"ic_sales_link":"",
"ring_period":0.321
},
{
"name":"ATSAM4S",
"serial_number":"",
......@@ -197,7 +207,7 @@
"name":"XMega8E5",
"serial_number":"",
"subdirectory_path":"gpio/8E5",
"dev_board_price":3.00,
"dev_board_price":4.00,
"dev_board_sales_link":"",
"ic_price":2.30,
"ic_sales_link":"",
......@@ -254,6 +264,16 @@
"ic_price":2.83,
"ic_sales_link":"",
"ring_period":0.008
},
{
"name":"XMEGA EventSys",
"serial_number":"",
"subdirectory_path":"wildwest/xmega-eventsys",
"dev_board_price":5.00,
"dev_board_sales link":"",
"ic_price":3.00,
"ic_sales_link":"",
"ring_period":0.169
}
]
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<title>Ring Test - XMEGA Event System</title><!DOCTYPE html>
<html>
<xmp theme="united" style="display:none;">
# XMEGA Ring with Event System
Here I'm using the XMEGA's Event System to run a ring oscillator. It runs at 6MHz - the XMEGA can be made to do the same thing at 5.2MHz through the CPU.
![osc](xmega-ring-evsys.jpg)
```C
void clock_init(void){
OSC.XOSCCTRL = OSC_XOSCSEL_XTAL_256CLK_gc | OSC_FRQRANGE_12TO16_gc; // select external source
OSC.CTRL = OSC_XOSCEN_bm; // enable external source
while(!(OSC.STATUS & OSC_XOSCRDY_bm)); // wait for external
OSC.PLLCTRL = OSC_PLLSRC_XOSC_gc | 3; // select external osc for pll, do pll = source * 3
OSC.CTRL |= OSC_PLLEN_bm; // enable PLL
while (!(OSC.STATUS & OSC_PLLRDY_bm)); // wait for PLL to be ready
CCP = CCP_IOREG_gc; // enable protected register change
CLK.CTRL = CLK_SCLKSEL_PLL_gc; // switch to PLL for main clock
/*
OSC.PLLCTRL = OSC_PLLFAC4_bm | OSC_PLLFAC3_bm; // 2 MHz * 24 = 48 MHz
OSC.CTRL = OSC_PLLEN_bm; // enable PLL
while (!(OSC.STATUS & OSC_PLLRDY_bm)); // wait for PLL to be ready
CCP = CCP_IOREG_gc; // enable protected register change
CLK.CTRL = CLK_SCLKSEL_PLL_gc; // switch to PLL
*/
}
void ring_evsys(void){
// set pin4 as input, fires interrupt / event on either edge
PORTF.DIRCLR = PIN4_bm;
PORTF.PIN4CTRL = PORT_ISC_BOTHEDGES_gc;
// event channel 0 on events from F4
EVSYS_CH0MUX = EVSYS_CHMUX_PORTF_PIN4_gc;
//EVSYS_CH0CTRL = EVSYS_DIGFILT_2SAMPLES_gc;
// we can't write an event directly to a pin,
// instead, setup a counter with EVCH0 as source and count to 0, wavegen on that
TCF0.CTRLA = TC_CLKSEL_EVCH0_gc;
TCF0.CTRLB = TC_WGMODE_FRQ_gc | (1 << 4); // frequency wave mode, and enable CCA channel output
// need to set CCA,
TCF0.CCABUFL = 0;
TCF0.CCABUFH = 0;
// we have to kick this to get it going
EVSYS.STROBE = 1;
}
int main(void){
clock_init();
ring_evsys();
while(1){
//
}
}
```
</xmp>
<script src="http://strapdownjs.com/v/0.2/strapdown.js"></script>
</html>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Atmel Studio Solution File, Format Version 11.00
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "xmega-eventsys-ring", "xmega-eventsys-ring\xmega-eventsys-ring.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AVR = Debug|AVR
Release|AVR = Release|AVR
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
SHELL := cmd.exe
RM := rm -rf
USER_OBJS :=
LIBS :=
PROJ :=
O_SRCS :=
C_SRCS :=
S_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
PREPROCESSING_SRCS :=
OBJS :=
OBJS_AS_ARGS :=
C_DEPS :=
C_DEPS_AS_ARGS :=
EXECUTABLES :=
OUTPUT_FILE_PATH :=
OUTPUT_FILE_PATH_AS_ARGS :=
AVR_APP_PATH :=$$$AVR_APP_PATH$$$
QUOTE := "
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:=
LIB_DEP:=
LINKER_SCRIPT_DEP:=
# Every subdirectory with source files must be described here
SUBDIRS :=
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../main.c
PREPROCESSING_SRCS +=
ASM_SRCS +=
OBJS += \
main.o
OBJS_AS_ARGS += \
main.o
C_DEPS += \
main.d
C_DEPS_AS_ARGS += \
main.d
OUTPUT_FILE_PATH +=xmega-eventsys-ring.elf
OUTPUT_FILE_PATH_AS_ARGS +=xmega-eventsys-ring.elf
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:= ./makedep.mk
LIB_DEP+=
LINKER_SCRIPT_DEP+=
# AVR32/GNU C Compiler
./%.o: .././%.c
@echo Building file: $<
@echo Invoking: AVR/GNU C Compiler : 5.4.0
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\XMEGAA_DFP\1.1.68\include" -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atxmega256a3u -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\XMEGAA_DFP\1.1.68\gcc\dev\atxmega256a3u" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<
# AVR32/GNU Preprocessing Assembler
# AVR32/GNU Assembler
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
@echo Building target: $@
@echo Invoking: AVR/GNU Linker : 5.4.0
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="xmega-eventsys-ring.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=atxmega256a3u -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\XMEGAA_DFP\1.1.68\gcc\dev\atxmega256a3u"
@echo Finished building target: $@
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "xmega-eventsys-ring.elf" "xmega-eventsys-ring.hex"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "xmega-eventsys-ring.elf" "xmega-eventsys-ring.eep" || exit 0
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "xmega-eventsys-ring.elf" > "xmega-eventsys-ring.lss"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "xmega-eventsys-ring.elf" "xmega-eventsys-ring.srec"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "xmega-eventsys-ring.elf"
# Other Targets
clean:
-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
-$(RM) $(C_DEPS_AS_ARGS)
rm -rf "xmega-eventsys-ring.elf" "xmega-eventsys-ring.a" "xmega-eventsys-ring.hex" "xmega-eventsys-ring.lss" "xmega-eventsys-ring.eep" "xmega-eventsys-ring.map" "xmega-eventsys-ring.srec" "xmega-eventsys-ring.usersignatures"
\ No newline at end of file
main.d main.o: .././main.c \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\inttypes.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdint.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdint.h \
C:\Program\ Files\ (x86)\Atmel\Studio\7.0\Packs\atmel\XMEGAA_DFP\1.1.68\include/avr/iox256a3u.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\portpins.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\common.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\version.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\xmega.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\fuse.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\lock.h
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\inttypes.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdint.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdint.h:
C:\Program\ Files\ (x86)\Atmel\Studio\7.0\Packs\atmel\XMEGAA_DFP\1.1.68\include/avr/iox256a3u.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\portpins.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\common.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\version.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\xmega.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\fuse.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\lock.h:
################################################################################
# Automatically-generated file. Do not edit or delete the file
################################################################################
main.c
:100000000C94FE000C940A010C940A010C940A0151
:100010000C940A010C940A010C940A010C940A0134
:100020000C940A010C940A010C940A010C940A0124
:100030000C940A010C940A010C940A010C940A0114
:100040000C940A010C940A010C940A010C940A0104
:100050000C940A010C940A010C940A010C940A01F4
:100060000C940A010C940A010C940A010C940A01E4
:100070000C940A010C940A010C940A010C940A01D4
:100080000C940A010C940A010C940A010C940A01C4
:100090000C940A010C940A010C940A010C940A01B4
:1000A0000C940A010C940A010C940A010C940A01A4
:1000B0000C940A010C940A010C940A010C940A0194
:1000C0000C940A010C940A010C940A010C940A0184
:1000D0000C940A010C940A010C940A010C940A0174
:1000E0000C940A010C940A010C940A010C940A0164
:1000F0000C940A010C940A010C940A010C940A0154
:100100000C940A010C940A010C940A010C940A0143
:100110000C940A010C940A010C940A010C940A0133
:100120000C940A010C940A010C940A010C940A0123
:100130000C940A010C940A010C940A010C940A0113
:100140000C940A010C940A010C940A010C940A0103
:100150000C940A010C940A010C940A010C940A01F3
:100160000C940A010C940A010C940A010C940A01E3
:100170000C940A010C940A010C940A010C940A01D3
:100180000C940A010C940A010C940A010C940A01C3
:100190000C940A010C940A010C940A010C940A01B3
:1001A0000C940A010C940A010C940A010C940A01A3
:1001B0000C940A010C940A010C940A010C940A0193
:1001C0000C940A010C940A010C940A010C940A0183
:1001D0000C940A010C940A010C940A010C940A0173
:1001E0000C940A010C940A010C940A010C940A0163
:1001F0000C940A010C940A010C940A0111241FBEEC
:10020000CFEFCDBFDFE5DEBF00E00CBF0E942501D0
:100210000C9446010C940000E0E5F0E083EC82834E
:1002200088E08083818183FFFDCFE0E5F0E083EC0F
:100230008583808180618083818184FFFDCF88ED0B
:1002400084BF84E08093400008950E940C0180E800
:1002500080938106E0EAF6E080E1828382E0848B8D
:10026000E0E8F1E08CE780831092880180E38093DE
:10027000B40081E0808BE0E0F6E09FEFC91AD90A74
:10028000E90AF90ACC20C9F38783F7CFF894FFCFA6
:00000001FF
S01B0000786D6567612D6576656E747379732D72696E672E737265636C
S11300000C94FE000C940A010C940A010C940A014D
S11300100C940A010C940A010C940A010C940A0130
S11300200C940A010C940A010C940A010C940A0120
S11300300C940A010C940A010C940A010C940A0110
S11300400C940A010C940A010C940A010C940A0100
S11300500C940A010C940A010C940A010C940A01F0
S11300600C940A010C940A010C940A010C940A01E0
S11300700C940A010C940A010C940A010C940A01D0
S11300800C940A010C940A010C940A010C940A01C0
S11300900C940A010C940A010C940A010C940A01B0
S11300A00C940A010C940A010C940A010C940A01A0
S11300B00C940A010C940A010C940A010C940A0190
S11300C00C940A010C940A010C940A010C940A0180
S11300D00C940A010C940A010C940A010C940A0170
S11300E00C940A010C940A010C940A010C940A0160
S11300F00C940A010C940A010C940A010C940A0150
S11301000C940A010C940A010C940A010C940A013F
S11301100C940A010C940A010C940A010C940A012F
S11301200C940A010C940A010C940A010C940A011F
S11301300C940A010C940A010C940A010C940A010F
S11301400C940A010C940A010C940A010C940A01FF
S11301500C940A010C940A010C940A010C940A01EF
S11301600C940A010C940A010C940A010C940A01DF
S11301700C940A010C940A010C940A010C940A01CF
S11301800C940A010C940A010C940A010C940A01BF
S11301900C940A010C940A010C940A010C940A01AF
S11301A00C940A010C940A010C940A010C940A019F
S11301B00C940A010C940A010C940A010C940A018F
S11301C00C940A010C940A010C940A010C940A017F
S11301D00C940A010C940A010C940A010C940A016F
S11301E00C940A010C940A010C940A010C940A015F
S11301F00C940A010C940A010C940A0111241FBEE8
S1130200CFEFCDBFDFE5DEBF00E00CBF0E942501CC
S11302100C9446010C940000E0E5F0E083EC82834A
S113022088E08083818183FFFDCFE0E5F0E083EC0B
S11302308583808180618083818184FFFDCF88ED07
S113024084BF84E08093400008950E940C0180E8FC
S113025080938106E0EAF6E080E1828382E0848B89
S1130260E0E8F1E08CE780831092880180E38093DA
S1130270B40081E0808BE0E0F6E09FEFC91AD90A70
S1130280E90AF90ACC20C9F38783F7CFF894FFCFA2
S9030000FC
/*
* xmega-eventsys-ring.c
*
* Created: 7/24/2018 9:13:26 AM
* Author : Jake
*/
#include <avr/io.h>
void clock_init(void){
// I'm using this on a board with a 16MHz external clock
OSC.XOSCCTRL = OSC_XOSCSEL_XTAL_256CLK_gc | OSC_FRQRANGE_12TO16_gc; // select external source
OSC.CTRL = OSC_XOSCEN_bm; // enable external source
while(!(OSC.STATUS & OSC_XOSCRDY_bm)); // wait for external
OSC.PLLCTRL = OSC_PLLSRC_XOSC_gc | 3; // select external osc for pll, do pll = source * 3
OSC.CTRL |= OSC_PLLEN_bm; // enable PLL
while (!(OSC.STATUS & OSC_PLLRDY_bm)); // wait for PLL to be ready
CCP = CCP_IOREG_gc; // enable protected register change
CLK.CTRL = CLK_SCLKSEL_PLL_gc; // switch to PLL for main clock
// if you want to set-up with the internal 2MHz osc, use this code (from Neil)
/*
OSC.PLLCTRL = OSC_PLLFAC4_bm | OSC_PLLFAC3_bm; // 2 MHz * 24 = 48 MHz
OSC.CTRL = OSC_PLLEN_bm; // enable PLL
while (!(OSC.STATUS & OSC_PLLRDY_bm)); // wait for PLL to be ready
CCP = CCP_IOREG_gc; // enable protected register change
CLK.CTRL = CLK_SCLKSEL_PLL_gc; // switch to PLL
*/
}
/*
this runs for ~12 cycles at 18MHz, and then dissapears.
*/
int main(void)
{
clock_init();
PORTE.DIRSET = PIN7_bm; // this is ATK0-TX
PORTF.DIRCLR = PIN4_bm; // this is ATK1-CLKIN
PORTF.PIN4CTRL = PORT_ISC_FALLING_gc; // sense when falling
// setup event channel 0 to have EVSYS_CHMUX_PORTD_PIN4_gc as input
EVSYS_CH0MUX = EVSYS_CHMUX_PORTF_PIN4_gc;
EVSYS_CH0CTRL = EVSYS_DIGFILT_1SAMPLE_gc;
// it seems we can only output events directly on pin7 of ports c, d or e :| (or pin 4 on the same ports)
// so output event 0 on port E, pin 7
PORTCFG_CLKEVOUT = PORTCFG_EVOUT_PE7_gc;
// kick the oscillator
EVSYS.STROBE = 1;
uint32_t tck;
while (1)
{
tck ++;
if(tck % 256){
PORTA.OUTTGL = PIN0_bm;
}
//EVSYS.STROBE = 1; // strobe event channel 0
//if(PORTF.IN & PIN4_bm){
// PORTF.OUTCLR = PIN0_bm;
//} else {
// PORTF.OUTSET = PIN0_bm;
//}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
<ProjectComponents>
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<CApiVersion></CApiVersion>
<CBundle></CBundle>
<CClass>Device</CClass>
<CGroup>Startup</CGroup>
<CSub></CSub>
<CVariant></CVariant>
<CVendor>Atmel</CVendor>
<CVersion>1.1.0</CVersion>
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\XMEGAA_DFP\1.1.68\include</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>include</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\XMEGAA_DFP\1.1.68\include\avr\iox256a3u.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>Ogej+KWLQ2y+wOiUkMjAUg==</FileContentHash>
<FileVersion></FileVersion>
<Name>include/avr/iox256a3u.h</Name>