replace project

This commit is contained in:
Vasily Markov 2024-05-13 15:21:22 +03:00
parent 65ca4d8ddb
commit bfb05211c1
221 changed files with 89115 additions and 88837 deletions

@ -1,7 +1,6 @@
set(elf_file stm32.elf)
add_executable(${elf_file}
app.c
main.c
syscalls.c
)

@ -1,23 +0,0 @@
#include "app.h"
void app() {
init_LWIP();
static uint32_t loop_cnt = 0;
printf("FLASH->ACR: %d\r\n", FLASH->ACR);
printf("RCC->CFGR: %d\r\n", RCC->CFGR);
printf("RCC->CR): %d\r\n", RCC->CR);
printf("RCC->PLLCFGR: %d\r\n", RCC->PLLCFGR);
printf("RCC->APB1ENR: %d\r\n", RCC->APB1ENR);
while(1) {
process_LWIP();
// if(loop_cnt == 10000) {
// GPIO_ToggleBits(GPIOB, GPIO_Pin_14);
// loop_cnt = 0;
// }
// loop_cnt++;
GPIO_ToggleBits(GPIOB, GPIO_Pin_14);
delay(1000);
};
}

@ -1,7 +0,0 @@
#ifndef APP_H
#define APP_H
#include "../bsp/bsp.h"
void app();
#endif

