Skip to content

Commit b2deccf

Browse files
committed
Clean up, FREE command, Build instructions
1 parent 8aeb070 commit b2deccf

File tree

5 files changed

+176
-3
lines changed

5 files changed

+176
-3
lines changed

src/platform/teensy/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ set(CMAKE_SYSTEM_NAME Generic)
1212
set(TARGET "smallbasic")
1313

1414
# 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
1523
set(MODULES ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)
1624
set(TEENSY_SRC ${MODULES}/cores/teensy4)
1725
set(MCU "IMXRT1062")
18-
set(MCU_LD ${TEENSY_SRC}/imxrt1062.ld)
26+
set(MCU_LD ${TEENSY_SRC}/imxrt1062_t41.ld)
27+
set(MCU_DEF "ARDUINO_TEENSY41")
1928
set(CPU_OPTIONS "-mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb")
2029

2130
# Preprocessor flags for both C and C++
2231
add_compile_options(-g -O2 -ffunction-sections -fdata-sections -DENABLE_LOGGING
23-
-DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -D__${MCU}__ -DARDUINO=10813 -DTEENSYDUINO=159 -DARDUINO_TEENSY40)
32+
-DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -D__${MCU}__ -DARDUINO=10813 -DTEENSYDUINO=159 -D${MCU_DEF})
2433

2534
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CPU_OPTIONS}")
2635
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPU_OPTIONS} -std=gnu++17 -felide-constructors -fno-exceptions -fpermissive -fno-rtti -Wno-error=narrowing")

src/platform/teensy/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ build/smallbasic.elf : \
3131
all: build/smallbasic.elf
3232

3333
install: build/smallbasic.elf
34-
@build/modules/teensy_loader_cli/teensy_loader_cli --mcu=IMXRT1062 -w -v build/smallbasic.hex && \
34+
@build/modules/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY41 -w -v -s build/smallbasic.hex && \
3535
sleep 1 && \
3636
lsusb | grep -i teensy

src/platform/teensy/README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Build
2+
3+
## Build SmallBASIC
4+
5+
Download and build SmallBASIC as described [here](https://github.com/smallbasic/SmallBASIC).
6+
7+
## Configure Tennsy version
8+
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.
12+
13+
1. `src/platform/teensy/Makefile.am`
14+
`--mcu=TENNSY4` or `--mcu=TENNSY41`
15+
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+
```
22+
23+
2. `src/platform/teensy/CMakeLists.txt`
24+
Comment/Uncomment settings for Teensy 4 / Tennsy 4.1
25+
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")
34+
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+
```
43+
44+
## Build firmware in Manjaro (arch)
45+
46+
```
47+
$ sudo pacman -S arm-none-eabi-binutils arm-none-eabi-gcc arm-none-eabi-newlib libusb-compat
48+
$ ./configure --enable-teensy
49+
$ cd src/platform/teensy
50+
$ ./setup.sh
51+
$ make
52+
```
53+
54+
> If setup.sh displays an error massage that cmake minimum version is not set,
55+
> open `build/modules/CMSIS-DSP/CMakeLists.txt`
56+
> and add in the beginning of the file `cmake_minimum_required(VERSION 4.1)`
57+
58+
## Upload the firmware
59+
60+
```
61+
make install
62+
```
63+
64+
or
65+
66+
```
67+
build/modules/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY41 -w -v -s build/smallbasic.hex
68+
```
69+
70+
# Run your SMALLBASIC program
71+
72+
SMALLBASIC for Teensy offers three ways to upload and run a program.
73+
74+
1. Format a SD card using FAT32. Rename your program to `MAIN.BAS` and copy it to the SD card.
75+
2. Include your program in the firmware. Replace `main.bas` in `src/platform/teensy` by your program and build
76+
the firmware.
77+
3. Send your program via USB-serial connection to the Teensy. In Linux use ` cat YourProgram.bas > /dev/ttyACM0`
78+
Change `/dev/ttyACM0` to the USB-serial port of your Teensy.
79+
4. Goto 3.
80+
81+
When the Teensy starts up, it will check in the above indicated order for your program. If it finds
82+
a SD card and the SD card contains a file `MAIN.BAS`, it will execute it. Otherwise it will check, if a program
83+
was included in the firmware. If no program was included, the Teensy will switch to interactive mode and waits
84+
for a program upload via USB-serial.
85+
86+
While your program is running, the Teensy will check continuously if data is available at the USB-serial port.
87+
If data is available for longer than one second your running program will be terminated and the queued data of the
88+
USB-serial port will be interpreted as the new program. Once the upload is finished, the new program will be executed.
89+
If you are using the USB-serial port for communication, read the queued data within one second. Alternately, you
90+
can turn on/off this behavior during runtime.
91+
92+
If an error occurred, for example a syntax error, execution will stop and you have to read the error message from
93+
the USB-serial port.
94+
95+
If the execution of your program comes to an end, for example when reaching the end of the program or when `STOP` is
96+
called, the program is terminated and the next section in the above list is performed.
97+
98+
# Read output from your running program
99+
100+
The `PRINT` command can be used to print to the USB-serial port. To access the output, connect to the serial
101+
port using, i.e. `PUTTY` or any other serial-port monitor / terminal. Using Linux, the easiest way is to run
102+
`cat /dev/ttyACM0`
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import teensy
2+
3+
const usbSerial = teensy.openSerial()
4+
const BuiltInLED = teensy.openDigitalOutput(13)
5+
value = 0
6+
7+
teensy.SetInteractive(1)
8+
9+
while(1)
10+
if(usbSerial.ready()) then
11+
s = usbSerial.read(2)
12+
print s
13+
if(len(s) == 2) then
14+
if(s[0] == 81) then ' if first Byte is a Q
15+
print "Quit program."
16+
stop
17+
endif
18+
endif
19+
else
20+
delay(50)
21+
endif
22+
23+
BuiltInLED.write(1)
24+
delay(25)
25+
BuiltInLED.write(0)
26+
delay(25)
27+
wend
28+
29+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import teensy
2+
3+
const usbSerial = teensy.openSerial()
4+
const BuiltInLED = teensy.openDigitalOutput(13)
5+
value = 0
6+
7+
teensy.SetInteractive(1)
8+
9+
while(1)
10+
if(usbSerial.ready()) then
11+
s = usbSerial.receive()
12+
if(len(s) > 0) then
13+
select case s
14+
case "quit"
15+
print "Quit program."
16+
stop
17+
case "led"
18+
value = !value
19+
print "LED: "; value
20+
BuiltInLED.write(value)
21+
case else
22+
print s
23+
end select
24+
endif
25+
else
26+
delay(50)
27+
endif
28+
29+
BuiltInLED.write(1)
30+
delay(25)
31+
BuiltInLED.write(0)
32+
delay(25)
33+
wend

0 commit comments

Comments
 (0)