Skip to content

Commit f09c94a

Browse files
Merge pull request #248 from HyperloopUPV-H8/fix/ethernetbug
Fix/ethernetbug
2 parents f472bff + 4cea325 commit f09c94a

9 files changed

Lines changed: 87 additions & 101 deletions

File tree

Inc/HALAL/Services/Time/Time.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern TIM_HandleTypeDef htim5; // Used for the high precision alarms (1uS)
2222
extern TIM_HandleTypeDef htim24; // Used for the high precision alarms (1uS)
2323

2424
// LOW RESOLUTION TIMERS
25-
extern TIM_HandleTypeDef htim6; // Used for the low precision alarms (1mS)
25+
extern TIM_HandleTypeDef htim7; // Used for the low precision alarms (1mS)
2626

2727
class Time {
2828

@@ -92,6 +92,7 @@ public :
9292
* @return uint8_t Returns id of the alarm.
9393
*/
9494
static uint8_t register_low_precision_alarm(uint32_t period_in_ms, function<void()> func);
95+
static uint8_t register_low_precision_alarm(uint32_t period_in_ms, void(*func)());
9596
static bool unregister_low_precision_alarm(uint16_t id);
9697

9798
/**
@@ -114,6 +115,10 @@ public :
114115
uint8_t day;
115116
uint8_t month;
116117
uint16_t year;
118+
119+
string serialize(){
120+
return "Counter: " + to_string(counter) + ",Second: " + to_string(second) + ",Minute: " + to_string(minute) + ",Hour: " + to_string(hour) + ",Day: " + to_string(day) + ",Month: " + to_string(month) + ",Year: " + to_string(year);
121+
}
117122
};
118123

119124
static void start_rtc();
@@ -124,4 +129,4 @@ public :
124129
#endif
125130
};
126131

127-
#endif
132+
#endif

Inc/main.h

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,50 +59,16 @@ void Error_Handler(void);
5959
/* USER CODE END EFP */
6060

6161
/* Private defines -----------------------------------------------------------*/
62-
#define PWM_OUT_N_Pin GPIO_PIN_4
63-
#define PWM_OUT_N_GPIO_Port GPIOE
64-
#define PWM_OUT_Pin GPIO_PIN_5
65-
#define PWM_OUT_GPIO_Port GPIOE
66-
#define PWM_OUTE6_Pin GPIO_PIN_6
67-
#define PWM_OUTE6_GPIO_Port GPIOE
68-
#define PWM_IN_Pin GPIO_PIN_0
69-
#define PWM_IN_GPIO_Port GPIOF
70-
#define PWM_OUTF3_Pin GPIO_PIN_3
71-
#define PWM_OUTF3_GPIO_Port GPIOF
72-
#define ADC_12BIT_Pin GPIO_PIN_5
73-
#define ADC_12BIT_GPIO_Port GPIOF
74-
#define ADC_12BITF6_Pin GPIO_PIN_6
75-
#define ADC_12BITF6_GPIO_Port GPIOF
76-
#define ADC_12BITF7_Pin GPIO_PIN_7
77-
#define ADC_12BITF7_GPIO_Port GPIOF
78-
#define ADC_12BITF8_Pin GPIO_PIN_8
79-
#define ADC_12BITF8_GPIO_Port GPIOF
80-
#define ADC_12BITF9_Pin GPIO_PIN_9
81-
#define ADC_12BITF9_GPIO_Port GPIOF
82-
#define ADC_12BITF10_Pin GPIO_PIN_10
83-
#define ADC_12BITF10_GPIO_Port GPIOF
84-
#define HSE_IN_Pin GPIO_PIN_0
85-
#define HSE_IN_GPIO_Port GPIOH
86-
#define ADC_16BIT_Pin GPIO_PIN_0
87-
#define ADC_16BIT_GPIO_Port GPIOC
62+
#define MCO_Pin GPIO_PIN_0
63+
#define MCO_GPIO_Port GPIOH
8864
#define RMII_MDC_Pin GPIO_PIN_1
8965
#define RMII_MDC_GPIO_Port GPIOC
90-
#define ADC_12BITC2_Pin GPIO_PIN_2
91-
#define ADC_12BITC2_GPIO_Port GPIOC
92-
#define ADC_12BITC3_Pin GPIO_PIN_3
93-
#define ADC_12BITC3_GPIO_Port GPIOC
94-
#define ADC_16BITA0_Pin GPIO_PIN_0
95-
#define ADC_16BITA0_GPIO_Port GPIOA
66+
#define RMII_REF_CLK_Pin GPIO_PIN_1
67+
#define RMII_REF_CLK_GPIO_Port GPIOA
9668
#define RMII_MDIO_Pin GPIO_PIN_2
9769
#define RMII_MDIO_GPIO_Port GPIOA
98-
#define ADC_16BITA3_Pin GPIO_PIN_3
99-
#define ADC_16BITA3_GPIO_Port GPIOA
100-
#define ADC_16BITA4_Pin GPIO_PIN_4
101-
#define ADC_16BITA4_GPIO_Port GPIOA
102-
#define ADC_16BITA5_Pin GPIO_PIN_5
103-
#define ADC_16BITA5_GPIO_Port GPIOA
104-
#define ADC_16BITA6_Pin GPIO_PIN_6
105-
#define ADC_16BITA6_GPIO_Port GPIOA
70+
#define RMII_CRS_DV_Pin GPIO_PIN_7
71+
#define RMII_CRS_DV_GPIO_Port GPIOA
10672
#define RMII_RXD0_Pin GPIO_PIN_4
10773
#define RMII_RXD0_GPIO_Port GPIOC
10874
#define RMII_RXD1_Pin GPIO_PIN_5
@@ -171,6 +137,12 @@ void Error_Handler(void);
171137
#define PWM_OUTB8_GPIO_Port GPIOB
172138
#define PWM_OUTB9_Pin GPIO_PIN_9
173139
#define PWM_OUTB9_GPIO_Port GPIOB
140+
#define SWO_Pin GPIO_PIN_3
141+
#define SWO_GPIO_Port GPIOB
142+
#define SWDIO_Pin GPIO_PIN_13
143+
#define SWDIO_GPIO_Port GPIOA
144+
#define SWCLK_Pin GPIO_PIN_14
145+
#define SWCLK_GPIO_Port GPIOA
174146
/* USER CODE BEGIN Private defines */
175147

176148
/* USER CODE END Private defines */

LWIP/Target/ethernetif.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ uint64_t last_tick;
5454
/* Private variables ---------------------------------------------------------*/
5555
/*
5656
@Note: This interface is implemented to operate in zero-copy mode only:
57-
- Rx buffers will be allocated from LwIP stack memory heap,
58-
then passed to ETH HAL driver.
59-
- Tx buffers will be allocated from LwIP stack memory heap,
57+
- Rx buffers are allocated statically and passed directly to the LwIP stack
58+
they will return back to ETH DMA after been processed by the stack.
59+
- Tx Buffers will be allocated from LwIP stack memory heap,
6060
then passed to ETH HAL driver.
6161
6262
@Notes:
@@ -98,13 +98,13 @@ static uint8_t RxAllocStatus;
9898

9999
#pragma location=0x30000000
100100
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
101-
#pragma location=0x30000060
101+
#pragma location=0x30000100
102102
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
103103

104104
#elif defined ( __CC_ARM ) /* MDK ARM Compiler */
105105

106106
__attribute__((at(0x30000000))) ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
107-
__attribute__((at(0x30000060))) ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
107+
__attribute__((at(0x30000100))) ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
108108

109109
#elif defined ( __GNUC__ ) /* GNU Compiler */
110110

@@ -183,7 +183,7 @@ static void low_level_init(struct netif *netif)
183183
heth.Init.MediaInterface = HAL_ETH_RMII_MODE;
184184
heth.Init.TxDesc = DMATxDscrTab;
185185
heth.Init.RxDesc = DMARxDscrTab;
186-
heth.Init.RxBuffLen = 1524;
186+
heth.Init.RxBuffLen = 1536;
187187

188188
/* USER CODE BEGIN MACADDRESS */
189189

@@ -271,7 +271,8 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
271271
{
272272
uint32_t i = 0U;
273273
struct pbuf *q = NULL;
274-
ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT] = {0};
274+
err_t errval = ERR_OK;
275+
ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT];
275276

