cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX what are expected steps for F767ZIT for FreeRTOS+LwIP+ETH ?

Sebastian Gniazdowski
Associate III
Posted on March 24, 2018 at 02:19

I enable Ethernet in RMII mode, tried PHY address 0 and 1, Ienable FreeRTOS, automatically configure clock, etc. I set breakpoints (SW4STM32) and program waits in lwip's 'accept' function, the one that waits for connection. So it looks like some problem with ETH configuration, as I should see the board under local IP, I point browser to port 80, etc. (I'm using simple http server code from here:

https://www.carminenoviello.com/2016/01/22/getting-started-stm32-nucleo-f746zg/

).

I just want few basic directions on this. Otherwise I doubt if I receive answer. I'm sure my actions are close to correct, I just need to catch some wrong action, probably on ETH hardware.

Best regards,

Sebastian

#freertos+tcp
10 REPLIES 10
Joerg Wagner
Senior III
Posted on March 25, 2018 at 00:43

Use more heap space (the example uses 128 only, it's not enough).

I would recommend at least the size like you find in ST example code in file

~/STM32Cube/Repository/STM32Cube_FW_F7_V1.11.0/Projects/STM32F767ZI-Nucleo/Applications/LwIP/LwIP_HTTP_Server_Netconn_RTOS/Src/main.c:

#if defined(__GNUC__)

  osThreadDef(Start, StartThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 5);

#else

...

I would recommend 1024 at least when you want to do more in the thread.

Do not forget to verify the total heap space in FreeRTOS settings.

Posted on March 26, 2018 at 07:15

Thanks for pointers about heap size. It wasn't the direct cause, however, I managed to catch minimal changes needed to CubeMX generated project in order to make the board respond to ping and serve on port 80. It's GPIO initialization! Original CubeMX code:

void HAL_ETH_MspInit(ETH_HandleTypeDef* ethHandle)

{

  GPIO_InitTypeDef GPIO_InitStruct;

  if(ethHandle->Instance==ETH)

  {

  /* USER CODE BEGIN ETH_MspInit 0 */

  /* USER CODE END ETH_MspInit 0 */

    /* Enable Peripheral clock */

    __HAL_RCC_ETH_CLK_ENABLE();

 

    /**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

    */

    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;

    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;

    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /* Peripheral interrupt init */

    HAL_NVIC_SetPriority(ETH_IRQn, 5, 0);

    HAL_NVIC_EnableIRQ(ETH_IRQn);

  /* USER CODE BEGIN ETH_MspInit 1 */

    __HAL_RCC_ETH_CLK_ENABLE();

    /* Output HSE clock (25MHz) on MCO pin (PA8) to clock the PHY */

    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_4);

  /* USER CODE END ETH_MspInit 1 */

  }

}

First change:

    GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13;

into:

    GPIO_InitStruct.Pin = GPIO_PIN_13;

Second change: add GPIOG configuration:

    /* Configure PG2, PG11, PG13 and PG14 */

    GPIO_InitStruct.Pin =  GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13;

    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

Then also add __HAL_RCC_GPIOG_CLK_ENABLE() into MX_GPIO_Init().

Could someone explain those changes? The comment on GPIO config in `Applications/...` example matches the one generated by CubeMX, but the code differs, as it is shown (above changes makes CubeMX code match the `Applications/...` one).

Posted on March 26, 2018 at 08:31

Are you using the latest CubeMX 4.25 with FW_F7_V1.11.0 ?

Posted on March 26, 2018 at 08:34

Yes, I've installed this setup 3 days ago, and now checked in menu Help.

Posted on March 26, 2018 at 08:55

Basically it was an issue with PB12 and PB11 for STM32H743 in HAL 1.1.0 and less.

Are you sure you selected the board Nucleo-F767ZI for your project?

It tried to reproduce your problem, but CubeMX generates the right code:

void HAL_ETH_MspInit(ETH_HandleTypeDef* ethHandle)

{

  GPIO_InitTypeDef GPIO_InitStruct;

  if(ethHandle->Instance==ETH)

  {

  /* USER CODE BEGIN ETH_MspInit 0 */

  /* USER CODE END ETH_MspInit 0 */

    /* Enable Peripheral clock */

    __HAL_RCC_ETH_CLK_ENABLE();

 

    /**ETH GPIO Configuration    

    PC1     ------> ETH_MDC

    PA1     ------> ETH_REF_CLK

    PA2     ------> ETH_MDIO

    PA7     ------> ETH_CRS_DV

    PC4     ------> ETH_RXD0

    PC5     ------> ETH_RXD1

    PB13     ------> ETH_TXD1

    PG11     ------> ETH_TX_EN

    PG13     ------> ETH_TXD0

    */

    GPIO_InitStruct.Pin = RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;

    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = RMII_TXD1_Pin;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;

    HAL_GPIO_Init(RMII_TXD1_GPIO_Port, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = RMII_TX_EN_Pin|RMII_TXD0_Pin;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;

    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

  /* USER CODE BEGIN ETH_MspInit 1 */

  /* USER CODE END ETH_MspInit 1 */

  }

}
Posted on March 26, 2018 at 09:10

Yes, few lines from ioc file:

Mcu.Name=STM32F767ZITx

Mcu.Package=LQFP144

PCC.MCU=STM32F767ZITx

PCC.PartNumber=STM32F767ZITx

ProjectManager.DeviceId=STM32F767ZITx

ProjectManager.FirmwarePackage=STM32Cube FW_F7 V1.11.0

There's also the file STM32F767ZITx_FLASH.ld. I generate SW4STM32 project.

Posted on March 26, 2018 at 10:41

I've recalled something. Before selecting RMII mode for ETH, I've selected MII and generated code.

Posted on March 26, 2018 at 20:19

 ,

 ,

I would recommend 1024 at least when you want to do more in the thread.

Do not forget to verify the total heap space in FreeRTOS settings.

I'm having a problem – step-over while debugging doesn't go onward through:

s = lwip_socket( AF_INET, , SOCK_RAW, IP_PROTO_ICMP ),

I was suspecting too low heap size (but is socket that large?), so I've increased heap size of task from 512 to 1024. Now debugger doesn't reach the main thread function. 768 still works, but 1024 doesn't, nor does 2048. In FreeRTOSConfig.h there is:

♯ define configMINIMAL_STACK_SIZE , , , , , , , , , , , , , , , , ((uint16_t)128)

 ,

♯ define configTOTAL_HEAP_SIZE , , , , , , , , , , , , , , , , , , , ((size_t)15360)

I might need more heap also for other reasons, for processing, like you wrote. What can be wrong?

Posted on March 26, 2018 at 21:56

Increase configTOTAL_HEAP_SIZE up to i.e. 32768.

In CubeMX you can check the free space for just a quick overview:

>Configuration>FreeRTOS>FreeRTOS Heap Usage

But not every task is shown and included in the calculation.

To get an exact information of the left space, use  a FreeRTOS function call while your app is running.

A good starting point to learn a little bit about the RTOS functions.