Module 5Módulo 5

Memory and architectureMemoria y arquitectura

Where MSP430 code, data and peripherals actually live, and the rules that govern that space. Dónde viven realmente el código, los datos y los periféricos del MSP430, y las reglas de ese espacio.

Santi Scagliusi, PhD

▶Simulator: M5 · Demo: Little-endian, byte a byteSimulador: M5 · Demo: Little-endian, byte a byte

Same word, two bytesMisma palabra, dos bytes

dato:  .word 0x1234

       mov.w &dato, R4    ; R4 = 0x1234
       mov.b &dato, R5    ; R5 = ?
       mov.b &dato+1, R6  ; R6 = ?
Pause and predictPausa y predice

What will R5 hold?¿Qué valor tendrá R5?

0x12 or 0x34? Commit before you run it.¿0x12 o 0x34? Decide antes de ejecutar.

No single memory wins on everythingNinguna memoria gana en todo

SRAM
volatilevolátil
0xCAFE
FRAM
non-volatileno volátil
0xBEEF

The real question is the lifetime of the data, not which memory is best. La pregunta real es cuánto debe vivir el dato, no qué memoria es mejor.

FRAM writes a byte, Flash erases a sectorLa FRAM escribe un byte, la Flash borra un sector

FRAM
one byte, in placeun byte, en el sitio

Write the target cell directly.Escribe la celda objetivo directo.

Flash
erase the sector, then writeborrar el sector, luego escribir

The whole sector erases first.Primero se borra el sector entero.

~1015 writes · byte-addressable ~1015 escrituras · direccionable por byte

Two memories on the FR6989Dos memorias en el FR6989

FRAM · 128 KB 0x4400–0xFFFF + 0x10000–0x243FF
Program codeCódigo
ConstantsConstantes
Retained dataDatos retenidos

Non-volatile: survives power loss.No volátil: sobrevive sin energía.

other regions: ROM, info, peripheralsotras regiones: ROM, info, periféricos
SRAM · 2 KB 0x1C00–0x23FF
VariablesVariables
The stackLa pila
BuffersBuffers

Volatile: fast, lost without power.Volátil: rápida, se pierde sin energía.

Von Neumann: one shared busVon Neumann: un solo bus compartido

CPU
MAB · one address + data busun bus de direcciones + datos · MDB
one unified memory spaceun espacio de memoria unificado
codecódigo
FRAM
datadatos
SRAM
I/O
MMIO

Same instructions for everything. The cost: fetch and data share one bus. Las mismas instrucciones para todo. El coste: fetch y datos comparten un bus.

A peripheral is just an addressUn periférico es solo una dirección

The same MOV that touches RAM can change a real pin.El mismo MOV que toca la RAM puede cambiar un pin real.

MOV.B #BIT0, &P1DIR
P1.0 becomes an output.P1.0 pasa a ser salida.
BIS.B #BIT0, &P1OUT
Drive the pin high.Forzar el pin a nivel alto.

Set the direction register first. Writing P1OUT only lights the LED once the pin is an output.Primero fija el registro de dirección. Escribir P1OUT solo enciende el LED cuando el pin ya es salida.

&P1DIR0x00
&P1OUT0x00
P1.0input / offentrada / apagado
P1OUT @ 0x0202
▶Simulator: M5 · Demo: Un periférico es solo una direcciónSimulador: M5 · Demo: Un periférico es solo una dirección

A name is just an addressUn nombre es solo una dirección

bis.b #BIT0, &P1DIR    ; salida
bis.b #BIT0, &P1OUT    ; LED encendido
bic.b #BIT0, &0x0202   ; sin nombre
mov.b &0x0202, R5      ; R5 = ?
Pause and predictPausa y predice

Does the LED turn off?¿Se apaga el LED?

0x0202 has no name. Does the CPU care?0x0202 no tiene nombre. ¿Le importa a la CPU?

Endianness is byte order, not valueEl endianness es orden de bytes, no valor

.word 0x1234

Big-endian MSB at the lower addressMSB en la dirección más baja
0x1C00
12
0x1C01
34
Little-endian LSB at the lower address · MSP430LSB en la dirección más baja · MSP430
0x1C00
34
0x1C01
12

