diff --git a/examples/platforms/nrf52840/crypto/nrf52840-mbedtls-config.h b/examples/platforms/nrf52840/crypto/nrf52840-mbedtls-config.h index 1ebb8ddc3..2713e983e 100644 --- a/examples/platforms/nrf52840/crypto/nrf52840-mbedtls-config.h +++ b/examples/platforms/nrf52840/crypto/nrf52840-mbedtls-config.h @@ -30,4 +30,4 @@ #if defined(__ICCARM__) _Pragma("diag_suppress=Pe549") -#endif \ No newline at end of file +#endif diff --git a/examples/platforms/nrf52840/crypto/sha256_alt.h b/examples/platforms/nrf52840/crypto/sha256_alt.h index e4233dda0..96327806f 100644 --- a/examples/platforms/nrf52840/crypto/sha256_alt.h +++ b/examples/platforms/nrf52840/crypto/sha256_alt.h @@ -35,6 +35,10 @@ extern "C" { #endif +#if defined(__CC_ARM) +#pragma anon_unions +#endif + /** * \brief SHA-256 context structure */ @@ -51,6 +55,10 @@ typedef union } mbedtls_sha256_context; +#if defined(__CC_ARM) +#pragma no_anon_unions +#endif + /** * @brief Initialize SHA-256 context * diff --git a/examples/platforms/nrf52840/flash.c b/examples/platforms/nrf52840/flash.c index 0c34b05cc..d3e700ed8 100644 --- a/examples/platforms/nrf52840/flash.c +++ b/examples/platforms/nrf52840/flash.c @@ -40,31 +40,55 @@ #include "platform-nrf5.h" -extern uint32_t __flash_data_start; -extern uint32_t __flash_data_end; - #define FLASH_PAGE_ADDR_MASK 0xFFFFF000 #define FLASH_PAGE_SIZE 4096 -#define FLASH_START_ADDR ((uint32_t)&__flash_data_start) -#define FLASH_END_ADDR ((uint32_t)&__flash_data_end) + +static uint32_t sFlashDataStart; +static uint32_t sFlashDataEnd; static inline uint32_t mapAddress(uint32_t aAddress) { - return aAddress + FLASH_START_ADDR; + return aAddress + sFlashDataStart; } otError utilsFlashInit(void) { +#if defined(__CC_ARM) + // Temporary solution for Keil compiler. + uint32_t const bootloaderAddr = NRF_UICR->NRFFW[0]; + uint32_t const pageSize = NRF_FICR->CODEPAGESIZE; + uint32_t const codeSize = NRF_FICR->CODESIZE; + + if (bootloaderAddr != 0xFFFFFFFF) + { + sFlashDataEnd = bootloaderAddr; + } + else + { + sFlashDataEnd = pageSize * codeSize; + } + + sFlashDataStart = sFlashDataEnd - (pageSize * SETTINGS_CONFIG_PAGE_NUM); + +#elif defined(__GNUC__) || defined(__ICCARM__) + extern uint32_t __flash_data_start; + extern uint32_t __flash_data_end; + + sFlashDataStart = (uint32_t)&__flash_data_start; + sFlashDataEnd = (uint32_t)&__flash_data_end; + +#endif + // Just ensure that the start and end addresses are page-aligned. - assert((FLASH_START_ADDR % FLASH_PAGE_SIZE) == 0); - assert((FLASH_END_ADDR % FLASH_PAGE_SIZE) == 0); + assert((sFlashDataStart % FLASH_PAGE_SIZE) == 0); + assert((sFlashDataEnd % FLASH_PAGE_SIZE) == 0); return OT_ERROR_NONE; } uint32_t utilsFlashGetSize(void) { - return FLASH_END_ADDR - FLASH_START_ADDR; + return sFlashDataEnd - sFlashDataStart; } otError utilsFlashErasePage(uint32_t aAddress) diff --git a/examples/platforms/nrf52840/openthread-core-nrf52840-config.h b/examples/platforms/nrf52840/openthread-core-nrf52840-config.h index 60ba17854..7f7afb43a 100644 --- a/examples/platforms/nrf52840/openthread-core-nrf52840-config.h +++ b/examples/platforms/nrf52840/openthread-core-nrf52840-config.h @@ -156,4 +156,12 @@ */ #define OPENTHREAD_CONFIG_MBEDTLS_HEAP_SIZE_NO_DTLS 2048 +/* + * Suppress the ARMCC warning on unreachable statement, + * e.g. break after assert(false) or ExitNow() macro. + */ +#if defined(__CC_ARM) + _Pragma("diag_suppress=111") +#endif + #endif // OPENTHREAD_CORE_NRF52840_CONFIG_H_ diff --git a/examples/platforms/nrf52840/platform.c b/examples/platforms/nrf52840/platform.c index 931fe1cd9..4e1f1bca6 100644 --- a/examples/platforms/nrf52840/platform.c +++ b/examples/platforms/nrf52840/platform.c @@ -94,3 +94,14 @@ __WEAK void PlatformEventSignalPending(void) { // Intentionally empty } + +#if defined(__CC_ARM) +__WEAK void __aeabi_assert(const char *aExpr, const char *aFile, int aLine) +{ + (void) aExpr; + (void) aFile; + (void) aLine; + + while (1); +} +#endif diff --git a/examples/platforms/nrf52840/softdevice.h b/examples/platforms/nrf52840/softdevice.h index 34aaf556e..9a15275c4 100644 --- a/examples/platforms/nrf52840/softdevice.h +++ b/examples/platforms/nrf52840/softdevice.h @@ -35,7 +35,7 @@ #ifndef SOFTDEVICE_H_ #define SOFTDEVICE_H_ -#if defined ( __GNUC__ ) +#if defined(__GNUC__) _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") @@ -47,7 +47,7 @@ #include #include -#if defined ( __GNUC__ ) +#if defined(__GNUC__) _Pragma("GCC diagnostic pop") #endif diff --git a/examples/platforms/nrf52840/usb-cdc-uart.c b/examples/platforms/nrf52840/usb-cdc-uart.c index 7db9ea234..c9be43bf7 100644 --- a/examples/platforms/nrf52840/usb-cdc-uart.c +++ b/examples/platforms/nrf52840/usb-cdc-uart.c @@ -33,9 +33,7 @@ */ #if defined(__GNUC__) - #pragma GCC diagnostic ignored "-Wpedantic" - #endif #include diff --git a/include/openthread/icmp6.h b/include/openthread/icmp6.h index 5ba9826c8..aed42dfc9 100644 --- a/include/openthread/icmp6.h +++ b/include/openthread/icmp6.h @@ -86,12 +86,12 @@ struct otIcmp6Header uint8_t mType; ///< Type uint8_t mCode; ///< Code uint16_t mChecksum; ///< Checksum - union + union OT_TOOL_PACKED_FIELD { uint8_t m8[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint8_t)]; uint16_t m16[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint16_t)]; uint32_t m32[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint32_t)]; - } mData; ///< Message-specific data + } mData; ///< Message-specific data } OT_TOOL_PACKED_END; /** diff --git a/include/openthread/platform/toolchain.h b/include/openthread/platform/toolchain.h index 6b9e83f2f..c3971ce94 100644 --- a/include/openthread/platform/toolchain.h +++ b/include/openthread/platform/toolchain.h @@ -246,6 +246,18 @@ extern "C" { CODE \ _Pragma("diag_default=Pe111") +#elif defined(__CC_ARM) + +#include + +#define OT_UNUSED_VARIABLE(VARIABLE) \ + do \ + { \ + if (&VARIABLE == NULL) {} \ + } while (false) + +#define OT_UNREACHABLE_CODE(CODE) CODE + #else #define OT_UNUSED_VARIABLE(VARIABLE) \ diff --git a/include/openthread/types.h b/include/openthread/types.h index 9fe96db04..27506acfc 100644 --- a/include/openthread/types.h +++ b/include/openthread/types.h @@ -416,7 +416,7 @@ typedef struct otExtAddress OT_TOOL_PACKED_BEGIN struct otIp6Address { - union + union OT_TOOL_PACKED_FIELD { uint8_t m8[OT_IP6_ADDRESS_SIZE]; ///< 8-bit fields uint16_t m16[OT_IP6_ADDRESS_SIZE / sizeof(uint16_t)]; ///< 16-bit fields @@ -693,11 +693,17 @@ enum /** * This structure represents an IPv6 prefix. */ -typedef struct otIp6Prefix +OT_TOOL_PACKED_BEGIN +struct otIp6Prefix { otIp6Address mPrefix; ///< The IPv6 prefix. uint8_t mLength; ///< The IPv6 prefix length. -} otIp6Prefix; +} OT_TOOL_PACKED_END; + +/** + * This type represents an IPv6 prefix. + */ +typedef struct otIp6Prefix otIp6Prefix; #define OT_NETWORK_DATA_ITERATOR_INIT 0 ///< Initializer for otNetworkDataIterator. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 2a10140a2..cdc433c8d 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -470,11 +470,13 @@ void Interpreter::ProcessChild(int argc, char *argv[]) otError error = OT_ERROR_NONE; otChildInfo childInfo; long value; - bool isTable = false; + bool isTable; VerifyOrExit(argc > 0, error = OT_ERROR_PARSE); - if (strcmp(argv[0], "list") == 0 || (isTable = (strcmp(argv[0], "table") == 0))) + isTable = (strcmp(argv[0], "table") == 0); + + if (isTable || strcmp(argv[0], "list") == 0) { if (isTable) { @@ -1412,12 +1414,14 @@ void Interpreter::ProcessNeighbor(int argc, char *argv[]) { otError error = OT_ERROR_NONE; otNeighborInfo neighborInfo; - bool isTable = false; + bool isTable; otNeighborInfoIterator iterator = OT_NEIGHBOR_INFO_ITERATOR_INIT; VerifyOrExit(argc > 0, error = OT_ERROR_PARSE); - if (strcmp(argv[0], "list") == 0 || (isTable = (strcmp(argv[0], "table") == 0))) + isTable = (strcmp(argv[0], "table") == 0); + + if (isTable || strcmp(argv[0], "list") == 0) { if (isTable) { @@ -2224,11 +2228,13 @@ void Interpreter::ProcessRouter(int argc, char *argv[]) otError error = OT_ERROR_NONE; otRouterInfo routerInfo; long value; - bool isTable = false; + bool isTable; VerifyOrExit(argc > 0, error = OT_ERROR_PARSE); - if (strcmp(argv[0], "list") == 0 || (isTable = (strcmp(argv[0], "table") == 0))) + isTable = (strcmp(argv[0], "table") == 0); + + if (isTable || strcmp(argv[0], "list") == 0) { if (isTable) { diff --git a/src/cli/cli_console.hpp b/src/cli/cli_console.hpp index afdacca3e..5b81e6e77 100644 --- a/src/cli/cli_console.hpp +++ b/src/cli/cli_console.hpp @@ -68,7 +68,7 @@ public: * @returns The number of bytes placed in the output queue. * */ - int Output(const char *aBuf, uint16_t aBufLength); + virtual int Output(const char *aBuf, uint16_t aBufLength); /** * This method delivers formatted output to the client. @@ -79,7 +79,7 @@ public: * @returns The number of bytes placed in the output queue. * */ - int OutputFormat(const char *fmt, ...); + virtual int OutputFormat(const char *fmt, ...); /** * This method sets a callback that is called when console has some output. diff --git a/src/core/coap/coap_secure.hpp b/src/core/coap/coap_secure.hpp index bc763415a..25360d67e 100644 --- a/src/core/coap/coap_secure.hpp +++ b/src/core/coap/coap_secure.hpp @@ -199,7 +199,7 @@ public: * @param[in] aMessageInfo A reference to the message info associated with @p aMessage. * */ - void Receive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo); + virtual void Receive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo); private: virtual otError Send(Message &aMessage, const Ip6::MessageInfo &aMessageInfo); diff --git a/src/core/mac/mac_frame.hpp b/src/core/mac/mac_frame.hpp index 2b4ae5b4d..eb6628651 100644 --- a/src/core/mac/mac_frame.hpp +++ b/src/core/mac/mac_frame.hpp @@ -174,7 +174,6 @@ struct Address * This class implements IEEE 802.15.4 MAC frame generation and parsing. * */ -OT_TOOL_PACKED_BEGIN class Frame: public otRadioFrame { public: @@ -827,7 +826,7 @@ private: static uint8_t GetKeySourceLength(uint8_t aKeyIdMode); -} OT_TOOL_PACKED_END; +}; OT_TOOL_PACKED_BEGIN class Beacon diff --git a/src/core/net/dhcp6_server.cpp b/src/core/net/dhcp6_server.cpp index b0a12e22d..880bc1a06 100644 --- a/src/core/net/dhcp6_server.cpp +++ b/src/core/net/dhcp6_server.cpp @@ -428,7 +428,7 @@ otError Dhcp6Server::SendReply(otIp6Address &aDst, uint8_t *aTransactionId, Clie SuccessOrExit(error = AppendRapidCommit(*message)); memset(&messageInfo, 0, sizeof(messageInfo)); - memcpy(&messageInfo.GetPeerAddr().mFields.m8, &aDst, sizeof(otIp6Address)); + memcpy(messageInfo.GetPeerAddr().mFields.m8, &aDst, sizeof(otIp6Address)); messageInfo.mPeerPort = kDhcpClientPort; SuccessOrExit(error = mSocket.SendTo(*message, messageInfo)); diff --git a/src/core/net/ip6_headers.hpp b/src/core/net/ip6_headers.hpp index 7e7038a32..2e1c44efa 100644 --- a/src/core/net/ip6_headers.hpp +++ b/src/core/net/ip6_headers.hpp @@ -115,7 +115,7 @@ enum OT_TOOL_PACKED_BEGIN struct HeaderPoD { - union + union OT_TOOL_PACKED_FIELD { uint8_t m8[kVersionClassFlowSize / sizeof(uint8_t)]; uint16_t m16[kVersionClassFlowSize / sizeof(uint16_t)]; diff --git a/src/core/thread/lowpan.cpp b/src/core/thread/lowpan.cpp index 09aab63cd..138738958 100644 --- a/src/core/thread/lowpan.cpp +++ b/src/core/thread/lowpan.cpp @@ -1178,7 +1178,7 @@ otError FragmentHeader::Init(const uint8_t *aFrame, uint8_t aFrameLength) otError error = OT_ERROR_PARSE; VerifyOrExit(aFrameLength >= sizeof(mDispatchSize) + sizeof(mTag)); - memcpy(&mDispatchSize, aFrame, sizeof(mDispatchSize) + sizeof(mTag)); + memcpy(reinterpret_cast(&mDispatchSize), aFrame, sizeof(mDispatchSize) + sizeof(mTag)); aFrame += sizeof(mDispatchSize) + sizeof(mTag); aFrameLength -= sizeof(mDispatchSize) + sizeof(mTag); diff --git a/src/core/thread/lowpan.hpp b/src/core/thread/lowpan.hpp index a8428c387..629e15673 100644 --- a/src/core/thread/lowpan.hpp +++ b/src/core/thread/lowpan.hpp @@ -378,11 +378,11 @@ private: uint8_t mDispatchHopsLeft; uint8_t mDeepHopsLeft; - struct + struct OT_TOOL_PACKED_FIELD { uint16_t mSource; uint16_t mDestination; - } mAddress OT_TOOL_PACKED_FIELD; + } mAddress; } OT_TOOL_PACKED_END; /** diff --git a/src/core/utils/child_supervision.cpp b/src/core/utils/child_supervision.cpp index 6081cd151..aeed16044 100644 --- a/src/core/utils/child_supervision.cpp +++ b/src/core/utils/child_supervision.cpp @@ -97,7 +97,6 @@ void ChildSupervisor::SendMessage(Child &aChild) { ThreadNetif &netif = GetNetif(); Message *message = NULL; - otError error = OT_ERROR_NONE; uint8_t childIndex; VerifyOrExit(aChild.GetIndirectMessageCount() == 0); @@ -111,9 +110,9 @@ void ChildSupervisor::SendMessage(Child &aChild) // `ChildSupervisor::GetDestination(message)`. childIndex = netif.GetMle().GetChildIndex(aChild); - SuccessOrExit(error = message->Append(&childIndex, sizeof(childIndex))); + SuccessOrExit(message->Append(&childIndex, sizeof(childIndex))); - SuccessOrExit(error = netif.SendMessage(*message)); + SuccessOrExit(netif.SendMessage(*message)); message = NULL; otLogInfoMle(GetInstance(), "Sending supervision message to child 0x%04x", aChild.GetRloc16()); diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index d62771aeb..34b7e3d33 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -756,16 +756,18 @@ otError NcpBase::InsertPropertyHandler_THREAD_ON_MESH_NETS(void) otBorderRouterConfig borderRouterConfig; bool stable = false; uint8_t flags = 0; + uint8_t prefixLength; memset(&borderRouterConfig, 0, sizeof(otBorderRouterConfig)); VerifyOrExit(mAllowLocalNetworkDataChange == true, error = OT_ERROR_INVALID_STATE); SuccessOrExit(error = mDecoder.ReadIp6Address(borderRouterConfig.mPrefix.mPrefix)); - SuccessOrExit(error = mDecoder.ReadUint8(borderRouterConfig.mPrefix.mLength)); + SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); SuccessOrExit(error = mDecoder.ReadBool(stable)); SuccessOrExit(error = mDecoder.ReadUint8(flags)); + borderRouterConfig.mPrefix.mLength = prefixLength; borderRouterConfig.mStable = stable; borderRouterConfig.mPreference = ((flags & SPINEL_NET_FLAG_PREFERENCE_MASK) >> SPINEL_NET_FLAG_PREFERENCE_OFFSET); @@ -786,13 +788,16 @@ otError NcpBase::RemovePropertyHandler_THREAD_ON_MESH_NETS(void) { otError error = OT_ERROR_NONE; otIp6Prefix ip6Prefix; + uint8_t prefixLength; memset(&ip6Prefix, 0, sizeof(otIp6Prefix)); VerifyOrExit(mAllowLocalNetworkDataChange == true, error = OT_ERROR_INVALID_STATE); SuccessOrExit(error = mDecoder.ReadIp6Address(ip6Prefix.mPrefix)); - SuccessOrExit(error = mDecoder.ReadUint8(ip6Prefix.mLength)); + SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); + + ip6Prefix.mLength = prefixLength; error = otBorderRouterRemoveOnMeshPrefix(mInstance, &ip6Prefix); @@ -1131,16 +1136,18 @@ otError NcpBase::InsertPropertyHandler_THREAD_OFF_MESH_ROUTES(void) otExternalRouteConfig routeConfig; bool stable = false; uint8_t flags = 0; + uint8_t prefixLength; memset(&routeConfig, 0, sizeof(otExternalRouteConfig)); VerifyOrExit(mAllowLocalNetworkDataChange == true, error = OT_ERROR_INVALID_STATE); SuccessOrExit(error = mDecoder.ReadIp6Address(routeConfig.mPrefix.mPrefix)); - SuccessOrExit(error = mDecoder.ReadUint8(routeConfig.mPrefix.mLength)); + SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); SuccessOrExit(error = mDecoder.ReadBool(stable)); SuccessOrExit(error = mDecoder.ReadUint8(flags)); + routeConfig.mPrefix.mLength = prefixLength; routeConfig.mStable = stable; routeConfig.mPreference = FlagByteToExternalRoutePreference(flags); @@ -1154,13 +1161,16 @@ otError NcpBase::RemovePropertyHandler_THREAD_OFF_MESH_ROUTES(void) { otError error = OT_ERROR_NONE; otIp6Prefix ip6Prefix; + uint8_t prefixLength; memset(&ip6Prefix, 0, sizeof(otIp6Prefix)); VerifyOrExit(mAllowLocalNetworkDataChange == true, error = OT_ERROR_INVALID_STATE); SuccessOrExit(error = mDecoder.ReadIp6Address(ip6Prefix.mPrefix)); - SuccessOrExit(error = mDecoder.ReadUint8(ip6Prefix.mLength)); + SuccessOrExit(error = mDecoder.ReadUint8(prefixLength)); + + ip6Prefix.mLength = prefixLength; error = otBorderRouterRemoveRoute(mInstance, &ip6Prefix); diff --git a/third_party/NordicSemiconductor/dependencies/sdk_config.h b/third_party/NordicSemiconductor/dependencies/sdk_config.h index 064a75dc2..4b30c5eea 100644 --- a/third_party/NordicSemiconductor/dependencies/sdk_config.h +++ b/third_party/NordicSemiconductor/dependencies/sdk_config.h @@ -5,10 +5,8 @@ #undef PACKAGE #if defined(__GNUC__) - #pragma GCC diagnostic ignored "-Wpedantic" #pragma GCC diagnostic ignored "-Wunused-parameter" - #endif //========================================================== diff --git a/third_party/NordicSemiconductor/device/nrf52840.h b/third_party/NordicSemiconductor/device/nrf52840.h index 53f5e97cc..b9543bfca 100644 --- a/third_party/NordicSemiconductor/device/nrf52840.h +++ b/third_party/NordicSemiconductor/device/nrf52840.h @@ -149,12 +149,12 @@ typedef enum { #define __FPU_PRESENT 1 /*!< FPU present or not */ /** @} */ /* End of group Configuration_of_CMSIS */ -#if defined ( __GNUC__ ) +#if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" #endif #include "core_cm4.h" /*!< Cortex-M4 processor and core peripherals */ -#if defined ( __GNUC__ ) +#if defined(__GNUC__) #pragma GCC diagnostic pop #endif