Skip to main content

Embedded Systems · Microcontrollers, memory-mapped I/O, and peripherals

GPIOA on Anvil-M0 provides three 32-bit registers that affect the same 16 output…

Problem

Embedded Systems practice problem

GPIOA on Anvil-M0 provides three 32-bit registers that affect the same 16 output latches ODR[15:0]\mathrm{ODR}[15:0]. Unused upper bits of each register read as zero and ignore writes. Starting value: ODR=0x0000C351\mathrm{ODR}=\mathtt{0x0000C351}. The port pins are all outputs.

• A write of word XX to ODR\mathrm{ODR} replaces ODR[15:0]\mathrm{ODR}[15:0] by X[15:0]X[15:0].
• A write of word SS to SET\mathrm{SET} sets every latch nn for which S[n]=1S[n]=1 and leaves latches with S[n]=0S[n]=0 unchanged.
• A write of word CC to CLR\mathrm{CLR} clears every latch nn for which C[n]=1C[n]=1 and leaves latches with C[n]=0C[n]=0 unchanged.

The desired update is: set pin 22, clear pin 88, and leave every other latch unchanged. No concurrent writer exists. Ignore pull-ups, modes, and BSRR.

(a) Decode 0xC351\mathtt{0xC351} into bits 1515 through 00. State the present values of pins 22 and 88.

(b) Compute the 16-bit image that a read-modify-write to ODR\mathrm{ODR} must write, namely (ODR∣0x0004)&∼0x0100(\mathrm{ODR}\mathbin{|}\mathtt{0x0004})\mathbin{\&}\mathord\sim\mathtt{0x0100}, and give it as four hexadecimal digits.

(c) Compute a SET\mathrm{SET} write word and a CLR\mathrm{CLR} write word that together realize the same update (order: SET then CLR). Give each as eight hexadecimal digits, with bits 31:1631:16 equal to 00.

(d) Starting from 0xC351\mathtt{0xC351}, determine the ODR\mathrm{ODR} that results if the firmware writes 0x0004\mathtt{0x0004} to ODR\mathrm{ODR} instead of to SET\mathrm{SET}, intending to “set pin 22.” Identify every latch that is corrupted relative to the requirement. Then state, using only the three register semantics, why a SET write of 0x0004\mathtt{0x0004} does not have that corruption.

Hint

Hint

Writing ODR replaces every latch; writing SET or CLR names only the one-bits.

Check your work

Work the problem yourself first. Then open it in Training to check your answer and read the full worked solution.

Create a free account to check your answer and see the solution. Create a free account.

More Embedded Systems practice problems

Back to Embedded Systems

An original ProofAnvil practice problem, written for this course. ProofAnvil is a practice course, not a homework-answer service.