0% found this document useful (0 votes)
5 views

Week 5 Memory

1

Uploaded by

shoangnt
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Week 5 Memory

1

Uploaded by

shoangnt
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

EMBEDDED SYSTEM DESIGN

MEMORY
Doan Duy, Ph. D.
Email: [email protected]

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 1


Objective and Content

 Overview of memory

 Memory Organization

 Example

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 2


Content

 Overview of memory

 Memory Organization

 Example

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 3


Role of memory in embedded systems

Traditional roles: Storage and Communication for Programs

In embedded systems:
 Communication with Sensors and Actuators
 Often much more constrained than in general-purpose
computing: Size, power, reliability, etc.

Can be important for programmers to understand these


constraints?

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 4


Practical Issues
 Types of memory
 volatile vs. non-volatile, SRAM vs. DRAM
 Memory maps
 Harvard architecture
 Memory-mapped I/O
 Memory organization
 statically allocated
 stacks
 heaps (allocation, fragmentation, garbage collection)
 The memory model of C
 Memory hierarchies
 scratchpads, caches, virtual memory)
 Memory protection
 segmented spaces

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 5


Memory mapping

Memory Map of an
ARM CortexTM - M3
architecture
Defines the mapping of
addresses to physical
memory.

Note that this does not


define how much physical
memory there is!
09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 6
Questions for understanding

 Why is it called an 8-bit


microcontroller?

 What is the difference between an


8-bit microcontroller and a 32-bit
microcontroller?

 Why use volatile memory? Why


not always use non-volatile
memory?

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 7


Objective and Content

 Overview of memory

 Memory Organization

 Example

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 8


Memory organization for Programs

 Statically-allocated memory
• Compiler chooses the address at which to store a
variable.
 Stack
• Dynamically allocated memory with a Last-in,
First-out (LIFO) strategy
 Heap
• Dynamically allocated memory

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 9


Memory allocation (1)
What is meant by the following C code:
char x;
void foo(void) {
x = 0x20;

}

An 8-bit quantity (hex 0x20) is stored at an address in statically


allocated memory in internal RAM determined by the compiler.

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 10


Memory allocation (2)

What is meant by the following C code:


char *x;
void foo(void) {
x = 0x20;

}

An 16-bit quantity (hex 0x0020) is stored at an address in statically


allocated memory in internal RAM determined by the compiler.

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 11


Memory allocation (3)

What is meant by the following C code:


char *x, y;
void foo(void) {
x = 0x20;
y = *x;

}

The 8-bit quantity in the I/O register at location 0x20 is


loaded into y, which is at a location in internal SRAM
determined by the compiler.

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 12


Memory allocation (4)
char foo() {
char *x, y;
x = 0x20;
y = *x;
Where are x, y, z in memory? return y;
}
char z;
int main(void) {
z = foo();

}

x occupies 2 bytes on the stack, y occupies 1 byte on the


stack, and z occupies 1 byte in static memory.
09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 13
Memory allocation (5)

What is meant by the following C code:

void foo(void) {
char *x, y;
x = &y;
*x = 0x20;

}

16 bits for x and 8 bits for y are allocated on the stack, then x is
loaded with the address of y, and then y is loaded with the 8-bit
quantity 0x20.
09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 14
Memory allocation (6)
What goes into z in the following program:
char foo() {
char y;
uint16_t x;
x = 0x20;
y = *x; z is loaded with the 8-bit
return y; quantity in the I/O register at
} location 0x20.
char z;
int main(void) {
z = foo();

}

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 15


Dynamically-Allocated Memory
The Heap

An operating system typically offers a way to dynamically allocate


memory on a “heap”.

Memory management (malloc() and free()) can lead to many


problems with embedded systems:
 Memory leaks (allocated memory is never freed)
 Memory fragmentation (allocatable pieces get smaller)

Automatic techniques (“garbage collection”) often require


stopping everything and reorganizing the allocated memory. This is
deadly for real-time programs.

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 16


Memory Hierarchies

 Cache:
 A subset of memory addresses is mapped to SRAM
 Accessing an address not in SRAM results in cache miss
 A miss is handled by copying contents of DRAM to SRAM
 Scratchpad:
 SRAM and DRAM occupy disjoint regions of memory space
 Software manages what is stored where
 Segmentation
 Logical addresses are mapped to a subset of physical addresses
 Permissions regulate which tasks can access which memory

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 17


Memory Hierarchies

Memory-
mapped I/O
devices

CPU
Cache Main memory Disk or Flash
registers

register address fits SRAM DRAM


within one
instruction word

Here, the cache or scratchpad, main memory, and disk or flash


share the same address space.
09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 18
Memory Hierarchies

Memory-
mapped I/O
devices
 Here, each distinct piece
CPU of memory hardware has
scratch
pad
its own segment of the
registers address space.
SRAM
 This requires more
Main
memory careful software design,
register address
fits within one DRAM
but gives more direct
instruction word control over timing.
Disk or Flash

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 19


Objective and Content

 Overview of memory

 Memory Organization

 Example

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 20


0xFFFFFFFF
Berkeley Microblaze
Personality Memory Map Unmapped Area
0xC220FFFF
ADC subsystem
0xC2200000
Unmapped Area
0x8440FFFF
MicroBlaze MEMORY Debugger
50MHz BRAM 0x84400000
Unmapped Area
0x8402FFFF
UARTs
UART0 0x84000000
UART1 Unmapped Area
0x83C0FFFF

ADC
Timer
0x83C00000
Subsystem Unmapped Area
0x8180FFFF
Interrupt controller
TIMER 0x81800000

Debugger Unmapped Area

Interrupt 0x0000FFFF
controller Memory for
Instructions and Data 0x00000000

09/27/2024 21
Copyrights 2020 CE-UIT. All Rights Reserved.
Conclusion

Understanding memory architectures is essential


to programming embedded systems!

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 22


Q&A

09/27/2024 Copyrights 2020 CE-UIT. All Rights Reserved. 23

You might also like