Skip to content

Commit d34d554

Browse files
bjorniuppsalakartben
authored andcommitted
arch: arm: mpu: Fix BUILD_ASSERT on pointer value
Some compilers (iccarm included) does not support BUILD_ASSERT() to check alignment of arrays. This fix checks if an IAR compiler is used and disables the start-alignment check if it is. Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
1 parent 43b43f5 commit d34d554

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

include/zephyr/arch/arm/mpu/arm_mpu_v7m.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,21 @@ typedef struct {
273273

274274
#endif /* _ASMLANGUAGE */
275275

276-
#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
276+
#define _ARCH_MEM_PARTITION_ALIGN_CHECK_SIZE(size) \
277277
BUILD_ASSERT(!(((size) & ((size) - 1))) && \
278-
(size) >= CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE && \
279-
!((uint32_t)(start) & ((size) - 1)), \
278+
(size) >= CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE, \
280279
"The size of the partition must be power of 2 and greater than or equal to " \
281-
"the minimum MPU region size.\n" \
280+
"the minimum MPU region size.\n")
281+
282+
/* Some compilers do not handle BUILD_ASSERT on the values of pointers.*/
283+
#if defined(__IAR_SYSTEMS_ICC__)
284+
#define _ARCH_MEM_PARTITION_ALIGN_CHECK_START(start, size)
285+
#else
286+
#define _ARCH_MEM_PARTITION_ALIGN_CHECK_START(start, size) \
287+
BUILD_ASSERT(!((uint32_t)(start) & ((size) - 1)), \
282288
"The start address of the partition must align with size.")
289+
#endif
290+
291+
#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
292+
_ARCH_MEM_PARTITION_ALIGN_CHECK_SIZE(size); \
293+
_ARCH_MEM_PARTITION_ALIGN_CHECK_START(start, size)

0 commit comments

Comments
 (0)