173 2438 5004
KEROS加密芯片——品牌直销 | 免费样品 | 技术支持
当前位置:网站首页 > 资讯中心 正文 资讯中心

stm32读取sram

keros@mark 2023-03-19 资讯中心

如何使用备份SRAM的EEPROM中STM32F4

1.必须做到如下: 启用压水堆时钟

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

能够访问到备份域

PWR_BackupAccessCmd(ENABLE);

启用备份SRAM时钟

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);

启用备份SRAM的低功耗稳压器,以保持它在VBAT模式的内容

PWR_BackupRegulatorCmd(ENABLE);

你可以读/写数据,建立SRAM(从STM32F4xx_DSP_StdPeriph_Lib BKP_Domain代码这些代码)(在我的MCU stm32f417 BKPSRAM_BASE=0x40024000)

// Write to Backup SRAM with 32-Bit Data

for (i = 0x0; i 0x100; i += 4) {

*(__IO uint32_t *) (BKPSRAM_BASE + i) = i;

}

// Check the written Data

for (i = 0x0; i 0x100; i += 4) {

if ((*(__IO uint32_t *) (BKPSRAM_BASE + i)) != i){

errorindex++;

}

}

那么,如果你想 //等到备份SRAM的低功耗稳压器已准备就绪

while(PWR_GetFlagStatus(PWR_FLAG_BRR) == RESET)

{}

你可以在STM32F4xx_DSP_StdPeriph_Lib找到这些函数。

2. 通过参考手册STM32F4和stm32f405xx / stm32f407xx书看完后,我同意这是不清楚如何备份SRAM(或所在)。下面是我发现。无论是RTC寄存器和备份SRAM包含存储的,只要你有电池电量维持量。该RTC含有20寄存器(80字节)和备份SRAM(这是它自己的周缘上AHB1和位于寄存器地址区域内)包含为0x1000(4096字节)。无论是默认启用的。 在DM00037051(stm32f405xx / stm32f407xx数据,P29):

The 4-Kbyte backup SRAM is an EEPROM-like memory area. It can be used to store

data which need to be retained in VBAT and standby mode. This memory area is

disabled by default to minimize power consumption (see Section 2.2.19:

Low-power modes). It can be enabled by software.

The backup registers are 32-bit registers used to store 80 bytes of user

application data when VDD power is not present. Backup registers are not reset

by a system, a power reset, or when the device wakes up from the Standby mode

(see Section 2.2.19: Low-power modes).

数据表71页参考手册和p65在

AHB1 | 0x4002 4000 - 0x4002 4FFF | BKPSRAM

和参考手册的datatasheet和P67的第73页

APB1 | 0x4000 2800 - 0x4000 2BFF | RTC BKP Registers

页面上启用备份SRAM和RTC寄存器参考手册118-119。 注意:如果你是RTC的备份域 CodeGo.net,只需要存储和LT=80个字节,那么你最好的支持RTC寄存器启用备份SRAM基本上会加倍消耗电流(参见stm32f405 / 7数据表25 )。 这里是我的写入和读取用于备份SRAM和备份函数的RTC寄存器

int8_t write_to_backup_sram( uint8_t *data, uint16_t bytes, uint16_t offset ) {

const uint16_t backup_size = 0x1000;

uint8_t* base_addr = (uint8_t *) BKPSRAM_BASE;

uint16_t i;

if( bytes + offset = backup_size ) {

/* ERROR : the last byte is outside the backup SRAM region */

return -1;

}

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);

/* disable backup domain write protection */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // set RCC-APB1ENR.pwren

PWR_BackupAccessCmd(ENABLE); // set PWR-CR.dbp = 1;

/** enable the backup regulator (used to maintain the backup SRAM content in

* standby and Vbat modes). NOTE : this bit is not reset when the device

* wakes up from standby, system reset or power reset. You can check that

* the backup regulator is ready on PWR-CSR.brr, see rm p144 */

PWR_BackupRegulatorCmd(ENABLE); // set PWR-CSR.bre = 1;

for( i = 0; i bytes; i++ ) {

*(base_addr + offset + i) = *(data + i);

}

PWR_BackupAccessCmd(DISABLE); // reset PWR-CR.dbp = 0;

return 0;

}

int8_t read_from_backup_sram( uint8_t *data, uint16_t bytes, uint16_t offset ) {

const uint16_t backup_size = 0x1000;

uint8_t* base_addr = (uint8_t *) BKPSRAM_BASE;

uint16_t i;

if( bytes + offset = backup_size ) {

/* ERROR : the last byte is outside the backup SRAM region */

return -1;

}

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);

for( i = 0; i bytes; i++ ) {

*(data + i) = *(base_addr + offset + i);

}

return 0;

}