276277
memset(Txbuffer, 0 , ETH_TX_DESC_CNT*sizeof(ETH_BufferTypeDef));
277278

@@ -300,12 +301,9 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
300301
TxConfig.TxBuffer = Txbuffer;
301302
TxConfig.pData = p;
302303

303-
SCB_CleanInvalidateDCache_by_Addr(p->payload, p->len);
304-
305-
HAL_ETH_Transmit(&heth, &TxConfig, 0);
306-
304+
HAL_ETH_Transmit(&heth, &TxConfig, ETH_DMA_TRANSMIT_TIMEOUT);
307305

308-
return ERR_OK;
306+
return errval;
309307
}
310308

311309
/**
@@ -322,9 +320,7 @@ static struct pbuf * low_level_input(struct netif *netif)
322320

323321
if(RxAllocStatus == RX_ALLOC_OK)
324322
{
325-
if(HAL_ETH_ReadData(&heth, (void **)&p) == HAL_ERROR && p != NULL && (p > (struct pbuf*)0x40000000 || p < (struct pbuf*)0x30000000)){
326-
SCB_CleanInvalidateDCache_by_Addr(p->payload, p->len);
327-
}
323+
HAL_ETH_ReadData(&heth, (void **)&p);
328324
}
329325

330326
return p;
@@ -506,28 +502,28 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef* ethHandle)
506502
GPIO_InitStruct.Pin = RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin;
507503
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
508504
GPIO_InitStruct.Pull = GPIO_NOPULL;
509-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
505+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
510506
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
511507
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
512508

513-
GPIO_InitStruct.Pin = GPIO_PIN_1|RMII_MDIO_Pin|GPIO_PIN_7;
509+
GPIO_InitStruct.Pin = RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin;
514510
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
515511
GPIO_InitStruct.Pull = GPIO_NOPULL;
516-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
512+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
517513
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
518514
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
519515

520516
GPIO_InitStruct.Pin = RMII_TXD1_Pin;
521517
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
522518
GPIO_InitStruct.Pull = GPIO_NOPULL;
523-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
519+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
524520
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
525521
HAL_GPIO_Init(RMII_TXD1_GPIO_Port, &GPIO_InitStruct);
526522

527523
GPIO_InitStruct.Pin = RMII_TX_EN_Pin|RMII_TXD0_Pin;
528524
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
529525
GPIO_InitStruct.Pull = GPIO_NOPULL;
530-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
526+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
531527
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
532528
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
533529

@@ -565,7 +561,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef* ethHandle)
565561
*/
566562
HAL_GPIO_DeInit(GPIOC, RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin);
567563

