Integrated MK22FN512xx USB VCOM driver with stdio system

replace/8d9706cbf89ba2eb59681009e8a25250317e7fc6
Silvano Seva 2020-12-22 12:16:01 +01:00
rodzic 498109a672
commit 0f09504453
5 zmienionych plików z 25 dodań i 22 usunięć

Wyświetl plik

@ -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_khci.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',
'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',

Wyświetl plik

@ -24,6 +24,7 @@
#include <sys/fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <usb_vcom.h>
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)
{
//vcom_writeBlock(buf, cnt);
//return cnt;
(void) buf;
(void) cnt;
return -1;
return vcom_writeBlock(buf, cnt);
}
/* 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(;;)
{
//ssize_t r = vcom_readBlock(buf, cnt);
//if((r < 0) || (r == (ssize_t)(cnt))) return r;
(void) buf;
(void) cnt;
return -1;
ssize_t r = vcom_readBlock(buf, cnt);
if((r < 0) || (r == (ssize_t)(cnt))) return r;
}
}
else

Wyświetl plik

@ -17,10 +17,11 @@
***************************************************************************/
#include <string.h>
#include <stdio.h>
#include "MK22F51212.h"
#include "system_MK22F51212.h"
#include <string.h>
#include <usb_vcom.h>
#include <MK22F51212.h>
#include <system_MK22F51212.h>
///< Entry point for system bootstrap after initial configurations.
void systemBootstrap();
@ -83,8 +84,8 @@ void Reset_Handler()
SIM->SCGC5 |= 0x3E00; // Enable GPIO clock
// // Enable virtual com port (for stdin, stdout and stderr redirection)
// vcom_init();
// Enable virtual com port (for stdin, stdout and stderr redirection)
vcom_init();
// Set no buffer for stdin, required to make scanf, getchar, ... working
// correctly

Wyświetl plik

@ -34,8 +34,8 @@
#include <stdbool.h>
#include <MK22F51212.h>
#include "virtual_com.h"
#include "usb/usb.h"
#include "usb_vcom.h"
#include "usb/fsl_common.h"
#include "usb/usb_device.h"
#include "usb/usb_device_ch9.h"
@ -627,13 +627,21 @@ void vcom_init()
ssize_t vcom_writeBlock(const void *buf, size_t len)
{
memcpy(sendBuf, buf, len);
if((cdcVcom.attach == 1) && (cdcVcom.startTransactions == 1))
{
usb_status_t st = USB_DeviceSendRequest(cdcVcom.deviceHandle,
USB_CDC_VCOM_BULK_IN_ENDPOINT,
sendBuf, len);
if(st != kStatus_USB_Success) return -1;
uint32_t bytesToSend = len;
while(bytesToSend > 0)
{
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;