Skip to content

Commit 568478e

Browse files
committed
Ensure backward compatibility
depending of the STM32 Core Version Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 7120886 commit 568478e

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/utility/stm32_eth.cpp

+29-4
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,16 @@ static uint8_t DHCP_Started_by_user = 0;
9696
/* Ethernet link status periodic timer */
9797
static uint32_t gEhtLinkTickStart = 0;
9898

99+
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
100+
/* Handler for stimer */
101+
static stimer_t TimHandle;
102+
#endif
103+
99104
/*************************** Function prototype *******************************/
100105
static void Netif_Config(void);
101106
static err_t tcp_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
102107
static err_t tcp_sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len);
103108
static void tcp_err_callback(void *arg, err_t err);
104-
static void scheduler_callback(HardwareTimer *HT);
105109
static void TIM_scheduler_Config(void);
106110

107111
/**
@@ -136,15 +140,35 @@ static void Netif_Config(void)
136140

137141
/**
138142
* @brief Scheduler callback. Call by a timer interrupt.
139-
* @param htim: pointer to HardwareTimer
143+
* @param htim: pointer to stimer_t or Hardware Timer
140144
* @retval None
141145
*/
142-
static void scheduler_callback(HardwareTimer *HT)
146+
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
147+
static void scheduler_callback(stimer_t *htim)
148+
#else
149+
static void scheduler_callback(HardwareTimer *htim)
150+
#endif
143151
{
144-
UNUSED(HT);
152+
UNUSED(htim);
145153
stm32_eth_scheduler();
146154
}
147155

156+
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
157+
/**
158+
* @brief Enable the timer used to call ethernet scheduler function at regular
159+
* interval.
160+
* @param None
161+
* @retval None
162+
*/
163+
static void TIM_scheduler_Config(void)
164+
{
165+
/* Set TIMx instance. */
166+
TimHandle.timer = DEFAULT_ETHERNET_TIMER;
167+
/* Timer set to 1ms */
168+
TimerHandleInit(&TimHandle, (uint16_t)(1000 - 1), ((uint32_t)(getTimerClkFreq(DEFAULT_ETHERNET_TIMER) / (1000000)) - 1));
169+
attachIntHandle(&TimHandle, scheduler_callback);
170+
}
171+
#else
148172
/**
149173
* @brief Enable the timer used to call ethernet scheduler function at regular
150174
* interval.
@@ -162,6 +186,7 @@ static void TIM_scheduler_Config(void)
162186
EthTim->attachInterrupt(scheduler_callback);
163187
EthTim->resume();
164188
}
189+
#endif
165190

166191
void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, const uint8_t *netmask)
167192
{

0 commit comments

Comments
 (0)