From e0aa5eac7449995847f72b007cd2ca1505bfd89b Mon Sep 17 00:00:00 2001 From: Florian La Roche Date: Tue, 8 Jul 2025 07:35:01 +0200 Subject: [PATCH] Fix optimization bug and cleanup (#1363) - Compiling Demo/Common/Minimal/TimerDemo.c with "gcc -flto" breaks the tests, so add "volatile" modifier to "ucOneShotTimerCounter" to fix this. - In Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c print the network configuration even more visible. - In MessageBufferDemo.c and Demo/Posix_GCC/main_full.c fix compiler warnings from "gcc -Wwrite-strings" by adding a const modifier. Signed-off-by: Florian La Roche --- .../Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c | 4 +++- FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c | 2 +- FreeRTOS/Demo/Common/Minimal/TimerDemo.c | 2 +- FreeRTOS/Demo/Posix_GCC/main_full.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c index 5e8835558..b1b560011 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c @@ -259,8 +259,10 @@ BaseType_t xTasksAlreadyCreated = pdFALSE; #else FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress ); #endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */ + FreeRTOS_printf( ( "Network Configuration:\r\n\r\n" ) ); + FreeRTOS_inet_ntoa( ulIPAddress, cBuffer ); - FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) ); + FreeRTOS_printf( ( "IP Address: %s\r\n", cBuffer ) ); FreeRTOS_inet_ntoa( ulNetMask, cBuffer ); FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) ); diff --git a/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c b/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c index d436727fb..925a19f37 100644 --- a/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c +++ b/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c @@ -849,7 +849,7 @@ static void prvEchoServer( void * pvParameters ) static void prvSpaceAvailableCoherenceActor( void * pvParameters ) { - static char * cTxString = "12345"; + static const char * cTxString = "12345"; char cRxString[ mbCOHERENCE_TEST_BYTES_WRITTEN + 1 ]; /* +1 for NULL terminator. */ ( void ) pvParameters; diff --git a/FreeRTOS/Demo/Common/Minimal/TimerDemo.c b/FreeRTOS/Demo/Common/Minimal/TimerDemo.c index be3002aaa..0a86e8e63 100644 --- a/FreeRTOS/Demo/Common/Minimal/TimerDemo.c +++ b/FreeRTOS/Demo/Common/Minimal/TimerDemo.c @@ -108,7 +108,7 @@ static uint8_t ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdFALSE; /* The one-shot timer is configured to use a callback function that increments * ucOneShotTimerCounter each time it gets called. */ static TimerHandle_t xOneShotTimer = NULL; -static uint8_t ucOneShotTimerCounter = ( uint8_t ) 0; +static volatile uint8_t ucOneShotTimerCounter = ( uint8_t ) 0; /* The ISR reload timer is controlled from the tick hook to exercise the timer * API functions that can be used from an ISR. It is configured to increment diff --git a/FreeRTOS/Demo/Posix_GCC/main_full.c b/FreeRTOS/Demo/Posix_GCC/main_full.c index 8764efb47..dcd9d63be 100644 --- a/FreeRTOS/Demo/Posix_GCC/main_full.c +++ b/FreeRTOS/Demo/Posix_GCC/main_full.c @@ -183,7 +183,7 @@ static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer ); /*-----------------------------------------------------------*/ /* The variable into which error messages are latched. */ -static char * pcStatusMessage = "OK: No errors"; +static const char * pcStatusMessage = "OK: No errors"; int xErrorCount = 0; /* This semaphore is created purely to test using the vSemaphoreDelete() and