Skip to content

Commit

Permalink
Merge branch 'vcom' into 'develop-UAC18'
Browse files Browse the repository at this point in the history
Add support for debbuger console through USB port, fix bugs in WP through USB.

See merge request isma-framework/nf-interpreter!18
  • Loading branch information
MateuszKlatecki committed Aug 6, 2019
2 parents a368b4b + 30e50e5 commit adcfa81
Show file tree
Hide file tree
Showing 17 changed files with 1,185 additions and 472 deletions.
2 changes: 1 addition & 1 deletion CMake/toolchain.FreeRtos.GCC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ endfunction()
function(NF_SET_OPTIMIZATION_OPTIONS TARGET)

target_compile_options(${TARGET} PRIVATE
$<$<CONFIG:Debug>:-O0 -femit-class-debug-always -g3 -ggdb>
$<$<CONFIG:Debug>:-Og -femit-class-debug-always -g3 -ggdb>
$<$<CONFIG:Release>:-O3 -flto -fuse-linker-plugin -fno-fat-lto-objects>
$<$<CONFIG:MinSizeRel>:-Os -flto -fuse-linker-plugin -fno-fat-lto-objects>
$<$<CONFIG:RelWithDebInfo>:-Os -femit-class-debug-always -g3 -ggdb>
Expand Down
2 changes: 1 addition & 1 deletion src/CLR/Include/WireProtocol_Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define TRACE0( f, msg ) if((f) & TRACE_MASK ) debug_printf( msg )
#define TRACE( f, msg, ...) if((f) & TRACE_MASK ) debug_printf( msg, __VA_ARGS__ )
#else
#define TRACE0(msg,...)
#define TRACE0(msg,...)
#define TRACE(msg,...)
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/CLR/WireProtocol/WireProtocol_Message.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ int WP_Message_Process(WP_Message* message)
}

memmove(&buf[0], &buf[1], len-1);

message->m_pos--;
message->m_size++;
}
Expand Down
2 changes: 1 addition & 1 deletion targets/FreeRTOS/GC5/LwIP/ethernetif.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
#endif
#else
#ifndef ENET_PRIORITY
#define ENET_PRIORITY (6U)
#define ENET_PRIORITY (3U)
#endif
#ifndef ENET_1588_PRIORITY
#define ENET_1588_PRIORITY (5U)
Expand Down
4 changes: 2 additions & 2 deletions targets/FreeRTOS/GC5/UAC18/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
* The priority value itself is platform-dependent, but is passed to
* sys_thread_new() when the thread is created.
*/
#define TCPIP_THREAD_PRIO 8
#define TCPIP_THREAD_PRIO 10

/**
* TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages
Expand All @@ -210,7 +210,7 @@
* The priority value itself is platform-dependent, but is passed to
* sys_thread_new() when the thread is created.
*/
#define DEFAULT_THREAD_PRIO 3
#define DEFAULT_THREAD_PRIO 6

/**
* DEFAULT_RAW_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
Expand Down
4 changes: 4 additions & 0 deletions targets/FreeRTOS/GC5/UAC18/target_common.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#define PLATFORM_HAS_RNG TRUE
/////////////////////////////////////

/////////////////////////////////////
#define WP_PACKET_SIZE 512U
/////////////////////////////////////

/////////////////////////////////////
// #define EVENTS_HEART_BEAT
/////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion targets/FreeRTOS/GC5/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ list(APPEND TARGET_NXP_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/drivers/usb/u
list(APPEND TARGET_NXP_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/drivers/usb/usb_osa_freertos.c")
list(APPEND TARGET_NXP_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/drivers/usb/usb_vcom.c")
list(APPEND TARGET_NXP_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/drivers/usb/usb_device_dci.c")
# list(APPEND TARGET_NXP_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/drivers/usb/usb_device_class.c")

# append nanoUSB
list(APPEND TARGET_NXP_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/nanoUSB.c")

list(APPEND TARGET_NXP_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/device/system_MIMXRT1062.c")

Expand Down
60 changes: 31 additions & 29 deletions targets/FreeRTOS/GC5/common/WireProtocol_HAL_Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,28 @@
// See LICENSE file in the project root for full license information.
//

#define HAL_USE_SERIAL_USB

#include "board.h"

#include <nanoHAL_v2.h>
#include <WireProtocol.h>
#include <WireProtocol_Message.h>
#include <WireProtocol_HAL_interface.h>

/* Debugging through USB port */
#ifdef HAL_USE_SERIAL_USB

