Closed belohoub closed 5 years ago
STM32 bootloader will be used to do so. As the information spread on the web is a bit confusing, I'll put the research results in a bit structured way below:
our board has boot0 pin grounded; we need to jump into bootloader from firmware
there is lot of tutorials (following STM docs) showing how to jump into bootloader area, e.g.:
However following those tutorials doesn't work because STM's bootloader checks the boot PINs state during initialization
It is necessary to follow these documents:
In AN2606, on page 223, the stm32l082 bootloader is described
Table 2 in AN2606 shows several patters (pattern 2 and pattern 7 groups) leading to bootloader activation:
This is also demonstrated in Figure 58 on page 225
In our case, the only possibility is to use the 3rd pattern; the bootloader initialization procedure will be then as follows:
this procedure should be initialized by a custom startBootloader command from the firmware (KETCuibe Terminal)
Advantages:
Disadvantages:
It may be a bug in FLASHER-STM32 ... ?
KETCube can be programmed by using the open-source tool stm32flash (https://sourceforge.net/projects/stm32flash/).
Enter following command into KETCube Terminal:
>> set core startBootloader
Use stm32flash to view KETCube details:
$ ./stm32flash /dev/ttyUSB0
stm32flash 0.5
http://stm32flash.sourceforge.net/
Interface serial_posix: 57600 8E1
Version : 0x31
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0447 (STM32L07xxx/08xxx)
- RAM : 20KiB (8192b reserved by bootloader)
- Flash : 192KiB (size first sector: 32x128)
- Option RAM : 32b
- System RAM : 8KiB
Use stm32flash to write KETCube firmware:
$ ./stm32flash -w KETCube.hex -e 255 -v -g 0x0 /dev/ttyUSB0
stm32flash 0.5
http://stm32flash.sourceforge.net/
Using Parser : Intel HEX
Interface serial_posix: 57600 8E1
Warning: the interface was not closed properly.
Version : 0x31
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0447 (STM32L07xxx/08xxx)
- RAM : 20KiB (8192b reserved by bootloader)
- Flash : 192KiB (size first sector: 32x128)
- Option RAM : 32b
- System RAM : 8KiB
Write to memory
Erasing memory
Wrote and verified address 0x08007f80 (19.61%) Done.
Starting execution at address 0x08000000... done.
Just to clarify, stm32flash allows to write up to 255 pages at once (parameter -e).
I don't understand this limitation, however removing the range limitation from stm32flash allows to write KETCube memory at once:
$ ./stm32flash -w KETCube.bin -e 1535 -v /dev/ttyUSB0
stm32flash 0.5
http://stm32flash.sourceforge.net/
Using Parser : Raw BINARY
Interface serial_posix: 57600 8E1
Version : 0x31
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0447 (STM32L07xxx/08xxx)
- RAM : 20KiB (8192b reserved by bootloader)
- Flash : 192KiB (size first sector: 32x128)
- Option RAM : 32b
- System RAM : 8KiB
Write to memory
Erasing memory
Wrote and verified address 0x08029348 (100.00%) Done.
Note: the 255 pages limitation will be removed in the next release of stm32flash (fix is a part of current dev version): https://sourceforge.net/p/stm32flash/tickets/115/
The official STM32 tool "STM32CubeProgrammer" works fine
$ ./STM32_Programmer.sh -c port=/dev/ttyUSB0 -w KETCube.bin 0x8000000
-------------------------------------------------------------------
STM32CubeProgrammer v2.4.0
-------------------------------------------------------------------
Serial Port /dev/ttyUSB0 is successfully opened.
Port configuration: parity = even, baudrate = 115200, data-bit = 8,
stop-bit = 1,0, flow-control = off
Timeout error occured while waiting for acknowledgement.
Activating device: OK
Chip ID: 0x447
BootLoader protocol version: 3.1
Device name : STM32L07x/L08x/L010
Flash size : 192 KBytes (default)
Device type : MCU
Device CPU : Cortex-M0+
Memory Programming ...
Opening and parsing file: KETCube.bin
File : KETCube.bin
Size : 175240 Bytes
Address : 0x08000000
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 1369]
Download in Progress:
[==================================================] 100%
File download complete
Time elapsed during download operation: 00:01:00.096
Allow KETCube programming over the same interface as used on the KETCube Terminal.