use atmel studio's configuration and init

This commit is contained in:
Joey Castillo 2021-07-30 13:49:09 -04:00
parent e68086a087
commit 6d2e5cd697
5 changed files with 153 additions and 9 deletions

View file

@ -0,0 +1,67 @@
/*
* Code generated from Atmel Start.
*
* This file will be overwritten when reconfiguring your Atmel Start project.
* Please copy examples or other code you want to keep to a separate file
* to avoid losing it when reconfiguring.
*/
#ifndef ATMEL_START_PINS_H_INCLUDED
#define ATMEL_START_PINS_H_INCLUDED
#include <hal_gpio.h>
// SAML22 has 9 pin functions
#define GPIO_PIN_FUNCTION_A 0
#define GPIO_PIN_FUNCTION_B 1
#define GPIO_PIN_FUNCTION_C 2
#define GPIO_PIN_FUNCTION_D 3
#define GPIO_PIN_FUNCTION_E 4
#define GPIO_PIN_FUNCTION_F 5
#define GPIO_PIN_FUNCTION_G 6
#define GPIO_PIN_FUNCTION_H 7
#define GPIO_PIN_FUNCTION_I 8
#define VBUS_DET GPIO(GPIO_PORTA, 2)
#define SEG1 GPIO(GPIO_PORTA, 4)
#define SEG2 GPIO(GPIO_PORTA, 5)
#define SEG3 GPIO(GPIO_PORTA, 6)
#define SEG4 GPIO(GPIO_PORTA, 7)
#define SEG5 GPIO(GPIO_PORTA, 8)
#define SEG6 GPIO(GPIO_PORTA, 9)
#define SEG7 GPIO(GPIO_PORTA, 10)
#define SEG8 GPIO(GPIO_PORTA, 11)
#define SEG14 GPIO(GPIO_PORTA, 12)
#define SEG15 GPIO(GPIO_PORTA, 13)
#define SEG16 GPIO(GPIO_PORTA, 14)
#define SEG17 GPIO(GPIO_PORTA, 15)
#define SEG18 GPIO(GPIO_PORTA, 16)
#define SEG19 GPIO(GPIO_PORTA, 17)
#define SEG20 GPIO(GPIO_PORTA, 18)
#define SEG21 GPIO(GPIO_PORTA, 19)
#define RED GPIO(GPIO_PORTA, 20)
#define GREEN GPIO(GPIO_PORTA, 21)
#define BTN_LIGHT GPIO(GPIO_PORTA, 22)
#define BTN_MODE GPIO(GPIO_PORTA, 23)
#define BUZZER GPIO(GPIO_PORTA, 27)
#define D1 GPIO(GPIO_PORTB, 0)
#define A1 GPIO(GPIO_PORTB, 1)
#define A2 GPIO(GPIO_PORTB, 2)
#define D0 GPIO(GPIO_PORTB, 3)
#define A0 GPIO(GPIO_PORTB, 4)
#define BTN_ALARM GPIO(GPIO_PORTB, 5)
#define COM0 GPIO(GPIO_PORTB, 6)
#define COM1 GPIO(GPIO_PORTB, 7)
#define COM2 GPIO(GPIO_PORTB, 8)
#define SEG0 GPIO(GPIO_PORTB, 9)
#define SEG9 GPIO(GPIO_PORTB, 11)
#define SEG10 GPIO(GPIO_PORTB, 12)
#define SEG11 GPIO(GPIO_PORTB, 13)
#define SEG12 GPIO(GPIO_PORTB, 14)
#define SEG13 GPIO(GPIO_PORTB, 15)
#define SEG22 GPIO(GPIO_PORTB, 16)
#define SEG23 GPIO(GPIO_PORTB, 17)
#define SDA GPIO(GPIO_PORTB, 30)
#define SCL GPIO(GPIO_PORTB, 31)
#endif // ATMEL_START_PINS_H_INCLUDED

View file

