Modifications for the final hardware
This commit is contained in:
parent
0fbd319883
commit
e53e5c79fb
@ -52,7 +52,7 @@ HAL_GPIO_PIN(nRESET, A, 9)
|
||||
#define DAP_CONFIG_VENDOR_STR "Alex Taradov"
|
||||
#define DAP_CONFIG_PRODUCT_STR "Generic CMSIS-DAP Adapter"
|
||||
#define DAP_CONFIG_SER_NUM_STR usb_serial_number
|
||||
#define DAP_CONFIG_FW_VER_STR "v0.5"
|
||||
#define DAP_CONFIG_FW_VER_STR "v1.0"
|
||||
#define DAP_CONFIG_DEVICE_VENDOR_STR NULL
|
||||
#define DAP_CONFIG_DEVICE_NAME_STR NULL
|
||||
|
||||
@ -66,7 +66,6 @@ HAL_GPIO_PIN(nRESET, A, 9)
|
||||
#define DAP_CONFIG_FAST_CLOCK 2200000 // Hz
|
||||
|
||||
/*- Prototypes --------------------------------------------------------------*/
|
||||
extern void app_led_set_state(int state);
|
||||
extern char usb_serial_number[16];
|
||||
|
||||
/*- Implementations ---------------------------------------------------------*/
|
||||
@ -208,8 +207,8 @@ static inline void DAP_CONFIG_CONNECT_JTAG(void)
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline void DAP_CONFIG_LED(int index, int state)
|
||||
{
|
||||
if (0 == index)
|
||||
app_led_set_state(state);
|
||||
(void)index;
|
||||
(void)state;
|
||||
}
|
||||
|
||||
#endif // _DAP_CONFIG_H_
|
||||
|
||||
@ -77,6 +77,7 @@
|
||||
PORT_IOBUS->Group[HAL_GPIO_PORT##port].DIRCLR.reg = (1 << pin); \
|
||||
PORT_IOBUS->Group[HAL_GPIO_PORT##port].PINCFG[pin].reg |= PORT_PINCFG_INEN; \
|
||||
PORT_IOBUS->Group[HAL_GPIO_PORT##port].PINCFG[pin].reg &= ~PORT_PINCFG_PULLEN;\
|
||||
PORT_IOBUS->Group[HAL_GPIO_PORT##port].CTRL.reg |= (1 << pin); \
|
||||
(void)HAL_GPIO_##name##_in; \
|
||||
} \
|
||||
\
|
||||
|
||||
@ -43,6 +43,7 @@
|
||||
/*- Definitions -------------------------------------------------------------*/
|
||||
#define USB_BUFFER_SIZE 64
|
||||
#define UART_WAIT_TIMEOUT 10 // ms
|
||||
#define STATUS_TIMEOUT 250 // ms
|
||||
|
||||
HAL_GPIO_PIN(VCP_STATUS, A, 2);
|
||||
HAL_GPIO_PIN(DAP_STATUS, A, 4);
|
||||
@ -57,8 +58,12 @@ static int app_recv_buffer_ptr = 0;
|
||||
static int app_send_buffer_ptr = 0;
|
||||
static bool app_send_buffer_free = true;
|
||||
static bool app_send_zlp = false;
|
||||
static int app_system_time = 0;
|
||||
static int app_uart_timeout = 0;
|
||||
static uint64_t app_system_time = 0;
|
||||
static uint64_t app_uart_timeout = 0;
|
||||
static uint64_t app_status_timeout;
|
||||
static bool app_dap_event = false;
|
||||
static bool app_vcp_event = false;
|
||||
static bool app_vcp_open = false;
|
||||
|
||||
/*- Implementations ---------------------------------------------------------*/
|
||||
|
||||
@ -119,7 +124,7 @@ static void sys_time_task(void)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
static int get_system_time(void)
|
||||
static uint64_t get_system_time(void)
|
||||
{
|
||||
return app_system_time;
|
||||
}
|
||||
@ -168,9 +173,8 @@ void usb_cdc_control_line_state_update(int line_state)
|
||||
{
|
||||
bool status = line_state & USB_CDC_CTRL_SIGNAL_DTE_PRESENT;
|
||||
|
||||
HAL_GPIO_VCP_STATUS_write(status);
|
||||
|
||||
// TODO: actually close/open the port
|
||||
// TODO: actually open/close the port?
|
||||
app_vcp_open = status;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -183,6 +187,7 @@ static void tx_task(void)
|
||||
|
||||
app_recv_buffer_ptr++;
|
||||
app_recv_buffer_size--;
|
||||
app_vcp_event = true;
|
||||
|
||||
if (0 == app_recv_buffer_size)
|
||||
usb_cdc_recv(app_recv_buffer, sizeof(app_recv_buffer));
|
||||
@ -201,6 +206,7 @@ static void rx_task(void)
|
||||
{
|
||||
app_uart_timeout = get_system_time() + UART_WAIT_TIMEOUT;
|
||||
app_send_buffer[app_send_buffer_ptr++] = byte;
|
||||
app_vcp_event = true;
|
||||
|
||||
if (USB_BUFFER_SIZE == app_send_buffer_ptr)
|
||||
{
|
||||
@ -237,19 +243,12 @@ void usb_hid_send_callback(void)
|
||||
//-----------------------------------------------------------------------------
|
||||
void usb_hid_recv_callback(int size)
|
||||
{
|
||||
app_dap_event = true;
|
||||
dap_process_request(app_request_buffer, app_response_buffer);
|
||||
|
||||
usb_hid_send(app_response_buffer, sizeof(app_response_buffer));
|
||||
|
||||
(void)size;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app_led_set_state(int state)
|
||||
{
|
||||
HAL_GPIO_DAP_STATUS_write(state);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool usb_class_handle_request(usb_request_t *request)
|
||||
{
|
||||
@ -261,21 +260,45 @@ bool usb_class_handle_request(usb_request_t *request)
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
static void status_timer_task(void)
|
||||
{
|
||||
if (get_system_time() < app_status_timeout)
|
||||
return;
|
||||
|
||||
app_status_timeout = get_system_time() + STATUS_TIMEOUT;
|
||||
|
||||
if (app_dap_event)
|
||||
HAL_GPIO_DAP_STATUS_toggle();
|
||||
else
|
||||
HAL_GPIO_DAP_STATUS_set();
|
||||
|
||||
if (app_vcp_event)
|
||||
HAL_GPIO_VCP_STATUS_toggle();
|
||||
else
|
||||
HAL_GPIO_VCP_STATUS_write(app_vcp_open);
|
||||
|
||||
app_dap_event = false;
|
||||
app_vcp_event = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
sys_init();
|
||||
sys_time_init();
|
||||
usb_init();
|
||||
dap_init();
|
||||
usb_init();
|
||||
usb_cdc_init();
|
||||
usb_hid_init();
|
||||
|
||||
app_status_timeout = STATUS_TIMEOUT;
|
||||
|
||||
HAL_GPIO_VCP_STATUS_out();
|
||||
HAL_GPIO_VCP_STATUS_clr();
|
||||
|
||||
HAL_GPIO_DAP_STATUS_out();
|
||||
HAL_GPIO_DAP_STATUS_clr();
|
||||
HAL_GPIO_DAP_STATUS_set();
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -284,6 +307,7 @@ int main(void)
|
||||
tx_task();
|
||||
rx_task();
|
||||
uart_timer_task();
|
||||
status_timer_task();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -69,10 +69,10 @@ ServiceBinary=%12%\usbser.sys
|
||||
[SourceDisksFiles]
|
||||
[SourceDisksNames]
|
||||
[DeviceList]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_6666&PID_8888
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_6666&PID_6600
|
||||
|
||||
[DeviceList.NTamd64]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_6666&PID_8888
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_6666&PID_6600
|
||||
|
||||
[Strings]
|
||||
MANUFACTURER="Alex Taradov"
|
||||
|
||||
@ -43,7 +43,7 @@ const alignas(4) usb_device_descriptor_t usb_device_descriptor =
|
||||
.bDeviceProtocol = USB_DEVICE_PROTOCOL_INTERFACE_ASSOCIATION,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = 0x6666,
|
||||
.idProduct = 0x8888,
|
||||
.idProduct = 0x6600,
|
||||
.bcdDevice = 0x0101,
|
||||
.iManufacturer = USB_STR_MANUFACTURER,
|
||||
.iProduct = USB_STR_PRODUCT,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Alex Taradov <alex@taradov.com>
|
||||
* Copyright (c) 2019, Alex Taradov <alex@taradov.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
Loading…
Reference in New Issue
Block a user