Skip to content

Implement use_global_block_protection_lock for write-enabling flash. #10249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion py/circuitpy_mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ typedef long mp_off_t;
#define CIRCUITPY_CONSOLE_UART (1)
#ifndef CIRCUITPY_CONSOLE_UART_BAUDRATE
#define CIRCUITPY_CONSOLE_UART_BAUDRATE (115200)
#endif
#if !defined(CIRCUITPY_CONSOLE_UART_PRINTF)
#define CIRCUITPY_CONSOLE_UART_PRINTF(...) mp_printf(&console_uart_print, __VA_ARGS__)
#endif
Expand All @@ -353,7 +354,6 @@ typedef long mp_off_t;
#if !defined(CIRCUITPY_CONSOLE_UART_TIMESTAMP)
#define CIRCUITPY_CONSOLE_UART_TIMESTAMP (0)
#endif
#endif
#else
#define CIRCUITPY_CONSOLE_UART (0)
#define CIRCUITPY_CONSOLE_UART_PRINTF(...) (void)0
Expand Down
1 change: 1 addition & 0 deletions supervisor/shared/external_flash/common_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
#define CMD_ENABLE_RESET 0x66
#define CMD_RESET 0x99
#define CMD_WAKE 0xab
#define CMD_GLOBAL_BLOCK_PROTECTION_UNLOCK 0x98
4 changes: 4 additions & 0 deletions supervisor/shared/external_flash/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ typedef struct {
// status register.
uint8_t quad_enable_bit_mask;

// Device has sector-level write protection
bool has_sector_protection : 1;

// Device uses global block protection lock instead of status register bits to enable sector writes
bool use_global_block_protection_lock : 1;

// Supports the 0x0b fast read command with 8 dummy cycles.
bool supports_fast_read : 1;

Expand Down
1 change: 1 addition & 0 deletions supervisor/shared/external_flash/devices.h.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
.max_clock_speed_mhz = {{ device.max_clock_speed_mhz }}, \
.quad_enable_bit_mask = {{ device.quad_enable_bit_mask }}, \
.has_sector_protection = {{ device.has_sector_protection | lower() }}, \
.use_global_block_protection_lock = {{ device.use_global_block_protection_lock | lower() }}, \
.supports_fast_read = {{ device.supports_fast_read | lower() }}, \
.supports_qspi = {{ device["6b_quad_read"] | lower() }}, \
.supports_qspi_writes = {{ device["32_qspi_write"] | lower() }}, \
Expand Down
8 changes: 6 additions & 2 deletions supervisor/shared/external_flash/external_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,12 @@ void supervisor_flash_init(void) {
write_enable();

// Turn off sector protection
uint8_t data[1] = {0x00};
spi_flash_write_command(CMD_WRITE_STATUS_BYTE1, data, 1);
if (flash_device->use_global_block_protection_lock) {
spi_flash_command(CMD_GLOBAL_BLOCK_PROTECTION_UNLOCK);
} else {
uint8_t data[1] = {0x00};
spi_flash_write_command(CMD_WRITE_STATUS_BYTE1, data, 1);
}
}

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