Skip to content

Commit 08fb9b2

Browse files
committed
drivers: flash_stm32_xspi: Fix Dummy Cycles on MX66UM1G45G NOR at 200MHz
This commit is fixing configuration of mx66uw1g45g NOR when working at 200MHz. According to its specification, when running at 200MHz, this memory should use a Number Dummy Cycles configuration of 20 (DC bits in CFGR2), which is the device's default configuration. Applying the 66MHz configuration as done today was preventing flash to run at frequency higher than 100Mhz. This commit doesn't solve the more generic problem of this driver which is applying this 66MHz configuration universally, irrespective of the frequency and the memory device, but fixes the configuration which was reported broken today. Providing a global change would require starting a clear split between XSPI controller configuration an bus device configuration, which is what new MSPI API intend to solve, so this will be tackled once this driver will be available. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent 5585a25 commit 08fb9b2

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/flash/flash_stm32_xspi.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,20 @@ static int stm32_xspi_write_enable(const struct device *dev,
568568
}
569569

570570
/* Write Flash configuration register 2 with new dummy cycles */
571-
static int stm32_xspi_write_cfg2reg_dummy(XSPI_HandleTypeDef *hxspi,
571+
static int stm32_xspi_write_cfg2reg_dummy(const struct device *dev,
572572
uint8_t nor_mode, uint8_t nor_rate)
573573
{
574-
uint8_t transmit_data = SPI_NOR_CR2_DUMMY_CYCLES_66MHZ;
575574
XSPI_RegularCmdTypeDef s_command = xspi_prepare_cmd(nor_mode, nor_rate);
575+
const struct flash_stm32_xspi_config *dev_cfg = dev->config;
576+
struct flash_stm32_xspi_data *dev_data = dev->data;
577+
uint8_t transmit_data;
578+
579+
if (dev_cfg->max_frequency == MHZ(200)) {
580+
/* Use memory default value */
581+
return 0;
582+
} else {
583+
transmit_data = SPI_NOR_CR2_DUMMY_CYCLES_66MHZ;
584+
}
576585

577586
/* Initialize the writing of configuration register 2 */
578587
s_command.Instruction = (nor_mode == XSPI_SPI_MODE)
@@ -583,13 +592,13 @@ static int stm32_xspi_write_cfg2reg_dummy(XSPI_HandleTypeDef *hxspi,
583592
s_command.DataLength = (nor_mode == XSPI_SPI_MODE) ? 1U
584593
: ((nor_rate == XSPI_DTR_TRANSFER) ? 2U : 1U);
585594

586-
if (HAL_XSPI_Command(hxspi, &s_command,
595+
if (HAL_XSPI_Command(&dev_data->hxspi, &s_command,
587596
HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
588597
LOG_ERR("XSPI transmit cmd");
589598
return -EIO;
590599
}
591600

592-
if (HAL_XSPI_Transmit(hxspi, &transmit_data,
601+
if (HAL_XSPI_Transmit(&dev_data->hxspi, &transmit_data,
593602
HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
594603
LOG_ERR("XSPI transmit ");
595604
return -EIO;
@@ -683,7 +692,7 @@ static int stm32_xspi_config_mem(const struct device *dev)
683692
}
684693

685694
/* Write Configuration register 2 (with new dummy cycles) */
686-
if (stm32_xspi_write_cfg2reg_dummy(&dev_data->hxspi,
695+
if (stm32_xspi_write_cfg2reg_dummy(dev,
687696
XSPI_SPI_MODE, XSPI_STR_TRANSFER) != 0) {
688697
LOG_ERR("XSPI write CFGR2 failed");
689698
return -EIO;

0 commit comments

Comments
 (0)