Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dfu_debug/config.xscope
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<xSCOPEconfig ioMode="basic" enabled="true"/>
13 changes: 13 additions & 0 deletions dfu_debug/dfu_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2019, XMOS Ltd, All rights reserved
#ifndef __dfu_handler_h__
#define __dfu_handler_h__

#include <xccompat.h>

#ifdef __XC__
[[distributable]] [[combinable]]
#endif
void DFUHandler(SERVER_INTERFACE(i_dfu, i),
NULLABLE_RESOURCE(chanend, c_user_cmd));

#endif
12 changes: 12 additions & 0 deletions dfu_debug/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2019, XMOS Ltd, All rights reserved
XUA = ../lib_xua/src/dfu

all:
xcc vfst_base_usb.xn \
-Os -lquadflash \
-D XUD_SERIES_SUPPORT=4 -D DFU_DEBUG=1 -D START_IN_DFU=1 \
-I . -I ${XUA} \
${XUA}/dfu.xc ${XUA}/flash_interface.c ${XUA}/flashlib_user.c \
config.xscope \
test.xc xud.xc requests.c
xobjdump -d a.xe > objdump
138 changes: 138 additions & 0 deletions dfu_debug/requests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Copyright (c) 2019, XMOS Ltd, All rights reserved
#include <xs1.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <xccompat.h>
#include "xud_device.h"
#include "dfu_interface.h"
#include "dfu_types.h"
#include "xua.h"
#include "xua_dfu.h"
#include "requests.h"

#define DFU_BLOCK 64

void get_status(CLIENT_INTERFACE(i_dfu, i))
{
printf("+ get_status\n");

USB_SetupPacket_t sp;

sp.bmRequestType.Recipient = USB_BM_REQTYPE_RECIP_INTER;
sp.bmRequestType.Type = USB_BM_REQTYPE_TYPE_CLASS;
sp.bmRequestType.Direction = USB_BM_REQTYPE_DIRECTION_D2H;
sp.bRequest = DFU_GETSTATUS;
sp.wValue = 0;
sp.wIndex = 0;
sp.wLength = 1;

XUD_ep epout = 0, epin = 0;
int reset = 0;

DFUDeviceRequests(epout, &epin, &sp, (chanend)NULL, 0, i, &reset);

int data_len = 0;
unsigned char data[64];

xud_read_get_data(data, &data_len);

printf("- get_data %d state=%d timeout=%d next_state=%d\n",
data_len, data[0], data[1], data[4]);
}

void download_block(CLIENT_INTERFACE(i_dfu, i), int block_num,
unsigned char data[], int data_length)
{
if (data_length == 0) {
printf("+ download_block %d 0 NULL\n", block_num);
}
else {
printf("+ download_block %d %d 0x%x 0x%x\n", block_num, data_length,
data[0], data[data_length - 1]);
}

USB_SetupPacket_t sp;

sp.bmRequestType.Recipient = USB_BM_REQTYPE_RECIP_INTER;
sp.bmRequestType.Type = USB_BM_REQTYPE_TYPE_CLASS;
sp.bmRequestType.Direction = USB_BM_REQTYPE_DIRECTION_H2D;
sp.bRequest = DFU_DNLOAD;
sp.wValue = block_num;
sp.wIndex = 0;
sp.wLength = data_length;

if (data_length > 0)
xud_prepare_set_data(data, data_length);

XUD_ep epout = 0, epin = 0;
int reset = 0;

DFUDeviceRequests(epout, &epin, &sp, (chanend)NULL, 0, i, &reset);

int set_status = xud_read_set_status();

printf("- set_status %d\n", set_status);
}

void download(CLIENT_INTERFACE(i_dfu, i), const char file_name[])
{
FILE *f = fopen(file_name, "rb" );
assert(f != NULL);
fseek(f, 0, SEEK_END);
int file_size = (int)ftell(f);
fseek(f, 0, SEEK_SET);
int num_blocks = file_size / DFU_BLOCK;
int remainder = file_size - num_blocks * DFU_BLOCK;
unsigned char block[DFU_BLOCK];
int block_count = 0;

for (int j = 0; j < num_blocks; j++) {
memset(block, 0, DFU_BLOCK);
fread(block, 1, DFU_BLOCK, f);
download_block(i, block_count, block, DFU_BLOCK);
get_status(i);
block_count++;
}

if (remainder > 0) {
memset(block, 0, DFU_BLOCK);
fread(block, 1, remainder, f);
download_block(i, block_count, block, DFU_BLOCK);
get_status(i);
}

// zero length to terminate
download_block(i, 0, block, 0);
get_status(i);
}