568-
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|RMII_MDIO_Pin|GPIO_PIN_7);
564+
HAL_GPIO_DeInit(GPIOA, RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin);
569565

570566
HAL_GPIO_DeInit(RMII_TXD1_GPIO_Port, RMII_TXD1_Pin);
571567

LWIP/Target/lwipopts.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#ifndef __LWIPOPTS__H__
2323
#define __LWIPOPTS__H__
2424

25+
#include "main.h"
26+
2527
/*-----------------------------------------------------------------------------*/
2628
/* Current version of LwIP supported by CubeMx: 2.1.2 -*/
2729
/*-----------------------------------------------------------------------------*/
@@ -46,31 +48,29 @@
4648
/* LwIP Stack Parameters (modified compared to initialization value in opt.h) -*/
4749
/* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
4850
/*----- Default value in ETH configuration GUI in CubeMx: 1524 -----*/
49-
#define ETH_RX_BUFFER_SIZE 1524
51+
#define ETH_RX_BUFFER_SIZE 1536
5052
/*----- Value in opt.h for NO_SYS: 0 -----*/
5153
#define NO_SYS 1
5254
/*----- Value in opt.h for SYS_LIGHTWEIGHT_PROT: 1 -----*/
5355
#define SYS_LIGHTWEIGHT_PROT 0
5456
/*----- Value in opt.h for MEM_ALIGNMENT: 1 -----*/
5557
#define MEM_ALIGNMENT 4
5658
/*----- Default Value for MEM_SIZE: 1600 ---*/
57-
#define MEM_SIZE 12000
59+
#define MEM_SIZE 32232
5860
/*----- Default Value for H7 devices: 0x30044000 -----*/
59-
#define LWIP_RAM_HEAP_POINTER 0x30004000
61+
#define LWIP_RAM_HEAP_POINTER 0x30000200
6062
/*----- Value supported for H7 devices: 1 -----*/
6163
#define LWIP_SUPPORT_CUSTOM_PBUF 1
6264
/*----- Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -*/
6365
#define LWIP_ETHERNET 1
6466
/*----- 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) -*/
6567
#define LWIP_DNS_SECURE 7
66-
/*----- Value in opt.h for TCP_SND_QUEUELEN: (4*TCP_SND_BUF + (TCP_MSS - 1))/TCP_MSS -----*/
67-
#define TCP_SND_QUEUELEN 9
68-
/*----- Value in opt.h for TCP_SNDLOWAT: LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) -*/
69-
#define TCP_SNDLOWAT 1071
70-
/*----- Value in opt.h for TCP_SNDQUEUELOWAT: LWIP_MAX(TCP_SND_QUEUELEN)/2, 5) -*/
71-
#define TCP_SNDQUEUELOWAT 5
72-
/*----- Value in opt.h for TCP_WND_UPDATE_THRESHOLD: LWIP_MIN(TCP_WND/4, TCP_MSS*4) -----*/
73-
#define TCP_WND_UPDATE_THRESHOLD 536
68+
/*----- Default Value for TCP_MSS: 536 ---*/
69+
#define TCP_MSS 1460
70+
/*----- Default Value for TCP_SND_BUF: 2920 ---*/
71+
#define TCP_SND_BUF 5840
72+
/*----- Default Value for TCP_SND_QUEUELEN: 17 ---*/
73+
#define TCP_SND_QUEUELEN 16
7474
/*----- Value in opt.h for LWIP_NETIF_LINK_CALLBACK: 0 -----*/
7575
#define LWIP_NETIF_LINK_CALLBACK 1
7676
/*----- Value in opt.h for LWIP_NETCONN: 1 -----*/

