Implement use_global_block_protection_lock for write-enabling flash.

Fix mis-placed conditional in circuitpy_mpconfig.h.
This commit is contained in:
eightycc 2025-04-14 07:47:59 -07:00
parent 361e0eb51c
commit 7012deb3e7
6 changed files with 14 additions and 4 deletions

@ -1 +1 @@
Subproject commit 6b678f15e378edce820f2ffdef3286b3e55449e7 Subproject commit 134051e3337df1f4cfaea8665bbfaa93c5dc4dbb

View file

@ -344,6 +344,7 @@ typedef long mp_off_t;
#define CIRCUITPY_CONSOLE_UART (1) #define CIRCUITPY_CONSOLE_UART (1)
#ifndef CIRCUITPY_CONSOLE_UART_BAUDRATE #ifndef CIRCUITPY_CONSOLE_UART_BAUDRATE
#define CIRCUITPY_CONSOLE_UART_BAUDRATE (115200) #define CIRCUITPY_CONSOLE_UART_BAUDRATE (115200)
#endif
#if !defined(CIRCUITPY_CONSOLE_UART_PRINTF) #if !defined(CIRCUITPY_CONSOLE_UART_PRINTF)
#define CIRCUITPY_CONSOLE_UART_PRINTF(...) mp_printf(&console_uart_print, __VA_ARGS__) #define CIRCUITPY_CONSOLE_UART_PRINTF(...) mp_printf(&console_uart_print, __VA_ARGS__)
#endif #endif
@ -353,7 +354,6 @@ typedef long mp_off_t;
#if !defined(CIRCUITPY_CONSOLE_UART_TIMESTAMP) #if !defined(CIRCUITPY_CONSOLE_UART_TIMESTAMP)
#define CIRCUITPY_CONSOLE_UART_TIMESTAMP (0) #define CIRCUITPY_CONSOLE_UART_TIMESTAMP (0)
#endif #endif
#endif
#else #else
#define CIRCUITPY_CONSOLE_UART (0) #define CIRCUITPY_CONSOLE_UART (0)
#define CIRCUITPY_CONSOLE_UART_PRINTF(...) (void)0 #define CIRCUITPY_CONSOLE_UART_PRINTF(...) (void)0

View file

@ -23,3 +23,4 @@
#define CMD_ENABLE_RESET 0x66 #define CMD_ENABLE_RESET 0x66
#define CMD_RESET 0x99 #define CMD_RESET 0x99
#define CMD_WAKE 0xab #define CMD_WAKE 0xab
#define CMD_GLOBAL_BLOCK_PROTECTION_UNLOCK 0x98

View file

@ -24,8 +24,12 @@ typedef struct {
// status register. // status register.
uint8_t quad_enable_bit_mask; uint8_t quad_enable_bit_mask;
// Device has sector-level write protection
bool has_sector_protection : 1; 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. // Supports the 0x0b fast read command with 8 dummy cycles.
bool supports_fast_read : 1; bool supports_fast_read : 1;

View file

@ -17,6 +17,7 @@
.max_clock_speed_mhz = {{ device.max_clock_speed_mhz }}, \ .max_clock_speed_mhz = {{ device.max_clock_speed_mhz }}, \
.quad_enable_bit_mask = {{ device.quad_enable_bit_mask }}, \ .quad_enable_bit_mask = {{ device.quad_enable_bit_mask }}, \
.has_sector_protection = {{ device.has_sector_protection | lower() }}, \ .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_fast_read = {{ device.supports_fast_read | lower() }}, \
.supports_qspi = {{ device["6b_quad_read"] | lower() }}, \ .supports_qspi = {{ device["6b_quad_read"] | lower() }}, \
.supports_qspi_writes = {{ device["32_qspi_write"] | lower() }}, \ .supports_qspi_writes = {{ device["32_qspi_write"] | lower() }}, \

View file

@ -268,8 +268,12 @@ void supervisor_flash_init(void) {
write_enable(); write_enable();
// Turn off sector protection // Turn off sector protection
uint8_t data[1] = {0x00}; if (flash_device->use_global_block_protection_lock) {
spi_flash_write_command(CMD_WRITE_STATUS_BYTE1, data, 1); 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. // Turn off writes in case this is a microcontroller only reset.