You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2017/01/20 18:24:58 UTC
[09/12] incubator-mynewt-core git commit: Fix rollback writing beyond
end of page
Fix rollback writing beyond end of page
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/753a3893
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/753a3893
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/753a3893
Branch: refs/heads/develop
Commit: 753a3893645770de4402c5882dc0bc28488caa31
Parents: 8e08f3e
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 19 08:09:00 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Fri Jan 20 07:27:40 2017 -0200
----------------------------------------------------------------------
hw/drivers/flash/at45db/src/at45db.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/753a3893/hw/drivers/flash/at45db/src/at45db.c
----------------------------------------------------------------------
diff --git a/hw/drivers/flash/at45db/src/at45db.c b/hw/drivers/flash/at45db/src/at45db.c
index 12d1abc..664f430 100644
--- a/hw/drivers/flash/at45db/src/at45db.c
+++ b/hw/drivers/flash/at45db/src/at45db.c
@@ -83,7 +83,7 @@ static struct at45db_dev at45db_default_dev = {
.hf_base_addr = 0,
.hf_size = 8192 * 512, /* FIXME: depends on page size */
.hf_sector_cnt = 8192,
- .hf_align = 1,
+ .hf_align = 0,
},
/* SPI settings + updates baudrate on _init */
@@ -277,6 +277,7 @@ at45db_write(const struct hal_flash *hal_flash_dev, uint32_t addr,
at45db_wait_ready(dev);
bfa = addr % page_size;
+ start_addr = at45db_page_start_address(dev, addr);
/**
* If the page is not being written from the beginning,
@@ -287,8 +288,7 @@ at45db_write(const struct hal_flash *hal_flash_dev, uint32_t addr,
* be written back again.
*/
if (bfa || len < page_size) {
- at45db_read_page(dev, at45db_page_start_address(dev, addr),
- page_size, g_page_buffer);
+ at45db_read_page(dev, start_addr, page_size, g_page_buffer);
at45db_wait_ready(dev);
}
@@ -299,15 +299,9 @@ at45db_write(const struct hal_flash *hal_flash_dev, uint32_t addr,
hal_spi_tx_val(dev->spi_num, 0xff);
- start_addr = at45db_page_start_address(dev, addr);
-
- if (page_size == 512) {
- hal_spi_tx_val(dev->spi_num, (start_addr >> 8) & 1);
- } else {
- hal_spi_tx_val(dev->spi_num, (start_addr >> 8) & 3);
- }
-
- hal_spi_tx_val(dev->spi_num, start_addr);
+ /* Always write at offset 0 of internal buffer */
+ hal_spi_tx_val(dev->spi_num, 0);
+ hal_spi_tx_val(dev->spi_num, 0);
/**
* Write back extra stuff at the beginning of page.
@@ -336,7 +330,7 @@ at45db_write(const struct hal_flash *hal_flash_dev, uint32_t addr,
* Write back extra stuff at the ending of page.
*/
if (bfa + len < page_size) {
- for (n = len; n < page_size; n++) {
+ for (n = len + bfa; n < page_size; n++) {
hal_spi_tx_val(dev->spi_num, g_page_buffer[n]);
}
}
@@ -357,7 +351,7 @@ at45db_write(const struct hal_flash *hal_flash_dev, uint32_t addr,
pa = addr / page_size;
hal_spi_tx_val(dev->spi_num, (pa >> 6) & ~0x80);
- hal_spi_tx_val(dev->spi_num, (pa << 2) | 0x3);
+ hal_spi_tx_val(dev->spi_num, pa << 2);
hal_spi_tx_val(dev->spi_num, 0xff);
hal_gpio_write(dev->ss_pin, 1);