bug in GroveShield Library

I’ve found a minor but irritating bug in the Grove shield library for Azure Sphere. The original code looks like:

[code]static int baudrate_conf(int *fd, UART_BaudRate_Type baudrate)
{
static uint8_t trial = 0;
uint8_t d0, d1;
uint8_t conf[4] = { 0 };

close(*fd);
*fd = GroveUART_Open(MT3620_RDB_HEADER2_ISU0_UART, 9600);

while (true)
{
	d0 = 0, d1 = 0;
            .
            .
            .
    }

[/code]
However, if GroveUART_Open fails, the baudrate_conf routine fails to return due to the loop immediately following. Instead, the code might look like the following:

[code]static int baudrate_conf(int *fd, UART_BaudRate_Type baudrate)
{
static uint8_t trial = 0;
uint8_t d0, d1;
uint8_t conf[4] = { 0 };

close(*fd);
*fd = GroveUART_Open(MT3620_RDB_HEADER2_ISU0_UART, 9600);
//Check for errors
if (*fd == -1)
{
            if (EACCES == errno)
            {
                    Log_Debug("[error] Failed to open COM port. Is manifest configured correctly?");
            }
            else
                     Log_Debug("[error] Failed to open COM port. Error %d", errno);
            return errno;
    }
while (true)
{
	d0 = 0, d1 = 0;

[/code]
I also modified the return from void to int and returned an error code for both baudrate_conf and the calling routine GroveShield_Initialize so that the main code can determine if the initialization failed. Note that forgetting to set the app_manifest.json file is pretty easy error to make.



Thanks for the Azure Sphere supporting products.