1/322
Looks like no tags are added yet.
What is a microcontroller?
A complete (or mostly complete) solution for embedded applications: one or more CPU cores, RAM, ROM, I/O ports, and timers
What is the Raspberry Pi 4 made up of?
Broadcom BCM2711 SoC processor, additional SDRAM, USB controller, Ethernet controller, WiFi controller, peripheral I/O
Why is the RP4 called an embedded subsystem?
It is a microcontroller plus additional support controllers
What important function is the RP4 missing?
An RTC (real time clock)
RP4 SoC key functions
4x ARM 64-bit Cortex-A72 cores, SDRAM controller, video decode (H.265/H.264), OpenGL ES 3.0 graphics, L1 and L2 cache, HDMI display interface, many I/O (DMA, USB, UART, SDIO, PWM, PCM/I2S, SPI, GPIO)
ESP32 compared to the RP4
Tensilica 32-bit core (1 or 2), onboard RTC, onboard ROM and RAM, onboard crypto engines, onboard RF logic, many I/O interfaces
Three things a CPU core does
1) Moves data 2) Manipulates data 3) Is controlled by instructions
Internal organization of a computer
CPU, memory, and I/O (input and output)
Memory capacity
The number of bits a memory can store (e.g. 128 Kbits, 256 Mbits)
Memory organization
How the locations are organized, e.g. 128 x 4 = 128 locations of 4 bits each
Memory access time
How long it takes to get data from memory; depends on location and interface speed
Access time: L1 cache vs L2 cache vs external RAM
L1: CPU clock speed. L2: multiple CPU clocks. External RAM: dozens to 100+ CPU clocks
RP4 clock speed
1.5 GHz (older), 1.8 GHz for the latest version. Study guide answer: 1.5 GHz
Three buses connecting CPU to memory and I/O
Address bus, data bus, control bus (read/write)
Memory control signals CS, WE, OE
Chip Select, Write Enable, Output Enable (read)
Port-mapped I/O
An IO/MEM select bit gives I/O its own independent address space
Memory-mapped I/O
I/O devices share the same address space as memory; a logic circuit (address decoder) enables CS for the right address range
Is the RP4 memory mapped or port mapped?
Everything is memory mapped, including I/O
Steps to design an address decoder
1) Write the address range in binary 2) Separate the fixed part of the address 3) Design a logic circuit whose output activates when the fixed bits appear
Address decoder for addresses 0 to 15 (8-bit address)
Fixed bits a7-a4 = 0000; CS (active low) asserted when a7..a4 are all 0
Address decoder for 300H to 3FFH
Fixed bits a11-a8 = 0011; decode those four bits to drive CS
Harvard architecture
Separate memory and buses for code and data
Von Neumann architecture
One shared memory and bus for code and data
Harvard pros and cons
More pins, power and area; more complex; faster with parallel/simultaneous instruction and data access; special purpose; used for registers and L1 cache
Von Neumann pros and cons
Fewer pins and less power; simpler; slower due to bottleneck; general purpose; used for L2, L3, main memory and storage
Program Counter (PC)
Special register inside the processor that stores the address of the next instruction
Stored program computer operation
Step 1: fetch the instruction at the address in the PC and increment the PC. Step 2: execute the instruction, repeat
Most powerful thing a computer can do
Repeat a set of operations until some condition is met
What is branching?
Setting the PC to a specified instruction location rather than the next instruction
Levels of program code
High-level language (C++, Rust, Python) -> assembly language (text form of instructions) -> hardware representation (binary opcodes)
What language does a processor actually run?
Binary machine code (opcodes)
What does a compiler do?
Converts high-level language to assembly/machine code for a specific processor architecture
RISC
Reduced Instruction Set Computing: operations as simple as possible, usually one instruction per clock. ARM, MIPS
CISC
Complex Instruction Set Computing: operations as powerful as possible, 1 to many clocks per instruction. x86
Hybrid (GPU) architecture
Vector or SIMD (single instruction multiple data); data-flow based. SSE, CUDA
Direct addressing
The operand is an address (a mailbox); the data is what is inside that location
Immediate addressing
The operand is a constant number, e.g. #3
Opcode
The fixed-size code in an instruction that identifies which operation to perform
Why do compilers/assemblers take multiple passes?
To resolve addresses of labels and variables that are not known on the first pass
RP4 pins you cannot control
3.3 V, 5 V and GND
Are the 5V and 3.3V PWR pins inputs?
No. They power external devices and are not for input voltage
Default state of GPIO 0-8
High, with a pullup resistor
Default state of GPIO 9-27
Low, with a pulldown resistor
Default internal pullup/pulldown value
About 50 kohm (weak)
Pullup value on GPIO 2 and 3
1.8 kohm, to meet the I2C spec
Typical external pullup/pulldown value
About 10 kohm; a stronger external resistor overrides the internal one
50 kohm pullup in parallel with 10 kohm
8.33 kohm
Max current for one GPIO
16 mA
Max current per pin when using multiple GPIOs
3 mA per I/O
Total GPIO current limit
Stay below about 51 mA (17 outputs at 3 mA each)
What happens if you overdrive the RP4 GPIOs?
The RP4 may reboot due to voltage drop
Ways to debounce a switch
Analog RC filter (0.1 uF capacitor), buffering, digital logic (cross-coupled NANDs / SR latch), software
Output good practices: datasheet items to check
Current, voltage, and time constraints (setup, hold, period)
BJT LED driver: purpose of RB and RC
RB limits current drawn from the Pi; RC limits current through the LED
Python call to force a pulldown on an input
GPIO.setup(gpio_number, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
Extra capabilities some GPIOs have
PWM, I2C, serial ports, etc.
Primary function of the assembler
Convert readable assembly into binary machine code (.s files to .o files)
Why are assemblers multi-pass?
To resolve loop/label dependencies, variable name dependencies, register renaming and reordering
Linker
Combines multiple object files, resolves symbol references and relocates data sections
objcopy
Translates object output from one format to another
objdump
A disassembler that gives readable output of the final result
What does the compiler (GCC) take in?
A mix of assembly (.s), C files (.c), object files (.o) and library files to generate a combined executable with the linker
GCC
GNU C Compiler; common compiler for Linux and bare-metal systems
Bare metal
No operating system; the processor runs only the code the user wrote
EABI (Lecture 3)
Embedded Application Binary Interface; often used for bare-metal programming
ELF
Executable (and Linkable) Format; often used for assembly programs run in a Linux environment
What is the makefile?
A file read by the Make utility that describes how to build the program
What does Make do?
Controls generation of executables, uses the makefile as input, automatically uses the files it needs based on what changed, helps with file management, automates the build
Primary tools for assembly on the RP4 under Linux
GCC and GDB
GDB
GNU Project Debugger
Flag needed to debug with GDB
-g, e.g. as -g prog.s -o prog.o
GDB: set a breakpoint
b
GDB: run the program
r
GDB: show registers
i r
GDB: step
s (or s 100 for 100 steps)
Who coined "debugging"?
Admiral Grace Hopper, Harvard, 1940s, after a moth was found in the computer
Examples of IDEs
VSCode, Geany, Eclipse
What are flowcharts and pseudocode for?
Giving structure to a program: validate the algorithm, find key functions/macros, break a big job into chunks, divide work among teams, communicate with stakeholders
Flowchart characteristics
Symbolic/pictorial, too much detail is bad, hard to modify when large, fixed set of symbols, more straightforward to understand, best for smaller code jobs
Pseudocode characteristics
Natural text, flexible level of detail, easy to modify, open-world structure, can be more complex to follow, best for larger code jobs
Common flowchart symbols
Start/End, Input/Output, Process, Connector, Direction of flow, Decision/condition, Delay
When are flowcharts useful?
At the start of a project to think through architecture, and at the end to document the code
Advantage of pseudocode with real code
It can morph along with the code and become the comments
One hex digit equals how many bits?
4 bits (a nibble)
Convert from a base to base 10
Multiply each digit by base^position and add
Convert from base 10 to another base
Divide repeatedly by the base; remainders are the digits, least significant first
How many values can n bits encode?
2^n
Powers of 2 from 2^0 to 2^10
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024
2^10, 2^20, 2^30 approximately
1 thousand, 1 million, 1 billion
2^32
4,294,967,296 (about 4.3 billion)
Bit
Can be 1 or 0
Nibble
4 bits
Byte
8 bits
Half word
16 bits
Word
32 bits
Kilobit (Kb) vs kilobyte (KB)
Kb = 1024 bits; KB = 1024 bytes = 8192 bits
Megabyte (MB)
2^20 bytes = 1,048,576 bytes
Binary: 1 + 1
10 (2)
Hex: 0x0A + 0x08
0x12 (18)
Prefixes for binary and hex
Binary: % or 0b. Hex: $ or 0x