Skip to content
Merged
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
41 changes: 26 additions & 15 deletions drivers/memc/memc_stm32_xspi_psram.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,8 @@ static int memc_stm32_xspi_psram_init(const struct device *dev)
{
const struct memc_stm32_xspi_psram_config *dev_cfg = dev->config;
struct memc_stm32_xspi_psram_data *dev_data = dev->data;
XSPI_HandleTypeDef hxspi = dev_data->hxspi;
XSPI_HandleTypeDef *hxspi = &dev_data->hxspi;
uint32_t ahb_clock_freq;
XSPIM_CfgTypeDef cfg = {0};
XSPI_RegularCmdTypeDef cmd = {0};
XSPI_MemoryMappedTypeDef mem_mapped_cfg = {0};
uint32_t prescaler = STM32_XSPI_CLOCK_PRESCALER_MIN;
Expand Down Expand Up @@ -287,24 +286,36 @@ static int memc_stm32_xspi_psram_init(const struct device *dev)
return -EINVAL;
}

hxspi.Init.ClockPrescaler = prescaler;
hxspi.Init.MemorySize = find_msb_set(dev_cfg->memory_size) - 2;
hxspi->Init.ClockPrescaler = prescaler;
hxspi->Init.MemorySize = find_msb_set(dev_cfg->memory_size) - 2;

if (HAL_XSPI_Init(&hxspi) != HAL_OK) {
if (HAL_XSPI_Init(hxspi) != HAL_OK) {
LOG_ERR("XSPI Init failed");
return -EIO;
}

cfg.nCSOverride = HAL_XSPI_CSSEL_OVR_NCS1;
cfg.IOPort = HAL_XSPIM_IOPORT_1;
if (!IS_ENABLED(CONFIG_STM32_APP_IN_EXT_FLASH)) {
/*
* Do not configure the XSPIManager if running on the ext flash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, i would rephrase this inline comment since it's inside the conditioned source lines.

Suggested change
* Do not configure the XSPIManager if running on the ext flash
* Configure XSPIManager only if not running on the external flash

Alternatively:

	/* Do not configure the XSPIManager if running on the external flash
	 * since this includes stopping each XSPI instance during configuration.
	 */
	if (!IS_ENABLED(CONFIG_STM32_APP_IN_EXT_FLASH)) {

* since this includes stopping each XSPI instance during configuration
*/
XSPIM_CfgTypeDef cfg = {0};

if (hxspi->Instance == XSPI1) {
cfg.IOPort = HAL_XSPIM_IOPORT_1;
} else if (hxspi->Instance == XSPI2) {
cfg.IOPort = HAL_XSPIM_IOPORT_2;
}
cfg.nCSOverride = HAL_XSPI_CSSEL_OVR_DISABLED;

if (HAL_XSPIM_Config(&hxspi, &cfg, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
LOG_ERR("XSPIMgr Init failed");
return -EIO;
if (HAL_XSPIM_Config(hxspi, &cfg, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
LOG_ERR("XSPIMgr Init failed");
return -EIO;
}
}

/* Configure AP memory registers */
ret = ap_memory_configure(&hxspi);
ret = ap_memory_configure(hxspi);
if (ret != 0) {
LOG_ERR("AP memory configuration failed");
return -EIO;
Expand All @@ -329,15 +340,15 @@ static int memc_stm32_xspi_psram_init(const struct device *dev)
cmd.DummyCycles = DUMMY_CLK_CYCLES_WRITE;
cmd.DQSMode = HAL_XSPI_DQS_ENABLE;

if (HAL_XSPI_Command(&hxspi, &cmd, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
if (HAL_XSPI_Command(hxspi, &cmd, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return -EIO;
}

cmd.OperationType = HAL_XSPI_OPTYPE_READ_CFG;
cmd.Instruction = BURST_READ_CMD;
cmd.DummyCycles = DUMMY_CLK_CYCLES_READ;

if (HAL_XSPI_Command(&hxspi, &cmd, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
if (HAL_XSPI_Command(hxspi, &cmd, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return -EIO;
}

Expand All @@ -350,12 +361,12 @@ static int memc_stm32_xspi_psram_init(const struct device *dev)
mem_mapped_cfg.NoPrefetchAXI = HAL_XSPI_AXI_PREFETCH_DISABLE;
#endif

if (HAL_XSPI_MemoryMapped(&hxspi, &mem_mapped_cfg) != HAL_OK) {
if (HAL_XSPI_MemoryMapped(hxspi, &mem_mapped_cfg) != HAL_OK) {
return -EIO;
}

#if defined(XSPI_CR_NOPREF)
stm32_reg_modify_bits(&hxspi.Instance->CR, XSPI_CR_NOPREF,
stm32_reg_modify_bits(&hxspi->Instance->CR, XSPI_CR_NOPREF,
HAL_XSPI_AUTOMATIC_PREFETCH_DISABLE);
#endif

Expand Down
Loading