@ -1,11 +1,157 @@
#include "app.h"
#include "../bsp/bsp.h"
int main() {
board_init();
app();
void MX_GPIO_Init(void)
{
RCC_AHB1PeriphClockCmd(
RCC_AHB1Periph_GPIOA |
RCC_AHB1Periph_GPIOB |
RCC_AHB1Periph_GPIOC |
RCC_AHB1Periph_GPIOD |
RCC_AHB1Periph_GPIOG,
ENABLE
);
const uint16_t led_pins = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14;
GPIO_InitTypeDef gpio;
GPIO_StructInit(&gpio);
gpio.GPIO_Mode = GPIO_Mode_OUT;
gpio.GPIO_Pin = led_pins;
GPIO_Init(GPIOB, &gpio);
GPIO_ResetBits(GPIOB, led_pins);
}
void MX_USART2_UART_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
GPIO_InitTypeDef gpio;
const uint16_t usart_pins = GPIO_Pin_5 | GPIO_Pin_6;
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);
// NVIC_SetPriority(USART2_IRQn, 0);
// NVIC_EnableIRQ(USART2_IRQn);
USART_InitTypeDef usart;
usart.USART_BaudRate = 115200;
usart.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &usart);
USART_Cmd(USART2, ENABLE);
}
void SystemClock_Config();
void eth_init() {
RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_ETHMACEN, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_ETHMACRXEN, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_ETHMACTXEN, ENABLE);
GPIO_InitTypeDef gpio;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_Speed = GPIO_Speed_100MHz;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
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
NVIC_SetPriority(ETH_IRQn, 0);
NVIC_EnableIRQ(ETH_IRQn);
}
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
SystemClock_Config();
uint32_t tick = SystemCoreClock/1000 - 1;
SysTick_Config(tick);
MX_GPIO_Init();
MX_USART2_UART_Init();
eth_init();
MX_LWIP_Init();
printf("Starting main loop..\r\n");
printf("SysClock: %d\r\n:", SystemCoreClock);
printf("FLASH->ACR: %d\r\n", FLASH->ACR);
printf("RCC->CFGR :%d\r\n", RCC->CFGR);
printf("RCC->CR :%d\r\n", RCC->CR);
printf("RCC->PLLCFGR :%d\r\n", RCC->PLLCFGR);
printf("RCC->APB1ENR :%d\r\n", RCC->APB1ENR);
udpServer_init();
while (1)
{
MX_LWIP_Process(); // poll for ethernet rx and timer operations.
const char *data = "Hello, world!";
udp_send_data(data, strlen(data));
GPIO_ToggleBits(GPIOB, GPIO_Pin_14);
delay(500);
}
}
void SystemClock_Config()
{
// SystemInit();
SystemCoreClock = 180000000;
}
void Error_Handler(void)
{
printf("Error Handler Triggered..\r\n");
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

@ -3,24 +3,42 @@
**
** File : syscalls.c
**
** Abstract : Atollic TrueSTUDIO Minimal System calls file
** Abstract : System Workbench Minimal System calls file
**
** For more information about which c-functions
** need which of these lowlevel functions
** please consult the Newlib libc-manual
**
** Environment : Atollic TrueSTUDIO
** Environment : System Workbench for MCU
**
** Distribution: The file is distributed <EFBFBD>as is,<EFBFBD> without any warranty
** Distribution: The file is distributed as is without any warranty
** of any kind.
**
** (c)Copyright Atollic AB.
** You may use this file as-is or modify it according to the needs of your
** project. Distribution of this file (unmodified or modified) is not
** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
** rights to distribute the assembled, compiled & linked contents of this
** file as part of an application binary file, provided that it is built
** using the Atollic TrueSTUDIO(R) Pro toolchain.
*****************************************************************************
**
** <h2><center>&copy; COPYRIGHT(c) 2014 Ac6</center></h2>
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
** 1. Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** 3. Neither the name of Ac6 nor the names of its contributors
** may be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
*****************************************************************************
*/
@ -37,7 +55,7 @@
#include "../bsp/bsp.h"
/* Variables */
#undef errno
//#undef errno
extern int errno;
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
@ -58,9 +76,9 @@ int _getpid(void)
return 1;
}
int _kill(__attribute__((unused)) int pid, __attribute__((unused)) int sig)
int _kill(int pid, int sig)
{
// errno = EINVAL;
errno = EINVAL;
return -1;
}
@ -70,31 +88,26 @@ void _exit (int status)
while (1) {} /* Make sure we hang here */
}
int _read (__attribute__((unused)) int file, char *ptr, int len)
int _read (int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
*ptr++ = __io_getchar();
}
return len;
return len;
}
int _write(__attribute__((unused)) int file, char *ptr, int len)
int _write(int file, char *ptr, int len)
{
int i= 0;
while(i < len) {
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, *ptr++);
// ringbuf_uint8t* printf_buffer = get_printf_buffer();
// if (!rb_is_full(printf_buffer)) {
// rb_put(printf_buffer, *ptr++);
// }
i++;
}
// USART2->CR1 |= USART_CR1_TXEIE;
return len;
}
@ -112,7 +125,7 @@ caddr_t _sbrk(int incr)
{
// write(1, "Heap and stack collision\n", 25);
// abort();
// errno = ENOMEM;
errno = ENOMEM;
return (caddr_t) -1;
}
@ -121,71 +134,71 @@ caddr_t _sbrk(int incr)
return (caddr_t) prev_heap_end;
}
int _close(__attribute__((unused)) int file)
int _close(int file)
{
return -1;
}
int _fstat(__attribute__((unused)) int file, struct stat *st)
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(__attribute__((unused)) int file)
int _isatty(int file)
{
return 1;
}
int _lseek(__attribute__((unused)) int file, __attribute__((unused)) int ptr, __attribute__((unused)) int dir)
int _lseek(int file, int ptr, int dir)
{
return 0;
}
int _open(__attribute__((unused)) char *path, __attribute__((unused)) int flags, ...)
int _open(char *path, int flags, ...)
{
/* Pretend like we always fail */
return -1;
}
int _wait(__attribute__((unused)) int *status)
int _wait(int *status)
{
// errno = ECHILD;
errno = ECHILD;
return -1;
}
int _unlink(__attribute__((unused)) char *name)
int _unlink(char *name)
{
// errno = ENOENT;
errno = ENOENT;
return -1;
}
int _times(__attribute__((unused)) struct tms *buf)
int _times(struct tms *buf)
{
return -1;
}
int _stat(__attribute__((unused)) char *file, struct stat *st)
int _stat(char *file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _link(__attribute__((unused)) char *old, __attribute__((unused)) char *new)
int _link(char *old, char *new)
{
// errno = EMLINK;
errno = EMLINK;
return -1;
}
int _fork(void)
{
// errno = EAGAIN;
errno = EAGAIN;
return -1;
}
int _execve(__attribute__((unused)) char *name, __attribute__((unused)) char **argv, __attribute__((unused)) char **env)
int _execve(char *name, char **argv, char **env)
{
// errno = ENOMEM;
errno = ENOMEM;
return -1;
}

@ -4,7 +4,7 @@ set(LWIP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lwip/src/core)
add_library(bsp STATIC
bsp.c
ring_buffer.c
ringbuffer.c
stm32f4xx_it.c
lwip/lwip.c
lwip/ethernetif.c
@ -28,7 +28,7 @@ add_library(bsp STATIC
${LWIP_SOURCE_DIR}/netif/ethernet.c
)
target_include_directories(bsp PRIVATE
target_include_directories(bsp PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/bsp/lwip
${CMAKE_SOURCE_DIR}/bsp/lwip/system

170
bsp/bsp.c

@ -1,36 +1,8 @@
#include "misc.h"
#include "bsp.h"
#define MAX_DELAY 0xFFFFFFFU
#define PRINTF_BUFFER_SIZE 128
static uint8_t printf_buffer[PRINTF_BUFFER_SIZE];
static ringbuf_uint8t ring_buffer;
ringbuf_uint8t* get_printf_buffer() {
return &ring_buffer;
}
static lwip_status_t lwip_status = {.link_status = LINK_DOWN};
lwip_status_t* get_lwip_status() {
return &lwip_status;
}
void delay(uint32_t delay) {
uint32_t tickStart = getSysTick();
uint32_t wait = delay;
if (wait < MAX_DELAY) {
wait++;
}
while((getSysTick() - tickStart) < wait) {}
}
void gpio_init() {
const uint16_t led_pins = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14;
void gpio_init()
{
RCC_AHB1PeriphClockCmd(
RCC_AHB1Periph_GPIOA |
RCC_AHB1Periph_GPIOB |
@ -39,6 +11,8 @@ void gpio_init() {
RCC_AHB1Periph_GPIOG,
ENABLE
);
const uint16_t led_pins = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14;
GPIO_InitTypeDef gpio;
GPIO_StructInit(&gpio);
@ -48,115 +22,51 @@ void gpio_init() {
GPIO_ResetBits(GPIOB, led_pins);
}
void usart_init() {
GPIO_InitTypeDef gpio;
void usart_init()
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
const uint16_t usart_pins = GPIO_Pin_5 | GPIO_Pin_6;
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);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
GPIO_InitTypeDef gpio;
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);
const uint16_t usart_pins = GPIO_Pin_5 | GPIO_Pin_6;
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);
// USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
// NVIC_SetPriority(USART2_IRQn, 0);
// NVIC_EnableIRQ(USART2_IRQn);
USART_Cmd(USART2, ENABLE);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
// NVIC_SetPriority(USART2_IRQn, 0);
// NVIC_EnableIRQ(USART2_IRQn);
USART_InitTypeDef usart;
usart.USART_BaudRate = 115200;
usart.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &usart);
USART_Cmd(USART2, ENABLE);
}
void tim_init() {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
TIM_TimeBaseInitTypeDef tim7;
TIM_TimeBaseStructInit(&tim7);
tim7.TIM_Prescaler = 9000-1;
tim7.TIM_CounterMode = TIM_CounterMode_Up;
tim7.TIM_Period = 2000;
tim7.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM7, &tim7);
TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
TIM_UpdateRequestConfig(TIM7, TIM_UpdateSource_Regular);
TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);
NVIC_SetPriority(TIM7_IRQn, 0);
NVIC_EnableIRQ(TIM7_IRQn);
TIM_Cmd(TIM7, ENABLE);
}
void dma_init() {
}
void eth_init() {
RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_ETHMACEN, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_ETHMACRXEN, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_ETHMACTXEN, ENABLE);
GPIO_InitTypeDef gpio;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_Speed = GPIO_Speed_100MHz;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
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
NVIC_SetPriority(ETH_IRQn, 0);
NVIC_EnableIRQ(ETH_IRQn);
}
void board_init() {
uint32_t tick = SystemCoreClock/1000 - 1;
FLASH_PrefetchBufferCmd(ENABLE);
SysTick_Config(tick);
NVIC_EnableIRQ(SysTick_IRQn);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
SystemInit();
SystemCoreClock = 180000000;
gpio_init();
usart_init();
printf("Starting main loop..\r\n");
printf("SysClock: %d\r\n:", SystemCoreClock);
// dma_init();
eth_init();
init_LWIP();
tim_init();
rb_init(&ring_buffer, printf_buffer, PRINTF_BUFFER_SIZE);
printf("SysClk: %d\r\n", SystemCoreClock);
printf("Controller is started...\r\n");
printf("FLASH->ACR: %d\r\n", FLASH->ACR);
printf("RCC->CFGR :%d\r\n", RCC->CFGR);
printf("RCC->CR :%d\r\n", RCC->CR);
printf("RCC->PLLCFGR :%d\r\n", RCC->PLLCFGR);
printf("RCC->APB1ENR :%d\r\n", RCC->APB1ENR);
MX_LWIP_Init();
}

