Skip to content

Commit 33de741

Browse files
committed
Fix peripheral access failed
1 parent e441264 commit 33de741

File tree

13 files changed

+286
-101
lines changed

13 files changed

+286
-101
lines changed

bsp/nxp/imx/imx91/.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ CONFIG_SOC_MIMX91X1D=y
14691469
#
14701470
# Hardware Drivers Config
14711471
#
1472-
# CONFIG_BSP_USING_EARLY_CONSOLE is not set
1472+
CONFIG_BSP_USING_EARLY_CONSOLE=y
14731473
CONFIG_BSP_USING_UART1=y
14741474
CONFIG_BSP_USING_GIC=y
14751475
CONFIG_BSP_USING_GICV3=y

bsp/nxp/imx/imx91/README.md

Lines changed: 172 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,189 @@
1-
# FRDM-IMX91 RT-Thread BSP
1+
# FRDM-IMX91 板级支持包 使用说明
22

3-
This folder contains the RT-Thread BSP for the NXP FRDM-IMX91 development board.
3+
本目录包含NXP FRDM-IMX91 开发板的板级支持包代码。
44

5-
## Board Overview
5+
## 1. 简介
66

7-
## Build and Run
7+
FRDM i.MX 91开发板是一款低成本、紧凑型开发板,采用i.MX 91应用处理器。该板配备板载IW610模块,集成了恩智浦的三频解决方案,支持Wi-Fi 6、BLE 5.4和802.15.4,适用于开发现代工业和物联网应用。该开发板包含LPDDR4、用于快速启动的eMMC存储、PMIC以及扩展功能。
88

9-
### Setup RT-Thread Development Environment
9+
FRDM i.MX 91开发板是一款入门级紧凑型开发板,采用i.MX 91应用处理器。
1010

11-
### Setup Network and TFTP Server for FRDM-IMX91
11+
![GS-FRDM-IMX91-IMG1](README.assets/GS-FRDM-IMX91-IMG1.webp)
1212

13-
### Build RT-Thread BSP for FRDM-IMX91
13+
在FRDM i.MX 91开发板上调测RT-Thread的过程中,需要使用到的接口有:
1414

15-
1. Clone the RT-Thread repository:
16-
```
17-
git clone https://github.com/RT-Thread/rt-thread.git
18-
```
15+
1. POWER(P1),USB供电接口,用于向开发板供电;
16+
2. DEBUG(P16),带有USB转串口芯片,用于U-Boot和RT-Thread日志输出、命令行交互;
17+
3. ENET1(P4)或者ENET2(P3),以太网口,用于网络下载编译生成的RT-Thread固件;
1918

20-
2. Navigate to the BSP folder:
21-
```
22-
cd rt-thread/bsp/nxp/imx/imx91
23-
```
2419

25-
3. Build the BSP:
26-
```
27-
scons -j 8
28-
```
2920

30-
4. copy the `rtthread.bin` to the TFTP server working directory:
31-
```
32-
cp rtthread.bin /path/to/tftp_work_dir/
33-
```
21+
## 2. 编译
3422

