Can be stored data inside non volative memory ?
Can be stored data inside non volative memory ?
Hi,
I've the need to store some data received by serial so that in case of power drop at the power up I can recall these data to be used as setting for my project.
I know that I could write the data inside a csv file but I'm curious to know if like can be done with a PIC there is an area of memory as EEPROM that can be used for this scope , and if possible have some example about how implement ?
Thanks.
I've the need to store some data received by serial so that in case of power drop at the power up I can recall these data to be used as setting for my project.
I know that I could write the data inside a csv file but I'm curious to know if like can be done with a PIC there is an area of memory as EEPROM that can be used for this scope , and if possible have some example about how implement ?
Thanks.
Thanks. Roberto
Re: Can be stored data inside non volative memory ?
Yes, both the left over flash memory and the sdcard can be written. See http://docs.micropython.org/en/latest/library/os.html
This thread might give you some clues and warnings: http://forum.micropython.org/viewtopic.php?t=86
This thread might give you some clues and warnings: http://forum.micropython.org/viewtopic.php?t=86
Re: Can be stored data inside non volative memory ?
There is a small amount of RAM (4 Kbytes) whose contents are retained as long as VBAT is supplied (typically using a coin cell).
Otherwise, you can use the flash file system to store information in a file.
Otherwise, you can use the flash file system to store information in a file.
Re: Can be stored data inside non volative memory ?
How do you get to that RAM? Is it part of the file system and not given over to the memory allocator?
Re: Can be stored data inside non volative memory ?
The datasheet (document RM0090) shows (on page 65) that the backup lives at address 0x40024000 - 0x40024fff
Page 118 has most of the stuff that needs to be initialized, although I think that the BRE bit (which enables the backup regulator) is needed in order to have this RAM retain its contents when VBAT is present).
So that 4K block is not included in the normal RAM that MicroPython processes, and is also not part of the file system.
Page 118 has most of the stuff that needs to be initialized, although I think that the BRE bit (which enables the backup regulator) is needed in order to have this RAM retain its contents when VBAT is present).
So that 4K block is not included in the normal RAM that MicroPython processes, and is also not part of the file system.
Re: Can be stored data inside non volative memory ?
dbc and Dave,
thank you so much for your suggestions.
For sure the use of file system is the most easy way , and I've already use in the past.
Let me see if I'm able to complicate my life trying to address the memory directly.
I can't promise good results..
Thanks again.
thank you so much for your suggestions.
For sure the use of file system is the most easy way , and I've already use in the past.
Let me see if I'm able to complicate my life trying to address the memory directly.
I can't promise good results..
Thanks again.
Thanks. Roberto
Re: Can be stored data inside non volative memory ?
bob63,
I may not have completely answered your whole question. So just to follow up, ST parts do not generally have EEPROM as a separate storage structure as found on some chips. ST expects you to use left-over program flash for that, and publishes an ap note on how to do that from low level code. In general, it isn't as nice a solution, since program flash must be erased and reprogrammed a page at a time. Most EEPROM (like on the AVR chips, for instance) is programmable a single byte at a time. Also, Atmel makes EEPROM using larger structures so that they can withstand more write cycles before dying.
In the case of the ST chip here, I suspect they expect you to use the battery-backed SRAM in the place of EEPROM.
I may not have completely answered your whole question. So just to follow up, ST parts do not generally have EEPROM as a separate storage structure as found on some chips. ST expects you to use left-over program flash for that, and publishes an ap note on how to do that from low level code. In general, it isn't as nice a solution, since program flash must be erased and reprogrammed a page at a time. Most EEPROM (like on the AVR chips, for instance) is programmable a single byte at a time. Also, Atmel makes EEPROM using larger structures so that they can withstand more write cycles before dying.
In the case of the ST chip here, I suspect they expect you to use the battery-backed SRAM in the place of EEPROM.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can be stored data inside non volative memory ?
@BOB63 For most purposes I'd use the filesystem, either via file read and write or via Pickle. However if you want to use the backup RAM - in particular if you want the RAM contents to be accessible after recovery from pyb.standby() - the following seems OK.
To faciltate accessing the RAM as an array of 32 bit words I use the following:
Code: Select all
import stm
stm.mem32[stm.RCC + stm.RCC_APB1ENR] |= 0x10000000 # PWREN bit
stm.mem32[stm.PWR + stm.PWR_CR] |= 0x100 # Set the DBP bit in the PWR power control register
stm.mem32[stm.RCC +stm.RCC_AHB1ENR]|= 0x40000 # enable BKPSRAMEN
stm.mem32[stm.PWR + stm.PWR_CSR] |= 0x200 # BRE backup register enable bit
Code: Select all
class BkpRAM(object):
def __getitem__(self, idx):
assert idx >= 0 and idx <= 0x3ff, "Index must be between 0 and 1023"
return stm.mem32[BKPSRAM + idx * 4]
def __setitem__(self, idx, val):
assert idx >= 0 and idx <= 0x3ff, "Index must be between 0 and 1023"
stm.mem32[BKPSRAM + idx * 4] = val
b = BkpRAM()
b[0] += 1 # Modify the contents of RAM address 0
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Can be stored data inside non volative memory ?
@pythoncoder - Nice! That is a great example of using stm to elegantly expose an otherwise unsupported function in Python. I'm still learning, none of my efforts in that direction were nearly as pretty
-Bryan
-Bryan
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can be stored data inside non volative memory ?
@blmorris Thank you
The code can be made neater by putting the mem32 stuff in the constructor thus:
The code can be made neater by putting the mem32 stuff in the constructor thus:
Code: Select all
import stm
class BkpRAM(object):
BKPSRAM = 0x40024000
def __init__(self):
stm.mem32[stm.RCC + stm.RCC_APB1ENR] |= 0x10000000 # PWREN bit
stm.mem32[stm.PWR + stm.PWR_CR] |= 0x100 # Set the DBP bit in the PWR power control register
stm.mem32[stm.RCC +stm.RCC_AHB1ENR]|= 0x40000 # enable BKPSRAMEN
stm.mem32[stm.PWR + stm.PWR_CSR] |= 0x200 # BRE backup register enable bit
def __getitem__(self, idx):
assert idx >= 0 and idx <= 0x3ff, "Index must be between 0 and 1023"
return stm.mem32[self.BKPSRAM + idx * 4]
def __setitem__(self, idx, val):
assert idx >= 0 and idx <= 0x3ff, "Index must be between 0 and 1023"
stm.mem32[self.BKPSRAM + idx * 4] = val
b = BkpRAM()
b[0] += 1
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.