12
« on: October 18, 2021, 04:49:15 pm »
Hey all,
I'm working on a project to turn the VNC2 into essentially a bootloader host for a Cypress PSoC5LP. The idea being to connect a USB flash drive to the system, read the firmware file, and bootload the MCU via the UART.
This would in theory not be too much trouble, as Cypress actually provides the C (I think GCC) code for a bootloader host for use in this exact kind of situation. I figured porting the bootloader host wouldn't be too tall of an order. However I am running into problems with VinC throwing some unexpected syntax errors.
First thing I noticed what was that the toolchain appears to have no stdint.h? Since all the bootloader host code is written with standard types like uint8_t/uint16_t/uint32_t I just needed a few typedefs. I included my own header file to provide the needed types and replaced the includes of stdint.h with my own little "int.h":
#ifndef _INT_H_
#define _INT_H_
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
#endif
No problems so far, I get a few warnings for mismatched widths/signs on certain calls but I can resolve those easily enough.
The real weirdness starts with the C1000 errors I'm getting:
..\cybootloaderutils\cybtldr_api.c line 401: (error) C1000 syntax error, unexpected TYPE_NAME
..\cybootloaderutils\cybtldr_api.c line 423: (error) C1000 syntax error, unexpected TYPE_NAME
..\cybootloaderutils\cybtldr_api.c line 456: (error) C1000 syntax error, unexpected TYPE_NAME
I'm not sure where these are cropping up from. Here's the function with the call that causes the first C1000 error:
int CyBtldr_ProgramRow_v1(uint32_t address, uint8_t* buf, uint16_t size)
{
const int TRANSFER_HEADER_SIZE = 15;
uint8_t inBuf[MAX_COMMAND_SIZE];
uint8_t outBuf[MAX_COMMAND_SIZE];
uint32_t inSize;
uint32_t outSize;
uint16_t offset = 0;
uint16_t subBufSize;
uint8_t status = CYRET_SUCCESS;
int err = CYRET_SUCCESS;
uint32_t chksum = CyBtldr_ComputeChecksum32bit(buf, size);
if (CYRET_SUCCESS == err)
err = SendData(buf, size, &offset, (uint16_t)(g_comm->MaxTransferSize - TRANSFER_HEADER_SIZE), inBuf, outBuf);
if (CYRET_SUCCESS == err)
{
subBufSize = (uint16_t)(size - offset);
err = CyBtldr_CreateProgramDataCmd(address, chksum, &buf[offset], subBufSize, inBuf, &inSize, &outSize); //401 - C1000 syntax error: unexpected TYPE NAME
if (CYRET_SUCCESS == err)
err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize);
if (CYRET_SUCCESS == err)
err = CyBtldr_ParseDefaultCmdResult(outBuf, outSize, &status);
if (CYRET_SUCCESS != status)
err = status | CYRET_ERR_BTLDR_MASK;
}
return err;
}
The code for the function in question is here:
int CyBtldr_CreateProgramDataCmd(uint32_t address, uint32_t chksum, uint8_t* buf, uint16_t size, uint8_t* cmdBuf, uint32_t* cmdSize, uint32_t* resSize)
{
const uint16_t COMMAND_DATA_SIZE = 8;
uint16_t i;
*resSize = BASE_CMD_SIZE;
*cmdSize = BASE_CMD_SIZE + COMMAND_DATA_SIZE + size;
fillData32(cmdBuf + 4, address);
fillData32(cmdBuf + 8, chksum);
for (i = 0; i < size; i++)
cmdBuf[i + 4 + COMMAND_DATA_SIZE] = buf[i];
return CreateCmd(cmdBuf, *cmdSize, CMD_PROGRAM_DATA);
}
I'm kind of at a loss as to where an unexpected TYPE_NAME could be coming up. If it was an issue with my typedefs, I'd think this error would be cropping up in many more places.
Here are the other places this error is thrown:
int CyBtldr_EraseRow_v1(uint32_t address)
{
uint8_t inBuf[MAX_COMMAND_SIZE];
uint8_t outBuf[MAX_COMMAND_SIZE];
uint32_t inSize = 0;
uint32_t outSize = 0;
uint8_t status = CYRET_SUCCESS;
int err = CYRET_SUCCESS;
if (CYRET_SUCCESS == err)
err = CyBtldr_CreateEraseDataCmd(address, inBuf, &inSize, &outSize); //423 - C1000 syntax error: unexpected TYPE NAME
if (CYRET_SUCCESS == err)
err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize);
if (CYRET_SUCCESS == err)
err = CyBtldr_ParseEraseRowCmdResult(outBuf, outSize, &status);
if (CYRET_SUCCESS != status)
err = status | CYRET_ERR_BTLDR_MASK;
return err;
}
int CyBtldr_VerifyRow_v1(uint32_t address, uint8_t* buf, uint16_t size)
{
const int TRANSFER_HEADER_SIZE = 15;
uint8_t inBuf[MAX_COMMAND_SIZE];
uint8_t outBuf[MAX_COMMAND_SIZE];
uint32_t inSize;
uint32_t outSize;
uint16_t offset = 0;
uint16_t subBufSize;
uint8_t status = CYRET_SUCCESS;
int err = CYRET_SUCCESS;
uint32_t chksum = CyBtldr_ComputeChecksum32bit(buf, size);
if (CYRET_SUCCESS == err)
err = SendData(buf, size, &offset, (uint16_t)(g_comm->MaxTransferSize - TRANSFER_HEADER_SIZE), inBuf, outBuf);
if (CYRET_SUCCESS == err)
{
subBufSize = (uint16_t)(size - offset);
err = CyBtldr_CreateVerifyDataCmd(address, chksum, &buf[offset], subBufSize, inBuf, &inSize, &outSize); //456 - C1000 syntax error: unexpected TYPE NAME
if (CYRET_SUCCESS == err)
err = CyBtldr_TransferData(inBuf, inSize, outBuf, outSize);
if (CYRET_SUCCESS == err)
err = CyBtldr_ParseDefaultCmdResult(outBuf, outSize, &status);
if (CYRET_SUCCESS != status)
err = status | CYRET_ERR_BTLDR_MASK;
}
return err;
}
Might anyone have an idea as to why this specific error is being thrown (or how to resolve it)?