前言
- 【STM32H7S78-DK】开箱与rtthread工程初体验
概述
板卡因为内置 flash 小的问题,采用 boot+application 运行方式,自带的 boot 固件已经开启了 flash 和 psram 的内存映射,可以直接访问对应的地址。现在我们就将 psram 内存添加至内存管理单元中
配置工程
打开 bsp/stm32/stm32h7s7-st-disco 目录
- 在
board/port/ 目录下新增 drv_psram.c ,添加如下代码 /*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-08-28 morph first implementation
*/
#include <board.h>
#include <rtthread.h>
#ifdef BSP_USING_PSRAM
#define DRV_DEBUG
#define LOG_TAG "drv.psram"
#include <drv_log.h>
#ifdef RT_USING_MEMHEAP_AS_HEAP
static struct rt_memheap system_heap;
#endif
static int PSRAM_Init(void)
{
int result = RT_EOK;
#ifdef RT_USING_MEMHEAP_AS_HEAP
/* If RT_USING_MEMHEAP_AS_HEAP is enabled, SDRAM is initialized to the heap */
rt_memheap_init(&system_heap, "psram", (void *)STM32_PSRAM_START, STM32_PSRAM_SIZE * 1024U);
#endif
return result;
}
INIT_BOARD_EXPORT(PSRAM_Init);
#endif /* BSP_USING_PSRAM */
- 修改
board/board.h/ 加入 psram 的配置信息
- 修改
board/linker_scripts/link.sct 链接文件,重新规划分区
- 修改
board/kconfig 文件,增加 PSRAM 配置项,因为 boot 已经支持就直接默认使能
- 修改
board/SConscript 文件,将 drv_psram.c 加入进来
- 使用 ****menuconfig** 查看 onboard 驱动,看到已经增加 PSRAM 配置****
- 在 kernel 目录,开启 memheap 管理,才能加入内存管理,保存退出
- 使用 ****scons --target=mdk5** 工具同步工程,重新编写下载,可以看到内存管理多了 psram 块**
使能 CACHE 和 MPU
- 修改
board/kconfig 文件,在 chip driver 栏增加 cache 配置项,这边我也是直接默认使能
- 修改
board/board.c 文件,增加 mpu 的配置 /*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-04-10 RealThread first version
*/
#include "board.h"
#define DBG_TAG "board"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
/* MPU Configuration */
static void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct = {0};
/* Disables the MPU */
HAL_MPU_Disable();
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.BaseAddress = 0x0;
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
MPU_InitStruct.SubRegionDisable = 0xA7;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
MPU_InitStruct.BaseAddress = 0x70000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_128MB;
MPU_InitStruct.SubRegionDisable = 0x0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER2;
MPU_InitStruct.Size = MPU_REGION_SIZE_2MB;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER3;
MPU_InitStruct.BaseAddress = 0x90000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER4;
MPU_InitStruct.BaseAddress = 0x20000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_64KB;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER5;
MPU_InitStruct.BaseAddress = 0x24000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER6;
MPU_InitStruct.BaseAddress = 0x2406e000;
MPU_InitStruct.Size = MPU_REGION_SIZE_16KB;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Enables the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
//Notice: system main clock is set in user boot stage.
//you can modify it but be aware on XPI1 and XPI2 status.
/* MPU Configuration--------------------------------------------------------*/
MPU_Config();
return;
}
int clock_information(void)
{
LOG_I("System Clock information");
LOG_I("SYSCLK_Frequency = %d", HAL_RCC_GetSysClockFreq());
LOG_I("HCLK_Frequency = %d", HAL_RCC_GetHCLKFreq());
LOG_I("PCLK1_Frequency = %d", HAL_RCC_GetPCLK1Freq());
LOG_I("PCLK2_Frequency = %d", HAL_RCC_GetPCLK2Freq());
LOG_I("XSPI1_Frequency = %d", HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_XSPI1));
LOG_I("XSPI2_Frequency = %d", HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_XSPI2));
return RT_EOK;
}
INIT_BOARD_EXPORT(clock_information);
- 使用 menuconfig 查看 onchip driver,看到已经增加 cache 配置
- 使用 scons --target=mdk5 工具同步工程,重新编写下载,运行无误
总结
评估板板载了 32MB 的 PSRAM,用于缓存图形数据提升显示效率 |