Comments (27)
Actually, I was yesterday considering buying a micro:bit as well as it's quite popular, will probably do that soon.
from tinygo.
My micro:bit arrived :D
For me the same, nothing happens. Will have to investigate what goes wrong, probably with OpenOCD + GDB.
from tinygo.
I see two problems right away:
- The CPU isn't set correctly. This is a Cortex-M0 instead of a Cortex-M4, so the LLVM target is
armv6m-none-eabi
and the linker (actually just GCC) must be passed-mcpu=cortex-m0
instead of-mcpu=cortex-m4
. This will crash the CPU immediately. - As far as I know, all micro:bit chips have 16K RAM instead of 64K (check it with the chip number, if it says QFAA it's 16K, if it says QFAC it is 32K). I don't think this is the issue, but you could try changing it.
from tinygo.
I had already found and changed the first one. When I change that, I receive the following compilation error:
$ make flash-serial TARGET=microbit
go build -o build/tgo -i .
./build/tgo build -target microbit -size=short -o build/serial.elf examples/serial
/tmp/tinygo896560428/main.o: In function `runtime.ticks':
/home/ron/.gvm/pkgsets/go1.11/global/src/github.com/aykevl/tinygo/src/runtime/runtime_nrf.go:79: undefined reference to `__umodsi3'
collect2: error: ld returned 1 exit status
error: exit status 1
Makefile:97: recipe for target 'build/serial.elf' failed
make: *** [build/serial.elf] Error 1
from tinygo.
Also, have you ever tried remote debugging? There is some (limited) support for debug symbols in the compiler, enough to print a stack trace. You'll probably see it hits a HardFault. Debugging a hard fault is difficult on the cortex-m0, but there is a trick to get the previous program counter, which can then be converted to a real function by inspecting the result of arm-none-eabi-objdump -d build/<example>.elf
.
from tinygo.
Ah, you probably need to remove -nostdlib
, see 0d8a7e1 for a similar change.
from tinygo.
Removing -nostdlib
results in:
$ make flash-serial TARGET=microbit
go build -o build/tgo -i .
./build/tgo build -target microbit -size=short -o build/serial.elf examples/serial
/usr/lib/gcc/arm-none-eabi/4.9.3/armv6-m/libgcc.a(unwind-arm.o): In function `get_eit_entry':
/build/gcc-arm-none-eabi-DRRnLA/gcc-arm-none-eabi-4.9.3+svn231177/build/arm-none-eabi/armv6-m/libgcc/../../../../src/libgcc/unwind-arm-common.inc:274: undefined reference to `__exidx_start'
/build/gcc-arm-none-eabi-DRRnLA/gcc-arm-none-eabi-4.9.3+svn231177/build/arm-none-eabi/armv6-m/libgcc/../../../../src/libgcc/unwind-arm-common.inc:274: undefined reference to `__exidx_end'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-abort.o): In function `abort':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv6-m/newlib/libc/stdlib/../../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-signalr.o): In function `_kill_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv6-m/newlib/libc/reent/../../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-signalr.o): In function `_getpid_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv6-m/newlib/libc/reent/../../../../../../newlib/libc/reent/signalr.c:97: undefined reference to `_getpid'
collect2: error: ld returned 1 exit status
error: exit status 1
Makefile:97: recipe for target 'build/serial.elf' failed
make: *** [build/serial.elf] Error 1
from tinygo.
Yes, the microbit is very common, hence why I started playing with this.
Also a chance to have 2 machines in the same family to work out side-by-side compilation, toolchain difference, etc.
from tinygo.
I'm suspecting a bit more linker magic is required, probably to remove the personality function.
Will need to investigate that.
from tinygo.
Some progress on compiling/linking. Still does not work yet.
from tinygo.
I'm looking into it. The weird thing is, as soon as I add -lgcc
to GCC (after the object files - this matters), it suddenly requires all kinds of symbols, even though they should be discarded by the linker (-Wl,--gc-sections
). I wonder why they're not being discarded.
from tinygo.
Fixed a bug in 5bf058a which caused the undefined reference as a side effect. You should now be able to compile for the nrf51 basically by copying pca10040.json and modifying the architecture, chip number and build tags - I am able to compile and run the blinky2 example on a PCA10040 when I switch to armv6m-none-eabi
and -mcpu=cortex-m0
.
from tinygo.
For the future, I should look into adopting compiler-rt to depend less on the oddities of GCC.
from tinygo.
I used the following microbit.json file:
{
"llvm-target": "armv6k-none-eabi",
"build-tags": ["microbit", "nrf51", "nrf", "arm", "js", "wasm"],
"linker": "arm-none-eabi-gcc",
"pre-link-args": ["-nostdlib", "-nostartfiles", "-mcpu=cortex-m0", "-mthumb", "-T", "targets/nrf51.ld", "-Wl,--gc-sections", "-fno-exceptions", "-fno-unwind-tables", "-ffunction-sections", "-fdata-sections", "-Os", "-DNRF51", "-Ilib/CMSIS/CMSIS/Include", "lib/nrfx/mdk/system_nrf51.c", "src/device/nrf/nrf51.s"],
"objcopy": "arm-none-eabi-objcopy",
"flash": "nrfjprog -f nrf51 --sectorerase --program {hex} --reset"
}
Was able to compile with your latest master
, but still cannot get anything visible to happen...
from tinygo.
"llvm-target": "armv6k-none-eabi",
Typo in armv6k
? That should be armv6m
.
Otherwise the file looks good.
from tinygo.
That was because I had originally received an error about needing that architecture for some instruction when I used armv6m-none-eabi
as you originally suggested. I cannot reproduce that error now, of course. Switched in the correct value, but still nothing happening.
from tinygo.
I managed to get a simple "hello world" to run in an emulator I once wrote. This is the diff I used:
diff --git a/targets/nrf52.ld b/targets/nrf52.ld
index a388cf7..442ae1b 100644
--- a/targets/nrf52.ld
+++ b/targets/nrf52.ld
@@ -2,7 +2,7 @@
MEMORY
{
FLASH_TEXT (rw) : ORIGIN = 0x00000000, LENGTH = 256K /* .text */
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K
}
_stack_size = 2K;
diff --git a/targets/pca10040.json b/targets/pca10040.json
index 8aec981..74b507e 100644
--- a/targets/pca10040.json
+++ b/targets/pca10040.json
@@ -1,8 +1,8 @@
{
- "llvm-target": "armv7em-none-eabi",
+ "llvm-target": "armv6m-none-eabi",
"build-tags": ["pca10040", "nrf52832", "nrf52", "nrf", "arm", "js", "wasm"],
"linker": "arm-none-eabi-gcc",
- "pre-link-args": ["-nostdlib", "-nostartfiles", "-mcpu=cortex-m4", "-mthumb", "-T", "targets/nrf52.ld", "-Wl,--gc-sections", "-fno-exceptions", "-fno-unwind-tables", "-ffunction-sections", "-fdata-sections", "-Os", "-DNRF52832_XXAA", "-Ilib/CMSIS/CMSIS/Include", "lib/nrfx/mdk/system_nrf52.c", "src/device/nrf/nrf52.s"],
+ "pre-link-args": ["-nostdlib", "-nostartfiles", "-mcpu=cortex-m0", "-mthumb", "-T", "targets/nrf52.ld", "-Wl,--gc-sections", "-fno-exceptions", "-fno-unwind-tables", "-ffunction-sections", "-fdata-sections", "-Os", "-DNRF52832_XXAA", "-Ilib/CMSIS/CMSIS/Include", "lib/nrfx/mdk/system_nrf52.c", "src/device/nrf/nrf51.s"],
"objcopy": "arm-none-eabi-objcopy",
"flash": "nrfjprog -f nrf52 --sectorerase --program {hex} --reset"
}
I should have a micro:bit soon so I can test it there.
from tinygo.
Error received in compile:
$ make flash-serial TARGET=microbit
./build/tgo build -target microbit -size=short -o build/serial.elf examples/serial
/tmp/tinygo517145424/main.o: In function `runtime.ticks':
/home/ron/.gvm/pkgsets/go1.11/global/src/github.com/aykevl/tinygo/src/runtime/runtime_nrf.go:78: undefined reference to `__umodsi3'
collect2: error: ld returned 1 exit status
error: exit status 1
Makefile:97: recipe for target 'build/serial.elf' failed
make: *** [build/serial.elf] Error 1
from tinygo.
I forgot to remove -nostdlib
from pre-link-args
.
Now back to this compile error:
$ make flash-serial TARGET=microbit
go build -o build/tgo -i .
./build/tgo build -target microbit -size=short -o build/serial.elf examples/serial
/usr/lib/gcc/arm-none-eabi/4.9.3/armv6-m/libgcc.a(unwind-arm.o): In function `get_eit_entry':
/build/gcc-arm-none-eabi-DRRnLA/gcc-arm-none-eabi-4.9.3+svn231177/build/arm-none-eabi/armv6-m/libgcc/../../../../src/libgcc/unwind-arm-common.inc:274: undefined reference to `__exidx_start'
/build/gcc-arm-none-eabi-DRRnLA/gcc-arm-none-eabi-4.9.3+svn231177/build/arm-none-eabi/armv6-m/libgcc/../../../../src/libgcc/unwind-arm-common.inc:274: undefined reference to `__exidx_end'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-abort.o): In function `abort':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv6-m/newlib/libc/stdlib/../../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-signalr.o): In function `_kill_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv6-m/newlib/libc/reent/../../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv6-m/libc.a(lib_a-signalr.o): In function `_getpid_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv6-m/newlib/libc/reent/../../../../../../newlib/libc/reent/signalr.c:97: undefined reference to `_getpid'
collect2: error: ld returned 1 exit status
error: exit status 1
Makefile:97: recipe for target 'build/serial.elf' failed
make: *** [build/serial.elf] Error 1
from tinygo.
Removing -nostdlib
should not be necessary anymore with master, the __umodsi3
reference is only the side effect of a now-fixed bug.
from tinygo.
You are correct, it builds correctly on master. Still nothing seems to be happening.
from tinygo.
I have improved the debugging experience a lot with the last few commits (diff). With that, I was able to pinpoint where the micro:bit gets stuck:
$ tinygo gdb -target microbit examples/serial
GNU gdb (7.12-6+9+b2) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /tmp/tinygo292972977/main...done.
Remote debugging using :3333
runtime.initLFCLK () at /home/ayke/src/github.com/aykevl/tinygo/src/runtime/runtime_nrf.go:40
40 for nrf.CLOCK.EVENTS_LFCLKSTARTED == 0 {
Loading section .text, size 0x35c lma 0x0
Start address 0x0, load size 860
Transfer rate: 1 KB/sec, 860 bytes/write.
Continuing.
WARNING! The target is already running. All changes GDB did to registers will be discarded! Waiting for target to halt.
^C
Program received signal SIGINT, Interrupt.
0x000001de in runtime.initLFCLK () at /home/ayke/src/github.com/aykevl/tinygo/src/runtime/runtime_nrf.go:40
40 for nrf.CLOCK.EVENTS_LFCLKSTARTED == 0 {
(gdb) bt
#0 0x000001de in runtime.initLFCLK () at /home/ayke/src/github.com/aykevl/tinygo/src/runtime/runtime_nrf.go:40
#1 runtime.init#1 () at /home/ayke/src/github.com/aykevl/tinygo/src/runtime/runtime_nrf.go:25
#2 runtime.initAll () at /home/ayke/src/github.com/aykevl/tinygo/src/runtime/runtime.go:11
#3 0x00000218 in main () at /home/ayke/src/github.com/aykevl/tinygo/src/runtime/runtime.go:33
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) list
35 }
36
37 func initLFCLK() {
38 nrf.CLOCK.LFCLKSRC = nrf.CLOCK_LFCLKSTAT_SRC_Xtal
39 nrf.CLOCK.TASKS_LFCLKSTART = 1
40 for nrf.CLOCK.EVENTS_LFCLKSTARTED == 0 {
41 }
42 nrf.CLOCK.EVENTS_LFCLKSTARTED = 0
43 }
44
(gdb) quit
Detaching from program: /tmp/tinygo292972977/main, Remote target
Ending remote debugging.
When I commented out the initLFCLK()
and fixed the UART pins, I was able to get a 'hello world!' on my serial monitor 😀 Of course, sleep doesn't work yet so that should still be fixed.
My microbit.json
:
{
"llvm-target": "armv6m-none-eabi",
"build-tags": ["microbit", "nrf51822", "nrf51", "nrf", "arm", "js", "wasm"],
"linker": "arm-none-eabi-gcc",
"pre-link-args": [
"-nostdlib",
"-nostartfiles",
"-mcpu=cortex-m0",
"-mthumb",
"-T", "targets/nrf51.ld",
"-Wl,--gc-sections",
"-fno-exceptions", "-fno-unwind-tables",
"-ffunction-sections", "-fdata-sections",
"-Os",
"-DNRF52832_XXAA",
"-Ilib/CMSIS/CMSIS/Include",
"lib/nrfx/mdk/system_nrf51.c",
"src/device/nrf/nrf51.s"
],
"objcopy": "arm-none-eabi-objcopy",
"flash": "nrfjprog -f nrf51 --sectorerase --program {hex} --reset",
"ocd-daemon": ["openocd", "-f", "interface/cmsis-dap.cfg", "-c", "transport select swd", "-f", "target/nrf51.cfg"],
"gdb": "arm-none-eabi-gdb",
"gdb-initial-cmds": ["target remote :3333", "monitor halt", "load", "monitor reset", "c"]
}
from tinygo.
OK that is very exciting!
from tinygo.
After some digging in old MicroPython source code, I finally figured out the problem with the clock: the micro:bit does not have a 32kHz crystal. I haven't tested it yet but I'm pretty sure that's it. The solution is simply to use the internal RC oscillator, which uses slightly more power and is not very precise without calibration.
from tinygo.
Just wondering if -DNRF52832_XXAA
should be -DNRF51_XXAA
in your microbit.json
?
from tinygo.
Just wondering if
-DNRF52832_XXAA
should be-DNRF51_XXAA
in yourmicrobit.json
?
Yes it should (or it should be -DNRF51
), but apparently it worked without the change. See #38.
from tinygo.
Fixed in #38.
from tinygo.
Related Issues (20)
- Missing C.CBytes HOT 1
- Cgo doesn't support bitshifted constants HOT 2
- Unable to Build LLVM on Windows with GCC Version 11.2.0 HOT 1
- When using Go modules the TinyGo compiler doesn't find the TinyGo packages like machine | ERROR: undefined machine.I2C0 HOT 3
- TypeError: WebAssembly.instantiate(): Import #0 "gojs": module is not an object or function TypeError: Cannot convert a BigInt value to a number HOT 2
- wasm: -target=wasi is now trying to use GOOS=wasip1, which is not existent in Go 1.20 HOT 2
- build with target "wasm-unknown" fail in windows10 22H2 HOT 2
- Cannot compile WASM module in 0.32.0 but works in 0.31.2 HOT 3
- wasm-unknown target shouldn't set `--import-memory` by default HOT 2
- Ability to pass flags to external linker (such as `wasm-ld`) HOT 1
- cannot use `tinygo build -ldflags "-X 'main.WASM_NAME=ws_conn.wasm'"` to modify variable WASM_NAME
- RP2040 I2C Target mode doubles first byte sent in Reply HOT 4
- tinygo fails to build at Arch Linux clean environment HOT 10
- "Over The Air" updates for Pico-w HOT 3
- bug: net/http server not working on linux HOT 3
- ci: llvm packages have unmet dependencies HOT 4
- Crash when compiling with a large number of embedded files
- runtime.hashmapStringGet segv HOT 4
- samd21: machine.Flash.WriteAt() crashes for unaligned offset values HOT 1
- Flash USB from https://play.tinygo.org/ on Chromebook? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinygo.