tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.2k stars 892 forks source link

tinygo flash command can only compile HEX files #142

Closed deadprogram closed 5 years ago

deadprogram commented 5 years ago

At the moment, the command tinygo flash will automatically assume that the target file to be compiled should be a HEX file, due to this parameter here: https://github.com/aykevl/tinygo/blob/master/main.go#L313

This is a small problem when using the bossac command with the UF2 bootloader. bossac works as expected only when flashing .BIN files. It will appear to flash the HEX file, but does not correctly complete the process of setting the user's code for execution. Hence when the MCU restarts, it returns to the bootloader mode, instead of starting up the user's code.

What I propose is to add a new key named "outputFormat" to the target.json file, which lets you set a desired output format. The default can be .hex if not specified.

aykevl commented 5 years ago

I think it is much easier to detect it based on the presence of the {hex} or {bin} substrings in target.Flasher. That should be trivial to implement as well, and doesn't require an extra option in the JSON file.

deadprogram commented 5 years ago

Do you mean to rename the target to something like itsybitsy-m0.bin.json and then determine the resulting file type by parsing the substring out of the file name?

aykevl commented 5 years ago

No, to see whether the "flash" attribute in the JSON file contains {hex} or {bin}. For example:

    "flash": "bossac -d -i -e -w -v -R --offset=0x2000 {hex}"

vs

    "flash": "bossac -d -i -e -w -v -R --offset=0x2000 {bin}"
deadprogram commented 5 years ago

That makes a lot more sense. OK I will look at creating PR for that.

deadprogram commented 5 years ago

This code is now in dev branch. Now closing.