SmartCAMPUSZCU / KETCube-fw

KETCube firmware
Other
1 stars 1 forks source link

Programming over USART1 #3

Closed belohoub closed 5 years ago

belohoub commented 5 years ago

Allow KETCube programming over the same interface as used on the KETCube Terminal.

belohoub commented 5 years ago

https://www.st.com/content/ccc/resource/technical/document/application_note/b9/9b/16/3a/12/1e/40/0c/CD00167594.pdf/files/CD00167594.pdf/jcr:content/translations/en.CD00167594.pdf

belohoub commented 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:

belohoub commented 5 years ago

It may be a bug in FLASHER-STM32 ... ?

belohoub commented 5 years ago

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.
belohoub commented 5 years ago

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.
belohoub commented 4 years ago

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/

belohoub commented 4 years ago

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