This commit is contained in:
Vasily Markov 2024-04-10 19:45:21 +03:00
parent dd461893db
commit 9e78b2b7eb
6 changed files with 90 additions and 25 deletions

View File

@ -5,8 +5,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
project(stm32) project(stm32)
add_subdirectory(bsp) add_subdirectory(bsp) #application
add_subdirectory(lib) add_subdirectory(lib) #stm32f4xx library
add_subdirectory(lwip) #lwip library

View File

@ -1,7 +1,5 @@
#include "app.h" #include "app.h"
void delay(uint32_t ms) { void delay(uint32_t ms) {
ms *= 16800; ms *= 16800;
while(ms--) { while(ms--) {
@ -20,8 +18,8 @@ void app() {
// printf("Hello, world%.2f\r\n", 2.71); // printf("Hello, world%.2f\r\n", 2.71);
RCC_ClocksTypeDef clk; RCC_ClocksTypeDef clk;
RCC_GetClocksFreq(&clk); RCC_GetClocksFreq(&clk);
printf("LOAD: %.d\r\n", SysTick->LOAD); printf("Status: %.d\r\n", getRegister());
printf("VAL: %.d\r\n", SysTick->VAL); // printf("VAL: %.d\r\n", SysTick->VAL);
loop(); loop();
}; };
} }

View File

@ -4,6 +4,10 @@ project(${target_base_name})
set(elf_file ${target_base_name}.elf) set(elf_file ${target_base_name}.elf)
set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/lwip)
find_package(LwIP REQUIRED)
add_executable(${elf_file} add_executable(${elf_file}
${CMAKE_SOURCE_DIR}/app/app.c ${CMAKE_SOURCE_DIR}/app/app.c
bsp.c bsp.c
@ -14,6 +18,7 @@ add_executable(${elf_file}
target_include_directories(${elf_file} PRIVATE target_include_directories(${elf_file} PRIVATE
${CMAKE_SOURCE_DIR}/app ${CMAKE_SOURCE_DIR}/app
${CMAKE_SOURCE_DIR}/bsp ${CMAKE_SOURCE_DIR}/bsp
# ${CMAKE_SOURCE_DIR}/lwip/src/include/lwip
) )
target_compile_options(${elf_file} PRIVATE -Wall -Wextra -Os) target_compile_options(${elf_file} PRIVATE -Wall -Wextra -Os)

View File

@ -1,15 +1,7 @@
#include "bsp.h"
#include <stdio.h> #include <stdio.h>
// int _write(int fd, char* ptr, int len) { #include "bsp.h"
// int i= 0;
// while(i < len) { static uint32_t EthStatus = 0;
// while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
// USART_SendData(USART2, *ptr++);
// i++;
// }
// return len;
// }
void SysTick_Handler(void) void SysTick_Handler(void)
{ {
@ -33,17 +25,26 @@ void gpio_init() {
const uint16_t led_pins = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14; 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; const uint16_t usart_pins = GPIO_Pin_5 | GPIO_Pin_6;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_AHB1PeriphClockCmd(
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); RCC_AHB1Periph_GPIOA |
RCC_AHB1Periph_GPIOB |
RCC_AHB1Periph_GPIOC |
RCC_AHB1Periph_GPIOD |
RCC_AHB1Periph_GPIOG,
ENABLE
);
GPIO_InitTypeDef gpio; GPIO_InitTypeDef gpio;
/***************LED_CONF********************/
GPIO_StructInit(&gpio); GPIO_StructInit(&gpio);
gpio.GPIO_Mode = GPIO_Mode_OUT; gpio.GPIO_Mode = GPIO_Mode_OUT;
gpio.GPIO_Pin = led_pins; gpio.GPIO_Pin = led_pins;
GPIO_Init(GPIOB, &gpio); GPIO_Init(GPIOB, &gpio);
GPIO_ResetBits(GPIOB, led_pins); GPIO_ResetBits(GPIOB, led_pins);
/*******************************************/
/**************UART_CONF********************/
gpio.GPIO_Mode = GPIO_Mode_AF; gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_Pin = usart_pins; gpio.GPIO_Pin = usart_pins;
gpio.GPIO_Speed = GPIO_Speed_50MHz; gpio.GPIO_Speed = GPIO_Speed_50MHz;
@ -53,6 +54,31 @@ void gpio_init() {
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2); GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2); GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
/*******************************************/
/***************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
/*******************************************/
} }
void usart_init() { void usart_init() {
@ -65,13 +91,43 @@ void usart_init() {
//NVIC_EnableIRQ(USART2_IRQn); //NVIC_EnableIRQ(USART2_IRQn);
} }
void ethernet_init() { const uint8_t MAC_ADDR[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
const uint8_t PHY_ADDR = 0x00;
void eth_init() {
ETH_InitTypeDef ETH_InitStructure; ETH_InitTypeDef ETH_InitStructure;
ETH_DeInit();
ETH_SoftwareReset();
printf("Eth reseting...\r\n");
while (ETH_GetSoftwareResetStatus() == SET);
printf("Done\r\n");
ETH_MACAddressConfig(ETH_MAC_Address0, MAC_ADDR);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC | RCC_AHB1Periph_ETH_MAC_Tx | RCC_AHB1Periph_ETH_MAC_Rx, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC | RCC_AHB1Periph_ETH_MAC_Tx | RCC_AHB1Periph_ETH_MAC_Rx, ENABLE);
ETH_StructInit(&ETH_InitStructure);
ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;
ETH_InitStructure.ETH_Speed = ETH_Speed_100M;
ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex;
ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable;
ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable;
ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Enable;
ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable;
ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
EthStatus = ETH_Init(&ETH_InitStructure, PHY_ADDR);
printf("Eth init with status: %d\r\n", EthStatus);
ETH_Start();
} }
void board_init() { void board_init() {
// uint32_t tick = 16777216;
uint32_t tick = 0x1000000; uint32_t tick = 0x1000000;
SysTick_Config(tick); SysTick_Config(tick);
@ -80,10 +136,13 @@ void board_init() {
__enable_irq(); __enable_irq();
gpio_init(); gpio_init();
usart_init(); usart_init();
// ETH_BSP_Config(); eth_init();
printf("Controller is started...\n"); printf("Controller is started...\n");
// printf("clk: %.d\r\n", tick); // printf("clk: %.d\r\n", tick);
} }
uint32_t getRegister() {
return EthStatus;
}

View File

@ -5,9 +5,10 @@
#include "stm32f4xx_gpio.h" #include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h" #include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h" #include "stm32f4xx_usart.h"
#include "stm32f4xx_exti.h"
#include "stm32f4x7_eth.h" #include "stm32f4x7_eth.h"
// #include "stm32f4x7_eth_bsp.h" #include "misc.h"
void board_init(); void board_init();
uint32_t getRegister();
#endif #endif

View File

@ -50,6 +50,7 @@ target_include_directories(stm32f4xx PUBLIC
target_compile_definitions(stm32f4xx PUBLIC USE_STDPERIPH_DRIVER) target_compile_definitions(stm32f4xx PUBLIC USE_STDPERIPH_DRIVER)
target_compile_definitions(stm32f4xx PUBLIC ${DEVICE_FAMILY}) target_compile_definitions(stm32f4xx PUBLIC ${DEVICE_FAMILY})
target_compile_definitions(stm32f4xx PUBLIC HSE_VALUE=8000000) target_compile_definitions(stm32f4xx PUBLIC HSE_VALUE=8000000)
target_compile_definitions(stm32f4xx PUBLIC USE_STM324x7I_EVAL)
target_compile_options(stm32f4xx PRIVATE -Wall -Wextra -Os -nostartfiles) target_compile_options(stm32f4xx PRIVATE -Wall -Wextra -Os -nostartfiles)
target_link_libraries(stm32f4xx PUBLIC -T${LINKER_SCRIPT}) target_link_libraries(stm32f4xx PUBLIC -T${LINKER_SCRIPT})