I know that DbgConsole_Init() has to be called with a debug_console_device_type_t == kDebugConsoleUSBCDC, but what else?
- Do I need to include the virtual_com.c & virtual_com.h files in my project?
- Do I need to grab the usb callback routines from the virtual com demo and put them somewhere?
- Where do I define BOARD_USE_VIRTUALCOM?
I'm trying to use the Virtual COM port for my console I/O on a FRDM-KL27Z running mqx-lite. I've successfully converted the virtual_com usb demo to use mqx-lite, and now I need to write my "real" application with real console I/O (not just echoed characters).
I have written a blog on exactly how to do this at: KSDK USB CDC PRINTF | Centaurian
Hope it helps.
Hi Wesley,
How to use the above link for scanf? I got it working for my (MK50DX256CLK10) custom board for printf. I want to make it work for scanf.
-Kiran
Hi,
I don't fully understand your question!
As my understanding, the debugger console should be configured by the IDE itself.
When using a usb stack, you may make a USB works as a virtual_com, but "Debugging" is IDE's job.
could you give me more description on this issue?
I use the IAR IDE. For any given bit of example code (lwdemo, for example), there is a workspace comprising several different projects. There's one project for each library (mqx library, ksdk library, etc)and then one for the example itself. In many (maybe all) of the example projects, there's a Debug Console sub-directory containing a number of files, including:
fsl_debug_console.c
fsl_debug_console.h
print_scan.c
print_scan.h
Maybe they're named improperly, and the fsl_debug_console files should just be named fsl_console.c & fsl_console.h. The point is, these files appear to let you redirect stdio to whichever port you'd like. In board.h, for the FRDM-KL43Z & -27Z, you'll find the line
#define BOARD_USE_LPUART
which makes stdio (printf, scanf) use the LPUART. On the FRDM boards, this actually gets sent out the SDA port. By using this line instead
#define BOARD_USE_VIRTUALCOM
the fsl_debug_console module should redirect stdio to the USB port using the CDC Virtual COM port functionality.
BUT it's not as simple as just changing the #define in board.h. I've added the USB Device library to the workspace, and link it into the example code. I've added virtual_com.c & .h and usb_descriptor.c & .h to the example project. I've merged the main functions together (virtual.c has its own main).
The first big problem is that the init_bsp.c function _bsp_pre_init() has code to configure the UART pins for BOARD_USE_LPSCI, BOARD_USE_LPUART, and BOARD_USE_UART. Anything else, like BOARD_USE_VIRTUALCOM, causes a compile error by way of this statement:
#error Default serial module is unsupported or undefined.
So, I need to know what else I need to do to make my USB port be used for stdio.
Hi,
Try the steps from this example:
For example on FRDM-K27, the steps to make USB virtual com work:
$PROJ_DIR$/../../../../../platform/osa/inc $PROJ_DIR$/../../../../../platform/utilities/inc $PROJ_DIR$/../../../../../platform/CMSIS/Include $PROJ_DIR$/../../../../../platform/devices $PROJ_DIR$/../../../../../platform/devices/MKL27Z644/include $PROJ_DIR$/../../../../../platform/devices/MKL27Z644/startup $PROJ_DIR$/../../../../../platform/hal/inc $PROJ_DIR$/../../../../../platform/drivers/inc $PROJ_DIR$/../../../../../platform/system/inc $PROJ_DIR$/../../../../../platform/utilities/inc $PROJ_DIR$/../../.. $PROJ_DIR$/../../../../../platform/utilities/inc/virtual_com $PROJ_DIR$/../../../../../usb/usb_core/device/include/frdmkl27z $PROJ_DIR$/../../../../../usb/usb_core/include $PROJ_DIR$/../../../../../usb/adapter/sources $PROJ_DIR$/../../../../../usb/adapter/sources/sdk $PROJ_DIR$/../../../../../usb/usb_core/hal $PROJ_DIR$/../../../../../usb/usb_core/include $PROJ_DIR$/../../../../../usb/usb_core/device/include $PROJ_DIR$/../../../../../usb/usb_core/device/sources/classes/audio $PROJ_DIR$/../../../../../usb/usb_core/device/sources/classes/cdc $PROJ_DIR$/../../../../../usb/usb_core/device/sources/classes/common $PROJ_DIR$/../../../../../usb/usb_core/device/sources/classes/composite $PROJ_DIR$/../../../../../usb/usb_core/device/sources/classes/hid $PROJ_DIR$/../../../../../usb/usb_core/device/sources/classes/include $PROJ_DIR$/../../../../../usb/usb_core/device/sources/classes/msd $PROJ_DIR$/../../../../../usb/usb_core/device/sources/classes/phdc $PROJ_DIR$/../../../../../usb/usb_core/device/sources/controller/khci $PROJ_DIR$/../../../../../usb/usb_core/device/sources/controller |
2
With release target, you must include release usb lib.a
__ram_vector_table__=1 __stack_size__=0x400 __heap_size__=0x400 |
/* The USB_CDC to use for debug messages. */ #ifndef BOARD_DEBUG_USBCDC_INSTANCE #define BOARD_DEBUG_USBCDC_INSTANCE 1 #endif #ifndef BOARD_DEBUG_USBCDC_BAUD #define BOARD_DEBUG_USBCDC_BAUD 115200 #endif |
void dbg_uart_init(void) { DbgConsole_Init(BOARD_DEBUG_USBCDC_INSTANCE, BOARD_DEBUG_USBCDC_BAUD, kDebugConsoleUSBCDC); } |
Not quite there yet…
In this snippet,
debug_console_status_t DbgConsole_Init(
uint32_t uartInstance, uint32_t baudRate, debug_console_device_type_t device)
{
if (s_debugConsole.type != kDebugConsoleNone)
{
return kStatus_DEBUGCONSOLE_Failed;
}
/* Set debug console to initialized to avoid duplicated init operation.*/
s_debugConsole.type = device;
s_debugConsole.instance = uartInstance;
/* Switch between different device. */
switch (device)
{
#if (defined(USB_INSTANCE_COUNT) && defined(BOARD_USE_VIRTUALCOM)) /&& defined()/
case kDebugConsoleUSBCDC:
{
VirtualCom_Init();
s_debugConsole.base = (void*)g_app_handle;
s_debugConsole.ops.tx_union.USB_Send = VirtualCom_SendDataBlocking;
s_debugConsole.ops.rx_union.USB_Receive = VirtualCom_ReceiveDataBlocking;
}
break;
#endif
In the line
s_debugConsole.base = (void*)g_app_handle;
g_app_handle = 0, so the program goes off into the weeds on execution of DbgConsole_Init. In the other cases, like the LPUART, s_debugConsole.base is set to the base address of the lpuart instance. What should I do here?
Thanks,
Mark Dobrosielski
Hi Mark,
I have a few more tips that might help.
When the program is downloaded and running, be sure to manually install the virtual cdc driver which is in directory:
C:\Freescale\KSDK_1.2.0\examples\frdmkl27z\demo_apps\usb\device\cdc\virtual_com\inf.
A more detail description is in the readme file of usb virtual cdc example:
C:\Freescale\KSDK_1.2.0\examples\frdmkl27z\demo_apps\usb\device\cdc\virtual_com\readme.pdf
Also, although I only highlighted the last parameter in the DbgConsole_Init function above, please note that all parameters need to be changed. See below.
void dbg_uart_init(void)
{
configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);
/* For UART */
// DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUD, kDebugConsoleUART);
/* For USB CDC */
DbgConsole_Init(BOARD_DEBUG_USBCDC_INSTANCE, BOARD_DEBUG_USBCDC_BAUD, kDebugConsoleUSBCDC);
}