@ -9,21 +9,7 @@
#include "stm32f4xx_tim.h"
#include "stm32f4xx_flash.h"
#include "lwip/lwip.h"
#include "ring_buffer.h"
typedef enum {
LINK_DOWN,
LINK_UP
} status_t;
typedef struct {
uint8_t link_status;
} lwip_status_t;
void board_init();
uint32_t getRegister();
uint32_t getSysTick();
void delay(uint32_t);
lwip_status_t* get_lwip_status();
ringbuf_uint8t* get_printf_buffer();
#endif

@ -57,13 +57,21 @@
#include "lwip/ethip6.h"
#include "ethernetif.h"
#include <string.h>
/* Within 'USER CODE' section, code will be kept by default at each generation */
/* USER CODE BEGIN 0 */
#include <stdio.h>
/* USER CODE END 0 */
/* Private define ------------------------------------------------------------*/
/* Network interface name */
#define IFNAME0 's'
#define IFNAME1 't'
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* Private variables ---------------------------------------------------------*/
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
@ -86,6 +94,9 @@ __ALIGN_BEGIN uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE] __ALIGN_END; /* Ethe
#endif
__ALIGN_BEGIN uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE] __ALIGN_END; /* Ethernet Transmit Buffer */
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Global Ethernet handle */
ETH_HandleTypeDef heth;
@ -94,6 +105,21 @@ ETH_HandleTypeDef* getEthStruct() {
return &heth;
}
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
/* Private functions ---------------------------------------------------------*/
// void HAL_ETH_MspInit(ETH_HandleTypeDef* ethHandle)
// {
// }
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/*******************************************************************************
LL Driver Interface ( LwIP stack --> ETH)
*******************************************************************************/
@ -109,8 +135,9 @@ static void low_level_init(struct netif *netif)
uint32_t regvalue = 0;
HAL_StatusTypeDef hal_eth_init_status;
/* Init ETH */
uint8_t MACAddr[6] ;
uint8_t MACAddr[6] ;
heth.Instance = ETH;
heth.Init.AutoNegotiation = ETH_AUTONEGOTIATION_ENABLE;
heth.Init.PhyAddress = LAN8742A_PHY_ADDRESS;
@ -125,11 +152,13 @@ static void low_level_init(struct netif *netif)
heth.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
heth.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;
/* USER CODE BEGIN MACADDRESS */
printf("LAN8742A PHYAD: 0x0\r\r\n");
printf("Setting MACaddr: %02x:%02x:%02x:%02x:%02x:%02x\r\r\n",
MACAddr[0], MACAddr[1], MACAddr[2],
MACAddr[3], MACAddr[4], MACAddr[5]);
printf("LAN8742A interface is RMII\r\r\n");
/* USER CODE END MACADDRESS */
hal_eth_init_status = HAL_ETH_Init(&heth);
@ -171,7 +200,10 @@ static void low_level_init(struct netif *netif)
/* Enable MAC and DMA transmission and reception */
HAL_ETH_Start(&heth);
printf("Starting Ethernet IRQ/DMA..\r\r\n");
/* USER CODE BEGIN PHY_PRE_CONFIG */
printf("Starting Ethernet IRQ/DMA..\r\r\n");
/* USER CODE END PHY_PRE_CONFIG */
/* Read Register Configuration */
HAL_ETH_ReadPHYRegister(&heth, PHY_ISFR, &regvalue);
@ -182,11 +214,31 @@ static void low_level_init(struct netif *netif)
/* Read Register Configuration */
HAL_ETH_ReadPHYRegister(&heth, PHY_ISFR , &regvalue);
/* USER CODE BEGIN PHY_POST_CONFIG */
/* USER CODE END PHY_POST_CONFIG */
#endif
#endif /* LWIP_ARP || LWIP_ETHERNET */
/* USER CODE BEGIN LOW_LEVEL_INIT */
/* USER CODE END LOW_LEVEL_INIT */
}
/**
* This function should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
* @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent
*
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue
* to become availale since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers).
*/
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
@ -288,6 +340,7 @@ static struct pbuf * low_level_input(struct netif *netif)
/* get received frame */
if (HAL_ETH_GetReceivedFrame(&heth) != HAL_OK)
return NULL;
/* Obtain the size of the packet and put it into the "len" variable. */
len = heth.RxFrameInfos.length;
buffer = (uint8_t *)heth.RxFrameInfos.buffer;
@ -351,29 +404,26 @@ static struct pbuf * low_level_input(struct netif *netif)
return p;
}
void check_link_status(struct netif* netif) {
void check_link_status(struct netif *netif) {
uint32_t regvalue = 0;
if (HAL_ETH_ReadPHYRegister(&heth, PHY_BSR, &regvalue) == HAL_OK)
{
if((regvalue & PHY_LINKED_STATUS)== (uint16_t)RESET)
{
// Link status = disconnected
if (netif_is_link_up(netif))
{
netif_set_down(netif);
get_lwip_status()->link_status = LINK_DOWN;
netif_set_link_down(netif);
}
}
else {
// Link status = connected
if (!netif_is_link_up(netif))
{
get_lwip_status()->link_status = LINK_UP;
NVIC_SystemReset();
}
get_lwip_status()->link_status = LINK_UP;
}
if((regvalue & PHY_LINKED_STATUS)== (uint16_t)RESET)
{
if (netif_is_link_up(netif))
{
// netif_set_down(netif);
printf("unplugged\r\n");
// netif_set_link_down(netif);
}
} else {
// Link status = connected
if (!netif_is_link_up(netif))
{
printf("plugged\r\n");
// NVIC_SystemReset();
}
}
}
}
@ -390,11 +440,9 @@ void ethernetif_input(struct netif *netif)
{
err_t err;
struct pbuf *p;
uint32_t regvalue = 0;
// HAL_GPIO_TogglePin(GPIOB, 7);
/* move received packet into a new pbuf */
p = low_level_input(netif);
// if (p == NULL) printf("Null\r\n");
// netif_set_link_callback(netif, ethernetif_update_config);
check_link_status(netif);
/* no packet could be read, silently ignore this */
if (p == NULL) return;
@ -422,6 +470,10 @@ static err_t low_level_output_arp_off(struct netif *netif, struct pbuf *q, const
err_t errval;
errval = ERR_OK;
/* USER CODE BEGIN 5 */
/* USER CODE END 5 */
return errval;
}
@ -478,6 +530,8 @@ err_t ethernetif_init(struct netif *netif)
return ERR_OK;
}
/* USER CODE BEGIN 6 */
/**
* @brief Returns the current time in milliseconds
* when LWIP_TIMERS == 1 and NO_SYS == 1
@ -500,6 +554,12 @@ u32_t sys_now(void)
return getSysTick();
}
/* USER CODE END 6 */
/* USER CODE BEGIN 7 */
/* USER CODE END 7 */
#if LWIP_NETIF_LINK_CALLBACK
/**
* @brief Link callback function, this function is called on change of link status
@ -511,10 +571,9 @@ void ethernetif_update_config(struct netif *netif)
{
__IO uint32_t tickstart = 0;
uint32_t regvalue = 0;
if(netif_is_link_up(netif))
{
GPIO_SetBits(GPIOB, GPIO_Pin_0);
GPIO_SetBits(GPIOB, GPIO_Pin_7);
/* Restart the auto-negotiation */
if(heth.Init.AutoNegotiation != ETH_AUTONEGOTIATION_DISABLE)
{
@ -584,14 +643,13 @@ void ethernetif_update_config(struct netif *netif)
else
{
/* Stop MAC interface */
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
GPIO_SetBits(GPIOB, GPIO_Pin_7);
// HAL_ETH_Stop(&heth);
HAL_ETH_Stop(&heth);
}
ethernetif_notify_conn_changed(netif);
}
/* USER CODE BEGIN 8 */
/**
* @brief This function notify user about link status changement.
* @param netif: the network interface
@ -604,7 +662,11 @@ __weak void ethernetif_notify_conn_changed(struct netif *netif)
*/
}
/* USER CODE END 8 */
#endif /* LWIP_NETIF_LINK_CALLBACK */
/* USER CODE BEGIN 9 */
/* USER CODE END 9 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

@ -1,3 +1,4 @@
#ifndef __ETHERNETIF_H__
#define __ETHERNETIF_H__
@ -11,9 +12,9 @@ err_t ethernetif_init(struct netif *netif);
void ethernetif_input(struct netif *netif);
void ethernetif_update_config(struct netif *netif);
void ethernetif_notify_conn_changed(struct netif *netif);
void check_link_status(struct netif* netif);
u32_t sys_jiffies(void);
u32_t sys_now(void);
ETH_HandleTypeDef* getEthStruct();
#endif

@ -7,10 +7,21 @@
#include "lwip/udp.h"
#include "lwip/timeouts.h"
#include "netif/etharp.h"
#include "ethernetif.h"
void Error_Handler(void);
/* DHCP Variables initialization ---------------------------------------------*/
uint32_t DHCPfineTimer = 0;
uint32_t DHCPcoarseTimer = 0;
/* USER CODE BEGIN 1 */
struct udp_pcb *upcb;
ip_addr_t remote_ip;
u16_t remote_port;
/* USER CODE END 1 */
/* Variables Initialization */
struct netif gnetif;
ip4_addr_t ipaddr;
ip4_addr_t netmask;
@ -18,35 +29,95 @@ ip4_addr_t gw;
uint8_t IP_ADDRESS[4];
uint8_t NETMASK_ADDRESS[4];
uint8_t GATEWAY_ADDRESS[4];
/* USER CODE BEGIN 2 */
err_t udp_client_init();
void init_LWIP(void)
void udpServer_init(void)
{
IP_ADDRESS[0] = 192;
IP_ADDRESS[1] = 168;
IP_ADDRESS[2] = 1;
IP_ADDRESS[3] = 66;
NETMASK_ADDRESS[0] = 255;
NETMASK_ADDRESS[1] = 255;
NETMASK_ADDRESS[2] = 0;
NETMASK_ADDRESS[3] = 0;
GATEWAY_ADDRESS[0] = 0;
GATEWAY_ADDRESS[1] = 0;
GATEWAY_ADDRESS[2] = 0;
GATEWAY_ADDRESS[3] = 0;
// UDP Control Block structure
err_t err;
/* 1. Create a new UDP control block */
upcb = udp_new();
ip_addr_t local_ip;
u16_t local_port;
local_port = 1234;
/* 2. Bind the upcb to the local port */
IP_ADDR4(&local_ip, 192, 168, 1, 66);
err = udp_bind(upcb, &local_ip, local_port); // 7 is the server UDP port
/* 3. Set a receive callback for the upcb */
if(err == ERR_OK)
{
IP4_ADDR(&remote_ip, 192, 168, 1, 111);
remote_port = 5678;
// udp_recv(udp_pcb, udp_receive_callback, NULL);
}
else
{
udp_remove(upcb);
}
}
void udp_send_data(const char *data, u16_t len)
{
struct pbuf *p;
err_t err;
p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
if (p != NULL)
{
memcpy(p->payload, data, len);
err = udp_sendto(upcb, p, &remote_ip, remote_port);
pbuf_free(p);
if (err != ERR_OK)
{
// handle error
}
}
}
/* USER CODE END 2 */
/**
* LwIP initialization function
*/
void MX_LWIP_Init(void)
{
IP_ADDRESS[0] = 192;
IP_ADDRESS[1] = 168;
IP_ADDRESS[2] = 1;
IP_ADDRESS[3] = 66;
NETMASK_ADDRESS[0] = 255;
NETMASK_ADDRESS[1] = 255;
NETMASK_ADDRESS[2] = 0;
NETMASK_ADDRESS[3] = 0;
GATEWAY_ADDRESS[0] = 0;
GATEWAY_ADDRESS[1] = 0;
GATEWAY_ADDRESS[2] = 0;
GATEWAY_ADDRESS[3] = 0;
/* Initilialize the LwIP stack without RTOS */
lwip_init();
/* IP addresses initialization with DHCP (IPv4) */
// ipaddr.addr = 0;
// netmask.addr = 0;
// gw.addr = 0;
IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);
/* add the network interface (IPv4b/IPv6) without RTOS */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
// netif_set_ipaddr(&gnetif, &ipaddr);
// netif_set_netmask(&gnetif, &netmask);
// netif_set_gw(&gnetif, &gw);
// /* Registers the default network interface */
/* add the network interface (IPv4/IPv6) without RTOS */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
// netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernetif_input);
/* Registers the default network interface */
netif_set_default(&gnetif);
if (netif_is_link_up(&gnetif))
@ -60,11 +131,119 @@ void init_LWIP(void)
netif_set_down(&gnetif);
}
/* Start DHCP negotiation for a network interface (IPv4) */
// dhcp_start(&gnetif);
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
}
void process_LWIP()
#ifdef USE_OBSOLETE_USER_CODE_SECTION_4
/* Kept to help code migration. (See new 4_1, 4_2... sections) */
/* Avoid to use this user section which will become obsolete. */
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
#endif
/**
* ----------------------------------------------------------------------
* Function given to help user to continue LwIP Initialization
* Up to user to complete or change this function ...
* Up to user to call this function in main.c in while (1) of main(void)
*-----------------------------------------------------------------------
* Read a received packet from the Ethernet buffers
* Send it to the lwIP stack for handling
* Handle timeouts if LWIP_TIMERS is set and without RTOS
* Handle the llink status if LWIP_NETIF_LINK_CALLBACK is set and without RTOS
*/
void MX_LWIP_Process(void)
{
/* USER CODE BEGIN 4_1 */
/* USER CODE END 4_1 */
ethernetif_input(&gnetif);
/* USER CODE BEGIN 4_2 */
/* USER CODE END 4_2 */
/* Handle timeouts */
sys_check_timeouts();
/* USER CODE BEGIN 4_3 */
/* USER CODE END 4_3 */
}
#if defined ( __CC_ARM ) /* MDK ARM Compiler */
/**
* Opens a serial device for communication.
*
* @param devnum device number
* @return handle to serial device if successful, NULL otherwise
*/
sio_fd_t sio_open(u8_t devnum)
{
sio_fd_t sd;
/* USER CODE BEGIN 7 */
sd = 0; // dummy code
/* USER CODE END 7 */
return sd;
}
/**
* Sends a single character to the serial device.
*
* @param c character to send
* @param fd serial device handle
*
* @note This function will block until the character can be sent.
*/
void sio_send(u8_t c, sio_fd_t fd)
{
/* USER CODE BEGIN 8 */
/* USER CODE END 8 */
}
/**
* Reads from the serial device.
*
* @param fd serial device handle
* @param data pointer to data buffer for receiving
* @param len maximum length (in bytes) of data to receive
* @return number of bytes actually received - may be 0 if aborted by sio_read_abort
*
* @note This function will block until data can be received. The blocking
* can be cancelled by calling sio_read_abort().
*/
u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
{
u32_t recved_bytes;
/* USER CODE BEGIN 9 */
recved_bytes = 0; // dummy code
/* USER CODE END 9 */
return recved_bytes;
}
/**
* Tries to read from the serial device. Same as sio_read but returns
* immediately if no data is available and never blocks.
*
* @param fd serial device handle
* @param data pointer to data buffer for receiving
* @param len maximum length (in bytes) of data to receive
* @return number of bytes actually received
*/
u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
{
u32_t recved_bytes;
/* USER CODE BEGIN 10 */
recved_bytes = 0; // dummy code
/* USER CODE END 10 */
return recved_bytes;
}
#endif /* MDK ARM Compiler */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

