Skip to content

Commit 347088e

Browse files
committed
ice40: Reuses prepare_flash_access/post_flash_access as much as possible. Removed dupplicated Flash dump informations. Be coherent to status message
1 parent 2e1c7e2 commit 347088e

File tree

1 file changed

+12
-42
lines changed

1 file changed

+12
-42
lines changed

src/ice40.cpp

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ void Ice40::reset()
4545
_spi->gpio_clear(_rst_pin);
4646
usleep(1000);
4747
_spi->gpio_set(_rst_pin);
48-
printInfo("Reset ", false);
4948
usleep(12000);
49+
printInfo("Reset and Wait for CDONE:");
5050
do {
5151
timeout--;
5252
usleep(12000);
5353
} while (((_spi->gpio_get(true) & _done_pin) == 0) && timeout > 0);
5454
if (timeout == 0)
55-
printError("FAIL");
55+
printError("Fail");
5656
else
57-
printSuccess("DONE");
57+
printSuccess("Done");
5858
}
5959

6060
/* cf. TN1248 (iCE40 Programming and Configuration)
@@ -96,25 +96,23 @@ bool Ice40::program_cram(const uint8_t *data, uint32_t length)
9696
/* wait CDONE */
9797
usleep(12000);
9898

99-
printInfo("Wait for CDONE ", false);
99+
printInfo("Wait for CDONE");
100100
do {
101101
timeout--;
102102
usleep(12000);
103103
} while (((_spi->gpio_get(true) & _done_pin) == 0) && timeout > 0);
104104
if (timeout == 0)
105-
printError("FAIL");
105+
printError("Fail");
106106
else
107-
printSuccess("DONE");
107+
printSuccess("Done");
108108

109109
_spi->setCs();
110110

111-
return true;
111+
return (timeout == 0) ? false : true;
112112
}
113113

114114
void Ice40::program(unsigned int offset, bool unprotect_flash)
115115
{
116-
uint32_t timeout = 1000;
117-
118116
if (_file_extension.empty())
119117
return;
120118

@@ -141,33 +139,19 @@ void Ice40::program(unsigned int offset, bool unprotect_flash)
141139
SPIFlash flash(reinterpret_cast<SPIInterface *>(_spi), unprotect_flash,
142140
_verbose_level);
143141

144-
printf("%02x\n", flash.read_status_reg());
145-
flash.read_id();
146142
flash.erase_and_prog(offset, data, length);
147143

148144
if (_verify)
149145
flash.verify(offset, data, length);
150146

151-
_spi->gpio_set(_rst_pin);
152-
usleep(12000);
153-
154-
printInfo("Wait for CDONE ", false);
155-
do {
156-
timeout--;
157-
usleep(12000);
158-
} while (((_spi->gpio_get(true) & _done_pin) == 0) && timeout > 0);
159-
if (timeout == 0)
160-
printError("FAIL");
161-
else
162-
printSuccess("DONE");
147+
/* release SPI access / reload */
148+
post_flash_access();
163149
}
164150

165151
bool Ice40::dumpFlash(uint32_t base_addr, uint32_t len)
166152
{
167-
uint32_t timeout = 1000;
168-
_spi->gpio_clear(_rst_pin);
169-
170153
/* prepare SPI access */
154+
prepare_flash_access();
171155
printInfo("Read Flash ", false);
172156
try {
173157
SPIFlash flash(reinterpret_cast<SPIInterface *>(_spi), false, _verbose_level);
@@ -180,22 +164,8 @@ bool Ice40::dumpFlash(uint32_t base_addr, uint32_t len)
180164
return false;
181165
}
182166

183-
/* release SPI access */
184-
185-
_spi->gpio_set(_rst_pin);
186-
usleep(12000);
187-
188-
printInfo("Wait for CDONE ", false);
189-
do {
190-
timeout--;
191-
usleep(12000);
192-
} while (((_spi->gpio_get(true) & _done_pin) == 0) && timeout > 0);
193-
if (timeout == 0)
194-
printError("FAIL");
195-
else
196-
printSuccess("DONE");
197-
198-
return false;
167+
/* release SPI access / reload */
168+
return post_flash_access();
199169
}
200170

201171
bool Ice40::protect_flash(uint32_t len)

0 commit comments

Comments
 (0)