7847c5e98d
* Microchip SAM MCU BSP update and add ethernet driver 1. Update Microchip SAM MCU BSP, add I2C, GMAC, ADC driver support. 2. Add ethernet driver support of SAM MCU for RT-Thread. * Add GMAC and I2C driver support 1. Update MCU BSP to support I2C/ADC/GMAC peripherals. 2. Add I2C and ethernet driver and LWIP support. 3. Update serial driver. * Add I2C driver and move some files to the common folder 1. Add I2C driver. 2. Move the same drivers and demo code to same folder to reduce duplicated code.
186 lines
4.3 KiB
C
186 lines
4.3 KiB
C
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include "driver_init.h"
|
|
#include <peripheral_clk_config.h>
|
|
#include <utils.h>
|
|
#include <hal_init.h>
|
|
|
|
#include <hpl_adc_base.h>
|
|
|
|
/*! The buffer size for USART */
|
|
#define TARGET_IO_BUFFER_SIZE 16
|
|
|
|
struct usart_async_descriptor TARGET_IO;
|
|
struct can_async_descriptor CAN_0;
|
|
|
|
static uint8_t TARGET_IO_buffer[TARGET_IO_BUFFER_SIZE];
|
|
|
|
struct adc_sync_descriptor ADC_0;
|
|
|
|
struct flash_descriptor FLASH_0;
|
|
|
|
struct i2c_m_sync_desc I2C_0;
|
|
|
|
void ADC_0_PORT_init(void)
|
|
{
|
|
|
|
// Disable digital pin circuitry
|
|
gpio_set_pin_direction(PA10, GPIO_DIRECTION_OFF);
|
|
|
|
gpio_set_pin_function(PA10, PINMUX_PA10B_ADC0_AIN10);
|
|
}
|
|
|
|
void ADC_0_CLOCK_init(void)
|
|
{
|
|
hri_mclk_set_APBCMASK_ADC0_bit(MCLK);
|
|
hri_gclk_write_PCHCTRL_reg(GCLK, ADC0_GCLK_ID, CONF_GCLK_ADC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
|
}
|
|
|
|
void ADC_0_init(void)
|
|
{
|
|
ADC_0_CLOCK_init();
|
|
ADC_0_PORT_init();
|
|
adc_sync_init(&ADC_0, ADC0, _adc_get_adc_sync());
|
|
}
|
|
|
|
void FLASH_0_CLOCK_init(void)
|
|
{
|
|
|
|
hri_mclk_set_AHBMASK_NVMCTRL_bit(MCLK);
|
|
}
|
|
|
|
void FLASH_0_init(void)
|
|
{
|
|
FLASH_0_CLOCK_init();
|
|
flash_init(&FLASH_0, NVMCTRL);
|
|
}
|
|
|
|
void I2C_0_PORT_init(void)
|
|
{
|
|
|
|
gpio_set_pin_pull_mode(PA08,
|
|
// <y> Pull configuration
|
|
// <id> pad_pull_config
|
|
// <GPIO_PULL_OFF"> Off
|
|
// <GPIO_PULL_UP"> Pull-up
|
|
// <GPIO_PULL_DOWN"> Pull-down
|
|
GPIO_PULL_OFF);
|
|
|
|
gpio_set_pin_function(PA08, PINMUX_PA08C_SERCOM0_PAD0);
|
|
|
|
gpio_set_pin_pull_mode(PA09,
|
|
// <y> Pull configuration
|
|
// <id> pad_pull_config
|
|
// <GPIO_PULL_OFF"> Off
|
|
// <GPIO_PULL_UP"> Pull-up
|
|
// <GPIO_PULL_DOWN"> Pull-down
|
|
GPIO_PULL_OFF);
|
|
|
|
gpio_set_pin_function(PA09, PINMUX_PA09C_SERCOM0_PAD1);
|
|
}
|
|
|
|
void I2C_0_CLOCK_init(void)
|
|
{
|
|
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM0_GCLK_ID_CORE, CONF_GCLK_SERCOM0_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
|
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM0_GCLK_ID_SLOW, CONF_GCLK_SERCOM0_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
|
hri_mclk_set_APBCMASK_SERCOM0_bit(MCLK);
|
|
}
|
|
|
|
void I2C_0_init(void)
|
|
{
|
|
I2C_0_CLOCK_init();
|
|
i2c_m_sync_init(&I2C_0, SERCOM0);
|
|
I2C_0_PORT_init();
|
|
}
|
|
|
|
/**
|
|
* \brief USART Clock initialization function
|
|
*
|
|
* Enables register interface and peripheral clock
|
|
*/
|
|
void TARGET_IO_CLOCK_init()
|
|
{
|
|
|
|
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM4_GCLK_ID_CORE, CONF_GCLK_SERCOM4_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
|
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM4_GCLK_ID_SLOW, CONF_GCLK_SERCOM4_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
|
hri_mclk_set_APBCMASK_SERCOM4_bit(MCLK);
|
|
}
|
|
|
|
/**
|
|
* \brief USART pinmux initialization function
|
|
*
|
|
* Set each required pin to USART functionality
|
|
*/
|
|
void TARGET_IO_PORT_init()
|
|
{
|
|
|
|
gpio_set_pin_function(PB10, PINMUX_PB10D_SERCOM4_PAD2);
|
|
|
|
gpio_set_pin_function(PB11, PINMUX_PB11D_SERCOM4_PAD3);
|
|
}
|
|
|
|
/**
|
|
* \brief USART initialization function
|
|
*
|
|
* Enables USART peripheral, clocks and initializes USART driver
|
|
*/
|
|
void TARGET_IO_init(void)
|
|
{
|
|
TARGET_IO_CLOCK_init();
|
|
usart_async_init(&TARGET_IO, SERCOM4, TARGET_IO_buffer, TARGET_IO_BUFFER_SIZE, (void *)NULL);
|
|
TARGET_IO_PORT_init();
|
|
}
|
|
|
|
void CAN_0_PORT_init(void)
|
|
{
|
|
|
|
gpio_set_pin_function(PA25, PINMUX_PA25G_CAN0_RX);
|
|
|
|
gpio_set_pin_function(PA24, PINMUX_PA24G_CAN0_TX);
|
|
}
|
|
/**
|
|
* \brief CAN initialization function
|
|
*
|
|
* Enables CAN peripheral, clocks and initializes CAN driver
|
|
*/
|
|
void CAN_0_init(void)
|
|
{
|
|
hri_mclk_set_AHBMASK_CAN0_bit(MCLK);
|
|
hri_gclk_write_PCHCTRL_reg(GCLK, CAN0_GCLK_ID, CONF_GCLK_CAN0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
|
can_async_init(&CAN_0, CAN0);
|
|
CAN_0_PORT_init();
|
|
}
|
|
|
|
void system_init(void)
|
|
{
|
|
init_mcu();
|
|
|
|
// GPIO on PA15
|
|
|
|
gpio_set_pin_level(LED0,
|
|
// <y> Initial level
|
|
// <id> pad_initial_level
|
|
// <false"> Low
|
|
// <true"> High
|
|
false);
|
|
|
|
// Set pin direction to output
|
|
gpio_set_pin_direction(LED0, GPIO_DIRECTION_OUT);
|
|
|
|
gpio_set_pin_function(LED0, GPIO_PIN_FUNCTION_OFF);
|
|
|
|
ADC_0_init();
|
|
|
|
FLASH_0_init();
|
|
|
|
I2C_0_init();
|
|
TARGET_IO_init();
|
|
CAN_0_init();
|
|
}
|