#include "usb.h"
#include "usb_vcom.h"
#include "stream_buffer.h"
#include "usb_device_config.h"

#elif defined HAL_USE_SERIAL
/* Debugging through serial port */
#elif defined HAL_USE_SERIAL
#include "fsl_lpuart_freertos.h"
#include "fsl_lpuart.h"

#endif

WP_Message inboundMessage;

USB_LINK_NONCACHE_NONINIT_DATA static uint8_t s_currSendBuf[0x1000];

bool WP_Port_Intitialised = false;
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
// The functions bellow are the ones that need to be ported to new channels/HALs when required
Expand All @@ -41,60 +37,66 @@ bool WP_Port_Intitialised = false;

#ifdef HAL_USE_SERIAL_USB

extern usb_cdc_vcom_struct_t s_cdcVcom;
extern usb_data_t s_cdc_data;
extern usb_data_t * s_cdc_data_p;
extern usb_device_composite_struct_t * g_composite_p;

int WP_ReceiveBytes(uint8_t* ptr, uint16_t* size)
{

{
size_t bytes_received = 0;
uint16_t requested_bytes = *size;

if (requested_bytes == 0)
{
vTaskDelay(pdMS_TO_TICKS(5)); /* Decide how responsive USB is, vs how much processing time it consumes */
return 1;
/* TODO: Check if this safecheck is needed. */
/* Wire Protocol may starve other threads while receiving zero bytes packets. */

// vTaskDelay(pdMS_TO_TICKS(20)); /* Decide how responsive USB is, vs how much processing time it consumes */
return true;
}

xStreamBufferSetTriggerLevel(s_cdc_data_p->data_in[0], requested_bytes);
bytes_received = xStreamBufferReceive(s_cdc_data_p->data_in[0], (void *) ptr, requested_bytes, portMAX_DELAY);

xStreamBufferSetTriggerLevel(s_cdc_data.data_in, requested_bytes);
bytes_received = xStreamBufferReceive(s_cdc_data.data_in, (void *) ptr, requested_bytes, portMAX_DELAY);

if (bytes_received == requested_bytes)
{
*size -= bytes_received;
return 1;
}
return 0;
ptr += bytes_received;
*size -= bytes_received;
return (bytes_received > 0); /* Watch performance and how this affects transmission */
}

int WP_TransmitMessage(WP_Message* message)
{
usb_status_t error = kStatus_USB_Error;
usb_cdc_vcom_struct_t *vcomInstance;

s_cdc_data.xWriteToNotify = xTaskGetCurrentTaskHandle();
s_cdc_data_p->xWriteToNotify[0] = xTaskGetCurrentTaskHandle();
vcomInstance = &g_composite_p->cdcVcom[0];

uint8_t * send_addr = (uint8_t *) &(message->m_header);
uint32_t send_size = sizeof(message->m_header);

/* Check for buffer overflow */
if ((send_size + message->m_header.m_size) > sizeof(s_currSendBuf) / sizeof(uint8_t)) return 0;
if ((send_size + message->m_header.m_size) > sizeof(s_cdc_data_p->s_currSendBuf[0]) / sizeof(uint8_t))
{
debug_printf("buffer overflow!");
configASSERT(1);
return 0;
}

memcpy(s_currSendBuf, send_addr, send_size);
memcpy(s_currSendBuf + send_size, (uint8_t *) (message->m_payload), message->m_header.m_size);
memcpy(s_cdc_data_p->s_currSendBuf[0], send_addr, send_size);
memcpy(s_cdc_data_p->s_currSendBuf[0] + send_size, (uint8_t *) (message->m_payload), message->m_header.m_size);

send_size = send_size + message->m_header.m_size;

error = USB_DeviceSendRequest(s_cdcVcom.deviceHandle, USB_CDC_VCOM_BULK_IN_ENDPOINT, s_currSendBuf, send_size);
error = USB_DeviceSendRequest(g_composite_p->deviceHandle, vcomInstance->bulkInEndpoint, s_cdc_data_p->s_currSendBuf[0], send_size);
if (error != kStatus_USB_Success) return false;

ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

return true;
}

#elif defined HAL_USE_SERIAL

bool WP_Port_Intitialised = false;

static lpuart_rtos_handle_t handle;
static struct _lpuart_handle t_handle;
uint8_t background_buffer[1024];
Expand Down
10 changes: 6 additions & 4 deletions targets/FreeRTOS/GC5/common/WireProtocol_ReceiverThread.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ void WP_Message_Process(WP_Message* a);
void ReceiverThread(void * argument)
{
(void)argument;

configASSERT(USB_Init() == kStatus_USB_Success);

// loop forever

extern usb_data_t s_cdc_data;

s_cdc_data.xReceiverTask = xTaskGetCurrentTaskHandle();
xTaskNotifyWait(0x0, 0x0, NULL, portMAX_DELAY);

while (1) {

WP_Message_Initialize(&inboundMessage);
Expand Down
6 changes: 3 additions & 3 deletions targets/FreeRTOS/GC5/common/drivers/usb/usb_device_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define USB_DEVICE_CONFIG_HID (0U)

/*! @brief CDC ACM instance count */
#define USB_DEVICE_CONFIG_CDC_ACM (1U)
#define USB_DEVICE_CONFIG_CDC_ACM (2U)

/*! @brief MSC instance count */
#define USB_DEVICE_CONFIG_MSC (0U)
Expand Down Expand Up @@ -80,7 +80,7 @@
#define USB_DEVICE_CONFIG_SELF_POWER (1U)

/*! @brief How many endpoints are supported in the stack. */
#define USB_DEVICE_CONFIG_ENDPOINTS (4U)
#define USB_DEVICE_CONFIG_ENDPOINTS (5U)

/*! @brief Whether the device task is enabled. */
#define USB_DEVICE_CONFIG_USE_TASK (0U)
Expand Down Expand Up @@ -149,7 +149,7 @@
#endif

/*! @brief Whether the device detached feature is enabled or not. */
#define USB_DEVICE_CONFIG_DETACH_ENABLE (0U)
#define USB_DEVICE_CONFIG_DETACH_ENABLE (1U)

/*! @brief Whether handle the USB bus error. */
#define USB_DEVICE_CONFIG_ERROR_HANDLING (0U)
Expand Down
6 changes: 3 additions & 3 deletions targets/FreeRTOS/GC5/common/drivers/usb/usb_device_dci.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ static usb_status_t USB_DeviceDetachNotification(usb_device_struct_t *handle,
/* Call device callback to notify the application that the device is disconnected from a host.
the deviceCallback is the second parameter of USB_DeviceInit */
return handle->deviceCallback(handle, kUSB_DeviceEventDetach, NULL);
(void) message;
}

/*!
Expand All @@ -532,6 +533,7 @@ static usb_status_t USB_DeviceAttachNotification(usb_device_struct_t *handle,
/* Call device callback to notify the application that the device is connected to a host.
the deviceCallback is the second parameter of USB_DeviceInit */
return handle->deviceCallback(handle, kUSB_DeviceEventAttach, NULL);
(void) message;
}
#endif

Expand Down Expand Up @@ -1032,9 +1034,7 @@ usb_status_t USB_DeviceSendRequest(usb_device_handle handle, uint8_t endpointAdd
*/
usb_status_t USB_DeviceRecvRequest(usb_device_handle handle, uint8_t endpointAddress, uint8_t *buffer, uint32_t length)
{
return USB_DeviceTransfer(handle, (endpointAddress & USB_ENDPOINT_NUMBER_MASK) |
(USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
buffer, length);
return USB_DeviceTransfer(handle, (endpointAddress & USB_ENDPOINT_NUMBER_MASK) | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), buffer, length);
}

/*!
Expand Down
Loading

0 comments on commit adcfa81

Please sign in to comment.