Skip to content

Commit

Permalink
release v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
josuah committed Dec 20, 2023
1 parent a2c2fe5 commit bdd0dca
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v1.5.0

* In the USB DFU interface, swap the alt=0 and alt=1 numbers to get APIO and
IceStudio to work again out of the box.

* Fix DFU CRAM programming.

## v1.3.1

* Make USB enumerate better in MacOS and everywhere (@dicristina).
Expand Down
4 changes: 2 additions & 2 deletions examples/pico_blinky_cplusplus/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ char const *tud_string_desc[STRID_NUM_TOTAL] = {
[STRID_PRODUCT] = USB_PRODUCT,
[STRID_SERIAL_NUMBER] = usb_serial_number,
[STRID_VENDOR] = USB_VENDOR,
[STRID_DFU+0] = "iCE40 DFU (CRAM)",
[STRID_DFU+1] = "iCE40 DFU (Flash)",
[STRID_DFU+0] = "iCE40 DFU (Flash)",
[STRID_DFU+1] = "iCE40 DFU (CRAM)",
};
4 changes: 2 additions & 2 deletions examples/pico_fpga_io/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ char const *tud_string_desc[STRID_NUM_TOTAL] = {
[STRID_PRODUCT] = USB_PRODUCT,
[STRID_SERIAL_NUMBER] = usb_serial_number,
[STRID_VENDOR] = USB_VENDOR,
[STRID_DFU+0] = "iCE40 DFU (CRAM)",
[STRID_DFU+1] = "iCE40 DFU (Flash)",
[STRID_DFU+0] = "iCE40 DFU (Flash)",
[STRID_DFU+1] = "iCE40 DFU (CRAM)",
};
4 changes: 2 additions & 2 deletions examples/pico_usb_fpga/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ char const *tud_string_desc[STRID_NUM_TOTAL] = {
[STRID_VENDOR] = USB_VENDOR,
[STRID_CDC+0] = "RP2040 logs",
[STRID_CDC+1] = "iCE40 UART",
[STRID_DFU+0] = "iCE40 DFU (CRAM)",
[STRID_DFU+1] = "iCE40 DFU (Flash)",
[STRID_DFU+0] = "iCE40 DFU (Flash)",
[STRID_DFU+1] = "iCE40 DFU (CRAM)",
};
4 changes: 2 additions & 2 deletions examples/pico_usb_spi/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ char const *tud_string_desc[STRID_NUM_TOTAL] = {
[STRID_VENDOR] = USB_VENDOR,
[STRID_CDC+0] = "RP2040 logs",
[STRID_CDC+1] = "SPI",
[STRID_DFU+0] = "iCE40 DFU (CRAM)",
[STRID_DFU+1] = "iCE40 DFU (Flash)",
[STRID_DFU+0] = "iCE40 DFU (Flash)",
[STRID_DFU+1] = "iCE40 DFU (CRAM)",
};
4 changes: 2 additions & 2 deletions examples/pico_usb_uart/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ char const *tud_string_desc[STRID_NUM_TOTAL] = {
[STRID_VENDOR] = USB_VENDOR,
[STRID_CDC+0] = "RP2040 logs",
[STRID_CDC+1] = "iCE40 UART",
[STRID_DFU+0] = "iCE40 DFU (CRAM)",
[STRID_DFU+1] = "iCE40 DFU (Flash)",
[STRID_DFU+0] = "iCE40 DFU (Flash)",
[STRID_DFU+1] = "iCE40 DFU (CRAM)",
};
4 changes: 2 additions & 2 deletions examples/pico_usb_uf2/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ char const *tud_string_desc[STRID_NUM_TOTAL] = {
[STRID_VENDOR] = USB_VENDOR,
[STRID_CDC+0] = "RP2040 logs",
[STRID_MSC+0] = "iCE40 MSC (Flash)",
[STRID_DFU+0] = "iCE40 DFU (CRAM)",
[STRID_DFU+1] = "iCE40 DFU (Flash)",
[STRID_DFU+0] = "iCE40 DFU (Flash)",
[STRID_DFU+1] = "iCE40 DFU (CRAM)",
};
5 changes: 3 additions & 2 deletions src/ice_cram.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "hardware/pio.h"
#include "pico/time.h"
#include "boards/pico_ice.h"
#include "ice_fpga.h"
#include "ice_cram.pio.h"

