Uninitialized use of static variable in RTOSDemo example's UARTCommandConsole.c

Hello,

When I use RTOSDemo example’s UARTCommandConsole.c, several compilers report the following warning. I read the source code and I notice that there is uninitialized use of static variable. I think that the same name local variable is no longer necessary and the static variable has to be used instead. Is there better way to fix it?

GNURL78 (4.9.2.202002):

'rl78-elf-gcc -Os -ffunction-sections -fdata-sections -mrelax -Wunused -Wuninitialized -Wall -Wextra -Wmissing-declarations -Wpointer-arith -Wbad-function-cast -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wno-unused-function -Wno-unused-label -Wno-main -Wstack-usage=100 -g2 -mg14 -mmul=g14 -std=gnu99 -fstack-usage -fdump-rtl-pro_and_epilogue -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS-Plus\\Source\\FreeRTOS-Plus-CLI" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Demo\\Common\\include" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Demo\\RL78_RL78G14_FPB_GCC_e2studio\\src\\FreeRTOS_Demo\\Full_Demo" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Demo\\RL78_RL78G14_FPB_GCC_e2studio\\src\\FreeRTOS_Demo" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Source\\portable\\GCC\\RL78" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Source\\include" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Demo\\RL78_RL78G14_FPB_GCC_e2studio\\src\\frtos_skeleton" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Demo\\RL78_RL78G14_FPB_GCC_e2studio\\src\\frtos_startup" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Demo\\RL78_RL78G14_FPB_GCC_e2studio\\src\\frtos_config" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Demo\\RL78_RL78G14_FPB_GCC_e2studio\\src" -I"C:\\Renesas\\GitHubDesktop\\work\\FreeRTOS\\FreeRTOS\\Demo\\RL78_RL78G14_FPB_GCC_e2studio\\generate" -DRL78_G14_FPB -DRENESAS_SIMULATOR_DEBUGGING=1 -Wa,-adlnh="UARTCommandConsole.lst" -MMD -MP -MF"src/FreeRTOS_Demo/Full_Demo/UARTCommandConsole.d" -MT"src/FreeRTOS_Demo/Full_Demo/UARTCommandConsole.o" "C:/Renesas/GitHubDesktop/work/FreeRTOS/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_CLI_Demos/UARTCommandConsole.c" -c -o "src/FreeRTOS_Demo/Full_Demo/UARTCommandConsole.o"'
C:/Renesas/GitHubDesktop/work/FreeRTOS/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_CLI_Demos/UARTCommandConsole.c: In function 'prvUARTCommandConsoleTask':
C:/Renesas/GitHubDesktop/work/FreeRTOS/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_CLI_Demos/UARTCommandConsole.c:112:16: warning: declaration of 'xPort' shadows a global declaration [-Wshadow]
 xComPortHandle xPort;
                ^
C:/Renesas/GitHubDesktop/work/FreeRTOS/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_CLI_Demos/UARTCommandConsole.c:85:23: warning: shadowed declaration is here [-Wshadow]
 static xComPortHandle xPort = 0;
                       ^

ICCRL78 (V4.20.1):

iccrl78 ..\..\..\..\FreeRTOS-Plus\Demo\Common\FreeRTOS_Plus_CLI_Demos\UARTCommandConsole.c -o src\FreeRTOS_Demo\Full_Demo\UARTCommandConsole.o --no_wrap_diagnostics --require_prototypes -e -Ohz --debug -lC ./ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS-Plus\Source\FreeRTOS-Plus-CLI/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Demo\Common\include/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Demo\RL78_RL78G14_FPB_IAR_e2studio_EWRL78\src\FreeRTOS_Demo\Full_Demo/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Demo\RL78_RL78G14_FPB_IAR_e2studio_EWRL78\src\FreeRTOS_Demo/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Source\portable\IAR\RL78/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Source\include/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Demo\RL78_RL78G14_FPB_IAR_e2studio_EWRL78\src\frtos_skeleton/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Demo\RL78_RL78G14_FPB_IAR_e2studio_EWRL78\src\frtos_startup/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Demo\RL78_RL78G14_FPB_IAR_e2studio_EWRL78\src\frtos_config/ -I C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS\Demo\RL78_RL78G14_FPB_IAR_e2studio_EWRL78\src/ -D __I_WILL_USE_EXTRA_OPTION__ --remarks --diag_suppress Pa091,Pe177,Pe082,Ta026 --diag_warning Pa045 -DRL78_G14_FPB -DRENESAS_SIMULATOR_DEBUGGING -DEWRL78_16K_KICKSTART_EDITION --calling_convention v2 --code_model near --core s3 --data_model near --double=32 --dlib_config C:/Renesas/EWB/8.4/rl78/LIB/DLib_Config_Normal.h --near_const_location rom0 

  xComPortHandle xPort;
                 ^
