Skip to content

Commit 5770096

Browse files
committed
fix: address PR review comments
- Add page-boundary and length validation in steami_flash_write_config - Fix steami_flash_get_size returning absolute address instead of relative size - Separate bad-parameters error from flash-write failure in TASK_WRITE_CONFIG - Update doc to reflect actual 28-byte max payload via I2C protocol - Document fixed 31-byte frame layout for WRITE_CONFIG command
1 parent a954f62 commit 5770096

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

source/board/steami/steami32.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,11 @@ void process_task()
440440
if( task_rx_len >= 3 ){
441441
uint16_t offset = ((uint16_t)task_rx[0] << 8) | task_rx[1];
442442
uint16_t len = task_rx[2];
443-
if( len <= task_rx_len - 3 && steami_flash_write_config(offset, task_rx + 3, len) ){
443+
if( len > task_rx_len - 3 ){
444+
error_status_bad_parameter(&status_error);
445+
steami_uart_write_string("ERROR Bad config write parameters.\n");
446+
}
447+
else if( steami_flash_write_config(offset, task_rx + 3, len) ){
444448
steami_uart_write_string("Config written.\n");
445449
}
446450
else{

source/board/steami/steami_flash.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ uint32_t steami_flash_get_size(){
138138

139139
for(uint16_t i = 0; i < STEAMI_FLASH_MAX_DATA_SIZE; ++i){
140140
if( data[i] == 0xFF ){
141-
return STEAMI_FLASH_FILE_ADDR + offset + i;
141+
return offset + i;
142142
}
143143
}
144144

@@ -228,22 +228,30 @@ bool steami_flash_erase_config(){
228228
wait_w25q64_wel();
229229
wait_w25q64_busy();
230230
bool result = w25q64_sector_erase(STEAMI_FLASH_CONFIG_ADDR);
231+
wait_w25q64_busy();
231232

232233
steami_led_turn_off_blue();
233234
return result;
234235
}
235236

236237
bool steami_flash_write_config(uint16_t offset, uint8_t* data, uint16_t len){
238+
if( len == 0 || len > 256 ){
239+
return false;
240+
}
237241
if( offset + len > STEAMI_FLASH_CONFIG_SIZE ){
238242
return false;
239243
}
244+
if( (offset % 256) + len > 256 ){
245+
return false;
246+
}
240247

241248
steami_led_turn_on_blue();
242249

243250
w25q64_write_enable();
244251
wait_w25q64_wel();
245252
wait_w25q64_busy();
246253
bool result = w25q64_page_program(data, STEAMI_FLASH_CONFIG_ADDR + offset, len);
254+
wait_w25q64_busy();
247255

248256
steami_led_turn_off_blue();
249257
return result;

source/board/steami/steami_flash.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <stdint.h>
44
#include <stdbool.h>
55

6-
#define STEAMI_FLASH_CONFIG_ADDR (uint32_t)0x00000000
6+
#define STEAMI_FLASH_FILE_ADDR (uint32_t)0x00000000
7+
#define STEAMI_FLASH_CONFIG_ADDR (uint32_t)0x007FE000 /* last 4K before filename */
78
#define STEAMI_FLASH_CONFIG_SIZE 4096
8-
#define STEAMI_FLASH_FILE_ADDR (uint32_t)0x00001000 /* after config zone */
99
#define STEAMI_FLASH_NAME_ADDR (uint32_t)0x007FF000
1010

11-
#define STEAMI_FLASH_FILE_SIZE 8380416 /* 0x7FF000 - 0x001000 */
11+
#define STEAMI_FLASH_FILE_SIZE 8380416 /* 0x7FE000 - 0x000000 (excludes config) */
1212

1313
#define STEAMI_FLASH_SECTOR 256
1414
#define STEAMI_FLASH_4K 4096
@@ -124,7 +124,7 @@ bool steami_flash_erase_config();
124124
*
125125
* @param offset byte offset within the config zone (0-4095)
126126
* @param data data array
127-
* @param len number of bytes to write (max 256 per call, must stay within one page)
127+
* @param len number of bytes to write (max 28 per call via I2C, must stay within one 256-byte page)
128128
* @return TRUE if successful, FALSE otherwise
129129
*/
130130
bool steami_flash_write_config(uint16_t offset, uint8_t* data, uint16_t len);

source/board/steami/steami_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static uint16_t get_argument_byte_number(uint8_t cmd){
6969
return 2;
7070

7171
case WRITE_CONFIG:
72-
return 31;
72+
return 31; /* fixed frame: [offset_hi, offset_lo, len, data(28 bytes max)] */
7373

7474
case READ_CONFIG:
7575
return 2;

0 commit comments

Comments
 (0)