Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: usb_configured on teensy 3.2

  1. #1
    Senior Member
    Join Date
    Sep 2015
    Posts
    101

    usb_configured on teensy 3.2

    I'm having problems with usb_configured on a new teensy 3.2 project.


    Have boiled it down to a simple test code,
    the usb_serial_avaialble() does not cause an error , but the usb_configured causes a error, "it was not defined "

    arduino 1.6.9 and teensduino 1.3

    Thoughts please ?


    void setup()
    {
    Serial.begin(9600); // USB is always 12 Mbit/sec
    }

    void loop()
    {
    Serial.println("Hello World...");
    usb_serial_available();
    usb_configured();
    delay(1000); // do not print too fast!
    }

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,422
    For me wondering what it is you are trying to do and why you are not just using standard Arduino stuff?

    That is, you can simply replace the line: usb_serial_available();
    with: Serial.available();

    And have no idea what is: usb_configured? When I do a search on sources installed as part of Teensyduino, I don't see this defined anywhere...

  3. #3
    Senior Member
    Join Date
    Sep 2015
    Posts
    101
    Its some one elses code I got handed, I was the last one to duck !
    This is just a demo of the code, the real thing is hundreds of lines long.

    I had not heard of usb_configured, but on search of the teensy site, found

    https://www.pjrc.com/teensy/usb_debug_only.html

    so wondered , and thought I'd ask.

  4. #4
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,717
    Quote Originally Posted by KurtE View Post
    For me wondering what it is you are trying to do and why you are not just using standard Arduino stuff?

    That is, you can simply replace the line: usb_serial_available();
    with: Serial.available();

    And have no idea what is: usb_configured? When I do a search on sources installed as part of Teensyduino, I don't see this defined anywhere...
    Well,
    the usb_serial stuff is the original, written in plain C and can be used to, say debug, plain C code.
    Serial.xxx is only a C++ wrapper useful only to cpp (including ino) files.

    @drjohnsmith
    in fact usb_configured is only defined in usb_debug_only
    uint8_t usb_configured(void)
    {
    return usb_configuration;
    }

    so you can simply add this function without sideffects

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,422
    Quote Originally Posted by WMXZ View Post
    Well,
    the usb_serial stuff is the original, written in plain C and can be used to, say debug, plain C code.
    Serial.xxx is only a C++ wrapper useful only to cpp (including ino) files.
    Thanks, I am aware...

    but they are already in a sketch (setup, loop), and are already calling other C++ wrappers, like Serial.println()...

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    Quote Originally Posted by drjohnsmith View Post
    Its some one elses code I got handed, I was the last one to duck !
    This is just a demo of the code, the real thing is hundreds of lines long.

    I had not heard of usb_configured, but on search of the teensy site, found

    https://www.pjrc.com/teensy/usb_debug_only.html

    so wondered , and thought I'd ask.
    Would have been very nice to mention that in the first post.

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,422
    Took a quick look at the zip file and it looks like none of the files have changed since 2009.

    The example program, had stuff in it like:
    Code:
    	usb_init();
    	while (!usb_configured()) /* wait */ ;
    Which today I would write as:
    Code:
        Serial.begin(115200);  // baud does not really matter here.
        while (!Serial) ;
    Actually I usually put a timeout in the !Serial... like: while(!Serial && (millis() < 5000)) ;
    So it will wait up to 5 seconds...

    Can probably also map most of the other stuff over to normal Arduino stuff, but again not sure what you are doing. The example program in the zip file was a simple program with a makefile... Not sure if what you are trying to do is as well? Also the zip file has files like print.h, analog.h as well as their .c files. Not sure how they would work in arduino builds.

  8. #8
    Senior Member
    Join Date
    Sep 2015
    Posts
    101
    Quote Originally Posted by Frank B View Post
    Would have been very nice to mention that in the first post.
    Why ?

    its a bit of code, I say its a cut down of , and I'm wondering what the procedure does,
    why does its provenience matter to you ?

  9. #9
    Senior Member
    Join Date
    Sep 2015
    Posts
    101
    Thanks KurtE

    Thats what I was hoping,
    could not work out easily which was the new style or the old style !

    usb_configured seemed 'tighter' to me , but !Serial as you say is the way forward.

    Thank you for your succinct answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •