Only perform W25Q80BV setup once, at startup.

hackrf_usb firmware does not run from SPI flash once the ROM bootloader is done. Simplify assumptions by initializing SPI flash once, early. Do not initialize it every 256 bytes that are read from or written to the device.
This commit is contained in:
Jared Boone
2015-08-28 13:03:40 -07:00
parent a4e447cb9e
commit 2022cc6351
2 changed files with 4 additions and 9 deletions

View File

@ -47,6 +47,7 @@
#include "sgpio_isr.h"
#include "usb_bulk_buffer.h"
#include "si5351c.h"
#include "w25q80bv.h"
static volatile transceiver_mode_t _transceiver_mode = TRANSCEIVER_MODE_OFF;
@ -224,6 +225,9 @@ int main(void) {
#endif
cpu_clock_init();
/* Code is not running from SPI flash, initialize for flash read/write over USB */
w25q80bv_setup();
usb_set_descriptor_by_serial_number();
usb_set_configuration_changed_cb(usb_configuration_changed);

View File

@ -33,14 +33,10 @@ uint8_t spiflash_buffer[W25Q80BV_PAGE_LEN];
usb_request_status_t usb_vendor_request_erase_spiflash(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
//FIXME This should refuse to run if executing from SPI flash.
if (stage == USB_TRANSFER_STAGE_SETUP) {
w25q80bv_setup();
/* only chip erase is implemented */
w25q80bv_chip_erase();
usb_transfer_schedule_ack(endpoint->in);
//FIXME probably should undo w25q80bv_setup()
}
return USB_REQUEST_STATUS_OK;
}
@ -51,8 +47,6 @@ usb_request_status_t usb_vendor_request_write_spiflash(
uint32_t addr = 0;
uint16_t len = 0;
//FIXME This should refuse to run if executing from SPI flash.
if (stage == USB_TRANSFER_STAGE_SETUP) {
addr = (endpoint->setup.value << 16) | endpoint->setup.index;
len = endpoint->setup.length;
@ -62,7 +56,6 @@ usb_request_status_t usb_vendor_request_write_spiflash(
} else {
usb_transfer_schedule_block(endpoint->out, &spiflash_buffer[0], len,
NULL, NULL);
w25q80bv_setup();
return USB_REQUEST_STATUS_OK;
}
} else if (stage == USB_TRANSFER_STAGE_DATA) {
@ -75,7 +68,6 @@ usb_request_status_t usb_vendor_request_write_spiflash(
} else {
w25q80bv_program(addr, len, &spiflash_buffer[0]);
usb_transfer_schedule_ack(endpoint->in);
//FIXME probably should undo w25q80bv_setup()
return USB_REQUEST_STATUS_OK;
}
} else {
@ -97,7 +89,6 @@ usb_request_status_t usb_vendor_request_read_spiflash(
|| ((addr + len) > W25Q80BV_NUM_BYTES)) {
return USB_REQUEST_STATUS_STALL;
} else {
w25q80bv_setup();
w25q80bv_read(addr, len, &spiflash_buffer[0]);
usb_transfer_schedule_block(endpoint->in, &spiflash_buffer[0], len,
NULL, NULL);