I’m having problems with a Release build that defines NDEBUG
, which was basically doing away with configASSERT
:
#ifdef NDEBUG /* required by ANSI standard */
# define configASSERT(__e) ((void)0)
#else
//...
A simple dir
command resulted in
Error: ff_findfirst() failed.
followed by
FF_GetBuffer[0x5EC0]: failed mode 0x1
I started playing with variations of configASSERT
macros and I found that if I use a version that allows the expression to have side effects*, the problem goes away. For example, this works fine:
#define assert_se(expr) \
do { \
if (!(expr)) \
{ for( ;; ); } \
} while (false)
#define configASSERT( x ) assert_se(x)
* See also: Examine ASSERT Statements
The problem seems to lie in ff_locking.c. There are a couple of calls like this:
void FF_UnlockDirectory( FF_IOManager_t *pxIOManager )
// ...
configASSERT( ( xEventGroupGetBits( pxIOManager->xEventGroup ) & FF_DIR_LOCK_EVENT_BITS ) == 0 );
xEventGroupSetBits( pxIOManager->xEventGroup, FF_DIR_LOCK_EVENT_BITS );
}
and
void FF_UnlockFAT( FF_IOManager_t *pxIOManager )
{
// ...
configASSERT( ( xEventGroupGetBits( pxIOManager->xEventGroup ) & FF_FAT_LOCK_EVENT_BITS ) == 0 );
pxIOManager->pvFATLockHandle = NULL;
xEventGroupSetBits( pxIOManager->xEventGroup, FF_FAT_LOCK_EVENT_BITS );
}
Could xEventGroupGetBits( pxIOManager->xEventGroup )
be having side effects? It doesn’t look like it:
#define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 )
but I don’t know how else to explain what I’m seeing.
Everything works if I replace configASSERT
in ff_locking.c
with assert_se
, but leave the optimized configASSERT
s everywhere else.
EDIT: I’m compiling with:
arm-none-eabi-gcc.exe -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mthumb
-I..\..\printf
-I..\FreeRTOS\FreeRTOS\Source\include
-I..\FreeRTOS\FreeRTOS\Source\portable\GCC\ARM_CM4F
-I.
-IGenerated_Source\PSoC6
-IGenerated_Source\PSoC6\pdl\cmsis/include/
-IGenerated_Source\PSoC6\pdl\devices/psoc6/include/
...
-IGenerated_Source\PSoC6\pdl\middleware/emWin/code/include/osnts_softfp/
-IGenerated_Source\PSoC6\pdl\utilities/
-Wa,-alh=.\CortexM4\ARM_GCC_Generic\Release/ff_locking.lst -D NDEBUG -D CY_CORE_ID=0 -D HEAP_NEWLIB=1 -D CY_PSOC_CREATOR_USED=1 -D CY8C6347BZI_BLD53 -Wall -ffunction-sections -ffat-lto-objects -O2 -Wno-unused-parameter -Wno-unused-variable -fdata-sections -g3 -c ff_locking.c -o .\CortexM4\ARM_GCC_Generic\Release\ff_locking.o
"C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2020-q4-major\bin\arm-none-eabi-gcc.exe" --version
arm-none-eabi-gcc.exe (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.