@@ -1845,6 +1845,49 @@ static int stm32_ospi_write_status_register(const struct device *dev, uint8_t re
1845
1845
return ospi_write_access (dev , & s_command , regs_p , size );
1846
1846
}
1847
1847
1848
+ static int stm32_ospi_program_addr_4b (const struct device * dev , bool write_enable )
1849
+ {
1850
+ uint8_t statReg ;
1851
+ struct flash_stm32_ospi_data * data = dev -> data ;
1852
+ OSPI_HandleTypeDef * hospi = & data -> hospi ;
1853
+ uint8_t nor_mode = OSPI_SPI_MODE ;
1854
+ uint8_t nor_rate = OSPI_STR_TRANSFER ;
1855
+ OSPI_RegularCmdTypeDef s_command = ospi_prepare_cmd (nor_mode , nor_rate );
1856
+
1857
+ if (write_enable ) {
1858
+ if (stm32_ospi_write_enable (data , nor_mode , nor_rate ) < 0 ) {
1859
+ LOG_DBG ("program_addr_4b failed to write_enable" );
1860
+ return - EIO ;
1861
+ }
1862
+ }
1863
+
1864
+ /* Initialize the write enable command */
1865
+ s_command .Instruction = SPI_NOR_CMD_4BA ;
1866
+ if (nor_mode != OSPI_OPI_MODE ) {
1867
+ /* force 1-line InstructionMode for any non-OSPI transfer */
1868
+ s_command .InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE ;
1869
+ }
1870
+ s_command .AddressMode = HAL_OSPI_ADDRESS_NONE ;
1871
+ s_command .DataMode = HAL_OSPI_DATA_NONE ;
1872
+ s_command .DummyCycles = 0U ;
1873
+
1874
+ if (HAL_OSPI_Command (hospi , & s_command , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
1875
+ LOG_DBG ("OSPI Address Mode Change cmd failed" );
1876
+ return - EIO ;
1877
+ }
1878
+
1879
+ /* Check that ADS Bit in Status Reg 3 is now set indicating 4 Byte Address mode */
1880
+ if (stm32_ospi_read_status_register (dev , 3 , & statReg )) {
1881
+ LOG_DBG ("Status reg read failed" );
1882
+ return - EIO ;
1883
+ }
1884
+
1885
+ if (statReg & 0x01 ) {
1886
+ return 0 ;
1887
+ }
1888
+ return - EIO ;
1889
+ }
1890
+
1848
1891
static int stm32_ospi_enable_qe (const struct device * dev )
1849
1892
{
1850
1893
struct flash_stm32_ospi_data * data = dev -> data ;
@@ -1983,6 +2026,7 @@ static int spi_nor_process_bfp(const struct device *dev,
1983
2026
const size_t flash_size = jesd216_bfp_density (bfp ) / 8U ;
1984
2027
struct jesd216_instr read_instr = { 0 };
1985
2028
struct jesd216_bfp_dw15 dw15 ;
2029
+ uint8_t addr_mode ;
1986
2030
1987
2031
if (flash_size != dev_cfg -> flash_size ) {
1988
2032
LOG_DBG ("Unexpected flash size: %u" , flash_size );
@@ -2002,8 +2046,29 @@ static int spi_nor_process_bfp(const struct device *dev,
2002
2046
++ etp ;
2003
2047
}
2004
2048
2005
- spi_nor_process_bfp_addrbytes (dev , jesd216_bfp_addrbytes (bfp ));
2049
+ addr_mode = jesd216_bfp_addrbytes (bfp );
2050
+ spi_nor_process_bfp_addrbytes (dev , addr_mode );
2006
2051
LOG_DBG ("Address width: %u Bytes" , data -> address_width );
2052
+ /* 4 Byte Address Mode has to be explicitly enabled for Winbond Flash */
2053
+ if (addr_mode == JESD216_SFDP_BFP_DW1_ADDRBYTES_VAL_3B4B ) {
2054
+ struct jesd216_bfp_dw16 dw16 ;
2055
+
2056
+ if (jesd216_bfp_decode_dw16 (php , bfp , & dw16 ) == 0 ) {
2057
+ /*
2058
+ * According to JESD216, the bit0 of dw16.enter_4ba
2059
+ * portion of flash description register 16 indicates
2060
+ * if it is enough to use 0xB7 instruction without
2061
+ * write enable to switch to 4 bytes addressing mode.
2062
+ * If bit 1 is set, a write enable is needed.
2063
+ */
2064
+ if (dw16 .enter_4ba & 0x3 ) {
2065
+ if (stm32_ospi_program_addr_4b (dev , dw16 .enter_4ba & 2 )) {
2066
+ LOG_ERR ("Unable to enter 4B mode." );
2067
+ return - EIO ;
2068
+ }
2069
+ }
2070
+ }
2071
+ }
2007
2072
2008
2073
/* use PP opcode based on configured data mode if nothing is set in DTS */
2009
2074
if (data -> write_opcode == SPI_NOR_WRITEOC_NONE ) {
0 commit comments