FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Show Posts

You can view here all posts made by this member. Note that you can only see posts made in areas to which you currently have access.

Topics - KTrenholm

Pages: [1]
1
Hello!

I'm looking to devise a way to handle connection and disconnection of a USB Flash Drive using the UART2DSC project as a base.  I wanted to ask a couple questions regarding what would be the "clean" way to handle such a thing?

My thought is to use a timer and essentially poll the USB host connection status every 250ms or so and act upon that.  The device configuration and timer thread looks like this:

Code: [Select]
vos_tcb_t *tcbPOLL_USB;
VOS_HANDLE hTIMER; //USB Poll Timer

void POLL_USB();

void main(void){
    // USB Host configuration context
    usbhost_context_t usbhostContext;
    //TIMER Configuration context
    tmr_context_t timerContext;

    // Initialise FAT File System Driver
    fatdrv_init(VOS_DEV_FAT_FILE_SYSTEM);

    // Initialise BOMS Device Driver
    boms_init(VOS_DEV_BOMS);

    // Initialise USB Host
    usbhostContext.if_count = 8;
    usbhostContext.ep_count = 16;
    usbhostContext.xfer_count = 2;
    usbhostContext.iso_xfer_count = 2;
    usbhost_init(VOS_DEV_USBHOST_1, -1, &usbhostContext);

    //Initialise Timer0 - USB Poll Device Status - Connect/Disconnect
    timerContext.timer_identifier = TIMER_0;
    tmr_init(TIMER_0, &timerContext);
    tcbPOLL_USB = vos_create_thread_ex(24, 256, POLL_USB, "PollUSB", 0);

    /*Snipped - Other Device Config*/

    vos_start_scheduler();
}

//POLL_USB TIMER THREAD
void POLL_USB(){
    tmr_ioctl_cb_t tmr_iocb;
    uint8_t usb_connstate;
    static uint8_t usb_connstate_prev = PORT_STATE_DISCONNECTED;

    hTIMER = vos_dev_open(TIMER0);

    tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_SET_TICK_SIZE;
    tmr_iocb.param = TIMER_TICK_MS;
    vos_dev_ioctl(hTIMER,&tmr_iocb);

    tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_SET_COUNT;
    tmr_iocb.param = 250;
    vos_dev_ioctl(hTIMER,&tmr_iocb);

    vos_iocb.ioctl_code = VOS_IOCTL_TIMER_SET_MODE;
    tmr_iocb.param = TIMER_MODE_CONTINUOUS;
    vos_dev_ioctl(hTIMER,&tmr_iocb);

    tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_START;
    vos_dev_ioctl(hTIMER,&tmr_iocb);

    while (1){
        tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_WAIT_ON_COMPLETE;
vos_dev_ioctl(hTIMER, &tmr_iocb);

usb_connstate = usbhost_connect_state(hUSBHOST_1);

if (usb_connstate == PORT_STATE_DISCONNECTED){

    if (usb_connstate_prev != PORT_STATE_DISCONNECTED){
                //Connected -> Disconnected --Detach BOMS and FAT File System
        boms_detach(hBOMS);
fat_detach(hFAT_FILE_SYSTEM);

    }

}

if (usb_connstat == PORT_STATE_ENUMERATED){

    if (usb_connstate_prev != PORT_STATE_ENUMERATED){
                //Un-enumerated -> Enumerated --Attach BOMS and FAT File system
hBOMS = boms_attach(hUSBHOST_1, VOS_DEV_BOMS);
hFAT_FILE_SYSTEM = fat_attach(hBOMS, VOS_DEV_FAT_FILE_SYSTEM);

//attach the stdio file system to the FAT file system
fsAttach(hFAT_FILE_SYSTEM);
     }

}

        usb_connstate_prev = usb_connstate;
    }

}

Would it all be just as simple at this above?  Do I have to do anything extra to cleanly detach the BOMS and FAT when the device has been removed?  Would I need to re-initialize them via their respective init_ functions or is detach/attach functions adequate after the initial init_ calls at the start of main()?  Is the call to fsAttach necessary after a disconnect/reconnect? or should I only call that once on initialization?

2
Hello,

I'm debugging a project in the Vinculum II IDE using a V2EVAL kit with the VNC2 48-pin Daughterboard.
I notice that the Thread Manager window has a column for Peak Stack (Bytes), but it is not populating with any information (all other columns show data, including Current Stack).

Has anyone come across this before?  Something I need to set somewhere maybe?

Thanks!

3
Discussion - Software / Vinculum II Toolchain (VinC) Issues Porting Code
« 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":

Code: [Select]
#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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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)?

Pages: [1]