void revertfactory(CLIENT_INTERFACE(i_dfu, i))
{
printf("+ revertfactory\n");

USB_SetupPacket_t sp;

sp.bmRequestType.Recipient = USB_BM_REQTYPE_RECIP_INTER;
sp.bmRequestType.Type = USB_BM_REQTYPE_TYPE_CLASS;
sp.bmRequestType.Direction = USB_BM_REQTYPE_DIRECTION_H2D;
sp.bRequest = XMOS_DFU_REVERTFACTORY;
sp.wValue = 0;
sp.wIndex = 0;
sp.wLength = 0;

XUD_ep epout = 0, epin = 0;
int reset = 0;

DFUDeviceRequests(epout, &epin, &sp, (chanend)NULL, 0, i, &reset);

int set_status = xud_read_set_status();

printf("- set_status %d\n", set_status);
}

void initialise(void)
{
DFUReportResetState((chanend)NULL);
}
11 changes: 11 additions & 0 deletions dfu_debug/requests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2019, XMOS Ltd, All rights reserved
#ifndef __requests_h__
#define __requests_h__

#include <xccompat.h>

void initialise(void);
void download(CLIENT_INTERFACE(i_dfu, i), const char file_name[]);
void revertfactory(CLIENT_INTERFACE(i_dfu, i));

#endif
25 changes: 25 additions & 0 deletions dfu_debug/test.xc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2019, XMOS Ltd, All rights reserved
#include <xs1.h>
#include <stdlib.h>
#include "xua.h"
#include "dfu_interface.h"
#include "dfu_handler.h"
#include "requests.h"

void test(client interface i_dfu i)
{
initialise();
download(i, "222.bin");
//revertfactory(i);
exit(0);
}

int main(void)
{
interface i_dfu i;
par {
test(i);
DFUHandler(i, null);
}
return 0;
}
9 changes: 9 additions & 0 deletions dfu_debug/uac_hwresources.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2019, XMOS Ltd, All rights reserved
#ifndef __uac_hwresources_h__
#define __uac_hwresources_h__

#include <xs1.h>

#define CLKBLK_FLASHLIB XS1_CLKBLK_1

#endif
122 changes: 122 additions & 0 deletions dfu_debug/vfst_base_usb.xn
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<Network xmlns="http://www.xmos.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xmos.com http://www.xmos.com">
<Type>Board</Type>
<Name>Mic Array Motherboard - Quad Tile - 167BGA</Name>

<Declarations>
<Declaration>tileref tile[4]</Declaration>
<Declaration>tileref usb_tile</Declaration>
</Declarations>

<Packages>
<Package id="0" Type="XS2-UFnA-1024-FB374">
<Nodes>
<Node Id="0" InPackageId="0" Type="XS2-L16A-512" SystemFrequency="500MHz" OscillatorSrc="1">
<Boot>
<Source Location="bootFlash0"/>
<Bootee NodeId="2"/>
</Boot>
<Tile Number="0" Reference="tile[0]">
<!-- QSPI Flash -->
<Port Location="XS1_PORT_1B" Name="PORT_SQI_CS_0"/>
<Port Location="XS1_PORT_1C" Name="PORT_SQI_SCLK_0"/>
<Port Location="XS1_PORT_4B" Name="PORT_SQI_SIO_0"/>
</Tile>
<Tile Number="1" Reference="tile[1]">
<!-- USB -->
<Port Location="XS1_PORT_1H" Name="PORT_USB_TX_READYIN"/>
<Port Location="XS1_PORT_1J" Name="PORT_USB_CLK"/>
<Port Location="XS1_PORT_1K" Name="PORT_USB_TX_READYOUT"/>
<Port Location="XS1_PORT_1I" Name="PORT_USB_RX_READY"/>
<Port Location="XS1_PORT_1E" Name="PORT_USB_FLAG0"/>
<Port Location="XS1_PORT_1F" Name="PORT_USB_FLAG1"/>
<Port Location="XS1_PORT_1G" Name="PORT_USB_FLAG2"/>
<Port Location="XS1_PORT_8A" Name="PORT_USB_TXD"/>
<Port Location="XS1_PORT_8B" Name="PORT_USB_RXD"/>
<Port Location="XS1_PORT_16B" Name="PORT_MCLK_COUNT"/>
<Port Location="XS1_PORT_1C" Name="PORT_MCLK_IN2"/>
</Tile>
</Node>
<Node Id="2" InPackageId="2" Type="XS2-L16A-512" SystemFrequency="500MHz" OscillatorSrc="1">
<Boot>
<Source Location="LINK" BootMode="4"/>
</Boot>
<Tile Number="0" Reference="tile[2]">
<!-- Audio Ports -->
<Port Location="XS1_PORT_1G" Name="PORT_MCLK_IN"/>
<Port Location="XS1_PORT_1L" Name="PORT_I2S_LRCLK"/>
<Port Location="XS1_PORT_1M" Name="PORT_I2S_BCLK"/>
<Port Location="XS1_PORT_1K" Name="PORT_I2S_DAC0"/>
<Port Location="XS1_PORT_1E" Name="PORT_I2S_ADC0"/>
<!-- Mics -->
<Port Location="XS1_PORT_1H" Name="PORT_PDM_CLK"/>
<Port Location="XS1_PORT_8B" Name="PORT_PDM_DATA"/>
<Port Location="XS1_PORT_1G" Name="PORT_PDM_MCLK"/> <!-- overlap with PORT_MCLK_IN -->
</Tile>
<Tile Number="1" Reference="tile[3]">
<!-- LED ports -->
<Port Location="XS1_PORT_1A" Name="PORT_LED_STCP"/>
<Port Location="XS1_PORT_1B" Name="PORT_LED_SHCP"/>
<Port Location="XS1_PORT_1E" Name="PORT_LED_DATA"/>
<Port Location="XS1_PORT_1F" Name="PORT_LED_OE_N"/>
</Tile>
</Node>
<Node Id="1" InPackageId="1" Type="periph:XS1-SU" Reference="usb_tile" Oscillator="24MHz">
</Node>
</Nodes>
<Links>
<Link Encoding="5wire" Delays="3clk">
<LinkEndpoint NodeId="0" Link="7"/>
<LinkEndpoint NodeId="2" Link="0"/>
</Link>
<Link Encoding="5wire" Delays="3clk">
<LinkEndpoint NodeId="0" Link="4"/>
<LinkEndpoint NodeId="2" Link="3"/>
</Link>
<Link Encoding="5wire" Delays="3clk">
<LinkEndpoint NodeId="0" Link="6"/>
<LinkEndpoint NodeId="2" Link="1"/>
</Link>
<Link Encoding="5wire" Delays="3clk">
<LinkEndpoint NodeId="0" Link="5"/>
<LinkEndpoint NodeId="2" Link="2"/>
</Link>
<Link Encoding="5wire">
<LinkEndpoint NodeId="0" Link="8" Delays="52clk,52clk"/>
<LinkEndpoint NodeId="1" Link="XL0" Delays="1clk,1clk"/>
</Link>
</Links>
</Package>
</Packages>

