Skip to content

Commit 70ec2a1

Browse files
authored
Merge pull request #10249 from eightycc/issue-10172
Implement use_global_block_protection_lock for write-enabling flash.
2 parents b9f631e + cfc6351 commit 70ec2a1

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ typedef long mp_off_t;
344344
#define CIRCUITPY_CONSOLE_UART (1)
345345
#ifndef CIRCUITPY_CONSOLE_UART_BAUDRATE
346346
#define CIRCUITPY_CONSOLE_UART_BAUDRATE (115200)
347+
#endif
347348
#if !defined(CIRCUITPY_CONSOLE_UART_PRINTF)
348349
#define CIRCUITPY_CONSOLE_UART_PRINTF(...) mp_printf(&console_uart_print, __VA_ARGS__)
349350
#endif
@@ -353,7 +354,6 @@ typedef long mp_off_t;
353354
#if !defined(CIRCUITPY_CONSOLE_UART_TIMESTAMP)
354355
#define CIRCUITPY_CONSOLE_UART_TIMESTAMP (0)
355356
#endif
356-
#endif
357357
#else
358358
#define CIRCUITPY_CONSOLE_UART (0)
359359
#define CIRCUITPY_CONSOLE_UART_PRINTF(...) (void)0

supervisor/shared/external_flash/common_commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
#define CMD_ENABLE_RESET 0x66
2424
#define CMD_RESET 0x99
2525
#define CMD_WAKE 0xab
26+
#define CMD_GLOBAL_BLOCK_PROTECTION_UNLOCK 0x98

supervisor/shared/external_flash/device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ typedef struct {
2424
// status register.
2525
uint8_t quad_enable_bit_mask;
2626

27+
// Device has sector-level write protection
2728
bool has_sector_protection : 1;
2829

30+
// Device uses global block protection lock instead of status register bits to enable sector writes
31+
bool use_global_block_protection_lock : 1;
32+
2933
// Supports the 0x0b fast read command with 8 dummy cycles.
3034
bool supports_fast_read : 1;
3135

supervisor/shared/external_flash/devices.h.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
.max_clock_speed_mhz = {{ device.max_clock_speed_mhz }}, \
1818
.quad_enable_bit_mask = {{ device.quad_enable_bit_mask }}, \
1919
.has_sector_protection = {{ device.has_sector_protection | lower() }}, \
20+
.use_global_block_protection_lock = {{ device.use_global_block_protection_lock | lower() }}, \
2021
.supports_fast_read = {{ device.supports_fast_read | lower() }}, \
2122
.supports_qspi = {{ device["6b_quad_read"] | lower() }}, \
2223
.supports_qspi_writes = {{ device["32_qspi_write"] | lower() }}, \

supervisor/shared/external_flash/external_flash.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,12 @@ void supervisor_flash_init(void) {
268268
write_enable();
269269

270270
// Turn off sector protection
271-
uint8_t data[1] = {0x00};
272-
spi_flash_write_command(CMD_WRITE_STATUS_BYTE1, data, 1);
271+
if (flash_device->use_global_block_protection_lock) {
272+
spi_flash_command(CMD_GLOBAL_BLOCK_PROTECTION_UNLOCK);
273+
} else {
274+
uint8_t data[1] = {0x00};
275+
spi_flash_write_command(CMD_WRITE_STATUS_BYTE1, data, 1);
276+
}
273277
}
274278

275279
// Turn off writes in case this is a microcontroller only reset.

0 commit comments

Comments
 (0)