Linux flashing tools: Difference between revisions

From Miosix Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(7 intermediate revisions by the same user not shown)
Line 59: Line 59:
== QSTLink2 ==
== QSTLink2 ==


An useful tool, wit a GUI, sadly unmaintained. This section is kept for reference, and should development of this tool restart.
An useful tool, with a GUI, sadly unmaintained. This section is kept for reference, and should development of this tool restart.


[https://code.google.com/p/qstlink2 QSTLink2]. It has a GUI but the precompiled ppa is no longer updated for the latest Ubuntu releases. The installation on Ubuntu/Debian requires to add a ''ppa'' and install it via ''apt-get''. Also, it is recomended to install the udev rules, which allow QSTLink2 to connect to the USB port without the need to run it from root.
[https://code.google.com/p/qstlink2 QSTLink2]. It has a GUI but the precompiled ppa is no longer updated for the latest Ubuntu releases. The installation on Ubuntu/Debian requires to add a ''ppa'' and install it via ''apt-get''. Also, it is recommended to install the udev rules, which allow QSTLink2 to connect to the USB port without the need to run it from root.


<source lang="bash">
<source lang="bash">
Line 91: Line 91:


<source lang="bash">
<source lang="bash">
sudo apt install lpc21isp
sudo apt install picotool
</source>
</source>


Older distros may not have it in their repos. In this case you'll need to compile it from sources.
Older distros may not have it in their repos. In this case you'll need to compile it from sources.


To use this flashing tool, you'll need to interact with your board to start the STM32 bootloader. This does not happen by default, and requires to tie the BOOT pin high while sending a RUN pulse (RP2040 microcontrollers call their RESET pin RUN). Annoyingly, official boards from Raspberry Pi only have a BOOT butting, and lack a reset button, so you'll either need to
To use this flashing tool, you'll need to interact with your board to start the bootloader. This does not happen by default, and requires to tie the BOOT pin high while sending a RUN pulse (RP2040 microcontrollers call their RESET pin RUN, go figure...). Annoyingly, official boards from Raspberry Pi only have a BOOT button, and lack a reset button, so you'll either need to
* solder a pushbutton between RUN and GND
* solder a pushbutton between RUN and GND
* disconnect and reconnect power while holding the BOOT button every time you want to flash the microcontroller
* disconnect and reconnect power while holding the BOOT button every time you want to flash the microcontroller
Line 116: Line 116:


Please replace main.bin with image.bin if you're using processes.
Please replace main.bin with image.bin if you're using processes.
'''Note:''' these chips have a quirk where once you first attach a debugger, power saving states don't work anymore until the next powercycle. There is a workaround in the ''exit_debug_mode'' function, to be called through gdb to end a debugging session [[https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/nrf52840_generic/openocd.cfg]]


= ATsam Microcontrollers =
= ATsam Microcontrollers =


== Flashing through gdb/openocd ==
== Flashing through gdb/openocd ==
'''Warning:''' these chips come from the factory with a bootloader in the FLASH memory. This means it's possible to accidentally overwrite the bootloader. The bootloader is stored from address 0x0 to 0x4000.


TODO this needs better documenting, the short version is to type in a gdb session
TODO this needs better documenting, the short version is to type in a gdb session
Line 134: Line 138:


TODO document using lrzsz to talk to the serial bootloader
TODO document using lrzsz to talk to the serial bootloader
'''Warning:''' these chips come from the factory with a bootloader in the FLASH memory. This means it's possible to accidentally overwrite the bootloader.


= LPC2000 Microcontrollers =
= LPC2000 Microcontrollers =

Latest revision as of 07:58, 10 May 2026

For most boards officially supported by the Miosix kernel, the build system includes a make program rule to easily flash the kernel (and application). If you use make program, the choice of which flashing tool to use has been made by whoever contributed the port. If you don't have the required tool, make program will fail with an error related to not finding the required flashing tool.

Using make program is only a convenience, not a necessity. Miosix can work with any flashing utility that accepts as input raw binary files. If you prefer to use another flashing program, just directly run your flashing program passing it the appropriate .bin file (the name is main.bin if you're not using processes, or image.bin if you are using processes).

Following is a list of suggestions for the most common microcontrollers used with Miosix.

STM32 microcontrollers

st-flash

A popular choice for STM32 development boards that have an embedded STLink USB programmer/debugger, such as discovery and nucleo boards. To install it on Debian/Ubuntu run:

sudo apt install stlink-tools

You'll need to connect the development board to your computer with an USB cable that will both provide power and allow programming. No user interaction on the board is required to enter programming mode.

dfu-util

This tool allows to program STM32 microcontrollers that have an USB bootloaders (roughly speaking, from STM32F2 onward). This tool is used for some third party development boards (such as the blackpill boards), but is also a convenient choice if you design your own boards.

To install it on Debian/Ubuntu run:

sudo apt install dfu-util

To use this flashing tool, you'll need to interact with your board to start the STM32 bootloader. This does not happen by default, and usually requires to tie the BOOT0 pin high while sending a RESET pulse. If you do so correctly, the microcontroller will show up when doing an lsusb as an STM32 in DFU mode:

Bus 001 Device 011: ID 0483:df11 STMicroelectronics STM Device in DFU Mode

stm32flash

This tool allows to program STM32 microcontrollers using the serial bootloader, which is supported by every STM32. It is also the slowest option, though.

To install it on Debian/Ubuntu run:

sudo apt install stm32flash

To use this flashing tool, you'll need to interact with your board to start the STM32 bootloader. This does not happen by default, and usually requires to tie the BOOT0 pin high while sending a RESET pulse.

Flashing through gdb/openocd

TODO this needs better documenting, the short version is to type in a gdb session

del break
monitor reset halt
monitor flash write_image erase main.bin 0x08000000

Please replace main.bin with image.bin if you're using processes.

QSTLink2

An useful tool, with a GUI, sadly unmaintained. This section is kept for reference, and should development of this tool restart.

QSTLink2. It has a GUI but the precompiled ppa is no longer updated for the latest Ubuntu releases. The installation on Ubuntu/Debian requires to add a ppa and install it via apt-get. Also, it is recommended to install the udev rules, which allow QSTLink2 to connect to the USB port without the need to run it from root.

sudo add-apt-repository ppa:fpoussin/ppa
sudo apt-get update
sudo apt-get install qstlink2
wget https://raw.githubusercontent.com/mobyfab/QStlink2/master/res/49-stlinkv2.rules
sudo mv 49-stlinkv2.rules /etc/udev/rules.d
sudo chown root:root /etc/udev/rules.d/49-stlinkv2.rules

If a PPA of QStlink2 is not available for your platform, you can compile the stable version V1.2.3 in this way

git clone https://github.com/fpoussin/QStlink2.git
cd QStlink2
git checkout v1.2.3
git submodule update --init
qmake -qt=qt5
make
sudo make install

RP2040 Microcontrollers

picotool

A tool for flashing RP2040 microcontrollers through USB. To install it on Debian/Ubuntu run:

sudo apt install picotool

Older distros may not have it in their repos. In this case you'll need to compile it from sources.

To use this flashing tool, you'll need to interact with your board to start the bootloader. This does not happen by default, and requires to tie the BOOT pin high while sending a RUN pulse (RP2040 microcontrollers call their RESET pin RUN, go figure...). Annoyingly, official boards from Raspberry Pi only have a BOOT button, and lack a reset button, so you'll either need to

  • solder a pushbutton between RUN and GND
  • disconnect and reconnect power while holding the BOOT button every time you want to flash the microcontroller
  • get creative shorting RUN and GND with tweezers or a short piece of wire

Unofficial boards, such as those from waveshare don't have this issue.

Nordic nRF Microcontrollers

Flashing through gdb/openocd

TODO this needs better documenting, the short version is to type in a gdb session

del break
monitor reset halt
monitor flash write_image erase main.bin 0x0

Please replace main.bin with image.bin if you're using processes.

Note: these chips have a quirk where once you first attach a debugger, power saving states don't work anymore until the next powercycle. There is a workaround in the exit_debug_mode function, to be called through gdb to end a debugging session [[1]]

ATsam Microcontrollers

Flashing through gdb/openocd

Warning: these chips come from the factory with a bootloader in the FLASH memory. This means it's possible to accidentally overwrite the bootloader. The bootloader is stored from address 0x0 to 0x4000.

TODO this needs better documenting, the short version is to type in a gdb session

del break
monitor reset halt
monitor flash write_image erase main.bin 0x4000

Please replace main.bin with image.bin if you're using processes.

EFM32 Micocontrollers

TODO document using lrzsz to talk to the serial bootloader

Warning: these chips come from the factory with a bootloader in the FLASH memory. This means it's possible to accidentally overwrite the bootloader.

LPC2000 Microcontrollers

lpc21isp

A tool to program LPC2000 microcontrollers using their serial bootloader. To install it on Debian/Ubuntu run:

sudo apt install lpc21isp

This tool was included in older versions of the Miosix Toolchain, as the LPC2138 was the first microcontoller supported by Miosix.