Middlewares/Third_Party/LwIP/src/core/ipv4/etharp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
11111111
LWIP_ASSERT("netif != NULL", netif != NULL);
11121112

11131113
/* allocate a pbuf for the outgoing ARP request packet */
1114-
p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_HDR, PBUF_POOL);
1114+
p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_HDR, PBUF_RAM);
11151115
/* could allocate a pbuf for an ARP request? */
11161116
if (p == NULL) {
11171117
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
@@ -1158,7 +1158,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
11581158

11591159
ETHARP_STATS_INC(etharp.xmit);
11601160
/* free ARP query packet */
1161-
memp_free_pool(memp_pools[8],p);
1161+
pbuf_free(p);
11621162
p = NULL;
11631163
/* could not allocate pbuf for ARP request */
11641164

Middlewares/Third_Party/LwIP/src/core/pbuf.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,11 +816,7 @@ pbuf_clen(const struct pbuf *p)
816816
__disable_irq();
817817
while (p != NULL) {
818818
++len;
819-
if(p->next > (uint32_t*)0x5000000){
820-
return len;
821-
}
822-
p = p->next;
823-
819+
p = p->next;
824820
}
825821
__enable_irq();
826822
return len;

Middlewares/Third_Party/LwIP/src/core/tcp_out.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ tcp_output_segment_busy(const struct tcp_seg *seg)
14551455
* @param pcb the tcp_pcb for the TCP connection used to send the segment
14561456
* @param netif the netif used to send the segment
14571457
*/
1458-
err_t
1458+
static err_t
14591459
tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif)
14601460
{
14611461
err_t err;

Middlewares/Third_Party/LwIP/src/include/lwip/opt.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@
354354
* bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more
355355
* reliable. */
356356
#if !defined MEM_USE_POOLS_TRY_BIGGER_POOL || defined __DOXYGEN__
357-
#define MEM_USE_POOLS_TRY_BIGGER_POOL 1
357+
#define MEM_USE_POOLS_TRY_BIGGER_POOL 0
358358
#endif
359359

360360
/**
@@ -408,7 +408,7 @@
408408
* this should be set high.
409409
*/
410410
#if !defined MEMP_NUM_PBUF || defined __DOXYGEN__
411-
#define MEMP_NUM_PBUF 32
411+
#define MEMP_NUM_PBUF 16
412412
#endif
413413

414414
/**
@@ -449,7 +449,7 @@
449449
* (requires the LWIP_TCP option)
450450
*/
451451
#if !defined MEMP_NUM_TCP_SEG || defined __DOXYGEN__
452-
#define MEMP_NUM_TCP_SEG 64
452+
#define MEMP_NUM_TCP_SEG 16
453453
#endif
454454

455455
/**
@@ -579,7 +579,7 @@
579579
* PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
580580
*/
581581
#if !defined PBUF_POOL_SIZE || defined __DOXYGEN__
582-
#define PBUF_POOL_SIZE 128
582+
#define PBUF_POOL_SIZE 16
583583
#endif
584584

585585
/** MEMP_NUM_API_MSG: the number of concurrently active calls to various
@@ -1290,7 +1290,7 @@
12901290
* an upper limit on the MSS advertised by the remote host.
12911291
*/
12921292
#if !defined TCP_MSS || defined __DOXYGEN__
1293-
#define TCP_MSS 1460
1293+
#define TCP_MSS 536
12941294
#endif
12951295

12961296
/**
@@ -1369,7 +1369,7 @@
13691369
* Only valid for TCP_QUEUE_OOSEQ==1.
13701370
*/
13711371
#if !defined TCP_OOSEQ_MAX_PBUFS || defined __DOXYGEN__
1372-
#define TCP_OOSEQ_MAX_PBUFS 3
1372+
#define TCP_OOSEQ_MAX_PBUFS 0
13731373
#endif
13741374

13751375
/**
@@ -1574,7 +1574,7 @@
15741574
* small real-life targets. Some code like routing etc. can be left out.
15751575
*/
15761576
#if !defined LWIP_SINGLE_NETIF || defined __DOXYGEN__
1577-
#define LWIP_SINGLE_NETIF 1
1577+
#define LWIP_SINGLE_NETIF 0
15781578
#endif
15791579

15801580
/**
@@ -3250,7 +3250,7 @@
32503250
* @see debugging_levels
32513251
*/
32523252
#if !defined LWIP_DBG_TYPES_ON || defined __DOXYGEN__
3253-
#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF
3253+
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
32543254
#endif
32553255

32563256
/**

0 commit comments

Comments
 (0)