Skip to content

Commit df11b18

Browse files
authored
Merge pull request #7 from Neotron-Compute/remove-snake
Remove snake and add ASM examples
2 parents 926ce2d + e6bad5e commit df11b18

File tree

16 files changed

+618
-596
lines changed

16 files changed

+618
-596
lines changed

.github/workflows/build.yml

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ jobs:
2323
rustup component add llvm-tools
2424
cargo install cargo-binutils
2525
26+
- name: Add targets
27+
run: |
28+
sudo apt-get -y install gcc-arm-none-eabi binutils-arm-none-eabi
29+
30+
- name: Find slug name
31+
run: |
32+
slug=$(./describe.sh "${GITHUB_REF}")
33+
echo "Building with slug '${slug}'"
34+
echo "slug=${slug}" >> "${GITHUB_ENV}"
35+
2636
- name: Build lib (native)
2737
run: |
2838
cargo build --verbose
@@ -31,14 +41,46 @@ jobs:
3141
run: |
3242
cargo test --verbose
3343
34-
- name: Build samples (Cortex-M0)
44+
- name: Build samples (Cortex-M0+)
3545
run: |
36-
cd samples && ./build.sh thumbv6m-none-eabi
46+
cd samples
47+
./build.sh thumbv6m-none-eabi
48+
mv release release-thumbv6m-none-eabi
3749
3850
- name: Build samples (Cortex-M3)
3951
run: |
40-
cd samples && ./build.sh thumbv7m-none-eabi
52+
cd samples
53+
./build.sh thumbv7m-none-eabi
54+
mv release release-thumbv7m-none-eabi
4155
4256
- name: Build samples (Cortex-M4)
4357
run: |
44-
cd samples && ./build.sh thumbv7em-none-eabi
58+
cd samples
59+
./build.sh thumbv7em-none-eabi
60+
mv release release-thumbv7em-none-eabi
61+
62+
- name: Assemble Artifacts
63+
run: |
64+
echo "Making ./neotron-sdk-${{ env.slug }}..."
65+
mkdir -p ./neotron-sdk-${{ env.slug }}/samples
66+
mv ./samples/release-thumbv6m-none-eabi ./neotron-sdk-${{ env.slug }}/samples/thumbv6m-none-eabi
67+
mv ./samples/release-thumbv7m-none-eabi ./neotron-sdk-${{ env.slug }}/samples/thumbv7m-none-eabi
68+
mv ./samples/release-thumbv7em-none-eabi ./neotron-sdk-${{ env.slug }}/samples/thumbv7em-none-eabi
69+
echo "Compressing ./neotron-sdk-${{ env.slug }}.zip..."
70+
zip -r ./neotron-sdk-${{ env.slug }}.zip ./neotron-sdk-${{ env.slug }}
71+
72+
- name: Upload Artifacts
73+
uses: actions/upload-artifact@v3
74+
if: ${{success()}}
75+
with:
76+
name: Artifacts
77+
if-no-files-found: error
78+
path: |
79+
./neotron-sdk-*/
80+
81+
- name: Create and Upload Release
82+
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags/')
83+
id: create_release
84+
uses: ncipollo/release-action@v1
85+
with:
86+
artifacts: ./neotron-sdk-${{ env.slug }}.zip

describe.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) Ferrous Systems, 2023
4+
#
5+
# This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
6+
7+
set -euo pipefail
8+
9+
GIVEN_REF=$1
10+
11+
case "${GIVEN_REF}" in
12+
refs/heads/*)
13+
slug="$(git branch --show)-$(git rev-parse --short HEAD)"
14+
;;
15+
refs/tags/*)
16+
slug="$(echo "${GIVEN_REF}" | awk '{split($0,a,"/"); print a[3]}')"
17+
;;
18+
refs/pull/*/merge)
19+
slug="pr-$(echo "${GIVEN_REF}" | awk '{split($0,a,"/"); print a[3]}')-$(git rev-parse --short HEAD)"
20+
;;
21+
esac
22+
23+
echo "${slug}"

samples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ members = [
33
"fault",
44
"hello",
55
"input-test",
6-
"snake",
76
"panic",
87
]
8+
resolver = "2"
99

1010
[profile.release]
1111
opt-level = "z"

samples/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ This application panics, printing a nice panic message.
4141
## [`fault`](./fault)
4242

4343
This application generates a Hard Fault.
44+
45+
## [`asmhello`](./asmhello)
46+
47+
A basic "Hello, world" but written in ARM assembly. It prints the string "Hello, world" to *standard output* and then exits with an exit code of 0.
48+
49+
## [`chello`](../chello)
50+
51+
A basic "Hello, world" but written in C. It prints the string "Hello, world" to *standard output* and then exits with an exit code of 0.

samples/asmhello/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.elf
2+
*.o

samples/asmhello/asmhello.S

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.syntax unified
2+
.thumb
3+
.cpu cortex-m0plus
4+
.global app_entry
5+
.thumb_func
6+
7+
.text
8+
.section ".text"
9+
10+
// r0 will contain a pointer to the syscall table
11+
// the write function is the third entry (offset 8)
12+
// and takes the arguments r0=handle, r1=pointer, r2=length
13+
app_entry:
14+
// Save registers
15+
push {r0, r1, r2, lr}
16+
// Fetch write function address
17+
ldr r3, [r0, #8]
18+
// Set up data length
19+
movs r2, #13
20+
// Set up file handle
21+
movs r0, #1
22+
// Set up data pointer
23+
ldr r1, =message
24+
// Call write function
25+
blx r3
26+
// Set return value
27+
movs r0, #0
28+
// Exit
29+
pop {r1, r2, r3, pc}
30+
31+
.data
32+
.section ".rodata"
33+
34+
message:
35+
.ascii "Hello world!\n"

samples/asmhello/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
arm-none-eabi-gcc -mcpu=cortex-m0 -Wl,-T../neotron-cortex-m.ld -o asmhello.elf asmhello.S -nostdlib

samples/build.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ cargo build
2424
echo "Building for ${TARGET}"
2525
cargo build --target ${TARGET} --release
2626

27-
for program in panic hello fault input-test snake; do
27+
pushd chello
28+
./build.sh
29+
popd
30+
31+
pushd asmhello
32+
./build.sh
33+
popd
34+
35+
for program in panic hello fault input-test; do
2836
cp ./target/${TARGET}/release/${program} ./release/${program}.elf
2937
done
38+
cp ./asmhello/asmhello.elf ./release
39+
cp ./chello/chello.elf ./release

samples/chello/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.elf

samples/chello/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
arm-none-eabi-gcc -Os -mcpu=cortex-m0 -Wl,-T../neotron-cortex-m.ld -o chello.elf chello.c -nostdlib

0 commit comments

Comments
 (0)