How to flash stm32 using only Linux terminal? - c++

So, threre are Archlinux distro, stm32 mc, and C code. How to flash stm32, without some IDE, only using console?

With Texane stlink
Install as described in the README
Convert your firmware to .bin if necessary
arm-none-eabi-objcopy -O binary firmware.elf firmware.bin
/opt/stlink/st-flash write firmware.bin 0x8000000
With OpenOCD, if your board is not supported by Texane
Get it from the link above and install (ignore the eclipse-specific parts)
Find your board description file in openocd/scripts/board, create one if necessary.
openocd -d0 -f board/yourboard.cfg -c "init;targets;halt;flash write_image erase firmware.hex;shutdown"

If you have USB to UART adapter, you can use stm32flash. Basically connect USART1 to the adapter, pull BOOT0 to high (there might be a jumper or button on the board) and power up / reset the board. Then you should be able to follow stm32flash -h to see what to do.
Some STM32 (e.g. STM32F042) has USB DFU bootloader built in, so you can also connect the MCU to USB directly and use dfu-utils.

Related

How to enable remoteproc and rpmsg in Google Coral Dev Board (NXP i.MX 8M)

Hi I'm using a Google coral with NXP i.MX 8M and I'm trying to enable communication between Cortex-A53 and Cortex M4F. For that I need the remoteproc and rpmsg.
So I already flashed the Mendel OS on the board. (https://coral.ai/docs/dev-board/get-started/)
Then I followed the exampled to enable the CORTEX M4F:
https://coral.googlesource.com/mcuxpresso_sdk/+/refs/heads/master/boards/evkmimx8mq/demo_apps/hello_world_tflite/
I was able to compile, and run the example with sucess on Cortex M4F.
Then I tried to follow the example to enable multicore: https://coral.googlesource.com/mcuxpresso_sdk/+/refs/heads/master/boards/evkmimx8mq/multicore_examples/rpmsg_lite_str_echo_rtos/readme.txt*https://coral.googlesource.com/mcuxpresso_sdk/+/refs/heads/master/boards/evkmimx8mq/multicore_examples/rpmsg_lite_str_echo_rtos/readme.txt
I was able to compile the bin file on the example and "flash" it on the Cortex-M4F using the same method as hello world:
On the device:
sudo cp hello_world_tflite.bin /boot
cd /boot
sudo ln -sf hello_world_tflite.bin m4_fw.bin
On the device, in u-boot:
setenv m4enabled 1
saveenv
boot
But no output is visible...
How do I enable the remoteproc on Mendel side?
What is missing?
I want to be able to control the cortex m4 with mendel-os.

OpenOCD how to flash local file to remote target?

(Using STM32F767 microcontroller)
I have a remote debugging environment setup on a RPI using OpenOCD. I can connect to it just fine using GDB.
However since I am writing a bootloader I need to flash the firmware to a specific offset in flash memory. E.g bootloader starts at 0x800000 and firmware should start at 0x8010000 for example so the offset would be (0x10000).
This works fine locally using: mon flash write_bank 0 main.bin 0x10000
But since I don't have the main.bin in the RPI, is there a way I could use OpenOCD or GDB to specify my local file instead and that would be sent over the remote connection?
Note that I would not like to setup a FTP and thus am looking for an alternate solution.
Best regards
gdb should supports sending files to remote via the 'remote put '. But, when I try this in gdb, I get the response "Remote I/O error: Function not implemented". Seems like OpenOCD does not support this
Use "file" to select the file and then "load" will send the file across to the device.

Uploading Arduino hex file using avrdude

I need to use avrdude from a terminal to upload the compiled Arduino sketch (.hex file) to my Arduino Pro Mini 5V. I am programming the Pro Mini board with an FTDI 5V. When I plug in the board into my machine and run the avrdude command with the following parameters, it says that it cannot find that device on that port (see image below). Can someone tell me how to get the port info ("-P") for where I plug in my board into my computer?
avrdude Upload Command showing exception:
I figured this out myself. In the Preferences tab in the Arduino IDE, I turned on verbosity while uploading the code to the board. From the dump, I figured out this is how you can upload the code (the compiled file - .hex file) to Arduino Pro Mini 5V board:
avrdude -C/usr/share/arduino/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/build8135728863211847829.tmp/sketch_may21b.cpp.hex:i

Compiling on Vortex86: "Illegal instruction"

I'm using an embedded PC which has a Vortex86-SG CPU, Ubuntu 10.04 w/ kernel 2.6.34.10-vortex86-sg. Unfortunately we can't compile a new kernel, cause we don't have any source code, not even drivers or patches.
I have to run a small project written in C++ with OpenFrameworks. The framework compiles right each script in of_v0071_linux_release/scripts/linux/ubuntu/install_*.sh.
I noticed that in order to compile against Vortex86/Ubuntu 10.04, the following options must be added in every config.make file:
USER_CFLAGS = -march=i486
USER_LDFLAGS = -lGLEW
In effects, it compiles without errors, but the generated binary doesn't start at all:
root#jb:~/openframeworks/of_v0071_linux_release/apps/myApps/emptyExample/bin# ./emptyExample
Illegal instruction
root#jb:~/openframeworks/of_v0071_linux_release/apps/myApps/emptyExample/bin# echo $?
132
Strace last lines:
munmap(0xb77c3000, 4096) = 0
rt_sigprocmask(SIG_BLOCK, [PIPE], NULL, 8) = 0
--- SIGILL (Illegal instruction) # 0 (0) ---
+++ killed by SIGILL +++
Illegal instruction
root#jb:~/openframeworks/of_v0071_linux_release/apps/myApps/emptyExample/bin#
Any idea to solve this problem?
I know I am a bit late on this but I recently had my own issues trying to compile the kernel for the vortex86dx. I finally was able to build the kernel as well. Use these steps at your own risk as I am not a Linux guru and some settings you may have to change to your own preference/hardware:
Download and use a Linux distribution that runs on a similar kernel version that you plan on compiling. Since I will be compiling Linux 2.6.34.14, I downloaded and installed Debian 6 on virtual box with adequate ram and processor allocations. You could potentially compile on the Vortex86DX itself, but that would likely take forever.
Made sure I hade decencies: #apt-get install ncurses-dev kernel-package
Download kernel from kernel.org (I grabbed Linux-2.6.34.14.tar.xz). Extract files from package.
Grab Config file from dmp ftp site: ftp://vxmx:gc301#ftp.dmp.com.tw/Linux/Source/config-2.6.34-vortex86-sg-r1.zip. Please note vxmx user name. Copy the config file to freshly extracted Linux source folder.
Grab Patch and at ftp://vxdx:gc301#ftp.dmp.com.tw/Driver/Linux/config%26patch/patch-2.6.34-hda.zip. Please note vxdx user name. Copy to kernel source folder.
Patch Kernel: #patch -p1 < patchfilename
configure kernel with #make menuconfig
Load Alternate Configuration File
Enable generic x86 support
Enable Math Emulation
I disabled generic IDE support because I will using legacy mode(selectable in bios)
Under Device Drivers -> Ethernet (10 or 100Mbit) -> Make sure RDC R6040 Fast Ethernet Adapter Support is selected
USB support -> Select Support for Host-side USB, EHCI HCD (USB 2.0) support, OHCI HCD support
safe config as .config
check serial ports: edit .config manually make sure CONFIG_SERIAL_8250_NR_UARTS = 4 (or more if you have additional), CONFIG_SERIAL_8250_RUNTIME_UARTS = 4(or more if you have additional). If you are to use more that 4 serial ports make use config_serail_8250_MANY_PORTs is set.
compile kernel headers and source: #make-kpkg --initrd kernel_image kernel_source kernel_headers modules_image

Upload sketch with C++

I want to compile the sketch with the Arduino IDE but then locate the bin file and upload it using another program.
How can I design a custom uploader for Arduino (specifications, etc.)?
You can already do this with avrdude. If you don't absolutely need to develop another program, try using this.
If you absolutely must implement your own programmer, check out the stk500 protocol.
Great information available via this forum post
Direct link to specs:
http://www.atmel.com/Images/doc2525.pdf
Sample usage:
/usr/local/bin/avrdude -V -F -C /etc/avrdude.conf -p atmega328p -P /dev/ttyACM0
-c stk500v1 -b 57600 -U flash:w:applet/helloworld.hex
Multiplatform tutorial:
http://www.ladyada.net/learn/avr/avrdude.html
Here's a similar program (written in c#) that relies on avrdude:
http://arduino.cc/playground/Code/ArduinoUpload
Command line example:
http://www.neuraladvance.com/2010/04/08/using-avrdude-with-the-arduino-duemilanove/
The following is the command that should be used for uploading a
program to an Arduino Duemilanove (with an ATmega168 chip).
avrdude -c arduino -p m168 -P usb -U flash:w:FILENAME
replace FILENAME
with the hex file you wish to upload to the board. This assumes that
you want to write a file to the flash memory. You can of course verify
or read from different portions of memory depending on your chip but
I’ll leave you to figure that out from the AVRdude manual.
You need to develop something which can speak the Arduino bootloader protocol. I suggest consulting the Arduino documentation and code available at http://arduino.cc for more information.
See the makefile - there is a separate task for uploading the binary to Arduino. This way you will find the tool that does it and the parameters (I don't remember from the top of my head) and you will be able to do it manually (using the tool) instead from IDE. Writing a tool like that seems to be reinventing the wjeel.