@ -1,8 +1,11 @@
#ifndef LWIP_H
#define LWIP_H
#ifndef __mx_lwip_H
#define __mx_lwip_H
void init_LWIP();
void process_LWIP();
#include "ethernetif.h"
#endif /* LWIP_H */
void udpServer_init(void);
void udp_send_data(const char *data, u16_t len);
void MX_LWIP_Init(void);
void MX_LWIP_Process(void);
#endif /*__ mx_lwip_H */

@ -52,6 +52,7 @@
#ifndef __LWIPOPTS__H__
#define __LWIPOPTS__H__
/*-----------------------------------------------------------------------------*/
/* Current version of LwIP supported by CubeMx: 2.0.3 -*/
/*-----------------------------------------------------------------------------*/
@ -88,7 +89,7 @@
/*----- Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -*/
#define LWIP_ETHERNET 1
/*----- Default Value for LWIP_DHCP_CHECK_LINK_UP: 0 ---*/
#define LWIP_DHCP_CHECK_LINK_UP 0
#define LWIP_DHCP_CHECK_LINK_UP 1
/*----- Value in opt.h for LWIP_DNS_SECURE: (LWIP_DNS_SECURE_RAND_XID | LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT) -*/
#define LWIP_DNS_SECURE 7
/*----- Value in opt.h for TCP_SND_QUEUELEN: (4*TCP_SND_BUF + (TCP_MSS - 1))/TCP_MSS -----*/
@ -145,15 +146,9 @@
/* USER CODE BEGIN 1 */
#define LWIP_DEBUG 1
#define LWIP_UDP 1
#define LWIP_TCP 0
#define LWIP_NETIF_LINK_CALLBACK 1
#define PBUF_POOL_SIZE 8
#define PBUF_POOL_BUFSIZE 512
/* USER CODE END 1 */
#ifdef __cplusplus