int8_t write_to_backup_rtc( uint32_t *data, uint16_t bytes, uint16_t offset ) {

const uint16_t backup_size = 80;

volatile uint32_t* base_addr = (RTC-BKP0R);

uint16_t i;

if( bytes + offset = backup_size ) {

/* ERROR : the last byte is outside the backup SRAM region */

return -1;

} else if( offset % 4 || bytes % 4 ) {

/* ERROR: data start or num bytes are not word aligned */

return -2;

} else {

bytes = 2; /* divide by 4 because writing words */

}

/* disable backup domain write protection */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // set RCC-APB1ENR.pwren

PWR_BackupAccessCmd(ENABLE); // set PWR-CR.dbp = 1;

for( i = 0; i bytes; i++ ) {

*(base_addr + offset + i) = *(data + i);

}

PWR_BackupAccessCmd(DISABLE); // reset PWR-CR.dbp = 0;

// consider also disabling the power peripherial?

return 0;

}

int8_t read_from_backup_rtc( uint32_t *data, uint16_t bytes, uint16_t offset ) {

const uint16_t backup_size = 80;

volatile uint32_t* base_addr = (RTC-BKP0R);

uint16_t i;

if( bytes + offset = backup_size ) {

/* ERROR : the last byte is outside the backup SRAM region */

return -1;

} else if( offset % 4 || bytes % 4 ) {

/* ERROR: data start or num bytes are not word aligned */

return -2;

} else {

bytes = 2; /* divide by 4 because writing words */

}

/* read should be 32 bit aligned */

for( i = 0; i bytes; i++ ) {

*(data + i) = *(base_addr + offset + i);

}

return 0;

}

3. 我是一个STM32F2xx微控制器。根据数据表: 4 KB的备份SRAM是EEPROM般的区域。 保留的RTC备份寄存器的内容......当VDD关闭时,VBAT引脚可以连接到由电池或由另一个源提供的可选的备份电压。 甲超级电容器,例如,将需要而在微控制器的电源关闭,以保持备份寄存器的内容。 此外,根据本 复位后,备份域(...备份SRAM)进行保护,防止可能有害的写访问。要允许访问备份域,请执行以下操作... 它为您提供了有关如何访问到备份域通过直接写入到某些外设寄存器指令。如果你有机会到STM32F4xx库,你可以这样调用(注意:我的STM32F2xx库):

PWR_BackupAccessCmd(ENABLE);

注:还有更多的是它不是简单地调用上面的函数,如启用备份SRAM接口时钟。咨询STM32F4系列 有很多嵌入的库源是无价的,如果它是可用的,应阅读。 在STM32F2系列微控制器,SRAM位于地址范围: 0x40024000-0x40024FFF 并且可以被写入到在位置,例如,如下所示:

#define VAR_LOC ((volatile uint8_t *)(0x40024000))

volatile uint8_t *pVar = VAR_LOC;

*pVar = 5;

stm32 fsmc怎么访问外扩的sram

首先确定sram的开始地址,然后这样使用(假设sram开始地址0x68000000):

u8 buf[100] __attribute__((at(0X68000000)));

这样就表示将buf放在了外扩的sram中。

stm32f4 如何往外部存储sram写数据

STM32控制器芯片内部有一定大小的SRAM及FLASH作为内存和程序存储空间,但当程序较大,内存和程序空间不足时,就需要在STM32芯片的外部扩展存储器了。STM32F4系列芯片可以扩展外部SRAM用作内存。

__TM32芯片扩展内存与给PC扩展内存的原理是一样的,只是PC上一般以内存条的形式扩展,而且内存条实质是由多个内存颗粒(即SDRAM芯片)组成的通用标准模块,而STM32扩展时,直接与SRAM芯片连接。

_蔡婊娲⑵? SRAM的存储单元以锁存器来存储数据。这种电路结构不需要定时刷新充电,就能保持状态(当然,如果断电了,数据还是会丢失的),所以这种存储器被称为“静态(Static)”RAM。

_栽谑导视τ贸『现校_RAM 一般只用于 CPU 内部的高速缓存(Cache),而外部扩展的内存一般使用 DRAM。

怎样实现stm32 自身sram数据读写

对绝对的地址空间进行读写即可。

比如STM32自身的SRAM地址空间范围是0x20000000-0xXXXXXXXX(结束地址根据不同型号而不同,比如STM32F103ZET6的SRAM地址空间为0x20000000-0x2000FFFF共64KB),对绝对地址进行访问的C语言代码是:

a = *(u8 *)0x20000000;//将地址为0x20000000的一个字节数据读取到变量a中

*(u8 *)0x20000100 = a; //将变量a的值放到地址0x20000100处

不过不推荐直接访问绝对地址,因为这样可能会破坏堆栈而导致程序跑乱跑飞等问题的出现。

本文标签:stm32读取sram

产品列表
产品封装
友情链接