Modbus-STM32-HAL-FreeRTOS icon indicating copy to clipboard operation
Modbus-STM32-HAL-FreeRTOS copied to clipboard

unknown type errors when trying to use library

Open krupis opened this issue 1 year ago • 3 comments

Hello. I have downloaded your modbus library and I am trying to use it. I use STM32F407. I have followed the steps that you have suggested:

  1. In CUBEMX, configured UART4 which I want to use for MODBUS
  2. Activated global interrupt
  3. Enabled DMA RX TX image
  4. Imported the MODBUS-LIB to my project, updated include path in project properties
  5. I have renamed ModbusConfigTemplate.h to ModbusConfig.h

When I try to build the project, I get 30 errors ( most of them are due to unknown types)

Project build log:

In file included from ../MODBUS-LIB/Src/Modbus.c:14:
C:/Users/petrikas.lu/Desktop/WORK/UTB/MODBUS-LIB/Inc/Modbus.h:195:2: error: unknown type name 'osMessageQueueId_t'
  195 |  osMessageQueueId_t QueueTelegramHandle;
      |  ^~~~~~~~~~~~~~~~~~
C:/Users/petrikas.lu/Desktop/WORK/UTB/MODBUS-LIB/Inc/Modbus.h:198:2: error: unknown type name 'osThreadId_t'
  198 |  osThreadId_t myTaskModbusAHandle;
      |  ^~~~~~~~~~~~
