samples: drivers: memc: get AHB address dynamically

Use MEMC API to extract AHB address from FlexSPI when using it with the
MEMC sample.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2023-08-17 16:01:57 -05:00 committed by Carles Cufí
parent 9a63f39cd8
commit 96d6d70f13
2 changed files with 11 additions and 3 deletions

View file

@ -5,4 +5,9 @@ cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(memc)
if(CONFIG_MEMC_MCUX_FLEXSPI)
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/drivers/memc)
endif()
target_sources(app PRIVATE src/main.c)

View file

@ -7,8 +7,11 @@
#include <zephyr/kernel.h>
#if DT_HAS_COMPAT_STATUS_OKAY(nxp_imx_flexspi)
/* FlexSPI memory mapped region is second register property of parent dev */
#define MEMC_BASE DT_REG_ADDR_BY_IDX(DT_PARENT(DT_ALIAS(sram_ext)), 1)
/* Use memc API to get AHB base address for the device */
#include "memc_mcux_flexspi.h"
#define FLEXSPI_DEV DEVICE_DT_GET(DT_PARENT(DT_ALIAS(sram_ext)))
#define MEMC_PORT DT_REG_ADDR(DT_ALIAS(sram_ext))
#define MEMC_BASE memc_flexspi_get_ahb_address(FLEXSPI_DEV, MEMC_PORT, 0)
#define MEMC_SIZE (DT_PROP(DT_ALIAS(sram_ext), size) / 8)
#endif
@ -49,7 +52,7 @@ int main(void)
for (i = 0; i < BUF_SIZE; i++) {
memc_write_buffer[i] = (uint8_t)i;
}
printk("Writing to memory region with base 0x%0x, size 0x%0x\n\n",
printk("Writing to memory region with base %p, size 0x%0x\n\n",
MEMC_BASE, MEMC_SIZE);
/* Copy write buffer into memc region */
for (i = 0, j = 0; j < (MEMC_SIZE / BUF_SIZE); i += BUF_SIZE, j++) {