Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views7 pages

Session 2-1

The document provides detailed notes on memory management and programming concepts in embedded systems, emphasizing the importance of memory types such as RAM, ROM, and flash memory. It discusses data storage, variable initialization, and the role of linker scripts in managing memory segments. Additionally, it covers programming practices in Embedded C, including the use of pointers, super loops, and makefiles for building applications.

Uploaded by

jady71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Session 2-1

The document provides detailed notes on memory management and programming concepts in embedded systems, emphasizing the importance of memory types such as RAM, ROM, and flash memory. It discusses data storage, variable initialization, and the role of linker scripts in managing memory segments. Additionally, it covers programming practices in Embedded C, including the use of pointers, super loops, and makefiles for building applications.

Uploaded by

jady71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Notes after 2nd break

• B match clock cycles kolha zay ba3d for ex 3 for fetch and 4 for excute (cisc)

• Fee combined ways 3ashan pipelining cisc at first then RISC for Pipeline

• Compiler more into this 3ashan yhawel mn c l assembly


• MEMORY

• Used to in targeting Code optimization

• Data memory (Ram) > global and local variable

• ROM > Stores the application code + not volatile

• Memory is Hardware based on Transistors and Capacitors

• Each segment can only store 1 bytes

• Addresses can start with OFFSET not always initialized by address 0 (Ex:0x2000
**** )

• When storing variable of 4 bytes we search for aligned location with 4 bytes
combined (0,4,8,12,16...)

• If 1 byte can be stored anywhere

• 8/16/32 bit microcontroller defines the data bus of microcontroller

• If 8 bit microcontroller the 4 bytes (32 bit) will be written in memory in 4 cycles
each with 8 bits (1 byte)

• The more the bit bus increase the faster the processing is

• Nonvolatile as Hard-Disk or flash memory

• Writing on volatile memory is faster in speed than nonvolatile memory

• Reading from nonvolatile memory is faster

• While code running is prohibited to write in flash memory just reading the data
in flash memory just reading to fetch the executions

• Updating flash memory only while in boot mode while connecting to PC


uploading the new HEX file saving in memory

• Bootloader usage ease the proess

• Slow in writing and Fast in reading (ROM)

• Dynamic Ram vs Static Ram

• DRAM : Capacitors based giving an electric signal to be translated from 0 > 1

• Takes time to charge and discharge so DRAM Slow in reading and Writing
• If capacitor left alone it will eventually discharge so we recharge using
perioding charging which increase power consumption

• SRAM : Transistors based gates opening so faster in writing data but higher in
memory space taken

• Variables stored in SRAM for faster process

• SRAM Used in Microcontrollers

• Know from data sheet the start and end of the memory and its size

• .data // .bss // stack

o Must know each size and there start address written in linker script

• Any variable initialized stored in .Data (ex: int x = 5)

• Any global variables not initialized stored in .bss (ex: unsigned char y=0 )

• If given 0 then its initialized

• while function using variables stores in Stack in new address each time
(push,pop)

• From the start to the end of the code running the variables are stored .data and
.bss

• Any global variable used can be used at any file using (extern)
• Linker used to link files global variables used combined if not found linker error

• Use (static) if u want the scope of the variable only in its file

• Local variable defined in stack

• Static local variable stores the variable as global variable with fixed space in
memory but its scope in the function its defined in

• if initialized saved in .data if not .bss

• .data and . Bss are virtual names agreed and defined in linker script each
section size and start memory known from data sheet

• IF nested functions used we use bigger stack to avoid stack overflow in .data
and .bss segments and also can overwrite data in .bss and .data values

• For extra assurance we add guarded sections at the end of the stack (4 bytes)
each time we check the sp and check these 4 values if same value if changed
then stack tried to overwrite these guarded sections and give alarm showing
overflow alert

• Before jumping to other function we save the pc in stack so when returning the
next instruction is executed

• Interrupts do context switching when triggered its saves the vales of general
purpose registers and variables store before interrupt handling and restore
after

• OS save its context in stack memory and restore the context of the other app
while task switching as in Computer app handling

• LR used in debugging to know what function called u

• Flash memory

o IVT

o .text

o .rodata

o .boot

o .data
• Startup code powers the start of the m/c as stack pointer initializing from linker
script

• .data saved in RAM & Flash memory

• Takes data saved in Flash memory and save in RAM

• Flash EEPROM

o Organized as sectors (256B - 16KB) so organized between .data .boot .text


...etc

• Data EEPOM

o Allows Writing/Reading while run time & remains saved even if power
supply is off

o ex: Bottle counting in factory + blackbox in airplanes

• OTP

o Only programmed once

o So cheap

Notes after 3rd break

• Embedded C

• Memory is so important to take into considerations (ex: int,char...etc)

• Target faster execution time

• Prime number ex: can't be divided 3ala rakam akbar mn noso as 100 msh akbar
mn ay rakam fo2 50

• We access the internal memory direct in embedded systems

• Locations given from data sheet as (ex: timers)

• We can direct access memory as (ex: pointers)

• Pointers is used frequently in embedded c

• Some macros used to access memory as (ex: bit masking)


• Super loop functions (ex: while(1) , for(;;) )

• Guarding header

o File1.h and File2.h included in main.c but inside file2.h file1.h is included
so content is duplicated

o Make sure files are not multiple included

• Using #ifdef and #endif

• Linker script

o Contains the start and size of (ex: .bss .data...etc)

• Makefile

o Makefile used to write in all source files and folders needed and path of
the compiler and open powershell to run the makefile

o We use separate tool to build the program as IDE and external compiler

• Test.c using Notepad++

• Compile using gcc >> .exe file

o IDE used just for text editor and make advantage of shortcuts in

o <> used in libraries standard made

o "" used in created files

o If linker error shows (ld error)

o In terminal use (-I headers/) to include all header files needed


o One main file + .h folder + .c Folder

You might also like