C12 Embedded systems in MicroPython and C · Practice
Blink in C: registers and memory-mapped I/O
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
A busy-wait loop takes 4 cycles per pass. About how many passes make 5 ms on the 10 MHz board?
Check
A loop toggles a pin once per pass, and each pass takes 3 cycles. What's the frequency of the square wave?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
What mask, in hex, selects pins P1 and P3 together?
Check
A GPIO register sits at offset 20 (decimal) from the GPIO base, 0x4000_0000. What address does the C header cast to a pointer, in hex?
Check
A register write takes 4 instructions in C (100 ns each) and 40 µs in MicroPython. How many times faster is C?
Check
LEDs are wired to P1 and P3 (the program can use the constants A and B). Make both pins outputs and turn both LEDs on.
C on the course's RISC-V board (10 MHz, no floating point). #include "board.h" for the registers; print(x) shows a number. Tab indents; press Esc and then Tab to move on.
Check
Blink P0 with HALF (10) ms on and 10 ms off, timing it with SYS_CYCLES (10 cycles per microsecond).
C on the course's RISC-V board (10 MHz, no floating point). #include "board.h" for the registers; print(x) shows a number. Tab indents; press Esc and then Tab to move on.
Check
A delay loop takes 4 cycles per pass on the 10 MHz board.
(a)
How many passes make 1 ms?
(b)
How long is one pass?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
A C loop toggles a pin every 3 instructions of one cycle each.
(a)
What frequency comes out?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
(b)
How many times faster than MicroPython's 12.5 kHz is that?
Check
Passes of a 5-cycle loop in 2 ms?
Check
Toggle frequency with 6 cycles per pass?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
Mask for P1 and P6, in hex?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12