Lecture 15 - DMA (Direct Memory Access), RTC (Real Time Clock)
Today we'll look at:
- What is DMA
- How does it work on the STM32?
- Real-Time Clock (and how it works on the STM32)
What is Direct Memory Access (DMA)?
- Allows access to memory by devices other than the CPU
- Enables the CPU to do other things
- Computation
- Go to sleep
Essentially, you can say "after 10 bytes of data, send an interrupt to the processor and do something with it". This is typically done for things like monitors where I/O data needs to be very "live" and real-time.
Used in many other computing applications:
- Complete DMA transfer can cause interrupt to wake CPU to use that I/O data.
- Hence, it can also be used to minimize power consumption on the CPU (since we don't have to poll)
DMA Delegation
Some tidbits on DMA is that:
- Allow remote devices to access memory
- May limit amount of memory accessible by remote
- Circular buffering
- Scatter-gather byte reordering (grab every
-th byte and put it into a list that row-major or column major order of a matrix)
- If many devices change the information at the same time, this can be a problem
- Worry about starvation / fairness
- Ways to handle: Round-Robin, Priority schemes
- Worry about starvation / fairness
- Different types of transfer
- Single-transfer: address + data
- Block-transfer: address + block of data
- Burst-block: address + multiple blocks of data
- ...
So if you have two DMA channels (ie: two devices) then they either use the same DMA engine. Or if there's two engines, these channels can work in parallel on different engines.
STM32
There's two DMAs on the STM32, each with 7 channels each
- Each channel is independently controllable
- Priority
- Transfer size (up to 64kB)
- Circular Buffers
- Interrupt capability
- Peripheral-to-memory, memory-to-peripheral, memory-to-memory, peripheral-to-peripheral
- Peripherals mapped to individual channels (table 44 in TRM)
Here the DMA is essentially a FIFO, where once its full the CPU core gets and interrupt and does something with it.
Registers
- Interrupt (status, flag)
- Control Register
- Config
- Data size
- Data address
- Channel Select
Real Time Clock (RTC)
Essentially an RTC is an alarm clock. An RTC clock can account for LEAP days among other things.
- Real-time clock and calendar mode providing:
- seconds, mins, ..., day of the week, day of month, month, year
- Interrupt capability
- Programmable alarms
- Real-time clock calibration / compensation for crystal error / drift
- Operation in Low-Power Modes
RTC Circuit
There's a lower-speed oscillator to drive this clock:
- LSE, HSE/32 (32kHz clock)
But as a bonus we get date/time
RTC_SSR
(subseconds)- ...
These 32khz crystal may have offset and drift:
- Offset: fixed skew - can compensate by 256/32k
- Drift: Temperature dependent can add +/- 256/32k
- Can use temperature readings in software (you have to set it up though)