This commit is contained in:
Vasily Markov 2024-04-11 21:53:16 +03:00
parent 9b60ed210b
commit 4102b5c52d
6 changed files with 56 additions and 44 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "lwip"]
path = lwip
url = git@github.com:lwip-tcpip/lwip.git

View File

@ -7,7 +7,7 @@ project(stm32)
add_subdirectory(bsp) #application
add_subdirectory(lib) #stm32f4xx library
add_subdirectory(lwip) #lwip library
# add_subdirectory(lwip) #lwip library

View File

@ -0,0 +1,7 @@
## Build
### Manual Build
$cmake -S . -B build
cmake --build build
### Auto Build
$./bld
The executables located in the bin directory

View File

@ -4,21 +4,30 @@ project(${target_base_name})
set(elf_file ${target_base_name}.elf)
set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/lwip)
find_package(LwIP REQUIRED)
# set(LWIP_SOURCE_DIR ${CMAKE_SOURCE_DIR}/lwip)
# file(GLOB_RECURSE LWIP_SOURCES ${LWIP_SOURCE_DIR}/*.c)
add_executable(${elf_file}
${CMAKE_SOURCE_DIR}/app/app.c
bsp.c
main.c
syscalls.c
# ${CMAKE_SOURCE_DIR}/lwip/src/core/init.c
# ${LWIP_SOURCES}
# ${CMAKE_SOURCE_DIR}/lwip/src/core/netif.c
# ${CMAKE_SOURCE_DIR}/lwip/src/core/udp.c
# ${CMAKE_SOURCE_DIR}/lwip/src/core/mem.c
# ${CMAKE_SOURCE_DIR}/lwip/src/core/sys.c
)
target_include_directories(${elf_file} PRIVATE
${CMAKE_SOURCE_DIR}/app
${CMAKE_SOURCE_DIR}/bsp
# ${CMAKE_SOURCE_DIR}/lwip/src/include/lwip
${CMAKE_SOURCE_DIR}/lwip
# ${CMAKE_SOURCE_DIR}/lwip/src/include
# ${CMAKE_SOURCE_DIR}/lwip/src/include/lwip
# ${CMAKE_SOURCE_DIR}/lwip/src/include/netif
# ${CMAKE_SOURCE_DIR}/lwip/system/
)
target_compile_options(${elf_file} PRIVATE -Wall -Wextra -Os)

View File

@ -1,6 +1,6 @@
#include <stdio.h>
#include "bsp.h"
static uint32_t EthStatus = 0;
void SysTick_Handler(void)
@ -94,37 +94,36 @@ void usart_init() {
const uint8_t MAC_ADDR[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
const uint8_t PHY_ADDR = 0x00;
#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;
void eth_init() {
ETH_InitTypeDef ETH_InitStructure;
// lwip_init();
ETH_DeInit();
ETH_SoftwareReset();
printf("Eth reseting...\r\n");
while (ETH_GetSoftwareResetStatus() == SET);
printf("Done\r\n");
ETH_MACAddressConfig(ETH_MAC_Address0, MAC_ADDR);
// 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);
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();
// netif_set_ipaddr(&gnetif, &ipaddr);
// netif_set_netmask(&gnetif, &netmask);
// netif_set_gw(&gnetif, &gw);
}
void board_init() {

View File

@ -60,7 +60,7 @@ int _getpid(void)
int _kill(int pid, int sig)
{
errno = EINVAL;
// errno = EINVAL;
return -1;
}
@ -79,7 +79,7 @@ int _read (int file, char *ptr, int len)
*ptr++ = __io_getchar();
}
return len;
return len;
}
int _write(int file, char *ptr, int len)
@ -108,7 +108,7 @@ caddr_t _sbrk(int incr)
{
// write(1, "Heap and stack collision\n", 25);
// abort();
errno = ENOMEM;
// errno = ENOMEM;
return (caddr_t) -1;
}
@ -147,13 +147,13 @@ int _open(char *path, int flags, ...)
int _wait(int *status)
{
errno = ECHILD;
// errno = ECHILD;
return -1;
}
int _unlink(char *name)
{
errno = ENOENT;
// errno = ENOENT;
return -1;
}
@ -170,18 +170,18 @@ int _stat(char *file, struct stat *st)
int _link(char *old, char *new)
{
errno = EMLINK;
// errno = EMLINK;
return -1;
}
int _fork(void)
{
errno = EAGAIN;
// errno = EAGAIN;
return -1;
}
int _execve(char *name, char **argv, char **env)
{
errno = ENOMEM;
// errno = ENOMEM;
return -1;
}