diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-27 14:28:37 -0500 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-27 14:28:37 -0500 |
commit | 45aa04f4acda9d4e67eedef84bb2b8e87994f999 (patch) | |
tree | b9602a540235dda974151837c904c4b8b1d60a2d | |
parent | 3801ee6b19fdb62004d6655604788b9a820e8603 (diff) | |
download | Sensor-Watch-45aa04f4acda9d4e67eedef84bb2b8e87994f999.tar.gz Sensor-Watch-45aa04f4acda9d4e67eedef84bb2b8e87994f999.tar.bz2 Sensor-Watch-45aa04f4acda9d4e67eedef84bb2b8e87994f999.zip |
spi test: set first 4096 bytes to 0
-rw-r--r-- | apps/spi-test/app.c | 44 | ||||
-rw-r--r-- | watch-library/shared/driver/spiflash.c | 2 |
2 files changed, 35 insertions, 11 deletions
diff --git a/apps/spi-test/app.c b/apps/spi-test/app.c index fc78bbc5..006067a4 100644 --- a/apps/spi-test/app.c +++ b/apps/spi-test/app.c @@ -6,15 +6,30 @@ // this is a very basic app to confirm that SPI is working, tested with board OSO-MISC-21-017 and a GD25Q16C Flash chip. +static bool wait_for_flash_ready(void) { + watch_set_pin_level(A3, false); + bool ok = true; + uint8_t read_status_response[1] = {0x00}; + do { + ok = spi_flash_read_command(CMD_READ_STATUS, read_status_response, 1); + } while (ok && (read_status_response[0] & 0x3) != 0); + watch_set_pin_level(A3, true); + return ok; +} + void app_init(void) { spi_flash_init(); + delay_ms(5000); - uint8_t buf[3] = {1, 2, 3}; - watch_set_pin_level(A3, false); - spi_flash_command(CMD_ENABLE_WRITE); - watch_set_pin_level(A3, true); - // note that you will need to erase the sector to write different values later - spi_flash_write_data(0, buf, 3); + uint8_t buf[256] = {0}; + for(int i = 1; i < 16; i++) { + wait_for_flash_ready(); + watch_set_pin_level(A3, false); + spi_flash_command(CMD_ENABLE_WRITE); + watch_set_pin_level(A3, true); + wait_for_flash_ready(); + spi_flash_write_data(i * 256, buf, 256); + } } void app_wake_from_backup(void) { @@ -31,13 +46,20 @@ void app_wake_from_standby(void) { bool app_loop(void) { - uint8_t buf[3] = {0}; + uint8_t buf[4100] = {0}; + printf("loop\n"); - // should print 1, 2, 3 - spi_flash_read_data(0, buf, 3); - printf("data: %x, %x, %x\n", buf[0], buf[1], buf[2]); + wait_for_flash_ready(); + spi_flash_read_data(0, buf, 4100); + for(int i = 0; i < 4100; i++) { + if (buf[i] > 0) { + // should break at "byte 4096 is 255" + printf(" byte %d is %d!\n", i, buf[i]); + break; + } + } - delay_ms(100); + delay_ms(10000); return false; } diff --git a/watch-library/shared/driver/spiflash.c b/watch-library/shared/driver/spiflash.c index da6b2630..0fb7f437 100644 --- a/watch-library/shared/driver/spiflash.c +++ b/watch-library/shared/driver/spiflash.c @@ -88,7 +88,9 @@ bool spi_flash_write_data(uint32_t address, uint8_t *data, uint32_t data_length) address_to_bytes(address, request + 1); flash_enable(); bool status = watch_spi_write(request, 4); + printf("status? "); if (status) { + printf("status! Writing %d bytes to %02x %02x %02x\n", data_length, request[1], request[2], request[3]); status = watch_spi_write(data, data_length); } flash_disable(); |