Add flash status read
This commit is contained in:
@ -39,11 +39,13 @@
|
||||
#define W25Q80BV_WRITE_ENABLE 0x06
|
||||
#define W25Q80BV_CHIP_ERASE 0xC7
|
||||
#define W25Q80BV_READ_STATUS1 0x05
|
||||
#define W25Q80BV_READ_STATUS2 0x35
|
||||
#define W25Q80BV_PAGE_PROGRAM 0x02
|
||||
#define W25Q80BV_DEVICE_ID 0xAB
|
||||
#define W25Q80BV_UNIQUE_ID 0x4B
|
||||
|
||||
#define W25Q80BV_STATUS_BUSY 0x01
|
||||
#define W25Q80BV_STATUS_WEL 0x02
|
||||
|
||||
#define W25Q80BV_DEVICE_ID_RES 0x13 /* Expected device_id for W25Q80BV */
|
||||
|
||||
@ -74,6 +76,17 @@ uint8_t w25q80bv_get_status(w25q80bv_driver_t* const drv)
|
||||
return data[1];
|
||||
}
|
||||
|
||||
void w25q80bv_get_full_status(w25q80bv_driver_t* const drv, uint8_t* data)
|
||||
{
|
||||
uint8_t cmd[] = { W25Q80BV_READ_STATUS1, 0xFF };
|
||||
spi_bus_transfer(drv->bus, cmd, ARRAY_SIZE(cmd));
|
||||
data[0] = cmd[1];
|
||||
cmd[0] =W25Q80BV_READ_STATUS2;
|
||||
cmd[1] = 0xFF;
|
||||
spi_bus_transfer(drv->bus, cmd, ARRAY_SIZE(cmd));
|
||||
data[1] = cmd[1];
|
||||
}
|
||||
|
||||
/* Release power down / Device ID */
|
||||
uint8_t w25q80bv_get_device_id(w25q80bv_driver_t* const drv)
|
||||
{
|
||||
@ -110,6 +123,7 @@ void w25q80bv_write_enable(w25q80bv_driver_t* const drv)
|
||||
|
||||
uint8_t data[] = { W25Q80BV_WRITE_ENABLE };
|
||||
spi_bus_transfer(drv->bus, data, ARRAY_SIZE(data));
|
||||
while (w25q80bv_get_status(drv) ^ W25Q80BV_STATUS_WEL);
|
||||
}
|
||||
|
||||
void w25q80bv_chip_erase(w25q80bv_driver_t* const drv)
|
||||
|
@ -53,6 +53,7 @@ struct w25q80bv_driver_t {
|
||||
};
|
||||
|
||||
void w25q80bv_setup(w25q80bv_driver_t* const drv);
|
||||
void w25q80bv_get_full_status(w25q80bv_driver_t* const drv, uint8_t* data);
|
||||
void w25q80bv_chip_erase(w25q80bv_driver_t* const drv);
|
||||
void w25q80bv_program(w25q80bv_driver_t* const drv, uint32_t addr, uint32_t len, uint8_t* data);
|
||||
uint8_t w25q80bv_get_device_id(w25q80bv_driver_t* const drv);
|
||||
|
@ -89,7 +89,8 @@ static const usb_request_handler_fn vendor_request_handler[] = {
|
||||
usb_vendor_request_operacake_set_ports,
|
||||
usb_vendor_request_set_hw_sync_mode,
|
||||
usb_vendor_request_reset,
|
||||
usb_vendor_request_operacake_set_ranges
|
||||
usb_vendor_request_operacake_set_ranges,
|
||||
usb_vendor_request_spiflash_status
|
||||
};
|
||||
|
||||
static const uint32_t vendor_request_handler_count =
|
||||
|
@ -121,3 +121,18 @@ usb_request_status_t usb_vendor_request_read_spiflash(
|
||||
}
|
||||
}
|
||||
|
||||
usb_request_status_t usb_vendor_request_spiflash_status(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
|
||||
{
|
||||
uint8_t data[2];
|
||||
if (stage == USB_TRANSFER_STAGE_SETUP) {
|
||||
w25q80bv_get_full_status(&spi_flash, data);
|
||||
usb_transfer_schedule_block(endpoint->in, &data, 2, NULL, NULL);
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
} else if (stage == USB_TRANSFER_STAGE_DATA) {
|
||||
usb_transfer_schedule_ack(endpoint->out);
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
} else {
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -32,5 +32,7 @@ usb_request_status_t usb_vendor_request_write_spiflash(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||
usb_request_status_t usb_vendor_request_read_spiflash(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||
usb_request_status_t usb_vendor_request_spiflash_status(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||
|
||||
#endif /* end of include guard: __USB_API_SPIFLASH_H__ */
|
||||
|
Submodule firmware/libopencm3 updated: d3d6f3e74b...c9f40aae0b
@ -102,6 +102,7 @@ static void usage()
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int opt;
|
||||
uint8_t status[2];
|
||||
uint32_t address = 0;
|
||||
uint32_t length = MAX_LENGTH;
|
||||
uint32_t tmp_length;
|
||||
@ -278,6 +279,8 @@ int main(int argc, char** argv)
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
hackrf_spiflash_status(device, status);
|
||||
printf("Status: 0x%02x %02x\n", status[0], status[1]);
|
||||
printf("Erasing SPI flash.\n");
|
||||
result = hackrf_spiflash_erase(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
@ -289,6 +292,8 @@ int main(int argc, char** argv)
|
||||
}
|
||||
if( !verbose ) printf("Writing %d bytes at 0x%06x.\n", length, address);
|
||||
while (length) {
|
||||
hackrf_spiflash_status(device, status);
|
||||
printf("Status: 0x%02x %02x\n", status[0], status[1]);
|
||||
xfer_len = (length > 256) ? 256 : length;
|
||||
if( verbose ) printf("Writing %d bytes at 0x%06x.\n", xfer_len, address);
|
||||
result = hackrf_spiflash_write(device, address, xfer_len, pdata);
|
||||
|
@ -79,6 +79,7 @@ typedef enum {
|
||||
HACKRF_VENDOR_REQUEST_SET_HW_SYNC_MODE = 29,
|
||||
HACKRF_VENDOR_REQUEST_RESET = 30,
|
||||
HACKRF_VENDOR_REQUEST_OPERACAKE_SET_RANGES = 31,
|
||||
HACKRF_VENDOR_REQUEST_SPIFLASH_STATUS = 32,
|
||||
} hackrf_vendor_request;
|
||||
|
||||
#define USB_CONFIG_STANDARD 0x1
|
||||
@ -957,6 +958,30 @@ int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address,
|
||||
}
|
||||
}
|
||||
|
||||
int ADDCALL hackrf_spiflash_status(hackrf_device* device, uint8_t* data)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = libusb_control_transfer(
|
||||
device->usb_device,
|
||||
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
||||
HACKRF_VENDOR_REQUEST_SPIFLASH_STATUS,
|
||||
0,
|
||||
0,
|
||||
data,
|
||||
2,
|
||||
0
|
||||
);
|
||||
|
||||
if (result < 1)
|
||||
{
|
||||
last_libusb_error = result;
|
||||
return HACKRF_ERROR_LIBUSB;
|
||||
} else {
|
||||
return HACKRF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
int ADDCALL hackrf_cpld_write(hackrf_device* device,
|
||||
unsigned char* const data, const unsigned int total_length)
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ extern ADDAPI int ADDCALL hackrf_rffc5071_write(hackrf_device* device, uint8_t r
|
||||
extern ADDAPI int ADDCALL hackrf_spiflash_erase(hackrf_device* device);
|
||||
extern ADDAPI int ADDCALL hackrf_spiflash_write(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* const data);
|
||||
extern ADDAPI int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* data);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_spiflash_status(hackrf_device* device, uint8_t* data);
|
||||
/* device will need to be reset after hackrf_cpld_write */
|
||||
extern ADDAPI int ADDCALL hackrf_cpld_write(hackrf_device* device,
|
||||
unsigned char* const data, const unsigned int total_length);
|
||||
|
Reference in New Issue
Block a user