2025-01-27 06:24 AM - last edited on 2025-01-27 06:30 AM by Andrew Neil
Good morning, I made a project using stm32f407vet6, configuring the stm32f407vet6 to use ethernet network without freertos, I can ping it and it responds immediately, follow the code:
#include "main.h"
#include "lwip.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_RTC_Init(void);
/* USER CODE BEGIN 0 */
extern struct netif gnetif;
struct pbuf *p;
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init(); MX_LWIP_Init();
MX_RTC_Init();
while (1)
{
ethernet_input(p, &gnetif);
sys_check_timeouts();
}
/* USER CODE END 3 */
}
but now I want to use freertos and have a UDp server, but when configuring freertos, stm32f407vet6 gets stuck inside MX_LWIP_Init();, the firmware version for STmf4 is 1.28.1, here is the code:
#include "main.h"
#include "cmsis_os.h"
#include "lwip.h"
osThreadId_t defaultTaskHandle; const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for task_2 */
osThreadId_t task_2Handle;
const osThreadAttr_t task_2_attributes = {
.name = "task_2",
.stack_size = 1024 * 4,
.priority = (osPriority_t) osPriorityLow,
};
/* Definitions for task_3 */
osThreadId_t task_3Handle;
const osThreadAttr_t task_3_attributes = {
.name = "task_3",
.stack_size = 1024 * 4,
.priority = (osPriority_t) osPriorityLow,
};
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
void StartDefaultTask(void *argument);
void StartTask02(void *argument);
void StartTask03(void *argument);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
osKernelInitialize();
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
task_2Handle = osThreadNew(StartTask02, NULL, &task_2_attributes);
task_3Handle = osThreadNew(StartTask03, NULL, &task_3_attributes);
osKernelStart();
while (1)
{
}
}
/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 50;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
static void MX_GPIO_Init(void)
{
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
}
void StartDefaultTask(void *argument)
{
/* init code for LWIP */
MX_LWIP_Init();
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
osDelay(5);
}
/* USER CODE END 5 */
}
void StartTask02(void *argument)
{
for(;;)
{
osDelay(10);
}
}
/
void StartTask03(void *argument)
{
for(;;)
{
osDelay(10);
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM6) {
HAL_IncTick();
}
}
void Error_Handler(void)
{
__disable_irq();
while (1)
{
}
}
2025-01-27 06:29 AM
welcome to the forum.
Please see How to write your question to maximize your chances to find a solution for how to properly post source code, and other tips.
@Mauricio_Vieira wrote:but now I want to use freertos and have a UDp server, but when configuring freertos, stm32f407vet6 gets stuck inside MX_LWIP_Init()
So where, exactly, does it get stuck?
2025-01-27 06:37 AM - last edited on 2025-01-27 06:41 AM by Andrew Neil
using the debugger, it gets stuck when executing this line:
netif_add( &gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input );
2025-01-27 06:44 AM
Again, please see How to insert source code.
So, again, step into that function to see where, exactly, it gets stuck.
Also see this on getting debug info out of LwIP:
Compare & contrast the working & non-working cases.