【STM32F723 Discovery Kit】外扩SRAM存储器读写测试
<div class='showpostmsg'> 本帖最后由 TL-LED 于 2023-9-23 10:22 编辑<p><span style="font-size:16px;">这篇来测试下开发板外扩SRAM存储器的读写。</span></p>
<p> </p>
<p><span style="font-size:16px;"><strong>一、外扩SRAM硬件电路</strong></span></p>
<p> </p>
<p><span style="font-size:16px;">1.1、外扩SRAM电路图部分</span></p>
<p> </p>
<p><span style="font-size:16px;"></span></p>
<p><span style="font-size:16px;">1.2、SRAM存储器的地址范围</span></p>
<p> </p>
<p><span style="font-size:16px;">SRAM 接在STM32的FMC总线接口,看下手册中FMC外扩存储器的框图</span></p>
<p><span style="font-size:16px;">SRAM存储器使用了FMC_NE1接口,对应的存储器地址如下</span></p>
<p><span style="font-size:16px;">存储地址范围:0X6000 0000 ~ 0x6FFF FFFF</span></p>
<p> </p>
<p><span style="font-size:16px;"></span></p>
<p> </p>
<p><span style="font-size:16px;">1.3、存储器容量</span></p>
<p> </p>
<p><span style="font-size:16px;">看下开发板使用的这款芯片的存储空间大小</span></p>
<p><span style="font-size:16px;"></span></p>
<p><span style="font-size:16px;">从芯片手册上看,存储空间是8Mbit,512K*16位的存储空间。</span></p>
<p> </p>
<p> </p>
<p><span style="font-size:16px;"><strong>二、测试程序</strong></span></p>
<p> </p>
<p><span style="font-size:16px;">测试程序对sram芯片1MB范围内数据的读写测试,存储地址存取每次增加4000。</span></p>
<p> </p>
<p><span style="font-size:16px;">2.1、sram.c</span></p>
<pre>
<code>#include "sram/sram.h"
#include "usart/usart.h"
#define BUFFER_SIZE ((uint32_t)0x8000)
#define WRITE_READ_ADDR ((uint32_t)0x0800)
#define WRITING_OFFSET ((uint32_t)0xC20F)
SRAM_HandleTypeDef psramHandle;
FMC_NORSRAM_TimingTypeDef Timing;
uint8_t aTxBuffer;
uint8_t aRxBuffer;
__IO uint32_t uwWriteReadStatus = 0;
uint32_t uwIndex = 0;
//uint32_t sram_test_buffer __attribute__((at(SRAM_BANK_ADDR)));
static void Error_Handler(void)
{
printf("error\r\n");
while (1)
{
}
}
void sram_Init(void)
{
/* SRAM device configuration */
psramHandle.Instance = FMC_NORSRAM_DEVICE;
psramHandle.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
/* Timing configuration derived from system clock (up to 200Mhz)
for 100Mhz as SRAM clock frequency */
Timing.AddressSetupTime = 9;
Timing.AddressHoldTime = 2;
Timing.DataSetupTime = 6;
Timing.BusTurnAroundDuration = 1;
Timing.CLKDivision = 2;
Timing.DataLatency = 2;
Timing.AccessMode = FMC_ACCESS_MODE_A;
psramHandle.Init.NSBank = FMC_NORSRAM_BANK1;
psramHandle.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
psramHandle.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
psramHandle.Init.MemoryDataWidth = SRAM_MEMORY_WIDTH;
psramHandle.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
psramHandle.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
psramHandle.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
psramHandle.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
psramHandle.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
psramHandle.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
psramHandle.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
psramHandle.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
psramHandle.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
/* Initialize the SRAM controller */
if(HAL_SRAM_Init(&psramHandle, &Timing, &Timing) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
}
void sram_test(void)
{
uint32_t i = 0;
uint8_t temp = 0;
printf("ext memoory test\r\n");
printf("\r\nwrite data:\r\n");
temp=0;
for (i = 0; i < 1024000; i += 4000)
{
aTxBuffer=temp;
temp++;
HAL_SRAM_Write_8b(&psramHandle, (uint32_t *)(SRAM_BANK_ADDR + i), aTxBuffer, 1);
printf(" %x",aTxBuffer);
}
printf("\r\nread data:\r\n");
temp=0;
for (i = 0; i < 1024000; i += 4000)
{
HAL_SRAM_Read_8b(&psramHandle, (uint32_t *)(SRAM_BANK_ADDR + i), aRxBuffer, 1);
printf(" %x",aRxBuffer);
aRxBuffer=0;
}
}</code></pre>
<p> </p>
<p><span style="font-size:16px;">2.2、sram.h</span></p>
<pre>
<code>#ifndef _SRAM_H
#define _SRAM_H
#include "stm32f7xx_hal.h"
#define SRAM_BANK_ADDR ((uint32_t)0x60000000)
/* #define SRAM_MEMORY_WIDTH FMC_NORSRAM_MEM_BUS_WIDTH_8*/
#define SRAM_MEMORY_WIDTH FMC_NORSRAM_MEM_BUS_WIDTH_16
#define SRAM_TIMEOUT ((uint32_t)0xFFFF)
void sram_Init(void);
void sram_test(void);
#endif</code></pre>
<p> </p>
<p><span style="font-size:16px;">2.3、main.c</span></p>
<pre>
<code>int main(void)
{
MPU_Config(); /* Configure the MPU attributes */
CPU_CACHE_Enable(); /* Enable the CPU Cache */
HAL_Init();
SystemClock_Config(); /* Configure the system clock to 216 MHz */
delay_init(216);
led_init();
usart_init(115200);
sram_Init();
sram_test();
LED5(0);
LED6(1);
while (1)
{
LED5_TOGGLE();
LED6_TOGGLE();
HAL_Delay(100);
}
}</code></pre>
<p> </p>
<p><span style="font-size:16px;"><strong>三、程序运行</strong></span></p>
<p> </p>
<p><span style="font-size:16px;">串口输出:</span></p>
<p><span style="font-size:16px;"></span></p>
<p> </p>
<p> </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>程序运行的串口输出应该是正确的</p>
火辣西米秀 发表于 2023-9-24 08:30
程序运行的串口输出应该是正确的
<p>嗯,测试输出正常</p>
<p>SRAM要技术支持吗?可以免费支持</p>
页:
[1]