NLP will be used on a Arduino Nano, then over UART 0, 1, 2 will be sent to the msp432p401r. This data will then turn on the LEDs, turn on/off a motor and turn on/off a buzzer if a sensor is active. The LED will be set to a random value by using a noisy unconnected pin and reading ADC
PM_ == Peripheral Mode / Port Mapping UCAx == eUSCI_Ax UCBx == eUSCI_Bx
- P1.2: UART RX (eUSCI_A0 / UCA0RXD) (internal) [used in uart_helper.c]
- P1.3: UART TX (eUSCI_A0 / UCA0TXD) (internal) [used in uart_helper.c]
- P3.2: UART RX (eUSCI_A2 / PM_UCA2RXD) [used in process_configure_uart.s]
- P3.3: UART TX (eUSCI_A2 / PM_UCA2TXD) [not used in this project]
- P1.0: RED LED (LED1) (internal)
- P2.0: RED LED (LED2) (internal) [used in configure_led.s]
- P2.1: GREEN LED (LED2) (internal) [used in configure_led.s]
- P2.2: BLUE LED (LED2) (internal) [used in configure_led.s]
- P5.3: ADC (ADC14MCTL2 / A2) (not connected to anything)
- P5.4: GPIO (IR Sensor)
- P5.5: GPIO (PIEZO Buzzer)
- P4.7: GPIO (Nano Wait Signal)
- P4.0: GPIO (SSD) 0
- P4.1: GPIO (SSD) 1
- P4.2: GPIO (SSD) 2
- P4.3: GPIO (SSD) 3
- P4.4: GPIO (SSD) 4
- P4.5: GPIO (SSD) 5
- P4.6: GPIO (SSD) 6
- Bit 15 - UCSWRST (Software Reset)
1
- UART held in reset state, useful during configuration.0
- UART operational, reset released.
- Bits 14-10 - Reserved
- Bits 9-8 - UCSSELx (Clock Source Select)
00
- UCLKI (external clock).01
- ACLK (auxiliary clock).10
- SMCLK (sub-main clock).11
- SMCLK.
- Bit 7 - UCTXBRK (Transmit Break)
1
- Send a break (low state) after transmitting the next character.0
- No break transmitted.
- Bit 6 - UCTXADDR (Transmit Address)
1
- Next character transmitted is an address.0
- Normal data transmission.
- Bit 5 - UCDORM (Dormant)
1
- Receiver ignores incoming data not addressing it.0
- Normal operation.
- Bit 4 - UCBRKIE (Receive Break Character Interrupt Enable)
1
- Interrupt on received break character.0
- No interrupt for break character.
- Bit 3 - UCRXEIE (Receive Erroneous-Character Interrupt Enable)
1
- Interrupt on erroneous character received.0
- No interrupt on erroneous characters.
- Bits 2-1 - UC7BIT (Character Length)
00
- 8-bit data.01
- 7-bit data.
- Bit 0 - UCPEN (Parity Enable)
1
- Parity enabled.0
- No parity.
- Bit 15-8 - Reserved
- Bit 7 - UCTXIFG (Transmit Buffer Empty Interrupt Flag)
1
- Transmit buffer is empty, ready for new data.0
- Transmit buffer not empty.
- Bit 6 - UCRXIFG (Receive Buffer Full Interrupt Flag)
1
- Receive buffer is full, contains unread data.0
- Receive buffer not full.
- Bits 5-0 - Reserved/Other Specific Flags
- BRW (Baud Rate Word)
- Sets the baud rate divisor based on the input clock.
- MCTLW (Modulation Control Word)
- Fine-tunes the baud rate via modulation settings; includes bits for oversampling.
- TXBUF (Transmit Buffer)
- Buffer for data to be transmitted.
- RXBUF (Receive Buffer)
- Buffer holding received data.
- IE (Interrupt Enable Register)
- Enables interrupts for specific UART events.
- IV (Interrupt Vector Register)
- Indicates the vector of the highest priority interrupt.
- ABCTL (Auto Baud Rate Control)
- Automatic baud rate detection feature.
- IRCTL (Infrared Control Register)
- Configures UART for infrared communication.
- Bit 7 - SPIE (SPI Interrupt Enable)
1
- Enables the SPI interrupt when a serial transfer is complete.0
- Disables the SPI interrupt.
- Bit 6 - SPE (SPI Enable)
1
- Enables the SPI bus; must be set to enable any SPI operations.0
- Disables the SPI bus.
- Bit 5 - DORD (Data Order)
1
- LSB (Least Significant Bit) first.0
- MSB (Most Significant Bit) first.
- Bit 4 - MSTR (Master/Slave Select)
1
- Sets the SPI bus configuration to Master.0
- Sets the SPI bus configuration to Slave.
- Bit 3 - CPOL (Clock Polarity)
1
- The clock is high when idle.0
- The clock is low when idle.
- Bit 2 - CPHA (Clock Phase)
1
- Data is sampled on the trailing edge of the clock.0
- Data is sampled on the leading edge of the clock.
- Bits 1-0 - SPR1, SPR0 (SPI Clock Rate Select)
00
- f_osc/4 (where f_osc is the oscillator frequency).01
- f_osc/16.10
- f_osc/64.11
- f_osc/128.
- Bit 7 - SPIF (SPI Interrupt Flag)
- This bit is set by hardware when a serial transfer is complete. Used to handle interrupts.
- Bit 6 - WCOL (Write Collision Flag)
1
- Indicates a write collision has occurred.0
- No collision.
- Bit 0 - SPI2X (Double SPI Speed Bit)
1
- SPI speed is doubled.0
- Normal SPI speed.
- Functionality
- This register is used for data transmission and reception. Writing to this register starts data transmission. Reading from this register reads the data received.
- SS Pin (Slave Select)
- In master mode, this pin must be managed (usually driven low) to select a slave device before starting communication.
- MISO (Master In Slave Out)
- This is the data line for sending data from slave to master.
- MOSI (Master Out Slave In)
- This is the data line for sending data from master to slave.
- SCK (Serial Clock)
- Clock line controlled by the master, used to synchronize data transmission.
- Bit 7 - IEN (I2C Enable)
1
- Enables the I2C module.0
- Disables the I2C module.
- Bit 6 - IRPT (Interrupt Enable)
1
- Enables the generation of interrupts.0
- Disables interrupts.
- Bit 5 - ACK (Acknowledge Control)
1
- Sends acknowledge when the acknowledge bit is required.0
- Does not send an acknowledge.
- Bit 4 - START (Start Condition)
1
- Generates a start condition.0
- Does not generate.
- Bit 3 - STOP (Stop Condition)
1
- Generates a stop condition.0
- Does not generate.
- Bit 2 - INT_FLAG (Interrupt Flag)
- This bit is set by hardware when an interrupt condition occurs. Must be cleared by software.
- Bits 1-0 - MODE (Operating Mode)
00
- Standard mode (100 kHz)01
- Fast mode (400 kHz)10
- Fast mode plus (1 MHz)11
- High-speed mode (3.4 MHz)
- Bit 7 - BUSY (Bus Busy)
1
- Indicates that the bus is busy.0
- Indicates that the bus is free.
- Bit 6 - ARLO (Arbitration Lost)
1
- The device lost arbitration and control of the bus.0
- The device has control or arbitration not applicable.
- Bit 5 - ACK_RECEIVED (Acknowledge Received)
1
- Acknowledge was received after sending a byte.0
- No acknowledge received.
- Bit 4 - OVR (Overrun/Underrun)
1
- Data was lost because of an overrun or underrun.0
- No data was lost.
- Bit 3 - PEC_ERR (PEC Error in Reception)
1
- Packet Error Checking code does not match.0
- No error detected.
- Bit 2 - TIMEOUT (Timeout Error)
1
- Timeout error occurred.0
- No timeout error.
- Bit 1-0 - Reserved
- Functionality
- This register holds the data to be transmitted or received. Data written to this register is queued for transmission; reading from this register gives the last received data.
- Functionality
- Sets the device address in master mode or the response address in slave mode. Can usually be configured to use 7-bit or 10-bit addressing.
- SCL (Serial Clock Line)
- The line over which the clock signal is transmitted. Controlled by the master.
- SDA (Serial Data Line)
- The line over which data is transmitted. It’s bidirectional and used for both sending and receiving data.
- Master/Slave Mode
- Devices on an I2C bus can act as either a master or a slave. The master controls the clock and initiates communication.
- Bit 15-14 - ADC14PDIV (Pre-divider)
00
- Pre-divider of 1.01
- Pre-divider of 4.10
- Pre-divider of 32.11
- Pre-divider of 64.
- Bits 13-12 - ADC14SHSx (Sample/Hold Source)
00
- ADC14SC bit (software trigger).01
- Timer trigger.10
- Other external triggers.
- Bits 11-10 - ADC14SHP (Sample/Hold Pulse Mode)
0
- Sample-and-hold source determined by ADC14SHSx bits.1
- Sample-and-hold signal sourced from the sampling timer.
- Bits 9-8 - ADC14DIVx (Clock Divider)
00
- Divider of 1.01
- Divider of 2.10
- Divider of 4.11
- Divider of 8.
- Bits 7-5 - Reserved
- Bit 4 - ADC14SSELx (Clock Source Select)
0
- MODOSC (modulator oscillator).1
- SMCLK (sub-main clock).
- Bit 3 - ADC14CONSEQx (Conversion Sequence Mode)
00
- Single-channel, single-conversion.01
- Sequence-of-channels.10
- Repeat-single-channel.11
- Repeat-sequence-of-channels.
- Bit 2 - ADC14BUSY (ADC Busy)
1
- ADC is active.0
- ADC is inactive.
- Bit 1 - Reserved
- Bit 0 - ADC14ON (ADC On/Off)
1
- ADC is on.0
- ADC is off.
- Bit 15-12 - ADC14WINCTH (Window Comparator High Threshold)
- Bit 11-8 - ADC14WINCCTL (Window Comparator Low Threshold)
- Bit 7 - ADC14DIF (Differential Mode)
1
- Differential mode enabled.0
- Single-ended mode.
- Bits 6-5 - Reserved
- Bits 4-0 - ADC14INCHx (Input Channel Select)
00000
- A0.00001
- A1.- Various other codes for additional analog channels.
- Start Conversion: Triggered by software or a dedicated hardware signal.
- Sampling: The ADC samples the analog signal based on the selected input channel.
- Conversion: The sampled value is converted into a digital number, reflecting the signal's intensity.
- Interrupts: The ADC can be configured to generate interrupts at the end of a conversion, when a certain threshold is reached, or if an error occurs.
- Low-Power Modes: Designed for efficient operation, the ADC can be shut down or operate in a reduced power mode when not actively converting, saving energy in battery-powered applications.
-
VCC: This is the power supply pin. It's connected to a positive voltage source. For the RFID-RC522, this is usually a 3.3V power supply.
-
RST: This stands for Reset. It is used to reset the RFID module. Applying a low signal to this pin resets the internal states of the module.
-
GND: This is the Ground pin. It is connected to the ground of the power supply and is used as a reference point for all signals.
-
MISO: This stands for Master In Slave Out. It is used in SPI (Serial Peripheral Interface) communication. This pin is used by the RFID module to send data back to the microcontroller.
-
MOSI: This stands for Master Out Slave In. It is also used in SPI communication. This pin is used by the microcontroller to send data to the RFID module.
-
SCK: This stands for Serial Clock. It is another pin used in SPI communication. This clock signal is provided by the microcontroller to synchronize data transmission between the microcontroller and the RFID module.
-
NSS: This stands for Negative Slave Select (also known as Chip Select or CS). It is used in SPI communication to activate the RFID module. It is typically active low, meaning the RFID module is selected for communication when this pin is pulled to a low logic level.
-
IRQ: This stands for Interrupt Request. This pin is used by the RFID module to alert the microcontroller of certain events (like the presence of an RFID tag in its vicinity). It is an optional connection, not always used in every project.
-
si
(stepi) - Steps one instruction at a time. This is your primary tool for moving through assembly code instruction by instruction. -
ni
(nexti) - Steps over the instruction; if the instruction is a function call,ni
executes the whole function as a single step, unlikesi
which would step into the function. -
disassemble
/disass
- Displays the assembly code for a specific function or memory range. You can use it likedisassemble function_name
ordisassemble $pc
to see the assembly at the current program counter. -
x
- Examines memory at a given address. It's versatile for inspecting memory in various formats and units. For example,x/10i $pc
displays 10 instructions starting from the program counter. -
info registers
- Shows the current values of all registers. You can also examine a specific register by usinginfo register $eax
, for instance, to see the value of theeax
register. -
set
- Allows you to modify the values of registers or variables. For example,set $eax = 0x1
sets theeax
register to 1. -
break
- Sets a breakpoint at a specific line or function or address. In assembly, you might set it at a specific instruction address, likebreak *0x00400576
. -
continue
(c) - Continues running the program until the next breakpoint or the end of the program. -
layout asm
- Switches the GDB layout to show the assembly code. This view is helpful for visualizing where in the code you are as you step through instructions. -
layout regs
- Shows both the assembly code and the current state of registers. It's particularly useful for seeing how each instruction affects the registers. -
info proc mappings
- Useful for viewing the memory mapping of the process, which helps in understanding where different parts of your code and data are located in memory. -
tui enable
- Activates the Text User Interface, making it easier to visualize code, registers, and source (if available).
In GDB, displaying the stack can provide crucial insights into the state of your program, especially when debugging complex issues involving function calls and memory management. Here are several ways to display the stack in GDB:
These commands display the call stack with function names, source file names, and line numbers, assuming debugging symbols are available.
-
info stack
orinfo frame
: Shows a detailed stack frame, which includes function names, arguments, and locals.- Example command:
(gdb) info stack
- Example command:
-
bt
orbacktrace
: Shows the call stack. You can limit the number of frames shown by specifying a number (e.g.,bt 10
).- Example command:
(gdb) bt
- Example command:
You can display the contents around the current stack pointer using the x
command, which is used to examine memory in various formats:
x/NFU ADDR
:N
tells GDB how many units to display.F
specifies the display format (x
for hexadecimal,d
for signed decimal, and so on).U
specifies the unit size (b
for byte,h
for halfword,w
for word,g
for giant/8 bytes).ADDR
is the address to start displaying from, often the stack pointer.
For example, to display 20 words at the current stack pointer:
(gdb) x/20xw $sp
or for a more typical 64-bit system:
(gdb) x/20xg $rsp
If you want to see local variables along with their values for a particular frame, you can use:
-
info locals
: Shows the local variables of the current function.- Example command:
(gdb) info locals
- Example command:
-
info args
: Shows the arguments passed to the current function.- Example command:
(gdb) info args
- Example command:
You can also switch to a specific frame to examine its contents more closely:
-
frame N
: Switch to frame numberN
.- Example command:
(gdb) frame 2
- Example command:
After switching, you can use info locals
, info args
, or x
commands to inspect the state of that particular frame.
These methods allow you to explore the stack in various levels of detail, helping to diagnose issues related to function calls, recursion, memory corruption, and more.
To set a breakpoint at a specific memory address in GDB, such as 0xf0
, you use the break
command with the *
symbol to indicate that you are specifying an address, not a function name or line number. Here's how you can do it:
(gdb) break *0xf0
This command tells GDB to insert a breakpoint at the memory address 0xf0
. When the program execution reaches this address, GDB will pause the execution, allowing you to inspect the program state, examine variables, and step through the code further.
-
Conditional Breakpoints: If you want to set a breakpoint that only triggers under certain conditions, you can add a condition to the breakpoint. For example, to break at address
0xf0
only when a certain registereax
equals5
, you would do:(gdb) break *0xf0 if $eax == 5
-
Temporary Breakpoints: If you only need the breakpoint once, you can make it temporary so that it automatically deletes itself after triggering:
(gdb) tbreak *0xf0
-
Checking Breakpoints: After setting breakpoints, you can check where they are set using:
(gdb) info breakpoints
This will list all the breakpoints you have set along with their conditions and hit counts.
Setting breakpoints at specific addresses is particularly useful when debugging low-level code, such as operating systems or embedded systems code, where execution paths are not straightforward, or source code may not be directly available.