C:/Users/petrikas.lu/Desktop/WORK/UTB/MODBUS-LIB/Inc/Modbus.h:204:2: error: unknown type name 'osSemaphoreId_t'
  204 |  osSemaphoreId_t ModBusSphrHandle;
      |  ^~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:44:7: error: unknown type name 'osMessageQueueAttr_t'
   44 | const osMessageQueueAttr_t QueueTelegram_attributes = {
      |       ^~~~~~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:45:8: error: field name not in record or union initializer
   45 |        .name = "QueueModbusTelegram"
      |        ^
../MODBUS-LIB/Src/Modbus.c:45:8: note: (near initialization for 'QueueTelegram_attributes')
../MODBUS-LIB/Src/Modbus.c:45:16: warning: initialization of 'int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   45 |        .name = "QueueModbusTelegram"
      |                ^~~~~~~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:45:16: note: (near initialization for 'QueueTelegram_attributes')
../MODBUS-LIB/Src/Modbus.c:49:7: error: unknown type name 'osThreadAttr_t'
   49 | const osThreadAttr_t myTaskModbusA_attributes = {
      |       ^~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:50:5: error: field name not in record or union initializer
   50 |     .name = "TaskModbusSlave",
      |     ^
../MODBUS-LIB/Src/Modbus.c:50:5: note: (near initialization for 'myTaskModbusA_attributes')
../MODBUS-LIB/Src/Modbus.c:50:13: warning: initialization of 'int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   50 |     .name = "TaskModbusSlave",
      |             ^~~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:50:13: note: (near initialization for 'myTaskModbusA_attributes')
../MODBUS-LIB/Src/Modbus.c:51:5: error: field name not in record or union initializer
   51 |     .priority = (osPriority_t) osPriorityNormal,
      |     ^
../MODBUS-LIB/Src/Modbus.c:51:5: note: (near initialization for 'myTaskModbusA_attributes')
../MODBUS-LIB/Src/Modbus.c:51:18: error: 'osPriority_t' undeclared here (not in a function); did you mean 'osPriority'?
   51 |     .priority = (osPriority_t) osPriorityNormal,
      |                  ^~~~~~~~~~~~
      |                  osPriority
../MODBUS-LIB/Src/Modbus.c:51:17: warning: excess elements in scalar initializer
   51 |     .priority = (osPriority_t) osPriorityNormal,
      |                 ^
../MODBUS-LIB/Src/Modbus.c:51:17: note: (near initialization for 'myTaskModbusA_attributes')
../MODBUS-LIB/Src/Modbus.c:51:32: error: expected '}' before 'osPriorityNormal'
   51 |     .priority = (osPriority_t) osPriorityNormal,
      |                                ^~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:49:49: note: to match this '{'
   49 | const osThreadAttr_t myTaskModbusA_attributes = {
      |                                                 ^
../MODBUS-LIB/Src/Modbus.c:55:7: error: unknown type name 'osThreadAttr_t'
   55 | const osThreadAttr_t myTaskModbusA_attributesTCP = {
      |       ^~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:56:5: error: field name not in record or union initializer
   56 |     .name = "TaskModbusSlave",
      |     ^
../MODBUS-LIB/Src/Modbus.c:56:5: note: (near initialization for 'myTaskModbusA_attributesTCP')
../MODBUS-LIB/Src/Modbus.c:56:13: warning: initialization of 'int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   56 |     .name = "TaskModbusSlave",
      |             ^~~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:56:13: note: (near initialization for 'myTaskModbusA_attributesTCP')
../MODBUS-LIB/Src/Modbus.c:57:5: error: field name not in record or union initializer
   57 |     .priority = (osPriority_t) osPriorityNormal,
      |     ^
../MODBUS-LIB/Src/Modbus.c:57:5: note: (near initialization for 'myTaskModbusA_attributesTCP')
../MODBUS-LIB/Src/Modbus.c:57:17: warning: excess elements in scalar initializer
   57 |     .priority = (osPriority_t) osPriorityNormal,
      |                 ^
../MODBUS-LIB/Src/Modbus.c:57:17: note: (near initialization for 'myTaskModbusA_attributesTCP')
../MODBUS-LIB/Src/Modbus.c:57:32: error: expected '}' before 'osPriorityNormal'
   57 |     .priority = (osPriority_t) osPriorityNormal,
      |                                ^~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:55:52: note: to match this '{'
   55 | const osThreadAttr_t myTaskModbusA_attributesTCP = {
      |                                                    ^
../MODBUS-LIB/Src/Modbus.c:65:7: error: unknown type name 'osThreadAttr_t'
   65 | const osThreadAttr_t myTaskModbusB_attributes = {
      |       ^~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:66:5: error: field name not in record or union initializer
   66 |     .name = "TaskModbusMaster",
      |     ^
../MODBUS-LIB/Src/Modbus.c:66:5: note: (near initialization for 'myTaskModbusB_attributes')
../MODBUS-LIB/Src/Modbus.c:66:13: warning: initialization of 'int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   66 |     .name = "TaskModbusMaster",
      |             ^~~~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:66:13: note: (near initialization for 'myTaskModbusB_attributes')
../MODBUS-LIB/Src/Modbus.c:67:5: error: field name not in record or union initializer
   67 |     .priority = (osPriority_t) osPriorityNormal,
      |     ^
../MODBUS-LIB/Src/Modbus.c:67:5: note: (near initialization for 'myTaskModbusB_attributes')
../MODBUS-LIB/Src/Modbus.c:67:17: warning: excess elements in scalar initializer
   67 |     .priority = (osPriority_t) osPriorityNormal,
      |                 ^
../MODBUS-LIB/Src/Modbus.c:67:17: note: (near initialization for 'myTaskModbusB_attributes')
../MODBUS-LIB/Src/Modbus.c:67:32: error: expected '}' before 'osPriorityNormal'
   67 |     .priority = (osPriority_t) osPriorityNormal,
      |                                ^~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:65:49: note: to match this '{'
   65 | const osThreadAttr_t myTaskModbusB_attributes = {
      |                                                 ^
../MODBUS-LIB/Src/Modbus.c:72:7: error: unknown type name 'osThreadAttr_t'
   72 | const osThreadAttr_t myTaskModbusB_attributesTCP = {
      |       ^~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:73:5: error: field name not in record or union initializer
   73 |     .name = "TaskModbusMaster",
      |     ^
../MODBUS-LIB/Src/Modbus.c:73:5: note: (near initialization for 'myTaskModbusB_attributesTCP')
../MODBUS-LIB/Src/Modbus.c:73:13: warning: initialization of 'int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   73 |     .name = "TaskModbusMaster",
      |             ^~~~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:73:13: note: (near initialization for 'myTaskModbusB_attributesTCP')
../MODBUS-LIB/Src/Modbus.c:74:5: error: field name not in record or union initializer
   74 |     .priority = (osPriority_t) osPriorityNormal,
      |     ^
../MODBUS-LIB/Src/Modbus.c:74:5: note: (near initialization for 'myTaskModbusB_attributesTCP')
../MODBUS-LIB/Src/Modbus.c:74:17: warning: excess elements in scalar initializer
   74 |     .priority = (osPriority_t) osPriorityNormal,
      |                 ^
../MODBUS-LIB/Src/Modbus.c:74:17: note: (near initialization for 'myTaskModbusB_attributesTCP')
../MODBUS-LIB/Src/Modbus.c:74:32: error: expected '}' before 'osPriorityNormal'
   74 |     .priority = (osPriority_t) osPriorityNormal,
      |                                ^~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:72:52: note: to match this '{'
   72 | const osThreadAttr_t myTaskModbusB_attributesTCP = {
      |                                                    ^
../MODBUS-LIB/Src/Modbus.c:82:7: error: unknown type name 'osSemaphoreAttr_t'
   82 | const osSemaphoreAttr_t ModBusSphr_attributes = {
      |       ^~~~~~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:83:5: error: field name not in record or union initializer
   83 |     .name = "ModBusSphr"
      |     ^
../MODBUS-LIB/Src/Modbus.c:83:5: note: (near initialization for 'ModBusSphr_attributes')
../MODBUS-LIB/Src/Modbus.c:83:13: warning: initialization of 'int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   83 |     .name = "ModBusSphr"
      |             ^~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c:83:13: note: (near initialization for 'ModBusSphr_attributes')
../MODBUS-LIB/Src/Modbus.c: In function 'ModbusInit':
../MODBUS-LIB/Src/Modbus.c:226:33: warning: implicit declaration of function 'osThreadNew'; did you mean 'osThreadDef'? [-Wimplicit-function-declaration]
  226 |     modH->myTaskModbusAHandle = osThreadNew(StartTaskModbusSlave, modH, &myTaskModbusA_attributes);
      |                                 ^~~~~~~~~~~
      |                                 osThreadDef
../MODBUS-LIB/Src/Modbus.c:263:33: warning: implicit declaration of function 'osMessageQueueNew'; did you mean 'osMessageDelete'? [-Wimplicit-function-declaration]
  263 |     modH->QueueTelegramHandle = osMessageQueueNew (MAX_TELEGRAMS, sizeof(modbus_t), &QueueTelegram_attributes);
      |                                 ^~~~~~~~~~~~~~~~~
      |                                 osMessageDelete
../MODBUS-LIB/Src/Modbus.c:265:34: warning: comparison between pointer and integer
  265 |     if(modH->QueueTelegramHandle == NULL)
      |                                  ^~
../MODBUS-LIB/Src/Modbus.c:276:35: warning: comparison between pointer and integer
  276 |    if  (modH->myTaskModbusAHandle == NULL)
      |                                   ^~
arm-none-eabi-gcc "../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c" -mcpu=cortex-m4 -std=gnu11 -DUSE_HAL_DRIVER -DSTM32F407xx -c -I../Core/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -I"C:/Users/petrikas.lu/Desktop/WORK/UTB/ADS7828/Inc" -I"C:/Users/petrikas.lu/Desktop/WORK/UTB/Custom_IO/Inc" -I"C:/Users/petrikas.lu/Desktop/WORK/UTB/MCP41/Inc" -I"C:/Users/petrikas.lu/Desktop/WORK/UTB/PCA9539/Inc" -I"C:/Users/petrikas.lu/Desktop/WORK/UTB/TB_specific/inc" -I"C:/Users/petrikas.lu/Desktop/WORK/UTB/UART3/inc" -I"C:/Users/petrikas.lu/Desktop/WORK/UTB/MODBUS-LIB/Inc" -I"C:/Users/petrikas.lu/Desktop/WORK/UTB/MODBUS-LIB/Config" -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.d" -MT"Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.o"
In file included from ../MODBUS-LIB/Src/UARTCallback.c:12:
C:/Users/petrikas.lu/Desktop/WORK/UTB/MODBUS-LIB/Inc/Modbus.h:195:2: error: unknown type name 'osMessageQueueId_t'
  195 |  osMessageQueueId_t QueueTelegramHandle;
      |  ^~~~~~~~~~~~~~~~~~
C:/Users/petrikas.lu/Desktop/WORK/UTB/MODBUS-LIB/Inc/Modbus.h:198:2: error: unknown type name 'osThreadId_t'
  198 |  osThreadId_t myTaskModbusAHandle;
      |  ^~~~~~~~~~~~
C:/Users/petrikas.lu/Desktop/WORK/UTB/MODBUS-LIB/Inc/Modbus.h:204:2: error: unknown type name 'osSemaphoreId_t'
  204 |  osSemaphoreId_t ModBusSphrHandle;
      |  ^~~~~~~~~~~~~~~
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:57,
                 from ../MODBUS-LIB/Src/UARTCallback.c:9:
../MODBUS-LIB/Src/UARTCallback.c: In function 'HAL_UART_TxCpltCallback':
../MODBUS-LIB/Src/Modbus.c:294:29: warning: implicit declaration of function 'osSemaphoreNew'; did you mean 'osSemaphoreDef'? [-Wimplicit-function-declaration]
  294 |    modH->ModBusSphrHandle = osSemaphoreNew(1, 1, &ModBusSphr_attributes);
      |                             ^~~~~~~~~~~~~~
      |                             osSemaphoreDef
../MODBUS-LIB/Src/Modbus.c:296:30: warning: comparison between pointer and integer
  296 |    if(modH->ModBusSphrHandle == NULL)
      |                              ^~
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:57,
                 from ../MODBUS-LIB/Src/Modbus.c:10:
../MODBUS-LIB/Src/Modbus.c: In function 'vTimerCallbackT35':
../MODBUS-LIB/Src/Modbus.c:461:28: warning: passing argument 1 of 'xTaskGenericNotify' makes pointer from integer without a cast [-Wint-conversion]
  461 |    xTaskNotify(mHandlers[i]->myTaskModbusAHandle, 0, eSetValueWithOverwrite);
../Middlewares/Third_Party/FreeRTOS/Source/include/task.h:1854:78: note: in definition of macro 'xTaskNotify'
 1854 | #define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )
      |                                                                              ^~~~~~~~~~~~~
../Middlewares/Third_Party/FreeRTOS/Source/include/task.h:1853:45: note: expected 'TaskHandle_t' {aka 'struct tskTaskControlBlock *'} but argument is of type 'int'
 1853 | BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
      |                                ~~~~~~~~~~~~~^~~~~~~~~~~~~
../MODBUS-LIB/Src/Modbus.c: In function 'vTimerCallbackTimeout':
../MODBUS-LIB/Src/Modbus.c:476:29: warning: passing argument 1 of 'xTaskGenericNotify' makes pointer from integer without a cast [-Wint-conversion]
  476 |     xTaskNotify(mHandlers[i]->myTaskModbusAHandle, ERR_TIME_OUT, eSetValueWithOverwrite);
../Middlewares/Third_Party/FreeRTOS/Source/include/task.h:1854:78: note: in definition of macro 'xTaskNotify'
 1854 | #define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )
      |                                                                              ^~~~~~~~~~~~~
../MODBUS-LIB/Src/UARTCallback.c:34:38: warning: passing argument 1 of 'xTaskGenericNotifyFromISR' makes pointer from integer without a cast [-Wint-conversion]
   34 |       xTaskNotifyFromISR(mHandlers[i]->myTaskModbusAHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
../Middlewares/Third_Party/FreeRTOS/Source/include/task.h:1945:119: note: in definition of macro 'xTaskNotifyFromISR'
 1945 | #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
      |                                                                                                                       ^~~~~~~~~~~~~
../Middlewares/Third_Party/FreeRTOS/Source/include/task.h:1853:45: note: expected 'TaskHandle_t' {aka 'struct tskTaskControlBlock *'} but argument is of type 'int'
 1853 | BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
      |                                ~~~~~~~~~~~~~^~~~~~~~~~~~~
../Middlewares/Third_Party/FreeRTOS/Source/include/task.h:1944:52: note: expected 'TaskHandle_t' {aka 'struct tskTaskControlBlock *'} but argument is of type 'int'
 1944 | BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
      |                                       ~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:60,
                 from ../MODBUS-LIB/Src/Modbus.c:10:
../MODBUS-LIB/Src/Modbus.c: In function 'StartTaskModbusSlave':
../MODBUS-LIB/Src/Modbus.c:731:21: warning: passing argument 1 of 'xQueueSemaphoreTake' makes pointer from integer without a cast [-Wint-conversion]
  731 |  xSemaphoreTake(modH->ModBusSphrHandle , portMAX_DELAY); //before processing the message get the semaphore
../Middlewares/Third_Party/FreeRTOS/Source/include/semphr.h:289:74: note: in definition of macro 'xSemaphoreTake'
  289 | #define xSemaphoreTake( xSemaphore, xBlockTime )  xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )
      |                                                                          ^~~~~~~~~~
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:59,
                 from ../MODBUS-LIB/Src/Modbus.c:10:
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:1418:47: note: expected 'QueueHandle_t' {aka 'struct QueueDefinition *'} but argument is of type 'int'
 1418 | BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
      |                                 ~~~~~~~~~~~~~~^~~~~~
../MODBUS-LIB/Src/Modbus.c: In function 'ModbusQuery':
../MODBUS-LIB/Src/Modbus.c:777:23: warning: passing argument 1 of 'xQueueGenericSend' makes pointer from integer without a cast [-Wint-conversion]
  777 |  xQueueSendToBack(modH->QueueTelegramHandle, &telegram, 0);
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:395:86: note: in definition of macro 'xQueueSendToBack'
  395 | #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
      |                                                                                      ^~~~~~
../MODBUS-LIB/Src/UARTCallback.c: In function 'HAL_UARTEx_RxEventCallback':
../MODBUS-LIB/Src/UARTCallback.c:152:42: warning: passing argument 1 of 'xTaskGenericNotifyFromISR' makes pointer from integer without a cast [-Wint-conversion]
  152 |           xTaskNotifyFromISR(mHandlers[i]->myTaskModbusAHandle, 0 , eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
../Middlewares/Third_Party/FreeRTOS/Source/include/task.h:1945:119: note: in definition of macro 'xTaskNotifyFromISR'
 1945 | #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
      |                                                                                                                       ^~~~~~~~~~~~~
../Middlewares/Third_Party/FreeRTOS/Source/include/task.h:1944:52: note: expected 'TaskHandle_t' {aka 'struct tskTaskControlBlock *'} but argument is of type 'int'
 1944 | BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
      |                                       ~~~~~~~~~~~~~^~~~~~~~~~~~~
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:650:45: note: expected 'QueueHandle_t' {aka 'struct QueueDefinition *'} but argument is of type 'int'
  650 | BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
      |                               ~~~~~~~~~~~~~~^~~~~~
../MODBUS-LIB/Src/Modbus.c: In function 'ModbusQueryInject':
../MODBUS-LIB/Src/Modbus.c:789:18: warning: passing argument 1 of 'xQueueGenericReset' makes pointer from integer without a cast [-Wint-conversion]
  789 |  xQueueReset(modH->QueueTelegramHandle);
      |              ~~~~^~~~~~~~~~~~~~~~~~~~~
      |                  |
      |                  int
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:1433:51: note: in definition of macro 'xQueueReset'
 1433 | #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
      |                                                   ^~~~~~
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:1644:46: note: expected 'QueueHandle_t' {aka 'struct QueueDefinition *'} but argument is of type 'int'
 1644 | BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
      |                                ~~~~~~~~~~~~~~^~~~~~
../MODBUS-LIB/Src/Modbus.c:791:24: warning: passing argument 1 of 'xQueueGenericSend' makes pointer from integer without a cast [-Wint-conversion]
  791 |  xQueueSendToFront(modH->QueueTelegramHandle, &telegram, 0);
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:313:87: note: in definition of macro 'xQueueSendToFront'
  313 | #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
      |                                                                                       ^~~~~~
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:650:45: note: expected 'QueueHandle_t' {aka 'struct QueueDefinition *'} but argument is of type 'int'
  650 | BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
      |                               ~~~~~~~~~~~~~~^~~~~~
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:60,
                 from ../MODBUS-LIB/Src/Modbus.c:10:
../MODBUS-LIB/Src/Modbus.c: In function 'SendQuery':
../MODBUS-LIB/Src/Modbus.c:841:21: warning: passing argument 1 of 'xQueueSemaphoreTake' makes pointer from integer without a cast [-Wint-conversion]
  841 |  xSemaphoreTake(modH->ModBusSphrHandle , portMAX_DELAY); //before processing the message get the semaphore
../Middlewares/Third_Party/FreeRTOS/Source/include/semphr.h:289:74: note: in definition of macro 'xSemaphoreTake'
  289 | #define xSemaphoreTake( xSemaphore, xBlockTime )  xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )
      |                                                                          ^~~~~~~~~~
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:59,
                 from ../MODBUS-LIB/Src/Modbus.c:10:
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:1418:47: note: expected 'QueueHandle_t' {aka 'struct QueueDefinition *'} but argument is of type 'int'
 1418 | BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
      |                                 ~~~~~~~~~~~~~~^~~~~~
../MODBUS-LIB/Src/Modbus.c: In function 'StartTaskModbusMaster':
../MODBUS-LIB/Src/Modbus.c:1057:22: warning: passing argument 1 of 'xQueueReceive' makes pointer from integer without a cast [-Wint-conversion]
 1057 |    xQueueReceive(modH->QueueTelegramHandle, &telegram, portMAX_DELAY);
      |                  ~~~~^~~~~~~~~~~~~~~~~~~~~
      |                      |
      |                      int
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:59,
                 from ../MODBUS-LIB/Src/Modbus.c:10:
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:868:41: note: expected 'QueueHandle_t' {aka 'struct QueueDefinition *'} but argument is of type 'int'
  868 | BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
      |                           ~~~~~~~~~~~~~~^~~~~~
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:60,
                 from ../MODBUS-LIB/Src/Modbus.c:10:
../MODBUS-LIB/Src/Modbus.c:1150:23: warning: passing argument 1 of 'xQueueSemaphoreTake' makes pointer from integer without a cast [-Wint-conversion]
 1150 |    xSemaphoreTake(modH->ModBusSphrHandle , portMAX_DELAY); //before processing the message get the semaphore
../Middlewares/Third_Party/FreeRTOS/Source/include/semphr.h:289:74: note: in definition of macro 'xSemaphoreTake'
  289 | #define xSemaphoreTake( xSemaphore, xBlockTime )  xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )
      |                                                                          ^~~~~~~~~~
In file included from ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:59,
                 from ../MODBUS-LIB/Src/Modbus.c:10:
../Middlewares/Third_Party/FreeRTOS/Source/include/queue.h:1418:47: note: expected 'QueueHandle_t' {aka 'struct QueueDefinition *'} but argument is of type 'int'
 1418 | BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
      |                                 ~~~~~~~~~~~~~~^~~~~~
make: *** [MODBUS-LIB/Src/subdir.mk:22: MODBUS-LIB/Src/UARTCallback.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [MODBUS-LIB/Src/subdir.mk:22: MODBUS-LIB/Src/Modbus.o] Error 1
"make -j16 all" terminated with exit code 2. Build might be incomplete.

For example, in Modbus.c, multiple types are not recognised: image

krupis avatar Aug 08 '22 12:08 krupis

Hi, You also need to enable FreeRTOS CMSIS_v2 under the middleware section in CubeMX. I updated the README to reflect this requirement.

alejoseb avatar Aug 09 '22 13:08 alejoseb

Thats great. I have managed to build project with your library. I have a few questions additional questions:

  1. If I want to use DMA for modbus RTU. Do I have to use circular or normal mode? At the moment I have both RX and TX DMA requests on circular modes.

image

  1. I tried to look at examples that you provide for various microcontrollers but it is still not fully clear to me how can I write some data to the registers as modbus master. For example, I want to write to slave 1, holding register offset 5 value 0x1234. Could you show me an example what function I need to call to do that. Thanks in advance!

krupis avatar Aug 10 '22 11:08 krupis

The DMA configuration does not require the circular mode. Check the corresponding examples.

Also check the following file, it contains an example for the modbus master

Examples/ModbusF429/Core/Src/freertos.c

alejoseb avatar Aug 11 '22 03:08 alejoseb

Thats great. I used the example that you have given to read slave register:

void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN 5 */
  /* Infinite loop */
	uint32_t u32NotificationValue;

	telegram.u8id = 1; // slave address
	telegram.u8fct = 3; // function code (this one is registers read)
	//telegram[0].u16RegAdd = 0x160; // start address in slave
	telegram.u16RegAdd = 0x0; // start address in slave
	telegram.u16CoilsNo = 1; // number of elements (coils or registers) to read
	telegram.u16reg = ModbusDATARX; // pointer to a memory array
  /* Infinite loop */
  for(;;)
  {
	  ModbusQuery(&ModbusH, telegram); // make a query
	  u32NotificationValue = ulTaskNotifyTake(pdTRUE, 500); // block until query finishes or timeout
	  if(u32NotificationValue)
	  {
		  DEBUG_PRINT("modbus responded \n");
		//handle error
		//  while(1);
	  }
	  osDelay(500);

  }
  /* USER CODE END 5 */
}

I can see on the logic analyzer that the data has been requested and sent.

I tried to debug what is happening in the code line by line but it seems very complicated and there are multiple layers behind this (Multiple freertos tasks, multiple queues and etc...)

I have been able to confirm that whenever I send data, SendQuery is getting executed. What I am confused about is the following: image

When I step the code with breakpoints, I can see that the case case MB_FC_READ_INPUT_REGISTER: is activated. I dont understand why that happens since I send modbus request with funcion code 3 so case MB_FC_READ_REGISTERS: should be activated (Not sure why its empty)

Another question that I have: Do you have a modbus parser implemented to print messages console? I mean when I send command to read certain register. For example I want to read multiple slave 1 coil status with address offset 5. Is there any way to printf result to the console for example: [SLAVE1] COIL5 = 0 [SLAVE1] COIL6 = 1 [SLAVE1[ COIL7 = 0

At the moment, I can see that my commands are working and I can send requests to read various registers but there is no point reading anything if I cant see the output.

Im sorry for troubling you so much

At the m

krupis avatar Aug 11 '22 05:08 krupis

Hi, MB_FC_READ_REGISTERS is not empty, it is handled by the code shown in line #870 of the code.

There is no functions to print to the console. In the example, you can check the data coming from the slave in the ModbusDATARX buffer, you can use breakpoints to verify that or print to the console by yourself.

alejoseb avatar Aug 11 '22 17:08 alejoseb