static PIO pio;
Expand Down Expand Up @@ -110,11 +111,11 @@ static void wait_idle(void)
void ice_cram_open(void)
{
// Hold FPGA in reset before doing anything with SPI bus.
gpio_put(ICE_FPGA_CRESET_B_PIN, false);
ice_fpga_stop();

state_machine_init();

// SPI_SS low signals FPGA to receive bitstream.
// SPI_SS low signals FPGA to receive the bitstream.
gpio_init(ICE_CRAM_CSN_PIN);
gpio_put(ICE_CRAM_CSN_PIN, false);
gpio_set_dir(ICE_CRAM_CSN_PIN, GPIO_OUT);
Expand Down
47 changes: 27 additions & 20 deletions src/ice_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@

#define WATCHDOG_DELAY 3000

#define DFU_ALT_CRAM 0
#define DFU_ALT_FLASH 1
#define DFU_ALT_FLASH 0
#define DFU_ALT_CRAM 1

// Provide a default config where some fields come be customized in <tusb_config.h>
const tusb_desc_device_t tud_desc_device = {
Expand Down Expand Up @@ -332,10 +332,12 @@ uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state)
return 0; // Request we are polled in 1ms
}

static bool dfu_init_done;
static bool dfu_ongoing;

void dfu_init(uint8_t alt)
{
ice_spi_init();

switch (alt) {
case DFU_ALT_CRAM:
ice_cram_open();
Expand All @@ -353,46 +355,49 @@ void dfu_init(uint8_t alt)

// Disable all interrupts except USB.
irq_set_mask_enabled(~(1 << USBCTRL_IRQ), false);

// Make sure the RP2040 have full access to the SPI bus
ice_fpga_stop();
break;
}

// Make sure the RP2040 have full access to the SPI bus
ice_fpga_stop();
ice_spi_init();
}

// Invoked when received DFU_DNLOAD (wLength>0) following by DFU_GETSTATUS (state=DFU_DNBUSY) requests
// This callback could be returned before flashing op is complete (async).
// Once finished flashing, application must call tud_dfu_finish_flashing()
void tud_dfu_download_cb(uint8_t alt, uint16_t block_num, const uint8_t *data, uint16_t length)
{
uint32_t dest_addr;
uint32_t addr;

ice_spi_wait_completion();

if (!dfu_init_done) {
if (!dfu_ongoing) {
dfu_init(alt);
dfu_init_done = true;
dfu_ongoing = true;
}

watchdog_update();

dest_addr = block_num * CFG_TUD_DFU_XFER_BUFSIZE;
addr = block_num * CFG_TUD_DFU_XFER_BUFSIZE;
for (uint32_t i = 0; i < length; i += ICE_FLASH_PAGE_SIZE) {
switch (alt) {
case DFU_ALT_CRAM:
ice_cram_write(data, length);
break;
case DFU_ALT_FLASH:
if ((dest_addr + i) % ICE_FLASH_SECTOR_SIZE == 0) {
ice_flash_erase_sector(dest_addr + i);
watchdog_update();

if ((addr + i) % ICE_FLASH_SECTOR_SIZE == 0) {
ice_flash_erase_sector(addr + i);
}
ice_flash_program_page(dest_addr + i, data + i);
ice_flash_program_page(addr + i, data + i);
break;
}
}

tud_dfu_finish_flashing(DFU_STATUS_OK);

while (dfu_ongoing) {
tud_task();
}
}

// Invoked when download process is complete, received DFU_DNLOAD (wLength=0)
Expand All @@ -405,14 +410,16 @@ void tud_dfu_manifest_cb(uint8_t alt)

switch (alt) {
case DFU_ALT_CRAM:
ice_cram_close();
ok = ice_cram_close();
break;
case DFU_ALT_FLASH:
ok = ice_fpga_start();
break;
}

ok = ice_fpga_start();
tud_dfu_finish_flashing(ok ? DFU_STATUS_OK : DFU_STATUS_ERR_FIRMWARE);

// Next init is not done yet
dfu_init_done = false;
dfu_ongoing = false;
}

// Called if -R option passed to dfu-util.
Expand Down

0 comments on commit bdd0dca

Please sign in to comment.