Now seems code works with short communication as for example
Code: Select all
esptool.py --not-stub read_mac
Here is code
Code: Select all
#include <platform.h>
#include <xs1.h>
#include <stdio.h>
#include <string.h>
#include "xud_device.h"
#include "xud_cdc.h"
#include "uart.h"
#include <xccompat.h>
extern void set_global(unsigned write_val);
extern unsigned get_global(void);
extern void get_global_ref(REFERENCE_PARAM(unsigned, read_val));
port p_uart_rx = on tile[0] : XS1_PORT_1B;
port p_uart_tx = on tile[0] : XS1_PORT_1L;
#define RX_BUFFER_SIZE 256
/* USB Endpoint Defines */
#define XUD_EP_COUNT_OUT 2 //Includes EP0 (1 OUT EP0 + 1 BULK OUT EP)
#define XUD_EP_COUNT_IN 3 //Includes EP0 (1 IN EP0 + 1 INTERRUPT IN EP + 1 BULK IN EP)
/* Endpoint type tables - informs XUD what the transfer types for each Endpoint in use and also
* if the endpoint wishes to be informed of USB bus resets
*/
XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_BUL};
XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_INT, XUD_EPTYPE_BUL};
/* Application task */
void app_virtual_com(client interface usb_cdc_interface cdc,
client uart_rx_if uart_rx , client uart_tx_buffered_if uart_tx,
client uart_config_if i_tx_cfg, client uart_config_if i_rx_cfg
){
static unsigned baud,lbaud=115200,cba=0,cps;
unsigned char databuf[1024];
while (1)
{
cps=cdc.available_bytes();
while(cps && uart_tx.get_available_buffer_size()>512)
{
// char cdc_char = cdc.get_char();
if(cps>uart_tx.get_available_buffer_size()) cps = uart_tx.get_available_buffer_size(); //maybe
cdc.read(databuf,cps);
for (int i=0; i<cps; i++) uart_tx.write(databuf[i]);
if (cps > 100)
cba += cps;
cps=cdc.available_bytes();
}
if(get_global()&0x2000000) {
//usb set speed reconfig uart
baud = get_global()&0xffffff;
if(baud > 1000000 || baud < 10000) baud=0; //error unsupported speed
else if(baud != lbaud) {
lbaud=baud;
cba++;
i_tx_cfg.set_baud_rate(baud);
i_rx_cfg.set_baud_rate(baud);
}
set_global(baud);
}
// Wait for a byte to uart
select {
case uart_rx.data_ready():
uint8_t data = uart_rx.read();
cdc.put_char(data);
break;
default : break;
}
}
}
int main()
{
/* Channels to communicate with USB endpoints */
chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
/* Interface to communicate with USB CDC (Virtual Serial) */
interface usb_cdc_interface cdc_data;
interface uart_rx_if i_rx;
interface uart_tx_buffered_if i_tx;
interface uart_config_if i_tx_cfg, i_rx_cfg;
input_gpio_if i_gpio_rx[1];
output_gpio_if i_gpio_tx[1];
par
{
on USB_TILE: XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
XUD_SPEED_HS, XUD_PWR_SELF);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
on USB_TILE: CdcEndpointsHandler(c_ep_in[1], c_ep_out[1], c_ep_in[2], cdc_data);
on tile[0]: output_gpio(i_gpio_tx, 1, p_uart_tx, null);
on tile[0]: uart_tx_buffered(i_tx, i_tx_cfg, 16384, 115200, UART_PARITY_NONE, 8, 1, i_gpio_tx[0]);
on tile[0].core[0] : input_gpio_with_events(i_gpio_rx, 1, p_uart_rx, null);
on tile[0].core[0] : uart_rx(i_rx, i_rx_cfg, RX_BUFFER_SIZE, 115200, UART_PARITY_NONE, 8, 1,
i_gpio_rx[0]);
on tile[0]: app_virtual_com(cdc_data , i_rx, i_tx ,i_tx_cfg, i_rx_cfg);
}
return 0;
}