|
| 1 | +# Build |
| 2 | + |
| 3 | +## Build SmallBASIC |
| 4 | + |
| 5 | +Teensy 4.0 and Teensy 4.1 are supported. Both using the same processor and running at the same speed. |
| 6 | +But Teensy 4.1 offers more features than Teensy 4.0. The standard build is for Teensy 4.1. |
| 7 | + |
| 8 | +Download and build SmallBASIC as described [here](https://github.com/smallbasic/SmallBASIC). |
| 9 | + |
| 10 | +## Build Teensy firmware |
| 11 | + |
| 12 | +### Initial setup |
| 13 | + |
| 14 | +Install the following packages (Manjaro (arch)): |
| 15 | + |
| 16 | +``` |
| 17 | +$ sudo pacman -S arm-none-eabi-binutils arm-none-eabi-gcc arm-none-eabi-newlib libusb-compat |
| 18 | +``` |
| 19 | + |
| 20 | +Add udev rules for serial USB: |
| 21 | + |
| 22 | +``` |
| 23 | +curl -sLO https://www.pjrc.com/teensy/00-teensy.rules |
| 24 | +sudo cp 00-teensy.rules /etc/udev/rules.d/ |
| 25 | +``` |
| 26 | + |
| 27 | +Download and build core libraries: |
| 28 | + |
| 29 | +``` |
| 30 | +$ ./configure --enable-teensy |
| 31 | +$ cd src/platform/teensy |
| 32 | +$ ./setup.sh |
| 33 | +``` |
| 34 | + |
| 35 | +### Build firmware for Teensy 4.1 |
| 36 | + |
| 37 | +The following instructions will build and install the firmware for Teensy 4.1. |
| 38 | + |
| 39 | +``` |
| 40 | +$ make |
| 41 | +``` |
| 42 | + |
| 43 | +> If setup.sh displays an error massage that cmake minimum version is not set, |
| 44 | +> open `build/modules/CMSIS-DSP/CMakeLists.txt` |
| 45 | +> and add in the beginning of the file `cmake_minimum_required(VERSION 4.1)` |
| 46 | +
|
| 47 | +Upload firmware: |
| 48 | + |
| 49 | +``` |
| 50 | +make install |
| 51 | +``` |
| 52 | + |
| 53 | +or |
| 54 | + |
| 55 | +``` |
| 56 | +build/modules/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY41 -w -v -s build/smallbasic.hex |
| 57 | +``` |
| 58 | + |
| 59 | +### Build firmware for Tennsy 4.0 |
| 60 | + |
| 61 | +If you want to build the firmware for Tennsy 4.0, you have to run the following commands after |
| 62 | +initial setup: |
| 63 | + |
| 64 | +``` |
| 65 | +cd build |
| 66 | +cmake .. -DTEENSY40=ON |
| 67 | +``` |
| 68 | + |
| 69 | +and run `./configure --enable-teensy` again. Next you can build the firmware: |
| 70 | + |
| 71 | +``` |
| 72 | +$ make |
| 73 | +``` |
| 74 | + |
| 75 | +> If setup.sh displays an error massage that cmake minimum version is not set, |
| 76 | +> open `build/modules/CMSIS-DSP/CMakeLists.txt` |
| 77 | +> and add in the beginning of the file `cmake_minimum_required(VERSION 4.1)` |
| 78 | +
|
| 79 | +Upload firmware: |
| 80 | + |
| 81 | +``` |
| 82 | +make install40 |
| 83 | +``` |
| 84 | + |
| 85 | +or |
| 86 | + |
| 87 | +``` |
| 88 | +build/modules/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY40 -w -v -s build/smallbasic.hex |
| 89 | +``` |
| 90 | + |
| 91 | +# Run your SMALLBASIC program |
| 92 | + |
| 93 | +SMALLBASIC for Teensy offers three ways to upload and run a program. |
| 94 | + |
| 95 | +1. Format a SD card using FAT32. Rename your program to `MAIN.BAS` and copy it to the SD card. |
| 96 | +2. Include your program in the firmware. Replace `main.bas` in `src/platform/teensy` by your program and build |
| 97 | + the firmware. |
| 98 | +3. Send your program via USB-serial connection to the Teensy. In Linux use ` cat YourProgram.bas > /dev/ttyACM0` |
| 99 | + Change `/dev/ttyACM0` to the USB-serial port of your Teensy. |
| 100 | +4. Goto 3. |
| 101 | + |
| 102 | +When the Teensy starts up, it will check in the above indicated order for your program. If it finds |
| 103 | +a SD card and the SD card contains a file `MAIN.BAS`, it will execute it. Otherwise it will check, if a program |
| 104 | +was included in the firmware. If no program was included, the Teensy will switch to interactive mode and waits |
| 105 | +for a program upload via USB-serial. |
| 106 | + |
| 107 | +While your program is running, the Teensy will check continuously if data is available at the USB-serial port. |
| 108 | +If data is available for longer than one second your running program will be terminated and the queued data of the |
| 109 | +USB-serial port will be interpreted as the new program. Once the upload is finished, the new program will be executed. |
| 110 | +If you are using the USB-serial port for communication, read the queued data within one second. Alternately, you |
| 111 | +can turn on/off this behavior during runtime. |
| 112 | + |
| 113 | +If an error occurred, for example a syntax error, execution will stop and you have to read the error message from |
| 114 | +the USB-serial port. |
| 115 | + |
| 116 | +If the execution of your program comes to an end, for example when reaching the end of the program or when `STOP` is |
| 117 | +called, the program is terminated and the next section in the above list is performed. |
| 118 | + |
| 119 | +# Read output from your running program |
| 120 | + |
| 121 | +The `PRINT` command can be used to print to the USB-serial port. To access the output, connect to the serial |
| 122 | +port using, i.e. `PUTTY` or any other serial-port monitor / terminal. Using Linux, the easiest way is to run |
| 123 | +`cat /dev/ttyACM0` |
| 124 | + |
| 125 | +# Debugging the Teensy crash screen |
| 126 | + |
| 127 | +To find the line that failed (but no stack) run: |
| 128 | + |
| 129 | +``` |
| 130 | +arm-none-eabi-addr2line -e smallbasic.elf ADDRESS |
| 131 | +``` |
| 132 | + |
| 133 | +Where `ADDRESS` is the address shown in the crash screen, for example `0x17D04` |
0 commit comments