samples: boards: mimxrt11xx_cm7: Magic addr sample

Add magic address sample to show how to use flexram
magic address using memc flexram driver.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2023-09-14 23:25:32 -05:00 committed by Carles Cufí
commit 31eb944fcd
5 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(magic_addr)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers/memc)
target_sources(app PRIVATE src/main.c)

View file

@ -0,0 +1,18 @@
.. _flexram_magic_addr:
FLEXRAM Magic Addr
##################
Overview
********
A sample that shows how to use RT11XX FLEXRAM Magic Addr functionality
Magic Addr is a feature of FlexRAM that allows user to configure an interrupt
on an arbitrary RAM/TCM address access. This sample shows how to use the custom
API for the flexram in zephyr to use this unique feature.
Building and Running
********************
see board documentation

View file

@ -0,0 +1,3 @@
CONFIG_MEMC_NXP_FLEXRAM_MAGIC_ADDR_API=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y

View file

@ -0,0 +1,12 @@
sample:
description: RT1170 FLEXRAM Magic Addr example
name: magic addr
common:
integration_platforms:
- mimxrt1170_evk_cm7
- mimxrt1160_evk_cm7
tests:
sample.boards.mimxrt1170_evk.magic_addr:
platform_allow:
- mimxrt1170_evk_cm7
- mimxrt1160_evk_cm7

View file

@ -0,0 +1,58 @@
/*
* Copyright 2023 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <zephyr/linker/section_tags.h>
#include "memc_nxp_flexram.h"
#include <zephyr/kernel.h>
#include <zephyr/console/console.h>
#include <zephyr/cache.h>
K_SEM_DEFINE(dtcm_magic, 0, 1);
__dtcm_bss_section uint8_t var;
int cnt;
void flexram_magic_addr_isr_cb(enum memc_flexram_interrupt_cause cause,
void *data)
{
ARG_UNUSED(data);
if (cause == flexram_dtcm_magic_addr) {
printf("Magic DTCM address accessed %d times\n", ++cnt);
k_sem_give(&dtcm_magic);
}
}
int main(void)
{
memc_flexram_register_callback(flexram_magic_addr_isr_cb, NULL);
console_init();
printf("%s is opening spellbook...\n", CONFIG_BOARD);
printf("Cast some characters:\n");
uint32_t dtcm_addr = (uint32_t)&var;
memc_flexram_set_dtcm_magic_addr(dtcm_addr);
uint8_t tmp;
while (1) {
printf("\n");
tmp = console_getchar();
printf("Writing %c to magic addr...\n", tmp);
var = tmp;
k_sem_take(&dtcm_magic, K_FOREVER);
printf("Reading from magic addr...\n");
printf("Magic variable got: %c\n", var);
k_sem_take(&dtcm_magic, K_FOREVER);
}
return 0;
}