@ -416,6 +416,7 @@ do_memp_free_pool(const struct memp_desc* desc, void *mem)
memp = (struct memp *)(void *)((u8_t*)mem - MEMP_SIZE);
SYS_ARCH_PROTECT(old_level);
#if MEMP_OVERFLOW_CHECK == 1
memp_overflow_check_element_overflow(memp, desc);
memp_overflow_check_element_underflow(memp, desc);
@ -484,7 +485,9 @@ memp_free(memp_t type, void *mem)
#ifdef LWIP_HOOK_MEMP_AVAILABLE
old_first = *memp_pools[type]->tab;
#endif
do_memp_free_pool(memp_pools[type], mem);
#ifdef LWIP_HOOK_MEMP_AVAILABLE
if (old_first == NULL) {
LWIP_HOOK_MEMP_AVAILABLE(type);

@ -59,7 +59,6 @@
#include "lwip/mld6.h"
#include "lwip/sys.h"
#include "lwip/pbuf.h"
#include "ethernetif.h"
#if LWIP_DEBUG_TIMERNAMES
#define HANDLER(x) x, #x
@ -207,6 +206,7 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
{
struct sys_timeo *timeout, *t;
u32_t now, diff;
timeout = (struct sys_timeo *)memp_malloc(MEMP_SYS_TIMEOUT);
if (timeout == NULL) {
LWIP_ASSERT("sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty", timeout != NULL);
@ -328,6 +328,7 @@ sys_check_timeouts(void)
had_one = 0;
tmptimeout = next_timeout;
if (tmptimeout && (tmptimeout->time <= diff)) {
/* timeout has expired */
had_one = 1;
timeouts_last_time += tmptimeout->time;

@ -98,7 +98,7 @@
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal_eth.h"
#include "bsp.h"
#include "stm32f4xx_it.h"
/** @addtogroup STM32F4xx_HAL_Driver
* @{
*/

@ -1,4 +1,4 @@
#include "ring_buffer.h"
#include "ringbuffer.h"
///////////////////////// UINT8_T RING BUFFER //////////////////////////////
@ -15,13 +15,13 @@ inline void rb_init(ringbuf_uint8t *rb, uint8_t *array, unsigned char length)
}
//returns boolean true if the ringbuffer is empty, false otherwise
inline unsigned char rb_is_empty(ringbuf_uint8t *rb)
inline unsigned char rb_isempty(ringbuf_uint8t *rb)
{
return (rb->head == rb->tail);
}
//returns boolean true if the ringbuffer is full, false otherwise
inline unsigned char rb_is_full(ringbuf_uint8t *rb)
inline unsigned char rb_isfull(ringbuf_uint8t *rb)
{
return (((rb->tail + 1) % rb->length) == rb->head);
}
@ -56,3 +56,4 @@ inline unsigned char rb_put(ringbuf_uint8t *rb, uint8_t c)
return 1;
}
}

@ -1,30 +1,29 @@
#ifndef RING_BUFFER_H
#define RING_BUFFER_H
#include <stdint.h>
///////////////////////// UINT8_T RING BUFFER //////////////////////////////
typedef struct {
typedef struct ringbuf_uint8_t
{
uint8_t *buf; //points to data array
unsigned char length; //length of data array
unsigned char head, tail; //producer and consumer indices
} ringbuf_uint8t;
//initializes the given ringbuffer with the supplied array and its length
void rb_init(ringbuf_uint8t *rb, uint8_t *array, unsigned char length);
extern void rb_init(ringbuf_uint8t *rb, uint8_t *array, unsigned char length);
//returns boolean true if the ringbuffer is empty, false otherwise
unsigned char rb_is_empty(ringbuf_uint8t *rb);
extern unsigned char rb_isempty(ringbuf_uint8t *rb);
//returns boolean true if the ringbuffer is full, false otherwise
unsigned char rb_is_full(ringbuf_uint8t *rb);
extern unsigned char rb_isfull(ringbuf_uint8t *rb);
//consumes an element from the buffer
//returns NULL if buffer is empty or a pointer to the array element otherwise
uint8_t* rb_get(ringbuf_uint8t *rb);
extern uint8_t* rb_get(ringbuf_uint8t *rb);
//puts an element into the buffer
//returns 0 if buffer is full, otherwise returns 1
unsigned char rb_put(ringbuf_uint8t *rb, uint8_t c);
extern unsigned char rb_put(ringbuf_uint8t *rb, uint8_t c);
#endif

@ -1,42 +1,37 @@
#include "stm32f4xx_it.h"
#include "ring_buffer.h"
#include "lwip/ethernetif.h"
static volatile uint32_t sysTick = 0;
// extern ETH_HandleTypeDef heth;
void TIM7_IRQHandler()
{
TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
if(get_lwip_status()->link_status == LINK_UP) {
GPIO_ToggleBits(GPIOB, GPIO_Pin_7);
}
else {
GPIO_ResetBits(GPIOB, GPIO_Pin_7);
}
}
void USART2_IRQHandler()
{
ringbuf_uint8t* printf_buffer = get_printf_buffer();
while(!rb_is_empty(printf_buffer)) {
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, (uint16_t)(rb_get(printf_buffer)));
}
USART1->CR1 &= ~USART_CR1_TXEIE;
GPIO_ToggleBits(GPIOB, GPIO_Pin_7);
}
static volatile uint32_t sys_tick = 0;
void SysTick_Handler(void)
{
static uint32_t cnt = 0;
if (cnt == 500) {
GPIO_ToggleBits(GPIOB, GPIO_Pin_0);
cnt = 0;
}
sysTick++;
cnt++;
sys_tick++;
}
uint32_t getSysTick() {
return sysTick;
return sys_tick;
}
#define MAX_DELAY 0xFFFFFFFFU
void delay(uint32_t delay) {
uint32_t tickStart = getSysTick();
uint32_t wait = delay;
if (wait < MAX_DELAY) {
wait++;
}
while((getSysTick() - tickStart) < wait) {}
}
void USART2_IRQHandler(void)
{
}
void ETH_IRQHandler(void)
{
HAL_ETH_IRQHandler(getEthStruct());
}

@ -1,7 +1,21 @@
#ifndef STM32F4XX_H
#define STM32F4XX_H
#include "bsp.h"
#ifndef __STM32F4xx_IT_H
#define __STM32F4xx_IT_H
#include "stdint.h"
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void USART2_IRQHandler(void);
void ETH_IRQHandler(void);
uint32_t getSysTick();
void delay(uint32_t);
#endif /* __STM32F4xx_IT_H */
#endif

@ -52,7 +52,7 @@ target_include_directories(stm32f4xx PUBLIC
target_compile_definitions(stm32f4xx PUBLIC USE_STDPERIPH_DRIVER)
target_compile_definitions(stm32f4xx PUBLIC ${DEVICE_FAMILY})
target_compile_definitions(stm32f4xx PUBLIC HSE_VALUE=8000000)
target_compile_definitions(stm32f4xx PUBLIC SYSTEM_CORE_CLOCK=160000000)
target_compile_definitions(stm32f4xx PUBLIC SYSTEM_CORE_CLOCK=180000000)
target_compile_definitions(stm32f4xx PUBLIC USE_STM324x7I_EVAL)
target_compile_options(stm32f4xx PRIVATE -nostartfiles)

1
terminal Executable file

@ -0,0 +1 @@
sudo screen /dev/ttyUSB0 115200