cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32CubeMX] lwIP + FreeRTOS Sample Project

emeydanli
Associate II
Posted on April 23, 2014 at 16:41

Hello Everyone,

I wonder if anyone has been able to get lwIP work properly?

My platform consists of Open407-D baseboard, STM32F4 Discovery and DP83848 Ethernet PHY. SysClk is clocked at 168 MHz.

I have been struggling with generated code by STM32CubeMX for two days. During this time, I have found several issues. 

1) In sys_mutex_lock function, mutex pointer seems incorrectly dereferenced.

2) Priority of the ethernet interrupt is incorrectly configured. It is higher than configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY. That's why firmware hangs in one of FreeRTOS assertions.

3) tcpip_thread is not created due to an incorrect parameter value. (TCPIP_THREAD_STACKSIZE equals to zero)

These are the things I could find but still I cannot get it work. Even though the DHCP option is enabled, the device cannot get an IP address. Giving a static IP address does not work too.

The worst thing is it does not even respond to pings. As an experiment, I created an UDP socket and sent data over it continuously. Green Ethernet LED blinks but of course the packets do not reach to anywhere. (checked with wireshark) 

What can be the problem? Do you have any ideas?

#freertos-lwip #stm32-discovery #cube-lwip-+-stm32f107-+-lan8720a #ethernet
40 REPLIES 40
Posted on July 30, 2015 at 16:56

Well the STM32 part is unreadable.

The PHY part, you have no pull-up on PWRDWN_INT, RBIAS has a 4K7 to an unconnected net, Neither pin 38 or 39 are connected properly to the STM32, pin 40 shouldn't need to be.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
Posted on July 30, 2015 at 22:33

Clive1, thanks for your suggestion, I'll give a look....

Here's STM32 schematic......on the chip area, it's simple.....I don't put anything special....

some capacitors and power supply are not displayed......making the image smaller and can't be seen......accept I can send the pdf file....attached...

0690X000006033WQAQ.jpg

________________

Attachments :

STM32F103V.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I12h&d=%2Fa%2F0X0000000bm0%2F0792_fMJQaQjYu0RGu5CQK6c3eaNkauqBjo44Yr4ETY&asPdf=false
Posted on July 31, 2015 at 02:57

Ok, figured out what you're doing with the RBIAS.

The pin 39/40 stuff troubles me

16 PC1 ETH_MDC Pin 31
24 PA1 ETH_REF_CLK Pin 38 ETH_RMII_REF_CLK
25 PA2 ETH_MDIO Pin 30
32 PA7 ETH_CRS_DV Pin 39 PD8 ETH_RMII_CRS_DV ETH_MII_RX_DV
33 PC4 ETH_RXD0 Pin 43 PD9 ETH_RMII_RXD0
34 PC5 ETH_RXD1 Pin 44 PD10 ETH_RMII_RXD1
48 PB11 ETH_TX_EN Pin 2 
51 PB12 ETH_TXD0 Pin 3
52 PB13 ETH_TXD1 Pin 4

Take a look at the STM32MICOS-EVAL schematic cited earlier Need to look at the 25 MHz vs 50 MHz clock for the PHY
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
80372
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
Posted on July 31, 2015 at 12:08

