Skip to content

Commit

Permalink
Merge pull request #14 from perry0513/main
Browse files Browse the repository at this point in the history
Lab manual updates
  • Loading branch information
lhstrh authored Aug 24, 2023
2 parents d99c111 + 888ac6a commit 06bdb76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/Peripherals.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ You could similarly replace the reaction to the `startup` event, but that turns

Note that this exercise reveals why we are using the C programming language and a bare-metal target processor. Higher-level languages like Python and operating systems like Linux do not allow such direct manipulation of hardware.

**Checkoff:** Show and explain how your code works.

## 5.3. Polling Input

A GPIO pin can serve as an input or an output. As shown in the schematic above, GPIO pin 25 is connected to Button A on the robot as well as to the LED. Your task is to create a Lingua Franca program that reads the state of this pin every 250ms to determine whether the button is being pushed or not. Since you cannot use the GPIO pin simultaneously as an input and output, we suggest importing the library reactor `lib/Display.lf` and using the LCD display on the robot to display the state of the button rather than trying to drive the LED.
A GPIO pin can serve as an input or an output. As shown in the schematic above, GPIO pin 25 is connected to Button A on the robot as well as to the LED. Your task is to create a Lingua Franca program (`PeripheralsButtonSolution.lf`) that reads the state of this pin every 250ms to determine whether the button is being pushed or not. Since you cannot use the GPIO pin simultaneously as an input and output, we suggest importing the library reactor `lib/Display.lf` and using the LCD display on the robot to display the state of the button rather than trying to drive the LED. Refer to Section 2.3.1.2 in the [RP2040 Datasheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf) on how to read from pins using APIs or through memory addresses.

The style of input where you periodically query the state of peripheral hardware is called "polling". What are some advantages and disadvantages of polling?
In the next lab, we will investigate a more reactive technique that uses interrupts.

**Checkoff:** Show and explain how your code works.

## 5.4. Postlab

1. Address 0xd000001c is defined in Section 2.3.1.7, List of Registers, of the [RP2040 Datasheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf) as `GPIO_OUT_XOR` or "GPIO output value XOR." Writing a mask to this address will, in one cycle, reverse the polarity of the GPIO pin; if it is set, it will be cleared, and if it is cleared, it will be set. Why do you think the hardware designers chose to provide this functionality? If this functionality were not available, how would you reverse the polarity of a pin? Is there a risk that your alternative solution would not cause anything to change on the pin?
Expand Down
25 changes: 17 additions & 8 deletions src/Tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ This should result in a rather lengthy output.
When it finally finishes, each of the subdirectories of the `build` directory will contain binary files that you can load onto the robot.

Connect the robot to the USB port of your host computer.
Before flashing the binary to your RP2040 based board, the board must be placed into `BOOTSEL` mode. On the Pololu 3Pi+ robot, hold the `B` button and press `RESET`.
Before flashing the binary to your RP2040 based board, the board must be placed into `BOOTSEL` mode. On the Pololu 3Pi+ robot, hold the `B` button, press and release `RESET`, then release the `B` button.
(On a Raspberry Pi Pico, hold the `RESET` button while connecting the board to the host.)
You can then use the `picotool` to load and execute one of the sample programs:

Expand All @@ -122,7 +122,7 @@ You can disconnect the robot and use the power button to start it running on bat

> **_Note_**
>
> When you put the robot in `BOOTSEL` mode, you should see an external disk appear with a name like `RPI-RP2`.
> When you put the robot in `BOOTSEL` mode, you should see the OLED display go blank and an external disk appear with a name like `RPI-RP2`.
> You can also deploy the `blink` demo by dragging `blink.uf2` (in `~/pico-examples/build/blink`) into the `RPI-RP2` folder. The robot should immediately start running the program.
> **_Troubleshooting_**
Expand Down Expand Up @@ -151,13 +151,18 @@ This will likely result in a popup appearing as follows:

<img src="img/SelectAKit.png" alt="Select a kit"/>

You should select the `arm-none-eabi` kit. If you do not see one, select "Scan for kits". It you do not see the popup above, click on "No kit selected" on bottom blue bar. **NOTE:** You may need to make sure that CMake Tools is the Configuration Provider. Select <kbd>View > Command Palette</kbd> in the menu and begin typing <kbd>C/C++ Change Configuration Provider</kbd> until you see this:
You should select the `arm-none-eabi` kit. If you do not see one, select "Scan for kits". If you do not see the popup above, click on "No kit selected" on bottom bar.


<img src="img/ConfigurationProvider.png" alt="Configuration Provider" width="60%"/>
> **NOTE**
> You may need to make sure that CMake Tools is the Configuration Provider. Select <kbd>View > Command Palette</kbd> in the menu and begin typing <kbd>C/C++ Change Configuration Provider</kbd> until you see this:
> <img src="img/ConfigurationProvider.png" alt="Configuration Provider" width="60%"/>
> If CMake Tools is not available, then the cmake extension is not installed in VS Code.
If CMake Tools is not available, then the cmake extension is not installed in VS Code.
> **_Note for VM users_**
> If you are using the [VM image](https://vm.lf-lang.org/), click on "No kit selected" and you should be able to find the `arm-non-eabi` kit in the drop-down menu. You might also be unable to find the `CMake Tools (active)` as above, but compilation should still work.
If all goes well, VS Code will have compiled all the examples, and you see output something like this:
If all goes well, VS Code will have configured and generated all the build files, and you see output something like this:

<img src="img/CompileOutput.png" alt="Compile output"/>

Expand Down Expand Up @@ -228,7 +233,7 @@ The C function `printf` sends textual data to a conceptual device called **stdou
By default, the robot is configured to direct all stdout text to a serial port on its USB interface.
The trick, therefore, is to get your host computer to connect to that serial port and display data that arrives from the robot.

To do that, we a terminal emulator called **screen**. But first, we have to identify the serial port device that was created when the program started up.
To do that, we use a terminal emulator called **screen**. But first, we have to identify the serial port device that was created when the program started up.

## Finding the device on macOS
On macOS, the device is likely to appear in the `/dev` directory on your computer under a name that includes "usb" in its name, which you can look up as follows:
Expand All @@ -251,6 +256,10 @@ On Linux, the device is likely to appear in the `/dev` directory under a name th
$ ls /dev/ttyACM*
```

> **_Note for VM users_**
> `ttyACM\*` cannot be found when Pololu is in BOOTSEL mode. To find it, press `RESET`, choose the USB device (in VirtualBox: `Device` -> `USB` -> `Raspberry Pi RP2 Boot`), and you should be able to see it under `/dev`.

## Using `screen`

To use screen, we specify a device (e.g., `/dev/ttyACM0`) and a baud rate, as follows:
Expand Down Expand Up @@ -334,7 +343,7 @@ These functions manipulate memory-mapped registers that control the GPIO pins of
On the robot, one of those pins, identified in the header files by the `PICO_DEFAULT_LED_PIN` macro, controls the LED you see blinking.
Subsequent labs will explore more deeply the use memory-mapped registers for I/O.

**Checkoff:** Show the diagram for your program.
**Checkoff:** Show and explain how your program works.


## 3.6 Postlab Questions
Expand Down

0 comments on commit 06bdb76

Please sign in to comment.