Skip to content

Commit 1e52f90

Browse files
committed
TEENSY: Improve build files
1 parent 19dfcb6 commit 1e52f90

File tree

3 files changed

+89
-50
lines changed

3 files changed

+89
-50
lines changed

src/platform/teensy/CMakeLists.txt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@
66
#
77

88
cmake_minimum_required(VERSION 3.10)
9+
option(TEENSY40 "Build for teensy 4.0 instead of 4.1" OFF)
910
project(SmallBASIC)
1011
include(ExternalProject)
1112
set(CMAKE_SYSTEM_NAME Generic)
1213
set(TARGET "smallbasic")
1314

14-
# settings for teensy 4.0
15-
#set(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)
16-
#set(TEENSY_SRC ${MODULES}/cores/teensy4)
17-
#set(MCU "IMXRT1062")
18-
#set(MCU_LD ${TEENSY_SRC}/imxrt1062.ld)
19-
#set(MCU_DEF "ARDUINO_TEENSY4")
20-
#set(CPU_OPTIONS "-mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb")
21-
22-
# settings for teensy 4.1
23-
set(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)
24-
set(TEENSY_SRC ${MODULES}/cores/teensy4)
25-
set(MCU "IMXRT1062")
26-
set(MCU_LD ${TEENSY_SRC}/imxrt1062_t41.ld)
27-
set(MCU_DEF "ARDUINO_TEENSY41")
28-
set(CPU_OPTIONS "-mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb")
15+
if(TEENSY40)
16+
message("Building for TEENSY 4.0")
17+
set(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)
18+
set(TEENSY_SRC ${MODULES}/cores/teensy4)
19+
set(MCU "IMXRT1062")
20+
set(MCU_LD ${TEENSY_SRC}/imxrt1062.ld)
21+
set(MCU_DEF "ARDUINO_TEENSY40")
22+
set(CPU_OPTIONS "-mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb")
23+
else()
24+
message("Building for TEENSY 4.1")
25+
set(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)
26+
set(TEENSY_SRC ${MODULES}/cores/teensy4)
27+
set(MCU "IMXRT1062")
28+
set(MCU_LD ${TEENSY_SRC}/imxrt1062_t41.ld)
29+
set(MCU_DEF "ARDUINO_TEENSY41")
30+
set(CPU_OPTIONS "-mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb")
31+
endif()
2932

3033
# Preprocessor flags for both C and C++
3134
add_compile_options(-g -O2 -ffunction-sections -fdata-sections -DENABLE_LOGGING

src/platform/teensy/Makefile.am

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77

88
tidy:
9-
@cd build && make tidy
9+
@cd build && make tidy
1010

1111
build/modules/cores/teensy4/Makefile:
1212
./setup.sh
@@ -34,3 +34,8 @@ install: build/smallbasic.elf
3434
@build/modules/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY41 -w -v -s build/smallbasic.hex && \
3535
sleep 1 && \
3636
lsusb | grep -i teensy
37+
38+
install40: build/smallbasic.elf
39+
@build/modules/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY40 -w -v -s build/smallbasic.hex && \
40+
sleep 1 && \
41+
lsusb | grep -i teensy

src/platform/teensy/README.md

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,49 @@
22

33
## Build SmallBASIC
44

5-
Download and build SmallBASIC as described [here](https://github.com/smallbasic/SmallBASIC).
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.
67

7-
## Configure Tennsy version
8+
Download and build SmallBASIC as described [here](https://github.com/smallbasic/SmallBASIC).
89

9-
Tennsy 4 and Tennsy 4.1 are supported. Both using the same processor and running at the same speed.
10-
But Tennsy 4.1 offers more features than Tennsy 4. Currently, you have to configure two files depending
11-
which MCU you use.
10+
## Build Teensy firmware
1211

13-
1. `src/platform/teensy/Makefile.am`
14-
`--mcu=TENNSY4` or `--mcu=TENNSY41`
12+
### Initial setup
1513

16-
```
17-
install: build/smallbasic.elf
18-
@build/modules/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY41 -w -v -s build/smallbasic.hex && \
19-
sleep 1 && \
20-
lsusb | grep -i teensy
21-
```
14+
Install the following packages (Manjaro (arch)):
2215

23-
2. `src/platform/teensy/CMakeLists.txt`
24-
Comment/Uncomment settings for Teensy 4 / Tennsy 4.1
16+
```
17+
$ sudo pacman -S arm-none-eabi-binutils arm-none-eabi-gcc arm-none-eabi-newlib libusb-compat
18+
```
2519

26-
```
27-
# settings for teensy 4.0
28-
#set(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)
29-
#set(TEENSY_SRC ${MODULES}/cores/teensy4)
30-
#set(MCU "IMXRT1062")
31-
#set(MCU_LD ${TEENSY_SRC}/imxrt1062.ld)
32-
#set(MCU_DEF "ARDUINO_TEENSY4")
33-
#set(CPU_OPTIONS "-mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb")
20+
Add udev rules for serial USB:
3421

35-
# settings for teensy 4.1
36-
set(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)
37-
set(TEENSY_SRC ${MODULES}/cores/teensy4)
38-
set(MCU "IMXRT1062")
39-
set(MCU_LD ${TEENSY_SRC}/imxrt1062_t41.ld)
40-
set(MCU_DEF "ARDUINO_TEENSY41")
41-
set(CPU_OPTIONS "-mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb")
42-
```
22+
```
23+
curl -sLO https://www.pjrc.com/teensy/00-teensy.rules
24+
sudo cp 00-teensy.rules /etc/udev/rules.d/
25+
```
4326

44-
## Build firmware in Manjaro (arch)
27+
Download and build core libraries:
4528

4629
```
47-
$ sudo pacman -S arm-none-eabi-binutils arm-none-eabi-gcc arm-none-eabi-newlib libusb-compat
4830
$ ./configure --enable-teensy
4931
$ cd src/platform/teensy
5032
$ ./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+
```
5140
$ make
5241
```
5342

5443
> If setup.sh displays an error massage that cmake minimum version is not set,
5544
> open `build/modules/CMSIS-DSP/CMakeLists.txt`
5645
> and add in the beginning of the file `cmake_minimum_required(VERSION 4.1)`
5746
58-
## Upload the firmware
47+
Upload firmware:
5948

6049
```
6150
make install
@@ -67,6 +56,38 @@ or
6756
build/modules/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY41 -w -v -s build/smallbasic.hex
6857
```
6958

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+
7091
# Run your SMALLBASIC program
7192

7293
SMALLBASIC for Teensy offers three ways to upload and run a program.
@@ -100,3 +121,13 @@ called, the program is terminated and the next section in the above list is perf
100121
The `PRINT` command can be used to print to the USB-serial port. To access the output, connect to the serial
101122
port using, i.e. `PUTTY` or any other serial-port monitor / terminal. Using Linux, the easiest way is to run
102123
`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

Comments
 (0)