alejoseb / Modbus-STM32-HAL-FreeRTOS

Modbus TCP and RTU, Master and Slave for STM32 using Cube HAL and FreeRTOS
GNU Lesser General Public License v2.1
519 stars 182 forks source link

Demo for modbus TCP is wrong #84

Closed nadav-bariks closed 11 months ago

nadav-bariks commented 11 months ago

in ModbusH743TCP demo ModbusInit()/ModbusStart() are called in main before calling osKernelInitialize() and MX_FREERTOS_Init() the code fails because netconn_new() returns NULL in TCPinitserver() if you move the call to ModbusInit()/ModbusStart() to be executed in StartDefaultTask() after the call to MX_LWIP_Init() then netconn_new() returns a nerconn object

alejoseb commented 11 months ago

The example works without any issue. ModbusInit()/ModbusStart() only creates tasks but they are not executed till kernel is initialized. In fact TCPinitserver is only called here: https://github.com/alejoseb/Modbus-STM32-HAL-FreeRTOS/blob/5018a8db85919ff9439f8fd1a018de5543630161/MODBUS-LIB/Src/Modbus.c#L640

Which is only executed within a task that is executed only after the kernel is initialized. Maybe you did some changes to the example.

I am closing this issue since the example is working.