cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use internal 64Kbytes SRAM ?

antonius
Senior
Posted on August 18, 2015 at 12:41

Guys,

How can I use internal 64Kbytes SRAM from STM32F107?

Any code example from StdPeripheral ?

Thanks
8 REPLIES 8
mh.ferris9
Associate II
Posted on August 18, 2015 at 13:14

Any normal variable you declare will be stored in SRAM automatically.

This'll be in SRAM:

u8 myArray[256];  

Am I perhaps not understanding what you mean?

antonius
Senior
Posted on August 18, 2015 at 13:18

I see, thanks for responding...

how to implement this in code ?

I read from datasheet reference :

3.3.1 Embedded SRAM

 

The STM32F10xxx features up to 96 Kbytes of static SRAM. It can be accessed as bytes,

 

half-words (16 bits) or full words (32 bits). The SRAM start address is 0x2000 0000.

 

3.3.2 Bit banding

 

The Cortex®-M3 memory map includes two bit-band regions. These regions map each word

 

in an alias region of memory to a bit in a bit-band region of memory. Writing to a word in the

 

alias region has the same effect as a read-modify-write operation on the targeted bit in the

 

bit-band region.

 

In the STM32F10xxx both peripheral registers and SRAM are mapped in a bit-band region.

 

This allows single bit-band write and read operations to be performed. The operations are

 

only available for Cortex®-M3 accesses, not from other bus masters (e.g. DMA).

 

A mapping formula shows how to reference each word in the alias region to a corresponding

 

bit in the bit-band region. The mapping formula is:

 

bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number × 4)

 

where:

 

bit_word_addr is the address of the word in the alias memory region that maps to the

 

targeted bit.

 

bit_band_base is the starting address of the alias region

 

byte_offset is the number of the byte in the bit-band region that contains the targeted

 

bit

 

bit_number is the bit position (0-7) of the targeted bit.

 

Example:

 

The following example shows how to map bit 2 of the byte located at SRAM address

 

0x20000300 in the alias region:

 

0x22006008 = 0x22000000 + (0x300*32) + (2*4).

 

Writing to address 0x22006008 has the same effect as a read-modify-write operation on bit

 

2 of the byte at SRAM address 0x20000300.

 

Reading address 0x22006008 returns the value (0x01 or 0x00) of bit 2 of the byte at SRAM

 

address 0x20000300 (0x01: bit set; 0x00: bit reset).

 

For more information on Bit-Banding, please refer to the Cortex®-M3 Technical Reference

 

Manual.

mh.ferris9
Associate II
Posted on August 18, 2015 at 13:28

Still not quite sure what you're worried about?

Are you writing code in assembler or C?
antonius
Senior
Posted on August 18, 2015 at 14:20

I'm writing on C,

I want to know the address of the data for reading and writing later on...

How can I point to one address and write ? then read ?

for example

write at the location 0x020000 = ''a''....

then read from that location later on...

thanks

Posted on August 18, 2015 at 14:43

The linker assigns addresses to variables in SRAM. Review the .MAP output to see where they are, and what's being used.

int a = 123;

printf(''%p\n'', &a); // Print address of 'a'

*((uint32_t *)0x20002000) = 0x12345678;

printf(''%08X\n'', *((uint32_t *)0x20002000) );

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mh.ferris9
Associate II
Posted on August 18, 2015 at 14:57

Its trivial to write and read variables that are in RAM.

Do you want to write and read random addresses in RAM?  If so, what for?

antonius
Senior
Posted on August 18, 2015 at 15:17

Thanks clive,

I think I can see how it works from here :

STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/Library_Examples.html

how do you reckon ?

Bit Banding

This example shows how to use CortexM3 Bit-Band access to perform atomic read-modify-write and read operations on a variable in SRAM.

Posted on August 18, 2015 at 16:29

Bit-Banding simply rebases the memory so that each bit is not represented by a 32-bit word.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..