mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-06-19 04:24:17 +08:00
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.
224 lines
4.3 KiB
C
224 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 <hal_init.h>
|
|
#include <hpl_pmc.h>
|
|
#include <peripheral_clk_config.h>
|
|
#include <utils.h>
|
|
#include <hpl_usart_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 i2c_m_sync_desc I2C_0;
|
|
|
|
struct mac_async_descriptor MACIF;
|
|
|
|
void ADC_0_PORT_init(void)
|
|
{
|
|
|
|
gpio_set_pin_function(PB0, GPIO_PIN_FUNCTION_OFF);
|
|
}
|
|
|
|
void ADC_0_CLOCK_init(void)
|
|
{
|
|
|
|
_pmc_enable_periph_clock(ID_AFEC0);
|
|
}
|
|
|
|
void ADC_0_init(void)
|
|
{
|
|
ADC_0_CLOCK_init();
|
|
ADC_0_PORT_init();
|
|
adc_sync_init(&ADC_0, AFEC0, (void *)NULL);
|
|
}
|
|
|
|
void I2C_0_PORT_init(void)
|
|
{
|
|
|
|
gpio_set_pin_function(PA4, MUX_PA4A_TWIHS0_TWCK0);
|
|
|
|
gpio_set_pin_function(PA3, MUX_PA3A_TWIHS0_TWD0);
|
|
}
|
|
|
|
void I2C_0_CLOCK_init(void)
|
|
{
|
|
_pmc_enable_periph_clock(ID_TWIHS0);
|
|
}
|
|
|
|
void I2C_0_init(void)
|
|
{
|
|
I2C_0_CLOCK_init();
|
|
|
|
i2c_m_sync_init(&I2C_0, TWIHS0);
|
|
|
|
I2C_0_PORT_init();
|
|
}
|
|
|
|
/**
|
|
* \brief USART Clock initialization function
|
|
*
|
|
* Enables register interface and peripheral clock
|
|
*/
|
|
void TARGET_IO_CLOCK_init()
|
|
{
|
|
_pmc_enable_periph_clock(ID_USART1);
|
|
}
|
|
|
|
/**
|
|
* \brief USART pinmux initialization function
|
|
*
|
|
* Set each required pin to USART functionality
|
|
*/
|
|
void TARGET_IO_PORT_init()
|
|
{
|
|
|
|
gpio_set_pin_function(PA21, MUX_PA21A_USART1_RXD1);
|
|
|
|
gpio_set_pin_function(PB4, MUX_PB4D_USART1_TXD1);
|
|
}
|
|
|
|
/**
|
|
* \brief USART initialization function
|
|
*
|
|
* Enables USART peripheral, clocks and initializes USART driver
|
|
*/
|
|
void TARGET_IO_init(void)
|
|
{
|
|
TARGET_IO_CLOCK_init();
|
|
TARGET_IO_PORT_init();
|
|
usart_async_init(&TARGET_IO, USART1, TARGET_IO_buffer, TARGET_IO_BUFFER_SIZE, _usart_get_usart_async());
|
|
}
|
|
|
|
void MACIF_PORT_init(void)
|
|
{
|
|
|
|
gpio_set_pin_function(PD8, MUX_PD8A_GMAC_GMDC);
|
|
|
|
gpio_set_pin_function(PD9, MUX_PD9A_GMAC_GMDIO);
|
|
|
|
gpio_set_pin_function(PD5, MUX_PD5A_GMAC_GRX0);
|
|
|
|
gpio_set_pin_function(PD6, MUX_PD6A_GMAC_GRX1);
|
|
|
|
gpio_set_pin_function(PD4, MUX_PD4A_GMAC_GRXDV);
|
|
|
|
gpio_set_pin_function(PD7, MUX_PD7A_GMAC_GRXER);
|
|
|
|
gpio_set_pin_function(PD2, MUX_PD2A_GMAC_GTX0);
|
|
|
|
gpio_set_pin_function(PD3, MUX_PD3A_GMAC_GTX1);
|
|
|
|
gpio_set_pin_function(PD0, MUX_PD0A_GMAC_GTXCK);
|
|
|
|
gpio_set_pin_function(PD1, MUX_PD1A_GMAC_GTXEN);
|
|
}
|
|
|
|
void MACIF_CLOCK_init(void)
|
|
{
|
|
_pmc_enable_periph_clock(ID_GMAC);
|
|
}
|
|
|
|
void MACIF_init(void)
|
|
{
|
|
MACIF_CLOCK_init();
|
|
mac_async_init(&MACIF, GMAC);
|
|
MACIF_PORT_init();
|
|
}
|
|
|
|
/**
|
|
* \brief MCAN Clock initialization function
|
|
*
|
|
* Enables register interface and peripheral clock
|
|
*/
|
|
void CAN_0_CLOCK_init()
|
|
{
|
|
_pmc_enable_periph_clock(ID_MCAN1);
|
|
}
|
|
|
|
/**
|
|
* \brief MCAN pinmux initialization function
|
|
*
|
|
* Set each required pin to MCAN functionality
|
|
*/
|
|
void CAN_0_PORT_init(void)
|
|
{
|
|
|
|
gpio_set_pin_function(PC12, MUX_PC12C_MCAN1_CANRX1);
|
|
|
|
gpio_set_pin_function(PC14, MUX_PC14C_MCAN1_CANTX1);
|
|
}
|
|
/**
|
|
* \brief CAN initialization function
|
|
*
|
|
* Enables CAN peripheral, clocks and initializes CAN driver
|
|
*/
|
|
void CAN_0_init(void)
|
|
{
|
|
CAN_0_CLOCK_init();
|
|
CAN_0_PORT_init();
|
|
can_async_init(&CAN_0, MCAN1);
|
|
}
|
|
|
|
void system_init(void)
|
|
{
|
|
init_mcu();
|
|
|
|
_pmc_enable_periph_clock(ID_PIOA);
|
|
|
|
_pmc_enable_periph_clock(ID_PIOC);
|
|
|
|
/* Disable Watchdog */
|
|
hri_wdt_set_MR_WDDIS_bit(WDT);
|
|
|
|
/* GPIO on PA11 */
|
|
|
|
// Set pin direction to input
|
|
gpio_set_pin_direction(SW0, GPIO_DIRECTION_IN);
|
|
|
|
gpio_set_pin_pull_mode(SW0,
|
|
// <y> Pull configuration
|
|
// <id> pad_pull_config
|
|
// <GPIO_PULL_OFF"> Off
|
|
// <GPIO_PULL_UP"> Pull-up
|
|
// <GPIO_PULL_DOWN"> Pull-down
|
|
GPIO_PULL_UP);
|
|
|
|
gpio_set_pin_function(SW0, GPIO_PIN_FUNCTION_OFF);
|
|
|
|
/* GPIO on PC8 */
|
|
|
|
gpio_set_pin_level(LED0,
|
|
// <y> Initial level
|
|
// <id> pad_initial_level
|
|
// <false"> Low
|
|
// <true"> High
|
|
true);
|
|
|
|
// 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();
|
|
|
|
I2C_0_init();
|
|
TARGET_IO_init();
|
|
|
|
MACIF_init();
|
|
CAN_0_init();
|
|
}
|