"C:\Renesas\GitHubDesktop\work\FreeRTOS\FreeRTOS-Plus\Demo\Common\FreeRTOS_Plus_CLI_Demos\UARTCommandConsole.c",112  Remark[Pe2349]: declaration hides variable "xPort" (declared at line 85)

UARTCommandConsole.c

/* The handle to the UART port, which is not used by all ports. */
static xComPortHandle xPort = 0; <---- !!! This xPort is file-static variable.
...
static void prvUARTCommandConsoleTask( void *pvParameters )
{
signed char cRxedChar;
uint8_t ucInputIndex = 0;
char *pcOutputString;
static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
BaseType_t xReturned;
xComPortHandle xPort; <---- !!! This xPort is function-local variable and no longer necessary.

    ( void ) pvParameters;

    /* Obtain the address of the output buffer.  Note there is no mutual
    exclusion on this buffer as it is assumed only one command console interface
    will be used at any one time. */
    pcOutputString = FreeRTOS_CLIGetOutputBuffer();

    /* Initialise the UART. */
    xPort = xSerialPortInitMinimal( configCLI_BAUD_RATE, cmdQUEUE_LENGTH );
!!! ^^^^^ This xPort is function-local, not file-static.

    /* Send the welcome message. */
    vSerialPutString( xPort, ( signed char * ) pcWelcomeMessage, ( unsigned short ) strlen( pcWelcomeMessage ) );

    for( ;; )
    {
        /* Wait for the next character.  The while loop is used in case
        INCLUDE_vTaskSuspend is not set to 1 - in which case portMAX_DELAY will
        be a genuine block time rather than an infinite block time. */
        while( xSerialGetChar( xPort, &cRxedChar, portMAX_DELAY ) != pdPASS );
...
    }
}

void vOutputString( const char * const pcMessage )
{
    if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
    {
        vSerialPutString( xPort, ( signed char * ) pcMessage, ( unsigned short ) strlen( pcMessage ) );
!!!                       ^^^^^ This xPort is file-static.
        xSemaphoreGive( xTxMutex );
    }
}

Best regards,
NoMaY

We will just remove the local (stack) variable.

See [Feature Request] Improvement to UARTCommandConsole.c · Issue #548 · FreeRTOS/FreeRTOS · GitHub

Hello Richard,

Thank you for creating the feature request. About UARTCommandConsole.c, GNURL78 (and GNURX) reports one more warning like the following.

...omit.../UARTCommandConsole.c: At top level:
...omit.../UARTCommandConsole.c:217:6: warning: no previous prototype for 'vOutputString' [-Wmissing-prototypes]
 void vOutputString( const char * const pcMessage )
      ^

So, I’d like to propose one more modification regarding UARTCommandConsole.c.

CURRENT SOURCE CODE

/*
 * The task that implements the command console processing.
 */
static void prvUARTCommandConsoleTask( void *pvParameters );
void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );

PROPOSED MODIFICATION

/*
 * The task that implements the command console processing.
 */
static void prvUARTCommandConsoleTask( void *pvParameters );
void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );
void vOutputString( const char * const pcMessage );    <----    HERE

Best regards,
NoMaY