Commit f3ee3cbe authored by Aaron Erhardt's avatar Aaron Erhardt
Browse files

Microcomputertechnik lecture 6.5


Signed-off-by: default avatarAaron Erhardt <aaron.erhardt@t-online.de>
parent 13f07540
Pipeline #531 passed with stage
in 1 minute and 38 seconds
# Assembler
## Arithmetic
### Add
```asm
add r0, r1, r2 ; ro = r1 + r2
add r0, r1 ; ro = r0 + r1
add r0, #1 ; ro = r0 + 1, for small constants
```
Set flags while adding
```asm
adds r0, r1, r2 ; ro = r1 + r2, also sets flags
```
### Subtract
```asm
sub r0, r1, r2 ; ro = r1 - r2
```
### Multiply
```asm
mul r0, r1, r2 ; ro = r1 * r2
```
### Divide
```asm
udiv r0, r1, r2 ; ro = r1 / r2, unsigned divide, always rounds down
```
## Logic
### And
```asm
and r0, r1, r2 ; ro = r1 AND r2
```
### OR
```asm
orr r0, r1, r2 ; ro = r1 OR r2
```
### Exclusive or
```asm
eor r0, r1, r2 ; ro = r1 XOR r2
```
## Shift
### Arithmetic shift right
```asm
asr r0, r1, r2 ; ro = r1 >> r2, keeps correct sign!
```
### Logical shift right
```asm
lsr r0, r1, r2 ; ro = r1 >> r2, fills with zeros and doesn't keep correct sign!
```
### Logical shift left
```asm
lsl r0, r1, r2 ; ro = r1 << r2, fills with zeros
```
### Rotate right
```asm
ror r0, r1, r2 ; ro = r1 >> r2, bits will wrap around
```
## Load ## Load
```asm ```asm
...@@ -15,25 +98,20 @@ MAX DCD 10 ...@@ -15,25 +98,20 @@ MAX DCD 10
ldr r3, MAX ldr r3, MAX
``` ```
## Move ### Store
```asm
mov r0, r1 ; r0 := r1
mov rd, #const ; const max. 16-Bit, otherwise load
```
## Add
```asm ```asm
add r0, r1, r2 ; ro = r1 + r2 str r1, [r0] ; store content of r1 into address of r0
add r0, r1 ; ro = r0 + r1 str r1, [r0, #8] ; same with offset
add r0, #1 ; ro = r0 + 1, for small constants str r1, [r0], #8 ; post-increment
str r1, [r0, #8]! ; pre-increment
``` ```
Set flags while adding ## Move
```asm ```asm
adds r0, r1, r2 ; ro = r1 + r2, also sets flags mov r0, r1 ; r0 := r1
mov rd, #const ; const max. 16-Bit, otherwise load
``` ```
## Compare ## Compare
...@@ -92,7 +170,7 @@ push {lr, r3, r10-12} ; push lr, r3 and r10-r12 ...@@ -92,7 +170,7 @@ push {lr, r3, r10-12} ; push lr, r3 and r10-r12
pop {lr, r3, r10-12} ; pop lr, r3 and r10-r12 pop {lr, r3, r10-12} ; pop lr, r3 and r10-r12
``` ```
# Subroutines ## Subroutines
```asm ```asm
main main
...@@ -157,3 +235,92 @@ add_nums ...@@ -157,3 +235,92 @@ add_nums
pop {lr, r0-r2} pop {lr, r0-r2}
bx lr bx lr
``` ```
# IO
IO is memory mapped, it is read and set just like a block of memory.
## Typical register types
+ Control register (set behavior)
+ Status register
+ Data register
## STM32
### RCC (Reset and Control Logic)
Used to explicitly turn on other I/O blocks by setting bits in the registers.
### GPIO (General Purpose I/O)
Configuration:
+ Set RCC bits to enable I/O block
+ Set pins as input, output, alternate function (reserve pin for other I/O blocks) or analog with two bits in the MODER register
+ Adjust edge steepness (Flankensteilheit) with two bits in the OSPEEDR register
+ Set pull up resistance to NONE, UP or DOWN with two bits in the PUPDR register
Output: Set bits of the ODR register to activate individual pins
Input: Read bits of the IDR register to get values of individual pin
**Example**
```asm
; define port addresses and register offsets (data sheet)...
InitOutputPortB
push {r0, r3, r4, lr}
; Enable I/O block for PortB
ldr r3, = RCC ; Load start address of RCC registers into r3
ldr r0, [r3, #AHB1ENR] ; Load current register values
orr r0, r0, #IOPBEN ; Use logical OR to enable the bit for GPIOBEN and leave the rest unchanged
str r0, [r3, #AHB1ENR] ; Store value into the register to enable I/O on PortB
; Configure PortB
ldr r3, = GPIOB ; Load start address of GPIOB registers into r3
ldr r0, = 0x00005555 ; Load values for configuring the MODER register, using 0x5 = 01_01 to set all pins as output
str r0, [r3, #MODER] ; Store value into the register to enable configuration
; Turn on LEDs
ldr r0, #3 ; Set first to bits
str r0, [r3, #ODR] ; Load value into ODR register to enable the first to outputs (LEDs)
pop {r0, r3, r4, lr}
```
### Systick timer
Counts down from a start value until it reaches zero. Then is sets a flag, invokes an interrupt, resets the start value and counts down again.
STK_CTRL register:
+ COUNTFLAG: counter has reached zero
+ CLKSOURCE: select counter clock
+ TICKINT: enable interrupt
+ ENABLE: enable counter
STK_LOAD register: 24 bit reset value
STK_VAL register: current counter value
### Capture/Compare-Timer
CR1 register: configure timer
CNT register: counter value
ARR register: reset value
PSC register: pre-scale value, divide clock frequency
CCR1-CCR4 registers:
+ compare with counter value and set output pin if counter surpasses the control value
+ on input (e. g. rising edge) capture the current counter value
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment