diff --git a/books/beaglebone-cookbook/07kernel/kernel.rst b/books/beaglebone-cookbook/07kernel/kernel.rst index 5f76ac16d2a82384fca51cc1f9e35e049938144f..25f4a90d9142713863ac5c8d5d0fcf2498d39825 100644 --- a/books/beaglebone-cookbook/07kernel/kernel.rst +++ b/books/beaglebone-cookbook/07kernel/kernel.rst @@ -173,6 +173,22 @@ Headers for the version of the kernel you're running: This took a little more than three minutes on my Bone. The ``uname -r`` part of the command looks up what version of the kernel you are running and loads the headers for it. +.. note:: + If you don't have a network connection you can get the headers from the running kernel with + the following. + + .. code-block:: + + sudo modprobe kheaders + rm -rf $HOME/headers + mkdir -p $HOME/headers + tar -xvf /sys/kernel/kheaders.tar.xz -C $HOME/headers > /dev/null + cd my-kernel-module + make -C $HOME/headers M=$(pwd) modules + sudo rmmod kheaders + + The ``modprobe kheaders`` makes the ``/sys/kernel/kheaders.tar.xz`` appear. + Next, add the code in :ref:`kernel_Makefle` to a file called ``Makefile``. .. _kernel_Makefle: diff --git a/books/beaglebone-cookbook/11misc/misc.rst b/books/beaglebone-cookbook/11misc/misc.rst index 5bb4fa96b46347cb2f51c8d5d50480c91c6d059c..75e50459a7133f3dffcfeecded4ccd889c963d5c 100644 --- a/books/beaglebone-cookbook/11misc/misc.rst +++ b/books/beaglebone-cookbook/11misc/misc.rst @@ -1015,15 +1015,27 @@ The Play's Boot Sequence ========================== The BeagleBoard Play is based on the Texas Instrument's AM625 Sitara -processor which supports many boot modes. Here we'll look at -booting from the user's view and from the developer's view. +processor which supports many boot modes. + +.. note:: + bootlin (https://bootlin.com/) has many great Linux + training materials for free on their site. Their embedded Linux workshop + (https://bootlin.com/training/embedded-linux/) + gives a detailed presentation of the Play's boot sequence + (https://bootlin.com/doc/training/embedded-linux-beagleplay/embedded-linux-beagleplay-labs.pdf, + starting at page 9). + Check it out for details on building the boot sequence + from scratch. + +Here we'll take a high-level look at +booting from both the user's view and the developer's view. Booting for the User -------------------- The most common way for the Play to boot is the power up the board, if the micro SD card is present, it will boot from it, if it isn't -present it will boot from the bultin eMMC. +present it will boot from the built in eMMC. You can override the boot sequence by using the **USR** button (located near the micro SD cage). If the **USR** button is pressed @@ -1077,7 +1089,7 @@ The table on page 2465 shows the BOOTMODE pins. BOOTMODE Pin Mapping -Page 14 of of the Plays schematic +Page 14 of of the Play's schematic (https://git.beagleboard.org/beagleplay/beagleplay/-/blob/main/BeaglePlay_sch.pdf) shows how the BOOTMODE pins are set during boot. @@ -1123,8 +1135,8 @@ are **tiboot3.bin** and **tispl.bin** runnng on the *R5* and **u-boot.img** runn on the *A53*. These binary files are found on the Play in ``/boot/firmware``. .. note:: - The files on the CD card and the eMMC are in ``ext4`` format. The files used for booting - must be in ``vfat`` format. There for ``/boot/firmware`` is mounted in ``vfat`` as + The files on the SD card and the eMMC are in ``ext4`` format. The files used for booting + must be in ``vfat`` format. Therefore ``/boot/firmware`` is mounted in ``vfat`` as seen in ``/etc/fstab``. .. code-block:: diff --git a/intro/blinkLED.rst b/intro/blinkLED.rst index 75a38f46e8cde911370f9cba778280fb5e93485c..1cd993f0b4a17f74ab9ed47b0a433ff2d3782987 100644 --- a/intro/blinkLED.rst +++ b/intro/blinkLED.rst @@ -26,7 +26,7 @@ heart beat. The Beagle is now up and running, but you didn't have to load up Linux. This is because all Beagles -(except the PocketBeagle, see :ref:`flash-latest-image` +(except PocketBeagle, see :ref:`flash-latest-image` to install an image on the Pocket) have built-in flash memory that has the Debian distribution of Linux preinstalled. @@ -34,138 +34,243 @@ Login ----- Next you login to the Beagle from your host computer. -This is slightly different if you host is running Windows. +Here you have a choice. If you want a graphical approach, +choose the ``VS Code`` tab. If you want a command line +and are running Linux on your host, +take the ``ssh (Linux/Mac)`` tab. Finally take the +``Windown (Putty)`` tab for command line from windows. -Login from Windows -^^^^^^^^^^^^^^^^^^ +.. tabs:: -If you are running Window you need to run an ``ssh`` client -to connect to the Beagle. I suggest you use ``putty``. -You can download it here: https://www.putty.org/. -Once installed, launch it and connect to your Beagle -by sshing to ``192.168.7.2``. + .. group-tab:: VS Code -.. figure:: putty.png + Recent Beagles come with the IDE Visual Studio Code + (https://code.visualstudio.com/) installed and + running. To access it, open a web browse on + your host computer and browse to: ``192.168.7.2:3000`` + and you will see something like: + .. figure:: figures/vscode1.png -Login with user ``debian`` -and password ``temppwd``. + Use the file navigator on the left to naviagte to + ``examples/BeagleBone/Black/blinkInternalLED.sh`` + and you will see: -Login from Linux -^^^^^^^^^^^^^^^^ + .. figure:: figures/vscode2.png -If you are running a Linux host, open a terminal widow and run + This code blinks one of the USR LEDs built into the board. + Click on the ``RUN Code`` triangle on the upper right of + the screen to run the code. (You could also enter ``Ctrl+Alt+N``) + The USR3 LED should now be blinking. -.. code-block:: shell-session + Click on the ``Stop Code Run`` (``Ctrl+Alt+M``) square to the right of the + ``Run Code`` button. - host:~$ ssh debian@192.168.7.2 + Time to play! Try changing the LED number (on line 10) from + 3 to something else. Click the ``Run Code`` button (no + need to save the file, autosave is on by default). -Use password ``temppwd``. + Try running ``seqLEDs.py``. -Blink an LED ------------- + .. group-tab:: Command line -Once logged in the rest is easy. First: + This is command line. -.. code-block:: shell-session + .. tabs:: - bone:~$ cd /sys/class/LEDs - bone:~$ ls - beaglebone:green:usr0 beaglebone:green:usr2 mmc0:: - beaglebone:green:usr1 beaglebone:green:usr3 mmc1:: - -Here you see a list of LEDs. Your list may be slightly -different depending on which Beagle you are running. -You can blink any of them. Let's try ``usr1``. + .. group-tab:: ssh (Linux/Mac) -.. code-block:: shell-session - - bone:~$ cd beaglebone\:green\:usr1/ - bone:~$ ls - brightness device max_brightness power subsystem trigger uevent - bone:~$ echo 1 > brightness - bone:~$ echo 0 > brightness + If you are running a Linux host, open a terminal widow and run -When you echo 1 into ``brightness`` the LED turns on. -Echoing a 0 turns it off. Congratulations, you've blinked -your first LED! + .. code-block:: shell-session -Blinking other LEDs -------------------- + host:~$ ssh debian@192.168.7.2 -You can blink the other LEDs by changing in to thier -directories and doing the same. + Use password ``temppwd``. -.. code-block:: shell-session - - bone:~$ cd ../beaglebone\:green\:usr0/ - bone:~$ echo 1 > brightness - bone:~$ echo 0 > brightness + .. group-tab:: Windows (Putty) -Did you notice that LED ``usr0`` blinks on it's own in a -heartbeat pattern? You can set an LED trigger. Here's -what triggers you can set: + If you are running Window you need to run an ``ssh`` client + to connect to the Beagle. I suggest you use ``putty``. + You can download it here: https://www.putty.org/. + Once installed, launch it and connect to your Beagle + by sshing to ``192.168.7.2``. -.. code-block:: shell-session + .. figure:: figures/putty.png - bone:~$ cat trigger - none usb-gadget usb-host rfkill-any rfkill-none - kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock - kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock - kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock - timer oneshot disk-activity disk-read disk-write i - de-disk mtd nand-disk [heartbeat] backlight gpio c - pu cpu0 cpu1 cpu2 cpu3 activity default-on panic - netdev mmc0 mmc1 mmc2 phy0rx phy0tx phy0assoc phy0radio - rfkill0 gpio-0:00:link gpio-0:00:1Gbps gpio-0:00:100Mbps - gpio-0:00:10Mbps gpio-0:01:link gpio-0:01:10Mbps - bone:~$ echo none > trigger + Login with user ``debian`` + and password ``temppwd``. -Notice ``[heartbeat]`` is in brackets. This shows it's the -current trigger. The echo changes the trigger to ``none``. + Blink an LED -Try experimenting with some of the other triggers and see if you -can figure them out. + Once logged in the rest is easy. First: -Another way to Blink an LED ---------------------------- + .. code-block:: shell-session -An interesting thing about Linux is there are often many ways -to do the same thing. FOr example, I can think of at least six ways to blink -an LED. Here's another way using the ``gpiod`` system. + bone:~$ cd ~/examples/BeagleBone/Black + bone:~$ ls + README.md blinkInternalLED.sh blinkLED2.py input2.js + analogIn.py blinkLED.bs.js blinkLEDold.py seqLEDs.py + analogInCallback.js blinkLED.c fadeLED.js swipeLED.js + analogInContinuous.py blinkLED.js fadeLED.py + analogInOut.js blinkLED.py gpiod + analogInSync.js blinkLED.sh input.js -.. code-block:: shell-session + Here you see a list of many scripts that demo simple + input/output on the Beagle. Try one that works on the + internal LEDs. - bone:~$ gpioinfo | grep -e chip -ie led - gpiochip0 - 32 lines: - gpiochip1 - 32 lines: - line 21: "[usr0 led]" "beaglebone:green:usr0" output active-high [used] - line 22: "[usr1 led]" "beaglebone:green:usr1" output active-high [used] - line 23: "[usr2 led]" "beaglebone:green:usr2" output active-high [used] - line 24: "[usr3 led]" "beaglebone:green:usr3" output active-high [used] - gpiochip2 - 32 lines: - gpiochip3 - 32 lines: + .. code-block:: shell-session -Here we asked how the LEDs are attached to the General Purpose -IO (gpio) system. The answer is, (yours will be different for a -different Beagle) -there are four interface chips and the LEDs are attached to -chip 1. You can control the gpios (and thus the LEDs) using -the ``gpioset`` command. + bone:~$ cat blinkInternalLED.py + LED="3" + + LEDPATH='/sys/class/leds/beaglebone:green:usr' + + while true ; do + echo "1" > ${LEDPATH}${LED}/brightness + sleep 0.5 + echo "0" > ${LEDPATH}${LED}/brightness + sleep 0.5 + done + bone:~$ ./blinkInternalLED.py + ^c -.. code-block:: shell-session + Here you see a simple bash script that turns an LED + on and off. Enter control-c to stop the script. - bone:~$ gpioset --mode=time --sec=2 1 22=1 - bone:~$ gpioset --mode=time --sec=2 1 22=0 + Blinking via Python -The first command sets chip 1, line 22 (the usr1 led) to 1 (on) for -2 seconds. The second command turns it off for 2 seconds. - -Try it for the other LEDs. - -.. note:: - - This may not work on all Beagles since it depends on which - version of Debian you are running. + Here's a script that sequences the LEDs on and off. + + .. code-block:: shell-session + + bone:~$ cat seqLEDs.py + import time + import os + + LEDs=4 + LEDPATH='/sys/class/leds/beaglebone:green:usr' + + # Open a file for each LED + f = [] + for i in range(LEDs): + f.append(open(LEDPATH+str(i)+"/brightness", "w")) + + # Sequence + while True: + for i in range(LEDs): + f[i].seek(0) + f[i].write("1") + time.sleep(0.25) + for i in range(LEDs): + f[i].seek(0) + f[i].write("0") + time.sleep(0.25) + bone:~$ ./seqLEDs.py + ^c + + Again, hit control-C to stop the script. + + Blinking from Command Line + + .. code-block:: shell-session + + bone:~$ cd /sys/class/leds + bone:~$ ls + beaglebone:green:usr0 beaglebone:green:usr2 mmc0:: + beaglebone:green:usr1 beaglebone:green:usr3 mmc1:: + + Here you see a list of LEDs. Your list may be slightly + different depending on which Beagle you are running. + You can blink any of them. Let's try ``usr1``. + + .. code-block:: shell-session + + bone:~$ cd beaglebone\:green\:usr1/ + bone:~$ ls + brightness device max_brightness power subsystem trigger uevent + bone:~$ echo 1 > brightness + bone:~$ echo 0 > brightness + + When you echo 1 into ``brightness`` the LED turns on. + Echoing a 0 turns it off. Congratulations, you've blinked + your first LED! + + Blinking other LEDs + + You can blink the other LEDs by changing in to thier + directories and doing the same. + + .. code-block:: shell-session + + bone:~$ cd ../beaglebone\:green\:usr0/ + bone:~$ echo 1 > brightness + bone:~$ echo 0 > brightness + + Did you notice that LED ``usr0`` blinks on it's own in a + heartbeat pattern? You can set an LED trigger. Here's + what triggers you can set: + + .. code-block:: shell-session + + bone:~$ cat trigger + none usb-gadget usb-host rfkill-any rfkill-none + kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock + kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock + kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock + timer oneshot disk-activity disk-read disk-write i + de-disk mtd nand-disk [heartbeat] backlight gpio c + pu cpu0 cpu1 cpu2 cpu3 activity default-on panic + netdev mmc0 mmc1 mmc2 phy0rx phy0tx phy0assoc phy0radio + rfkill0 gpio-0:00:link gpio-0:00:1Gbps gpio-0:00:100Mbps + gpio-0:00:10Mbps gpio-0:01:link gpio-0:01:10Mbps + bone:~$ echo none > trigger + + Notice ``[heartbeat]`` is in brackets. This shows it's the + current trigger. The echo changes the trigger to ``none``. + + Try experimenting with some of the other triggers and see if you + can figure them out. + + Another way to Blink an LED + + An interesting thing about Linux is there are often many ways + to do the same thing. For example, I can think of at least five ways to blink + an LED. Here's another way using the ``gpiod`` system. + + .. code-block:: shell-session + + bone:~$ gpioinfo | grep -e chip -ie usr + gpiochip0 - 32 lines: + gpiochip1 - 32 lines: + line 21: "[usr0 led]" "beaglebone:green:usr0" output active-high [used] + line 22: "[usr1 led]" "beaglebone:green:usr1" output active-high [used] + line 23: "[usr2 led]" "beaglebone:green:usr2" output active-high [used] + line 24: "[usr3 led]" "beaglebone:green:usr3" output active-high [used] + gpiochip2 - 32 lines: + gpiochip3 - 32 lines: + + Here we asked how the LEDs are attached to the General Purpose + IO (gpio) system. The answer is, (yours will be different for a + different Beagle) + there are four interface chips and the LEDs are attached to + chip 1. You can control the gpios (and thus the LEDs) using + the ``gpioset`` command. + + .. code-block:: shell-session + + bone:~$ gpioset --mode=time --sec=2 1 22=1 + bone:~$ gpioset --mode=time --sec=2 1 22=0 + + The first command sets chip 1, line 22 (the usr1 led) to 1 (on) for + 2 seconds. The second command turns it off for 2 seconds. + + Try it for the other LEDs. + + .. note:: + + This may not work on all Beagles since it depends on which + version of Debian you are running. diff --git a/intro/putty.png b/intro/figures/putty.png similarity index 100% rename from intro/putty.png rename to intro/figures/putty.png diff --git a/intro/figures/vscode1.png b/intro/figures/vscode1.png new file mode 100644 index 0000000000000000000000000000000000000000..1c27052b72cf2bfe2cc4e303a87659447de7ee13 Binary files /dev/null and b/intro/figures/vscode1.png differ diff --git a/intro/figures/vscode2.png b/intro/figures/vscode2.png new file mode 100644 index 0000000000000000000000000000000000000000..6b08183f0353ccae88322e4d07913958b072e8af Binary files /dev/null and b/intro/figures/vscode2.png differ