From 9bff7f9ae364f1e68cc2f26b8bbdfbeff5e57c05 Mon Sep 17 00:00:00 2001 From: Henri de Veer Date: Fri, 13 Feb 2026 13:31:42 +0100 Subject: [PATCH] Fix some warnings including issue #610. --- 301/CO_HBconsumer.c | 8 +++++--- 301/CO_HBconsumer.h | 2 ++ 301/CO_ODinterface.c | 8 +++++--- 301/CO_ODinterface.h | 4 +++- 301/CO_PDO.c | 3 ++- 301/CO_PDO.h | 2 ++ example/CO_driver_blank.c | 2 ++ example/main_blank.c | 8 +++++--- 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/301/CO_HBconsumer.c b/301/CO_HBconsumer.c index 2216f9c..f9f2fce 100644 --- a/301/CO_HBconsumer.c +++ b/301/CO_HBconsumer.c @@ -18,6 +18,8 @@ * See the License for the specific language governing permissions and limitations under the License. */ +#include + #include "301/CO_HBconsumer.h" #if ((CO_CONFIG_HB_CONS)&CO_CONFIG_HB_CONS_ENABLE) != 0 @@ -91,7 +93,7 @@ OD_write_1016(OD_stream_t* stream, const void* buf, OD_size_t count, OD_size_t* uint32_t val = CO_getUint32(buf); uint8_t nodeId = (uint8_t)((val >> 16) & 0xFFU); uint16_t consumer_time = (uint16_t)(val & 0xFFFFU); - CO_ReturnError_t ret = CO_HBconsumer_initEntry(HBcons, stream->subIndex - 1U, nodeId, consumer_time); + CO_ReturnError_t ret = CO_HBconsumer_initEntry(HBcons, stream->subIndex - (uint8_t)1U, nodeId, consumer_time); if (ret != CO_ERROR_NO) { return ODR_PAR_INCOMPAT; } @@ -120,8 +122,8 @@ CO_HBconsumer_init(CO_HBconsumer_t* HBcons, CO_EM_t* em, CO_HBconsNode_t* monito HBcons->CANdevRxIdxStart = CANdevRxIdxStart; /* get actual number of monitored nodes */ - HBcons->numberOfMonitoredNodes = ((OD_1016_HBcons->subEntriesCount - 1U) < monitoredNodesCount) - ? (OD_1016_HBcons->subEntriesCount - 1U) + HBcons->numberOfMonitoredNodes = ((OD_1016_HBcons->subEntriesCount - (uint8_t)1U) < monitoredNodesCount) + ? (OD_1016_HBcons->subEntriesCount - (uint8_t)1U) : monitoredNodesCount; for (uint8_t i = 0; i < HBcons->numberOfMonitoredNodes; i++) { diff --git a/301/CO_HBconsumer.h b/301/CO_HBconsumer.h index 904781e..d024f57 100644 --- a/301/CO_HBconsumer.h +++ b/301/CO_HBconsumer.h @@ -21,6 +21,8 @@ #ifndef CO_HB_CONS_H #define CO_HB_CONS_H +#include + #include "301/CO_driver.h" #include "301/CO_ODinterface.h" #include "301/CO_NMT_Heartbeat.h" diff --git a/301/CO_ODinterface.c b/301/CO_ODinterface.c index 8b96115..49f7698 100644 --- a/301/CO_ODinterface.c +++ b/301/CO_ODinterface.c @@ -17,7 +17,9 @@ * See the License for the specific language governing permissions and limitations under the License. */ +#include #include + #define OD_DEFINITION #include "301/CO_ODinterface.h" @@ -143,13 +145,13 @@ OD_find(OD_t* od, uint16_t index) { } uint16_t min = 0; - uint16_t max = od->size - 1U; + uint16_t max = od->size - (uint16_t)1U; /* Fast search in ordered Object Dictionary. If indexes are mixed, this won't work. If Object * Dictionary has up to N entries, then the max number of loop passes is log2(N) */ while (min < max) { /* get entry between min and max */ - uint16_t cur = (min + max) >> 1; + uint16_t cur = (uint16_t)(min + max) >> 1; OD_entry_t* entry = &od->list[cur]; if (index == entry->index) { @@ -157,7 +159,7 @@ OD_find(OD_t* od, uint16_t index) { } if (index < entry->index) { - max = (cur > 0U) ? (cur - 1U) : cur; + max = (cur > 0U) ? (cur - (uint16_t)1U) : cur; } else { min = cur + 1U; } diff --git a/301/CO_ODinterface.h b/301/CO_ODinterface.h index 6c6bd65..1c11a03 100644 --- a/301/CO_ODinterface.h +++ b/301/CO_ODinterface.h @@ -21,6 +21,8 @@ #ifndef CO_OD_INTERFACE_H #define CO_OD_INTERFACE_H +#include + #include "301/CO_driver.h" #ifdef __cplusplus @@ -393,7 +395,7 @@ OD_requestTPDO(OD_entry_t* entry, uint8_t subIndex) { #if OD_FLAGS_PDO_SIZE > 0 if ((entry != NULL) && (entry->extension != NULL) && (subIndex < (OD_FLAGS_PDO_SIZE * 8U))) { /* clear subIndex-th bit */ - uint8_t mask = ~(1U << (subIndex & 0x07U)); + uint8_t mask = (uint8_t)~(1U << (subIndex & 0x07U)); entry->extension->flagsPDO[subIndex >> 3] &= mask; } #endif diff --git a/301/CO_PDO.c b/301/CO_PDO.c index 913b1cf..051a5e8 100644 --- a/301/CO_PDO.c +++ b/301/CO_PDO.c @@ -18,6 +18,7 @@ * See the License for the specific language governing permissions and limitations under the License. */ +#include #include #include "301/CO_PDO.h" @@ -290,7 +291,7 @@ OD_write_PDO_mapping(OD_stream_t* stream, const void* buf, OD_size_t count, OD_s PDO->mappedObjectsCount = mappedObjectsCount; } else { uint32_t val = CO_getUint32(buf); - ODR_t odRet = PDOconfigMap(PDO, val, stream->subIndex - 1U, PDO->isRPDO, PDO->OD); + ODR_t odRet = PDOconfigMap(PDO, val, stream->subIndex - (uint8_t)1U, PDO->isRPDO, PDO->OD); if (odRet != ODR_OK) { return odRet; } diff --git a/301/CO_PDO.h b/301/CO_PDO.h index 0f2408e..db54310 100644 --- a/301/CO_PDO.h +++ b/301/CO_PDO.h @@ -21,6 +21,8 @@ #ifndef CO_PDO_H #define CO_PDO_H +#include + #include "301/CO_ODinterface.h" #include "301/CO_Emergency.h" #include "301/CO_SYNC.h" diff --git a/example/CO_driver_blank.c b/example/CO_driver_blank.c index 7eeeddc..db5b2e4 100644 --- a/example/CO_driver_blank.c +++ b/example/CO_driver_blank.c @@ -24,6 +24,7 @@ void CO_CANsetConfigurationMode(void* CANptr) { + (void)(CANptr); /* Put CAN module in configuration mode */ } @@ -37,6 +38,7 @@ CO_CANsetNormalMode(CO_CANmodule_t* CANmodule) { CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t* CANmodule, void* CANptr, CO_CANrx_t rxArray[], uint16_t rxSize, CO_CANtx_t txArray[], uint16_t txSize, uint16_t CANbitRate) { + (void)(CANbitRate); uint16_t i; /* verify arguments */ diff --git a/example/main_blank.c b/example/main_blank.c index 90dd293..24805cb 100644 --- a/example/main_blank.c +++ b/example/main_blank.c @@ -20,6 +20,8 @@ */ #include +#include +#include #include "CANopen.h" #include "OD.h" @@ -80,7 +82,7 @@ main(void) { log_printf("Error: Can't allocate memory\n"); return 0; } else { - log_printf("Allocated %u bytes for CANopen objects\n", heapMemoryUsed); + log_printf("Allocated %" PRIu32 " bytes for CANopen objects\n", heapMemoryUsed); } #if (CO_CONFIG_STORAGE) & CO_CONFIG_STORAGE_ENABLE @@ -138,7 +140,7 @@ main(void) { activeNodeId, &errInfo); if (err != CO_ERROR_NO && err != CO_ERROR_NODE_ID_UNCONFIGURED_LSS) { if (err == CO_ERROR_OD_PARAMETERS) { - log_printf("Error: Object Dictionary entry 0x%X\n", errInfo); + log_printf("Error: Object Dictionary entry 0x%" PRIu32 "\n", errInfo); } else { log_printf("Error: CANopen initialization failed: %d\n", err); } @@ -148,7 +150,7 @@ main(void) { err = CO_CANopenInitPDO(CO, CO->em, OD, activeNodeId, &errInfo); if (err != CO_ERROR_NO && err != CO_ERROR_NODE_ID_UNCONFIGURED_LSS) { if (err == CO_ERROR_OD_PARAMETERS) { - log_printf("Error: Object Dictionary entry 0x%X\n", errInfo); + log_printf("Error: Object Dictionary entry 0x%" PRIu32 "\n", errInfo); } else { log_printf("Error: PDO initialization failed: %d\n", err); }