<Nodes>
<Node Id="3" Type="device:" RoutingId="0x8000">
<Service Id="0" Proto="xscope_host_data(chanend c);">
<Chanend Identifier="c" end="3"/>
</Service>
</Node>
</Nodes>

<Links>
<Link Encoding="2wire" Delays="4,4" Flags="XSCOPE">
<LinkEndpoint NodeId="0" Link="XL0"/>
<LinkEndpoint NodeId="3" Chanend="1"/>
</Link>
</Links>

<ExternalDevices>
<Device NodeId="0" Tile="0" Class="SQIFlash" Name="bootFlash0">
<Attribute Name="PORT_SQI_CS" Value="PORT_SQI_CS_0"/>
<Attribute Name="PORT_SQI_SCLK" Value="PORT_SQI_SCLK_0"/>
<Attribute Name="PORT_SQI_SIO" Value="PORT_SQI_SIO_0"/>
</Device>
</ExternalDevices>

<JTAGChain>
<JTAGDevice NodeId="0"/>
<JTAGDevice NodeId="2"/>
</JTAGChain>

</Network>
46 changes: 46 additions & 0 deletions dfu_debug/xua.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2019, XMOS Ltd, All rights reserved
#ifndef __xua_h__
#define __xua_h__

#include <xs1.h>

#define DFU_VENDOR_ID 0x20B1
#define DFU_PID 19
#define BCD_DEVICE 0x220

#define XUA_DFU_EN 1

#define QUAD_SPI_FLASH 1

#define FL_QUADDEVICE_ISSI_IS25LQ016B_12_5MHZ \
{ \
20, /* Enum value to identify the flashspec in a list */ \
256, /* page size */ \
8192, /* num pages */ \
3, /* address size */ \
4, /* log2 clock divider */ \
0x9F, /* QSPI_RDID */ \
0, /* id dummy bytes */ \
3, /* id size in bytes */ \
0x9D4015, /* device id */ \
0x20, /* QSPI_SE */ \
4096, /* Sector erase is always 4KB */ \
0x06, /* QSPI_WREN */ \
0x04, /* QSPI_WRDI */ \
PROT_TYPE_NONE, /* no protection */ \
{{0,0},{0x00,0x00}}, /* QSPI_SP, QSPI_SU */ \
0x02, /* QSPI_PP */ \
0xEB, /* QSPI_READ_FAST */ \
1, /* 1 read dummy byte */ \
SECTOR_LAYOUT_REGULAR, /* mad sectors */ \
{4096,{0,{0}}}, /* regular sector sizes */ \
0x05, /* QSPI_RDSR */ \
0x01, /* QSPI_WRSR */ \
0x01, /* QSPI_WIP_BIT_MASK */ \
}

#define DFU_FLASH_DEVICE FL_QUADDEVICE_ISSI_IS25LQ016B_12_5MHZ

#define FLASH_MAX_UPGRADE_SIZE (512 * 1024)

#endif
Loading