looking for help with usb-serial and chprintf

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm

looking for help with usb-serial and chprintf

Post by jscott »

I am trying to use chprintf with usb-serial in general functions. I can see how it works when
writing command functions using the shell.c module. I have been playing with this for several
days now, and have not had much luck figuring out how to get this to work.

here is the error I am getting.. Program compiles and works fine when I comment out chprintf
The chprintf is the very last line in the code below.

===================================================
R:\ChibiOS\projects\usb_2>make
Compiling main.c
main.c: In function 'main':
main.c:136:3: error: incompatible type for argument 1 of 'chprintf'
In file included from main.c:29:0:
../../../chibios/os/various/chprintf.h:42:8: note: expected 'struct BaseSequentialStream *' but argument is of type 'SerialUSBDriver'
make: *** [build/obj/main.o] Error 1

==================================================================


Code: Select all

/*
      ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
                         2011,2012 Giovanni Di Sirio.

      This file is part of ChibiOS/RT.

      ChibiOS/RT is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 3 of the License, or
      (at your option) any later version.

      ChibiOS/RT is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program.   If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "ch.h"
#include "hal.h"

#include "shell.h"
#include "chprintf.h"

//#include "myPWM.h"
//#include "myADC.h"
#include "myUSB.h"
#include "myMisc.h"


/*
 * assert Shell Commands to functions
 */

static const ShellCommand commands[] =
{
   {"mem", cmd_mem},
   {"threads", cmd_threads},
   {"toggle", cmd_toggle},
   {"t", cmd_toggle},
   {"blinkspeed", cmd_blinkspeed},
   {"bs", cmd_blinkspeed},
/*
   {"cycle", cmd_cycle},
   {"c", cmd_cycle},
   {"ramp", cmd_ramp},
   {"r", cmd_ramp},
   {"measure", cmd_measure},
   {"m", cmd_measure},
   {"measureAnalog", cmd_measureA},
   {"ma", cmd_measureA},
   {"measureDirect", cmd_measureDirect},
   {"md", cmd_measureDirect},
   {"measureContinuous", cmd_measureCont},
   {"mc", cmd_measureCont},
   {"readContinuousData", cmd_measureRead},
   {"rd", cmd_measureRead},
   {"stopContinuous", cmd_measureStop},
   {"sc", cmd_measureStop},
*/
   {NULL, NULL}
};


/*
 * Shell configuration
 */

#define SHELL_WA_SIZE    THD_WA_SIZE(2048)

static const ShellConfig shell_cfg1 =
{
   (BaseSequentialStream *)&SDU1,
   commands
};


/*
 * Application entry point.
 */
int main(void)
{
   char msg[]="sos  sos  sos";

   /*
    * Shell thread
    */
   Thread *shelltp = NULL;

   /*
    * System initializations.
    * - HAL initialization, this also initializes the configured device drivers
    *    and performs the board-specific initializations.
    * - Kernel initialization, the main() function becomes a thread and the
    *    RTOS is active.
    */
   halInit();
   chSysInit();

   /*
    * Activate custom stuff
    */
   //   mypwmInit();
   //   myADCinit();

   /*
    * Creates the blinker thread.
    */
   startBlinker();

   /*
    * Activates the USB driver and then the USB bus pull-up on D+.
    */
   myUSBinit();


   /*
    * Main loop, does nothing except spawn a shell when the old one was terminated
    */
   while (TRUE)
   {
      if (!shelltp && isUsbActive())
         {
            shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
         }
      else if (chThdTerminated(shelltp))
      {
         chThdRelease(shelltp);      /* Recovers memory of the previous shell.   */
         shelltp = NULL;            /* Triggers spawning of a new shell.   */
      }
      chThdSleepMilliseconds(5000);
      SendMorse( msg );
      chprintf( SDU1, "%s\n", msg );
   }
}
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: looking for help with usb-serial and chprintf

Post by Giovanni »

Hi,

Rewrite this:

Code: Select all

chprintf( SDU1, "%s\n", msg );


this way:

Code: Select all

chprintf( (BaseSequentialStream *)&SDU1, "%s\n", msg );


The first parameter is a pointer and must be casted to the expected type.

Giovanni
jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm

Re: looking for help with usb-serial and chprintf

Post by jscott »

AH! Got it!

I tried numerous variations, but did not keep track of what I did... ( yea, yea... I git it now!! )

I also got it going in the module that I needed it in.

Giovanni, Thanks for your help, and for the project overall!

-John
Post Reply