CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to add a selective menu in ex_usb_bootloader.c ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
LiLou



Joined: 04 Feb 2014
Posts: 26

View user's profile Send private message

How to add a selective menu in ex_usb_bootloader.c ?
PostPosted: Fri Mar 28, 2014 1:49 am     Reply with quote

I want to add some extra functionalities to the bootloader and I need a menu that waits for an order. I'm using CDC API (usb_cdc.h).

Right now I have:

Code:
void main(void)

    HW_INIT();   

    unsigned int8 cmd;
    int1 finish=FALSE;
    //unsigned int32 timeout=60000; // ~1 min.

    //we use a button as an event to determine if we should start the USB CDC
    //bootloader.  if button is not pressed then goto the application, else if
    //button is pressed then do the bootloader.
    if(BUTTON_PRESSED())  // Defined in ex_usb_common.h
    {
        usb_init_cs();

        // Wait usb to be ready, I guess
        while(!usb_enumerated())
        {   
            // necessary for polling function to work
            #ifdef USB_ISR_POLLING
                usb_task();
            #endif
        }
       
        // Main loop
        while(!finish)  //alternative: while(timeout)
        {
            usb_task();
            if (!usb_cdc_kbhit()){
                //timeout--;
                continue;
            }
         
            cmd = usb_cdc_getc();
            switch(cmd)
            {
                case VERSION_INFO:      //'V'
                    usb_cdc_putc(MAJOR_VER);
                    usb_cdc_putc(MINOR_VER);
                    break;

                case ERASE_EE:          //'E'
                    clear_eeprom();
                    //timeout=60000;
                    break;

                case LOAD_PROG:         //'P'                   
                    load_program();
                    //timeout=60000;
                    break;           

                case ERASE_PROG:        //'e'                   
                    clear_program();
                    //timeout=60000;
                    break;
               
                case QUIT:              //'q'
                    finish=TRUE;
                    break;

                default:
                    break;

             }
         
        }         

    }

    #asm
        goto APPLICATION_START
    #endasm
}


It doesn't work, and I can't discover why as I can't debugg-it.

I believe that the problem has to do with this:

Code:

usb_task();
if (!usb_cdc_kbhit()){                 
     continue;
}

That code is also present in load_program()

Do you think the design is fine?
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 4:13 am     Reply with quote

No.

That just means 'loop back' and re-test the 'while'.

Odds are, that if you are adding extra functions, the code has got larger. The examples reserve enough space for the code 'as given'. If your code gets more complex, you have to compile it, check it's actual size, and modify the size values in bootloader.h, to work at the next page boundary above the end of your new code.
LiLou



Joined: 04 Feb 2014
Posts: 26

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 4:41 am     Reply with quote

Ttelmah wrote:
No.

That just means 'loop back' and re-test the 'while'.


That is what I want. How then?

Ttelmah wrote:

Odds are, that if you are adding extra functions, the code has got larger. The examples reserve enough space for the code 'as given'. If your code gets more complex, you have to compile it, check it's actual size, and modify the size values in bootloader.h, to work at the next page boundary above the end of your new code.

Already check it. I'm within the boundary.
LiLou



Joined: 04 Feb 2014
Posts: 26

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 6:06 am     Reply with quote

I think I found the error. It's from software, I send strings (not integers), as this strings are null-terminated when bootloader reads the order, the last thing he gets is the null '\0'.

EDIT:
Well, that has only solved part of the problem. The issue is that if I go to load_program, which also does usb_task and usb_cdc_getc (reads the hex file), then the bootloader breaks, doesn't respond. If I do other simpler functions (clear_eeprom, read version), it works well.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group