A word, byte by byte in memoryUna palabra, byte a byte en memoria

.word 0x1234 at 0x1C00 splits into two bytes, low byte first..word 0x1234 en 0x1C00 se parte en dos bytes, primero el bajo.

source wordpalabra fuente
high bytebyte alto
12
low bytebyte bajo
34
memory, addresses growing downmemoria, direcciones creciendo hacia abajo
0x1C00
34
0x1C01
12
read back word at 0x1C00releer palabra en 0x1C00 = 0x1234

Endianness in real systemsEndianness en sistemas reales

MSP430 · x86
little-endian
low
34
high
12
ARM
bi-endian, runs LEbi-endian, corre LE
low
34
high
12
TCP/IP
big-endian
low
12
high
34

It matters when bytes leave the chip: agree the order. Importa cuando los bytes salen del chip: recuerda pactar el orden.

The FR6989 memory mapEl mapa de memoria del FR6989

20-bit address space: 128 KB of FRAM goes past 0xFFFF.Espacio de 20 bits: los 128 KB de FRAM pasan de 0xFFFF.

0x10000–0x243FF
Extended FRAMFRAM extendida 81 KB · code above 64 KB81 KB · código sobre 64 KB
0xFF80–0xFFFF
Interrupt vectorsVectores de interrupción reset at 0xFFFEreset en 0xFFFE
0x4400–0xFF7F
Main FRAMFRAM principal code + constantscódigo + constantes
0x2400–0x43FF
VacantVacío nothing heresin memoria
0x1C00–0x23FF
SRAMSRAM 2 KB · variables, stack2 KB · variables, pila
0x1800–0x1BFF
Info FRAM · TLV · boot codeFRAM info · TLV · arranque calibration, device IDcalibración, ID del chip
0x1000–0x17FF
Bootloader (BSL ROM)Bootloader (ROM BSL) 2 KB2 KB
0x0000–0x0FFF
Peripherals (MMIO)Periféricos (MMIO) SFR @ 0x0100 · P1OUT @ 0x0202SFR @ 0x0100 · P1OUT @ 0x0202

Three addresses worth memorizingTres direcciones que conviene memorizar

0xFFFE Reset vectorVector de reset

On power-up the CPU reads here to find where the program begins.Al encender, la CPU lee aquí para saber dónde empieza el programa.

0x4400 Code startsEmpieza el código

Main FRAM: your program and constants.FRAM principal: tu programa y tus constantes.

0x1C00 SRAM startsEmpieza la SRAM

Variables, buffers and the stack, in the 2 KB up to 0x23FF.Variables, buffers y la pila, en los 2 KB hasta 0x23FF.

▶Simulator: M5 · Demo: Constantes en FRAM, variables en RAMSimulador: M5 · Demo: Constantes en FRAM, variables en RAM

Copy from FRAM to RAMCopiar de FRAM a RAM

tabla: .word 10, 20, 30, 40   ; FRAM
       .bss  copia, 8           ; RAM

bucle: mov.w @R4+, R8
       mov.w R8, 0(R7)
       add.w R8, R6
       incd.w R7
       dec.w R5
       jnz   bucle              ; R6 = ?
Pause and predictPausa y predice

Where does each label land?¿Dónde cae cada etiqueta?

0x4400 or 0x1C00? And R6 at the end?¿0x4400 o 0x1C00? ¿Y R6 al final?

Memory is the terrainLa memoria es el terreno

FRAM + SRAMFRAM + SRAM

Lifetime decides the placeEl ciclo de vida decide el lugar

Persistent code and constants in FRAM, fast-changing state in SRAM.Código y constantes persistentes en FRAM, estado cambiante en SRAM.

One spaceUn espacio

Code, data and I/O share itCódigo, datos y E/S lo comparten

Von Neumann. The same MOV reaches RAM or a real peripheral pin.Von Neumann. El mismo MOV llega a la RAM o a un pin real.

Byte orderOrden de bytes

Little-endian, low byte firstLittle-endian, byte bajo primero

A word splits into bytes; the value never changes, only the order.Una palabra se parte en bytes; el valor no cambia, solo el orden.