This is an automated email from Gerrit. "Adrien Charruel <acharr...@nanoxplore.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8713
-- gerrit commit 949156bd43a7d822e88b589c6b129d3075f8a11f Author: Ahmed BOUDJELIDA <aboudjel...@nanoxplore.com> Date: Thu Dec 12 09:36:10 2024 +0100 contrib/firmware/angie: add GPIF configuration of ANGIE We make the proper GPIF configurations for OUT/IN transfers which are : the GPIF state machines for each direction OUT/IN We change the Vendor-commands to handle GPIF config before triggering it. Change-Id: I2f3bd7bed1a378536bf017336b5031683d93e3c1 Signed-off-by: Ahmed BOUDJELIDA <aboudjel...@nanoxplore.com> diff --git a/contrib/firmware/angie/c/src/main.c b/contrib/firmware/angie/c/src/main.c index bc8d2a3bb0..c5a04626bf 100644 --- a/contrib/firmware/angie/c/src/main.c +++ b/contrib/firmware/angie/c/src/main.c @@ -62,7 +62,8 @@ void gpif_init(void); int main(void) { - CPUCS = 0x10; /* Clock 48Mhz */ + CPUCS = ((CPUCS & ~bmclkspd) | (CLK_48M << 3) | CLKOE); /* required for sio0_init */ + sio0_init(115200); /* needed for printf */ ep_init(); gpif_init(); @@ -77,7 +78,4 @@ int main(void) /* stay here */ while (1) ; - - /* Never reached, but SDCC complains about missing return statement */ - return 0; } diff --git a/contrib/firmware/angie/c/src/usb.c b/contrib/firmware/angie/c/src/usb.c index bc888c9f77..5506114ec4 100644 --- a/contrib/firmware/angie/c/src/usb.c +++ b/contrib/firmware/angie/c/src/usb.c @@ -11,13 +11,16 @@ *****************************************************************************/ #include "usb.h" -#include "stdint.h" #include "delay.h" #include "io.h" #include "reg_ezusb.h" -#include <fx2macros.h> -#include <stdio.h> +#include "fx2macros.h" +#include "serial.h" #include "i2c.h" +#include <stdint.h> +#include <stdio.h> + +// #define PRINTF_DEBUG volatile __xdata __at 0xE6B8 struct setup_data setup_data; @@ -26,7 +29,6 @@ volatile __xdata __at 0xE6B8 struct setup_data setup_data; */ #define NUM_ENDPOINTS 2 - __code struct usb_device_descriptor device_descriptor = { .blength = sizeof(struct usb_device_descriptor), .bdescriptortype = DESCRIPTOR_TYPE_DEVICE, @@ -524,18 +526,6 @@ void usb_handle_set_interface(void) EP8BCH = 0; EP8BCL = 0x80; syncdelay(3); - EP2BCH = 0; - EP2BCL = 0x80; - syncdelay(3); - EP4BCH = 0; - EP4BCL = 0x80; - syncdelay(3); - EP6BCH = 0; - EP6BCL = 0x80; - syncdelay(3); - EP8BCH = 0; - EP8BCL = 0x80; - syncdelay(3); } /** @@ -606,54 +596,112 @@ void usb_handle_setup_data(void) /* Initialize GPIF interface transfer count */ void set_gpif_cnt(uint32_t count) { - EP1INCFG = 0x00; /* non VALID */ - syncdelay(3); - EP1OUTCFG = 0x00; /* non VALID */ + GPIFTCB3 = (uint8_t)(((uint32_t)(count) >> 24) & 0x000000ff); syncdelay(3); - - /* JTAG */ - EP2CFG = 0xA2; /* VALID | OUT | BULK | 512 Bytes | Double buffer */ + GPIFTCB2 = (uint8_t)(((uint32_t)(count) >> 16) & 0x000000ff); syncdelay(3); - EP4CFG = 0xE2; /* VALID | IN | BULK | 512 Bytes | Double buffer */ - syncdelay(3); - - /* I2C */ - EP6CFG = 0xA2; /* VALID | OUT | BULK | 512 Bytes | Double buffer */ - syncdelay(3); - EP8CFG = 0xE2; /* VALID | IN | BULK | 512 Bytes | Double buffer */ + GPIFTCB1 = (uint8_t)(((uint32_t)(count) >> 8) & 0x000000ff); syncdelay(3); + GPIFTCB0 = (uint8_t)((uint32_t)(count) & 0x000000ff); +} - /* arm EP6-OUT */ - EP6BCL = 0x80; - syncdelay(3); - EP6BCL = 0x80; - syncdelay(3); +/* + * Vendor commands handling: +*/ +#define VR_CFGOPEN 0xB0 +#define VR_DATAOUTOPEN 0xB2 - /* REVCTL.0 and REVCTL.1 set to 1 */ - REVCTL = 0x3; - /* Arm both EP2 buffers to “prime the pump” */ - OUTPKTEND = 0x82; - syncdelay(3); - OUTPKTEND = 0x82; - syncdelay(3); +uint8_t ix; +uint8_t bcnt; +uint8_t __xdata *eptr; +uint16_t wcnt; +uint32_t __xdata gcnt; +bool usb_handle_vcommands(void) +{ + eptr = EP0BUF; /* points to EP0BUF 64-byte register */ + wcnt = setup_data.wlength; /* total transfer count */ - /* Standard procedure to reset FIFOs */ - FIFORESET = BMNAKALL; /* NAK all transfers during the reset */ - syncdelay(3); - FIFORESET = BMNAKALL | 0x02; /* reset EP2 FIFO */ - syncdelay(3); - FIFORESET = BMNAKALL | 0x04; /* reset EP4 FIFO */ - syncdelay(3); - FIFORESET = 0x00; /* deactivate the NAK all */ - syncdelay(3); + /* Clear EP0BUF for OUT requests */ + if (setup_data.bmrequesttype & 0x80) { + bcnt = ((wcnt > 64) ? 64 : wcnt); + for (ix = 0; ix < bcnt; ix++) + eptr[ix] = 0; + } - /* configure EP2 in AUTO mode with 8-bit interface */ - EP2FIFOCFG = 0x00; - syncdelay(3); - EP2FIFOCFG = BMAUTOOUT; /* 8-bit Auto OUT mode */ - syncdelay(3); - EP4FIFOCFG = BMAUTOIN | BMZEROLENIN; /* 8-bit Auto IN mode */ - syncdelay(3); + switch (setup_data.brequest) { + case VR_CFGOPEN: + /* Clear bytecount / to allow new data in / to stops NAKing */ + EP0BCH = 0; + EP0BCL = 0; + while (EP0CS & EPBSY) + ; /* wait to finish transferring in EP0BUF, until not busy */ + gcnt = ((uint32_t)(eptr[0]) << 24) | ((uint32_t)(eptr[1]) << 16) + | ((uint32_t)(eptr[2]) << 8) | (uint32_t)(eptr[3]); + /* Angie board FPGA bitstream download */ + switch ((setup_data.wvalue) & 0x00C0) { + case 0x00: + /* Apply RPGM- pulse */ + PIN_PROGRAM_B = 0; + syncdelay(1); + /* Negate RPGM- pulse */ + PIN_PROGRAM_B = 1; + /* FPGA init time < 10mS */ + delay_ms(10); + /* Initialize GPIF interface transfer count */ + set_gpif_cnt(gcnt); + PIN_RDWR_B = 0; + PIN_SDA = 0; + /* Trigger GPIF OUT transfer on EP2 */ + GPIFTRIG = GPIF_EP2; + while (!(GPIFTRIG & BMGPIFDONE)) // poll GPIFTRIG.7 GPIF Done bit + ; + PIN_SDA = 1; + PIN_RDWR_B = 1; + #ifdef PRINTF_DEBUG + printf("Program SP6 Done.\n"); + #endif + /* Choose wich Waveform to use */ + GPIFWFSELECT = 0xF6; + break; + default: + break; + } + break; + case VR_DATAOUTOPEN: + /* Clear bytecount / to allow new data in / to stops NAKing */ + EP0BCH = 0; + EP0BCL = 0; + while (EP0CS & EPBSY) + ; /* wait to finish transferring in EP0BUF, until not busy */ + gcnt = ((uint32_t)(eptr[0]) << 24) | ((uint32_t)(eptr[1]) << 16) + | ((uint32_t)(eptr[2]) << 8) | (uint32_t)(eptr[3]); + /* Angie board FPGA bitstream download */ + PIN_RDWR_B = 0; + /* Initialize GPIF interface transfer count */ + GPIFTCB3 = (uint8_t)(((uint32_t)(gcnt) >> 24) & 0x000000ff); + GPIFTCB2 = (uint8_t)(((uint32_t)(gcnt) >> 16) & 0x000000ff); + GPIFTCB1 = (uint8_t)(((uint32_t)(gcnt) >> 8) & 0x000000ff); + GPIFTCB0 = (uint8_t)((uint32_t)(gcnt) & 0x000000ff); + /* Trigger GPIF OUT transfer on EP2 */ + GPIFTRIG = GPIF_EP2; + while (!(GPIFTRIG & BMGPIFDONE)) // poll GPIFTRIG.7 GPIF Done bit + ; + PIN_RDWR_B = 1; + /* Initialize GPIF interface transfer count */ + GPIFTCB3 = (uint8_t)(((uint32_t)(gcnt) >> 24) & 0x000000ff); + GPIFTCB2 = (uint8_t)(((uint32_t)(gcnt) >> 16) & 0x000000ff); + GPIFTCB1 = (uint8_t)(((uint32_t)(gcnt) >> 8) & 0x000000ff); + GPIFTCB0 = (uint8_t)((uint32_t)(gcnt) & 0x000000ff); + /* Initialize AUTOIN transfer count */ + EP4AUTOINLENH = (uint8_t)(((uint32_t)(gcnt) >> 8) & 0x000000ff); + EP4AUTOINLENL = (uint8_t)((uint32_t)(gcnt) & 0x000000ff); + /* Trigger GPIF IN transfer on EP4 */ + GPIFTRIG = BMGPIFREAD | GPIF_EP4; + break; + default: + return true; /* Error: unknown VR command */ + } + return false; /* no error; command handled OK */ } void i2c_recieve(void) --