Integrated MK22FN512xx USB VCOM driver with stdio system
This commit is contained in:
parent
498109a672
commit
0f09504453
|
|
@ -128,7 +128,7 @@ mk22fn512_src = ['platform/mcu/MK22FN512xxx12/boot/startup.c',
|
||||||
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_descriptor.c',
|
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_descriptor.c',
|
||||||
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_khci.c',
|
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_khci.c',
|
||||||
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_osa_bm.c',
|
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_osa_bm.c',
|
||||||
'platform/mcu/MK22FN512xxx12/drivers/virtual_com.c',
|
'platform/mcu/MK22FN512xxx12/drivers/usb_vcom.c',
|
||||||
'platform/mcu/CMSIS/Device/NXP/MK22FN512xxx12/Source/system_MK22F51212.c',
|
'platform/mcu/CMSIS/Device/NXP/MK22FN512xxx12/Source/system_MK22F51212.c',
|
||||||
'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M/os_cpu_c.c',
|
'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M/os_cpu_c.c',
|
||||||
'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M/os_cpu_a.s',
|
'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M/os_cpu_a.s',
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <usb_vcom.h>
|
||||||
|
|
||||||
|
|
||||||
void pthread_mutex_unlock(){}
|
void pthread_mutex_unlock(){}
|
||||||
|
|
@ -198,11 +199,7 @@ int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt)
|
||||||
{
|
{
|
||||||
if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
|
if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
|
||||||
{
|
{
|
||||||
//vcom_writeBlock(buf, cnt);
|
return vcom_writeBlock(buf, cnt);
|
||||||
//return cnt;
|
|
||||||
(void) buf;
|
|
||||||
(void) cnt;
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If fd is not stdout or stderr */
|
/* If fd is not stdout or stderr */
|
||||||
|
|
@ -220,11 +217,8 @@ int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt)
|
||||||
{
|
{
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
//ssize_t r = vcom_readBlock(buf, cnt);
|
ssize_t r = vcom_readBlock(buf, cnt);
|
||||||
//if((r < 0) || (r == (ssize_t)(cnt))) return r;
|
if((r < 0) || (r == (ssize_t)(cnt))) return r;
|
||||||
(void) buf;
|
|
||||||
(void) cnt;
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,11 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "MK22F51212.h"
|
#include <string.h>
|
||||||
#include "system_MK22F51212.h"
|
#include <usb_vcom.h>
|
||||||
|
#include <MK22F51212.h>
|
||||||
|
#include <system_MK22F51212.h>
|
||||||
|
|
||||||
///< Entry point for system bootstrap after initial configurations.
|
///< Entry point for system bootstrap after initial configurations.
|
||||||
void systemBootstrap();
|
void systemBootstrap();
|
||||||
|
|
@ -83,8 +84,8 @@ void Reset_Handler()
|
||||||
|
|
||||||
SIM->SCGC5 |= 0x3E00; // Enable GPIO clock
|
SIM->SCGC5 |= 0x3E00; // Enable GPIO clock
|
||||||
|
|
||||||
// // Enable virtual com port (for stdin, stdout and stderr redirection)
|
// Enable virtual com port (for stdin, stdout and stderr redirection)
|
||||||
// vcom_init();
|
vcom_init();
|
||||||
|
|
||||||
// Set no buffer for stdin, required to make scanf, getchar, ... working
|
// Set no buffer for stdin, required to make scanf, getchar, ... working
|
||||||
// correctly
|
// correctly
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <MK22F51212.h>
|
#include <MK22F51212.h>
|
||||||
|
|
||||||
#include "virtual_com.h"
|
|
||||||
#include "usb/usb.h"
|
#include "usb/usb.h"
|
||||||
|
#include "usb_vcom.h"
|
||||||
#include "usb/fsl_common.h"
|
#include "usb/fsl_common.h"
|
||||||
#include "usb/usb_device.h"
|
#include "usb/usb_device.h"
|
||||||
#include "usb/usb_device_ch9.h"
|
#include "usb/usb_device_ch9.h"
|
||||||
|
|
@ -627,13 +627,21 @@ void vcom_init()
|
||||||
|
|
||||||
ssize_t vcom_writeBlock(const void *buf, size_t len)
|
ssize_t vcom_writeBlock(const void *buf, size_t len)
|
||||||
{
|
{
|
||||||
memcpy(sendBuf, buf, len);
|
|
||||||
if((cdcVcom.attach == 1) && (cdcVcom.startTransactions == 1))
|
if((cdcVcom.attach == 1) && (cdcVcom.startTransactions == 1))
|
||||||
{
|
{
|
||||||
usb_status_t st = USB_DeviceSendRequest(cdcVcom.deviceHandle,
|
uint32_t bytesToSend = len;
|
||||||
USB_CDC_VCOM_BULK_IN_ENDPOINT,
|
while(bytesToSend > 0)
|
||||||
sendBuf, len);
|
{
|
||||||
if(st != kStatus_USB_Success) return -1;
|
uint32_t xFerLen = (bytesToSend > FS_CDC_VCOM_BULK_OUT_PACKET_SIZE)
|
||||||
|
? FS_CDC_VCOM_BULK_OUT_PACKET_SIZE : bytesToSend;
|
||||||
|
|
||||||
|
memcpy(sendBuf, buf, xFerLen);
|
||||||
|
usb_status_t st = USB_DeviceSendRequest(cdcVcom.deviceHandle,
|
||||||
|
USB_CDC_VCOM_BULK_IN_ENDPOINT,
|
||||||
|
sendBuf, xFerLen);
|
||||||
|
if(st != kStatus_USB_Success) return -1;
|
||||||
|
bytesToSend -= xFerLen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
Loading…
Reference in New Issue