@ -0,0 +1,80 @@
/*
* Code generated from Atmel Start.
*
* This file will be overwritten when reconfiguring your Atmel Start project.
* Please copy examples or other code you want to keep to a separate file
* to avoid losing it when reconfiguring.
*/
#ifndef DRIVER_INIT_INCLUDED
#define DRIVER_INIT_INCLUDED
#include "atmel_start_pins.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <hal_atomic.h>
#include <hal_delay.h>
#include <hal_gpio.h>
#include <hal_init.h>
#include <hal_io.h>
#include <hal_sleep.h>
#include <hal_adc_sync.h>
#include <hal_ext_irq.h>
#include <hal_calendar.h>
#include <hal_i2c_m_sync.h>
#include <hal_delay.h>
#include <hpl_tc_base.h>
#include <hal_pwm.h>
#include <hpl_tc_base.h>
#include <hal_pwm.h>
#include <hpl_tcc.h>
#include <hal_slcd_sync.h>
extern struct adc_sync_descriptor ADC_0;
extern struct calendar_descriptor CALENDAR_0;
extern struct i2c_m_sync_desc I2C_0;
extern struct pwm_descriptor PWM_0;
extern struct pwm_descriptor PWM_1;
extern struct slcd_sync_descriptor SEGMENT_LCD_0;
void ADC_0_PORT_init(void);
void ADC_0_CLOCK_init(void);
void ADC_0_init(void);
void CALENDAR_0_CLOCK_init(void);
void CALENDAR_0_init(void);
void I2C_0_CLOCK_init(void);
void I2C_0_init(void);
void I2C_0_PORT_init(void);
void delay_driver_init(void);
void PWM_0_PORT_init(void);
void PWM_0_CLOCK_init(void);
void PWM_0_init(void);
void PWM_1_PORT_init(void);
void PWM_1_CLOCK_init(void);
void PWM_1_init(void);
void EXTERNAL_IRQ_0_init(void);
void SEGMENT_LCD_0_init(void);
#ifdef __cplusplus
}
#endif
#endif // DRIVER_INIT_INCLUDED

View file

@ -33,6 +33,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include "saml22.h" #include "saml22.h"
#include "hal_init.h"
#include "peripheral_clk_config.h"
#include "hal_gpio.h" #include "hal_gpio.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -42,7 +44,7 @@ HAL_GPIO_PIN(UART_RX, B, 2)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static void uart_init(uint32_t baud) { static void uart_init(uint32_t baud) {
uint64_t br = (uint64_t)65536 * (F_CPU - 16 * baud) / F_CPU; uint64_t br = (uint64_t)65536 * (CONF_CPU_FREQUENCY - 16 * baud) / CONF_CPU_FREQUENCY;
HAL_GPIO_UART_TX_out(); HAL_GPIO_UART_TX_out();
HAL_GPIO_UART_TX_pmuxen(HAL_GPIO_PMUX_C); HAL_GPIO_UART_TX_pmuxen(HAL_GPIO_PMUX_C);
@ -79,12 +81,7 @@ static void uart_puts(char *s) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static void sys_init(void) { static void sys_init(void) {
// Switch to 16MHz clock (disable prescaler) init_mcu();
OSCCTRL->OSC16MCTRL.reg = OSCCTRL_OSC16MCTRL_ENABLE | OSCCTRL_OSC16MCTRL_FSEL_16;
// Switch to the highest performance level
PM->INTFLAG.reg = PM_INTFLAG_PLRDY;
PM->PLCFG.reg = PM_PLCFG_PLSEL_PL2_Val;
while (!PM->INTFLAG.reg);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -55,6 +55,7 @@ INCLUDES += \
-I../hpl/tc/ \ -I../hpl/tc/ \
-I../hri/ \ -I../hri/ \
-I../config/ \ -I../config/ \
-I../hw/ \
-I.. -I..
SRCS += \ SRCS += \
@ -95,8 +96,7 @@ SRCS += \
DEFINES += \ DEFINES += \
-D__SAML22J18A__ \ -D__SAML22J18A__ \
-DDONT_USE_CMSIS_INIT \ -DDONT_USE_CMSIS_INIT
-DF_CPU=16000000
CFLAGS += $(INCLUDES) $(DEFINES) CFLAGS += $(INCLUDES) $(DEFINES)