Here's my board configuration, defined from STM32CubeMx...

 /**ETH GPIO Configuration    

    PC1     ------> ETH_MDC

    PA1     ------> ETH_REF_CLK

    PA2     ------> ETH_MDIO

    PA7     ------> ETH_CRS_DV

    PC4     ------> ETH_RXD0

    PC5     ------> ETH_RXD1

    PB11     ------> ETH_TX_EN

    PB12     ------> ETH_TXD0

    PB13     ------> ETH_TXD1

Do I miss something here ?

from this link :

http://www.st.com/st-web-ui/static/active/en/resource/technical/layouts_and_diagrams/schematic_pack/stm322xg-eval_sch.zip

0690X00000602xUQAQ.jpg

antonius
Senior
Posted on July 31, 2015 at 15:56

Do you reckon I connect pin 39 to PA7 ? I can give a try by patching the pcb....thanks

antonius
Senior
Posted on August 01, 2015 at 06:35

I changed it to pin 39, and I could not get MAC address yet...

May the code from STM32CubeMX is not working at all ?? This is the main, I can get inside the loop already for blinking LED, but I can't get IP or MAC address ???

/**
******************************************************************************
* File Name : main.c
* Description : Main program body
******************************************************************************
*
* COPYRIGHT(c) 2015 STMicroelectronics
*
* 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 STMicroelectronics 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include ''stm32f1xx_hal.h''
#include ''lwip.h''
#include ''usart.h''
#include ''gpio.h''
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_LWIP_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Transmit(&huart1, ''HI There...LwIP STM32F107! 
'', 30, 1000);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_5 , 1 );
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_5 , 0 );
HAL_Delay(2000);
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6 , 1 );
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6 , 0 );
HAL_Delay(2000);
/*
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13 , 1 );
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13 , 0 );
HAL_Delay(2000);
*/
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* Read a received packet from the Ethernet buffers and send it
to the lwIP for handling */
//ethernetif_input(&gnetif);
/* Handle LwIP timeouts */
//sys_check_timeouts();
}
/* USER CODE END 3 */
}
/** System Clock Configuration
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV5;
RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_PLL2;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL5;
RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL2_ON;
RCC_OscInitStruct.PLL2.PLL2MUL = RCC_PLL2_MUL10;
RCC_OscInitStruct.PLL2.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV5;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
__HAL_RCC_PLLI2S_ENABLE();
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
#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,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* USER CODE END 6 */
}
#endif
/**
* @}
*/ 
/**
* @}
*/ 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Pm77
Associate II
Posted on November 30, 2015 at 11:15

I have used STM32CubeMX32 with custom board hosting Stm32F107 with LAN8720 PHY and RMII interface..

And it works great!

Just to note source code created by cube is for DP83848 PHY..

RMII being standard common registers are configured fine..just watch out for extended(vender specific) register like..

PHY_SR

PHY_MICR

PHY_MISR

just comment HAL_ETH_WritePHYRegister() for those register in ethernetif.c file to avoid setting wrong config for unintended register. OR Set correct address and mask for those register while configuring cube in Configuration>ETH>Advance parameter>extended  section.

Other hardware issue I had was I was getting RX packes but no TX packets. So I scoped MAC to PHY link specifically Eth_TX_En and Eth_Crs_Dv [Packet reception and transmission pins ] and it was bad soldering for TX side. Symptom of this issue is for ping you can see PHY link led blinking but destination unreachable as TX side fails.

//---------------------------------------------------------------------------

For tcp_echoserver_init(); I have added Tcp_echo_server.c file from other example project. But Ping should work without it.

int main(void)

{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_LWIP_Init();

  /* USER CODE BEGIN 2 */

    

    tcp_echoserver_init();

  /* USER CODE END 2 */

  /* Infinite loop */

  /* USER CODE BEGIN WHILE */

  while (1)

  {

MX_LWIP_Process();

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }

  /* USER CODE END 3 */

}

chrischris91
Associate
Posted on January 06, 2016 at 02:05

Hello Pankaj,

I am working on a project with STM32CubeMX32 on Stm32F407 with LAN8720 and I haven't been able to get it working. Do you happen to have the values that you changed for the PHY registers? Is there anything else that you needed to change from the default settings?

Many thanks,

Jordan

Pm77
Associate II
Posted on June 22, 2016 at 17:20

Hi its been while I did not visit site..

Here is link for ready working example..

https://www.element14.com/community/docs/DOC-51670/l/stm32f4dis-bb-discover-more-software-examples

Look into ''STM32F4xx_Ethernet_Example'' folder