Skip to content

Commit 6d69f16

Browse files
committed
soc: stm32n6: Add NPU driver
Provide Neural-ART driver for STM32N6. This driver handles unit initialization (clock, rif). Signed-off-by: Erwan Gouriou <[email protected]>
1 parent 413b789 commit 6d69f16

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

soc/st/stm32/stm32n6x/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ zephyr_sources(
55
soc.c
66
)
77

8+
zephyr_sources_ifdef(CONFIG_STM32N6_NPU
9+
npu/npu_stm32n6.c
10+
)
11+
812
zephyr_include_directories(.)
913

1014
set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "")

soc/st/stm32/stm32n6x/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ config SOC_SERIES_STM32N6X
2323

2424
config STM32N6_BOOT_SERIAL
2525
bool "Serial boot target (USB)"
26+
27+
config STM32N6_NPU
28+
bool "Neural-ART accelerator (NPU)"
29+
select USE_STM32_HAL_RIF
30+
select USE_STM32_HAL_CACHEAXI
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT st_stm32_npu
8+
9+
#include <errno.h>
10+
11+
#include <zephyr/device.h>
12+
#include <zephyr/drivers/reset.h>
13+
#include <zephyr/init.h>
14+
#include <soc.h>
15+
16+
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
17+
18+
/* Read-only driver configuration */
19+
struct npu_stm32_cfg {
20+
/* Clock configuration. */
21+
struct stm32_pclken pclken;
22+
/* Reset configuration */
23+
const struct reset_dt_spec reset;
24+
};
25+
26+
static void npu_risaf_config(void)
27+
{
28+
RIMC_MasterConfig_t RIMC_master = {0};
29+
30+
RIMC_master.MasterCID = RIF_CID_1;
31+
RIMC_master.SecPriv = RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV;
32+
HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_NPU, &RIMC_master);
33+
HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_NPU,
34+
RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
35+
}
36+
37+
static int npu_stm32_init(const struct device *dev)
38+
{
39+
const struct device *const clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
40+
const struct npu_stm32_cfg *cfg = dev->config;
41+
42+
if (!device_is_ready(clk)) {
43+
return -ENODEV;
44+
}
45+
46+
if (clock_control_on(clk, (clock_control_subsys_t) &cfg->pclken) != 0) {
47+
return -EIO;
48+
}
49+
50+
if (!device_is_ready(cfg->reset.dev)) {
51+
return -ENODEV;
52+
}
53+
54+
/* Reset timer to default state using RCC */
55+
(void)reset_line_toggle_dt(&cfg->reset);
56+
57+
npu_risaf_config();
58+
59+
return 0;
60+
}
61+
62+
63+
static const struct npu_stm32_cfg npu_stm32_cfg = {
64+
.pclken = {
65+
.enr = DT_CLOCKS_CELL(DT_NODELABEL(npu), bits),
66+
.bus = DT_CLOCKS_CELL(DT_NODELABEL(npu), bus),
67+
},
68+
.reset = RESET_DT_SPEC_GET(DT_NODELABEL(npu)),
69+
};
70+
71+
DEVICE_DT_DEFINE(DT_NODELABEL(npu), npu_stm32_init, NULL,
72+
NULL, &npu_stm32_cfg, POST_KERNEL,
73+
CONFIG_APPLICATION_INIT_PRIORITY, NULL);

0 commit comments

Comments
 (0)