35-
### Run RT-Thread on FRDM-IMX91 with u-boot
23+
### 2.1 下载AArch64工具链
24+
25+
从ARM开发者网站下载AArch64裸机工具链,
26+
27+
下载页面: [Arm GNU Toolchain Downloads – Arm Developer](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads)
28+
29+
例如,64位Windows主机上下载: https://developer.arm.com/-/media/Files/downloads/gnu/14.3.rel1/binrel/arm-gnu-toolchain-14.3.rel1-mingw-w64-x86_64-aarch64-none-elf.zip
30+
31+
例如,下载后解压到本地路径:`D:\ARM\arm-gnu-toolchain-14.3.rel1-mingw-w64-x86_64-aarch64-none-elf`
32+
33+
34+
35+
### 2.2 下载RT-Thread Env工具
36+
37+
下载页面:[rt-thread.org/download.html#download-rt-thread-env-tool](https://www.rt-thread.org/download.html#download-rt-thread-env-tool)
38+
39+
40+
41+
### 2.3 下载RT-Thread源代码
42+
43+
在Env环境中,使用git命令下载RT-Thread源代码,例如:
44+
45+
```sh
46+
git clone https://github.com/RT-Thread/rt-thread.git
47+
```
48+
49+
50+
51+
### 2.4 编译FRDM-i.MX 91目标
52+
53+
在Env环境中,转到`i.MX 91`的BSP目录:
54+
55+
```sh
56+
cd bsp/nxp/imx/imx91/
57+
```
58+
59+
然后,设置工具链路径(Windows Env环境):
60+
61+
```bat
62+
set RTT_EXEC_PATH=D:\ARM\arm-gnu-toolchain-14.3.rel1-mingw-w64-x86_64-aarch64-none-elf\bin
63+
```
64+
65+
或者(bash):
66+
67+
```sh''
68+
export RTT_EXEC_PATH=/path/to/aarch64-none-elf/bin
69+
```
70+
71+
接着,执行`scons`命令开始编译:
72+
73+
```sh
74+
scons -j 8
75+
```
76+
77+
78+
79+
## 3.下载
80+
81+
开发板默认固件带有U-Boot启动加载器,开机3秒内通过串口发送换行符,可以进入U-Boot命令行界面。
82+
83+
### 3.1 准备U-Boot网络环境
84+
85+
将开发板和PC连接到同一个路由器。
86+
87+
例如,PC的IP地址为:`192.168.0.101`
88+
89+
在开发板的U-Boot命令行界面内,设置FRDM-i.MX为静态IP:
90+
91+
```sh
92+
setenv ipaddr 192.168.0.120
93+
```
94+
95+
或者从路由器动态获取IP:
96+
97+
```sh
98+
dhcp
99+
```
100+
101+
成功后,可以使用ping命令测试是否可以访问PC:
36102

37103
```sh
104+
ping 192.168.0.101
105+
```
106+
107+
成功则表示网络环境正常,可以执行后续步骤。
108+
109+
110+
111+
### 3.2 安装TFTP服务
112+
113+
Windows系统可以使用Tftpd,下载链接: [Releases · PJO2/tftpd64](https://github.com/PJO2/tftpd64/releases/)
114+
115+
例如,下载portable免安装版本: https://github.com/PJO2/tftpd64/releases/download/v4.74/tftpd64_portable_v4.74.zip
116+
117+
启动后,设置TFTP工作目录:
118+
119+
![image-20251210021421740](README.assets/image-20251210021421740.png)
120+
121+
122+
123+
### 3.3 拷贝rtthread.bin到TFTP工作目录
124+
125+
在PC的Env环境中,将 `rtthread.bin` 拷贝到TFTP工作目录:
126+
```bat
127+
copy /Y rtthread.bin D:\PortableSoftwareApps\tftpd64_portable_v4.74\work\
128+
```
129+
130+
或者:
131+
132+
```sh
133+
cp rtthread.bin /path/to/tftp_work_dir/
134+
```
135+
136+
137+
138+
### 3.4 下载rtthread.bin到开发板内存中
139+
140+
在开发板的U-Boot命令行界面中,首先执行如下命令,设置TFTP服务地址(PC的IP地址):
141+
142+
```sh
143+
setenv serverip 192.168.0.101
144+
```
145+
146+
然后,继续在开发板的U-Boot命令行界面中,执行如下命令,将`rtthread.bin`下载到内存中:
147+
148+
```sh
149+
tftp 0x80000000 rtthread.bin
150+
```
151+
152+
下载的目标内存地址为:`0x80000000`
153+
154+
155+
156+
## 4. 运行
157+
158+
完成前面步骤后,继续在开发板的U-Boot命令行界面中,执行如下命令,跳转到`0x80000000`并开始执行:
159+
160+
```sh
161+
dcache flush
162+
icache flush
163+
go 0x80000000
164+
```
165+
166+
167+
168+
可以将以上三条命令设置到U-Boot的启动命令变量`bootcmd`中,实现下次开机自动执行。所有U-Boot命令如下:
169+
170+
```sh
171+
setenv ipaddr 192.168.0.120
172+
setenv serverip 192.168.0.101
38173
setenv bootcmd "tftp 0x80000000 rtthread.bin; dcache flush; icache flush; go 0x80000000"
39174
saveenv
40175
reset
41176
```
177+
178+
其中,最后的`reset`是重启命令。
179+
180+
181+
182+
## 5. 参考链接
183+
184+
1. 维护人: [xusiwei](https://github.com/xusiwei)
185+
2. AArch64工具链下载页面: [Arm GNU Toolchain Downloads – Arm Developer](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads)
186+
3. Tftp64下载页面:https://github.com/PJO2/tftpd64/releases
187+
4. FRDM-i.MX91开发板介绍:[FRDM i.MX 91 Development Board | NXP 半导体](https://www.nxp.com.cn/design/design-center/development-boards-and-designs/FRDM-IMX91)
188+
5. i.MX91处理器介绍: [i.MX 91 Applications Processors Family | NXP 半导体](https://www.nxp.com.cn/products/i.MX91)
189+

bsp/nxp/imx/imx91/drivers/board.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,25 @@
2323
#include <limits.h>
2424

2525
#define DRAM_MAP_START KERNEL_BOOT_ADDR
26-
#define DRAM_MAP_SIZE (64 * 1024 * 1024) // part of DRAM
26+
#define DRAM_MAP_SIZE MB_SIZE(256) // part of DRAM
2727

2828
#define MEM_DESC(vaddr_start, size, paddr_start, attr) \
2929
vaddr_start, (vaddr_start + size - 1uL), paddr_start, attr
3030

31-
static volatile unsigned long MMUTable[512*4] __attribute__((aligned(4 * 1024)));
31+
// static volatile unsigned long MMUTable[512*2] __attribute__((aligned(4 * 1024)));
32+
extern volatile unsigned long MMUTable[];
3233

33-
struct mem_desc platform_mem_desc[] = {
34-
{MEM_DESC(DRAM_MAP_START, DRAM_MAP_SIZE, DRAM_MAP_START, NORMAL_MEM)},
35-
// {MEM_DESC(LPUART1_BASE, LPUART1_SIZE, LPUART1_BASE, DEVICE_MEM)}, // 0x4438_0000
36-
// {MEM_DESC(CCM_CTRL_BASE, CCM_CTRL_SIZE, CCM_CTRL_BASE, DEVICE_MEM)}, // 0x4445_8000
37-
// {MEM_DESC(GIC_DISTRIBUTOR_BASE, GIC_DISTRIBUTOR_SIZE, GIC_DISTRIBUTOR_BASE, DEVICE_MEM)}, // 0x4800_0000
38-
// {MEM_DESC(GIC_REDISTRIBUTOR_BASE, GIC_REDISTRIBUTOR_SIZE, GIC_REDISTRIBUTOR_BASE, DEVICE_MEM)}, // 0x4804_0000
34+
static struct mem_desc platform_mem_desc[] = {
35+
{MEM_DESC(LPUART1_BASE, LPUART1_SIZE, LPUART1_BASE, DEVICE_MEM)}, // 0x4438_0000
36+
{MEM_DESC(CCM_CTRL_BASE, CCM_CTRL_SIZE, CCM_CTRL_BASE, DEVICE_MEM)}, // 0x4445_8000
37+
{MEM_DESC(GIC_DISTRIBUTOR_BASE, GIC_DISTRIBUTOR_SIZE, GIC_DISTRIBUTOR_BASE, DEVICE_MEM)}, // 0x4800_0000
38+
{MEM_DESC(GIC_REDISTRIBUTOR_BASE, GIC_REDISTRIBUTOR_SIZE, GIC_REDISTRIBUTOR_BASE, DEVICE_MEM)}, // 0x4804_0000
39+
{MEM_DESC(DRAM_MAP_START, DRAM_MAP_SIZE, DRAM_MAP_START, NORMAL_MEM)}, // 0x8000_0000
3940
};
4041

41-
const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
42+
static const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
4243

43-
rt_region_t init_page_region = {
44-
(rt_size_t)PAGE_START,
45-
(rt_size_t)PAGE_END,
46-
};
44+
static rt_region_t init_page_region;
4745

4846
static rt_base_t get_sctlr_el1()
4947
{
@@ -57,18 +55,21 @@ static rt_base_t get_sctlr_el1()
5755
*/
5856
void rt_hw_board_init(void)
5957
{
58+
rt_hw_earlycon_ioremap();
59+
rt_hw_earlycon_print_hex("sctlr_el1: ", get_sctlr_el1());
6060
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x080000000000, 0x10000000, (size_t *) MMUTable, 0);
61+
62+
init_page_region.start = BOARD_PAGE_START;
63+
init_page_region.end = BOARD_PAGE_END;
6164
rt_page_init(init_page_region);
65+
6266
rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
6367

64-
#ifdef RT_USING_HEAP
68+
#ifdef RT_USING_HEAP
6569
/* initialize system heap */
66-
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
70+
rt_system_heap_init((void *)BOARD_HEAP_BEGIN, (void *)BOARD_HEAP_END);
6771
#endif
6872

69-
/* map LPUART1/CCM_CTRL/GIC_DISTRIBUTOR/GIC_REDISTRIBUTOR virtual address to equals physical address */
70-
rt_ioremap_early((void*)LPUART1_BASE, GIC_REDISTRIBUTOR_BASE + GIC_REDISTRIBUTOR_SIZE - LPUART1_BASE);
71-
7273
/* initialize hardware interrupt */
7374
rt_hw_interrupt_init();
7475

@@ -80,7 +81,6 @@ void rt_hw_board_init(void)
8081

8182
rt_components_board_init();
8283
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
83-
rt_kprintf("[rt_hw_board_init] rt_kprintf works!\n");
8484
}
8585

8686
/*@}*/

bsp/nxp/imx/imx91/drivers/board.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Date Author Notes
88
* 2025-08-10 Siwei Xu Add i.MX91 SDK
99
* 2025-09-15 Siwei Xu Fix LPUART driver
10+
* 2025-12-10 Siwei Xu Fix ioremap issues
1011
*/
1112

1213
#ifndef __BOARD_H__
@@ -15,16 +16,18 @@
1516
#include "imx91.h"
1617
#include "rtconfig.h"
1718

18-
extern int __bss_end;
19-
#define HEAP_BEGIN ((void*)&__bss_end)
20-
2119
#ifndef KERNEL_BOOT_ADDR
2220
#define KERNEL_BOOT_ADDR (ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET)
2321
#endif
2422

25-
#define HEAP_END ((void*)((char*) HEAP_BEGIN + 32 * 1024 * 1024))
26-
#define PAGE_START ((size_t)HEAP_END)
27-
#define PAGE_END ((size_t)PAGE_START + 128 * 1024 * 1024)
23+
/* defined in linker script */
24+
extern unsigned char __bss_end;
25+
26+
#define BOARD_PAGE_START RT_ALIGN((rt_base_t)&__bss_end, KB_SIZE(4))
27+
#define BOARD_PAGE_END (BOARD_PAGE_START + MB_SIZE(1))
28+
29+
#define BOARD_HEAP_BEGIN (BOARD_PAGE_END)
30+
#define BOARD_HEAP_END (BOARD_HEAP_BEGIN + MB_SIZE(32))
2831

2932
void rt_hw_board_init(void);
3033

bsp/nxp/imx/imx91/drivers/imx91.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
rt_base_t platform_get_gic_dist_base(void)
1818
{
19-
return GIC_DISTRIBUTOR_BASE;
19+
return (rt_base_t) rt_ioremap((void*) GIC_DISTRIBUTOR_BASE, GIC_DISTRIBUTOR_SIZE);
2020
}
2121

2222
rt_base_t platform_get_gic_redist_base(void)
2323
{
24-
return GIC_REDISTRIBUTOR_BASE;
24+
return (rt_base_t) rt_ioremap((void*) GIC_REDISTRIBUTOR_BASE, GIC_REDISTRIBUTOR_SIZE);
2525
}
2626

2727
rt_base_t platform_get_gic_cpu_base(void)
2828
{
29-
return GIC_REDISTRIBUTOR_BASE;
29+
return (rt_base_t) rt_ioremap((void*) GIC_REDISTRIBUTOR_BASE, GIC_REDISTRIBUTOR_SIZE);
3030
}

bsp/nxp/imx/imx91/drivers/imx91.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ rt_base_t platform_get_gic_cpu_base(void);
3333
/* gic.c required */
3434
#define __REG32(x) (*((volatile unsigned int *)(x)))
3535

36-
#define GIC_DISTRIBUTOR_SIZE (64 * 1024)
37-
#define GIC_REDISTRIBUTOR_SIZE (768 * 1024)
36+
#define KB_SIZE(x) ((x) * 1024)
37+
#define MB_SIZE(x) ((x) * 1024 * 1024)
3838

39-
#define LPUART1_SIZE (64 * 1024)
40-
#define CCM_CTRL_SIZE (64 * 1024)
39+
#define GIC_DISTRIBUTOR_SIZE KB_SIZE(64)
40+
#define GIC_REDISTRIBUTOR_SIZE KB_SIZE(768)
41+
42+
#define LPUART1_SIZE KB_SIZE(64)
43+
#define CCM_CTRL_SIZE KB_SIZE(64)
4144

4245
#endif /* __IMX91_H__ */
4346

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "MIMX9131.h"
2+
3+
CCM_Type* CCM_CTRL = (CCM_Type *)CCM_CTRL_BASE;
4+
5+
LPUART_Type* LPUART1 = (LPUART_Type *)LPUART1_BASE;
6+
LPUART_Type* LPUART2 = (LPUART_Type *)LPUART2_BASE;
7+
LPUART_Type* LPUART3 = (LPUART_Type *)LPUART3_BASE;
8+
LPUART_Type* LPUART4 = (LPUART_Type *)LPUART4_BASE;
9+
LPUART_Type* LPUART5 = (LPUART_Type *)LPUART5_BASE;
10+
LPUART_Type* LPUART6 = (LPUART_Type *)LPUART6_BASE;
11+
LPUART_Type* LPUART7 = (LPUART_Type *)LPUART7_BASE;
12+
LPUART_Type* LPUART8 = (LPUART_Type *)LPUART8_BASE;

0 commit comments

Comments
 (0)