2024-04-08 14:21:04 +03:00
|
|
|
#include <stdio.h>
|
2024-04-10 19:45:21 +03:00
|
|
|
#include "bsp.h"
|
2024-04-11 21:53:16 +03:00
|
|
|
|
2024-04-10 19:45:21 +03:00
|
|
|
static uint32_t EthStatus = 0;
|
2024-04-02 12:47:04 +03:00
|
|
|
|
|
|
|
void SysTick_Handler(void)
|
|
|
|
{
|
2024-04-08 14:21:04 +03:00
|
|
|
GPIO_ToggleBits(GPIOB, GPIO_Pin_14);
|
2024-04-02 12:47:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void USART2_IRQHandler()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void sysTick_init(void) {
|
2024-04-08 14:21:04 +03:00
|
|
|
uint32_t tick = 10000000;
|
2024-04-02 12:47:04 +03:00
|
|
|
SysTick->LOAD = tick;
|
2024-04-08 14:21:04 +03:00
|
|
|
SysTick->VAL = 0;
|
2024-04-02 12:47:04 +03:00
|
|
|
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_init() {
|
|
|
|
|
|
|
|
const uint16_t led_pins = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14;
|
|
|
|
const uint16_t usart_pins = GPIO_Pin_5 | GPIO_Pin_6;
|
|
|
|
|
2024-04-10 19:45:21 +03:00
|
|
|
RCC_AHB1PeriphClockCmd(
|
|
|
|
RCC_AHB1Periph_GPIOA |
|
|
|
|
RCC_AHB1Periph_GPIOB |
|
|
|
|
RCC_AHB1Periph_GPIOC |
|
|
|
|
RCC_AHB1Periph_GPIOD |
|
|
|
|
RCC_AHB1Periph_GPIOG,
|
|
|
|
ENABLE
|
|
|
|
);
|
|
|
|
|
2024-03-28 17:51:39 +03:00
|
|
|
GPIO_InitTypeDef gpio;
|
2024-04-02 12:47:04 +03:00
|
|
|
|
2024-04-10 19:45:21 +03:00
|
|
|
/***************LED_CONF********************/
|
2024-03-28 17:51:39 +03:00
|
|
|
GPIO_StructInit(&gpio);
|
|
|
|
gpio.GPIO_Mode = GPIO_Mode_OUT;
|
2024-04-02 12:47:04 +03:00
|
|
|
gpio.GPIO_Pin = led_pins;
|
2024-03-28 17:51:39 +03:00
|
|
|
GPIO_Init(GPIOB, &gpio);
|
2024-04-02 12:47:04 +03:00
|
|
|
GPIO_ResetBits(GPIOB, led_pins);
|
2024-04-10 19:45:21 +03:00
|
|
|
/*******************************************/
|
2024-04-02 12:47:04 +03:00
|
|
|
|
2024-04-10 19:45:21 +03:00
|
|
|
/**************UART_CONF********************/
|
2024-04-02 12:47:04 +03:00
|
|
|
gpio.GPIO_Mode = GPIO_Mode_AF;
|
|
|
|
gpio.GPIO_Pin = usart_pins;
|
|
|
|
gpio.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
gpio.GPIO_OType = GPIO_OType_PP;
|
|
|
|
gpio.GPIO_PuPd = GPIO_PuPd_UP;
|
|
|
|
GPIO_Init(GPIOD, &gpio);
|
|
|
|
|
|
|
|
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
|
|
|
|
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
|
2024-04-10 19:45:21 +03:00
|
|
|
/*******************************************/
|
|
|
|
|
|
|
|
/***************ETH_CONF********************/
|
|
|
|
gpio.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7;
|
|
|
|
GPIO_Init(GPIOA, &gpio);
|
|
|
|
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_ETH); //RMII ref clock
|
|
|
|
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_ETH); //RMII MDIO
|
|
|
|
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_ETH); //RMII RX Data Valid
|
|
|
|
|
|
|
|
gpio.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5;
|
|
|
|
GPIO_Init(GPIOC, &gpio);
|
|
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_ETH); //RMII MDC
|
|
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_ETH); //RMII RXD0
|
|
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_ETH); //RMII RXD1
|
|
|
|
|
|
|
|
gpio.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_13;
|
|
|
|
GPIO_Init(GPIOG, &gpio);
|
|
|
|
GPIO_PinAFConfig(GPIOG, GPIO_PinSource11, GPIO_AF_ETH); //RMII TX enable
|
|
|
|
GPIO_PinAFConfig(GPIOG, GPIO_PinSource13, GPIO_AF_ETH); //RMII TXD0
|
|
|
|
|
|
|
|
gpio.GPIO_Pin = GPIO_Pin_13;
|
|
|
|
GPIO_Init(GPIOB, &gpio);
|
|
|
|
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_ETH); //RMII TXD1
|
|
|
|
/*******************************************/
|
|
|
|
|
2024-04-02 12:47:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void usart_init() {
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
|
|
|
USART_InitTypeDef usart;
|
|
|
|
usart.USART_BaudRate = 115200;
|
|
|
|
usart.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
|
|
|
USART_Init(USART2, &usart);
|
|
|
|
USART_Cmd(USART2, ENABLE);
|
|
|
|
//NVIC_EnableIRQ(USART2_IRQn);
|
|
|
|
}
|
|
|
|
|
2024-04-10 19:45:21 +03:00
|
|
|
const uint8_t MAC_ADDR[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
|
|
|
|
const uint8_t PHY_ADDR = 0x00;
|
|
|
|
|
2024-04-11 21:53:16 +03:00
|
|
|
#define IP_ADDR0 192
|
|
|
|
#define IP_ADDR1 168
|
|
|
|
#define IP_ADDR2 0
|
|
|
|
#define IP_ADDR3 5
|
|
|
|
|
|
|
|
#define NETMASK_ADDR0 255
|
|
|
|
#define NETMASK_ADDR1 255
|
|
|
|
#define NETMASK_ADDR2 255
|
|
|
|
#define NETMASK_ADDR3 0
|
|
|
|
|
|
|
|
#define GW_ADDR0 192
|
|
|
|
#define GW_ADDR1 168
|
|
|
|
#define GW_ADDR2 0
|
|
|
|
#define GW_ADDR3 1
|
|
|
|
|
|
|
|
// static struct udp_pcb *echo_pcb;
|
|
|
|
// static char echo_buffer[128];
|
|
|
|
// static ip_addr_t ipaddr, netmask, gw;
|
|
|
|
// static struct netif gnetif;
|
2024-04-10 19:45:21 +03:00
|
|
|
void eth_init() {
|
2024-04-11 21:53:16 +03:00
|
|
|
// lwip_init();
|
2024-04-10 19:45:21 +03:00
|
|
|
|
|
|
|
|
2024-04-11 21:53:16 +03:00
|
|
|
// IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
|
|
|
|
// IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
|
|
|
// IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
2024-04-10 19:45:21 +03:00
|
|
|
|
2024-04-11 21:53:16 +03:00
|
|
|
// netif_set_ipaddr(&gnetif, &ipaddr);
|
|
|
|
// netif_set_netmask(&gnetif, &netmask);
|
|
|
|
// netif_set_gw(&gnetif, &gw);
|
2024-04-08 14:21:04 +03:00
|
|
|
}
|
2024-04-02 12:47:04 +03:00
|
|
|
|
2024-04-08 14:21:04 +03:00
|
|
|
void board_init() {
|
|
|
|
uint32_t tick = 0x1000000;
|
|
|
|
|
|
|
|
SysTick_Config(tick);
|
|
|
|
|
|
|
|
NVIC_EnableIRQ(SysTick_IRQn);
|
|
|
|
__enable_irq();
|
2024-04-02 12:47:04 +03:00
|
|
|
gpio_init();
|
|
|
|
usart_init();
|
2024-04-10 19:45:21 +03:00
|
|
|
eth_init();
|
2024-04-08 14:21:04 +03:00
|
|
|
printf("Controller is started...\n");
|
|
|
|
// printf("clk: %.d\r\n", tick);
|
2024-03-28 17:51:39 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-04-10 19:45:21 +03:00
|
|
|
uint32_t getRegister() {
|
|
|
|
return EthStatus;
|
|
|
|
}
|
2024-03-28 17:51:39 +03:00
|
|
|
|