Mini STM32 V3

From DX, SKU 157301 - it looks like the Exasub MiniSTM32 V3.0

According to the documentation it has

"MINI-STM32-V3.0" development board

mcu: STM32F103RBT6, with an ARM Cortex-M3 core, 128 kb flash, 20 kb RAM, max mcu clock is 72 MHz

it has 8 MHz and 32.768 kHz crystals connected

other resources on board: 16-bit A/D, PWM, CAN, 2 x mini-USB ports,

standard ARM JTAG 20 pin connector,

RTC backup battery holder, for a CR1220 battery.

Power indicator light (LD3), USB status indicator (LD4), two user programmable LEDs (LED1, LED2)

Two user buttons (S1 / KEY1, S2 / KEY2), a BOOT select button (BOOT0 - S3), a reset button (RESET - S4)

  • KEY1 - PA0
  • KEY2 - PA1
  • LED1 - PA2
  • LED2 - PA3

a LCD board ("2.8 TFT Color LCD Module Rev 2.0") with

2.8 inch true color TFT touch screen (240x320, 26k color, i8080 16-bit parallel interface), ILI9325 controller

touch controller is ADS7843

SDcard slot (supports SD cards up to 2 GB)

back to microcontrollers page.

Links

Exasub Mini STM32 V3.0, libopencm3, Open source drivers for the mini-stm32 board built around libopencm3, summon-arm-toolchain, GNU Tools for ARM Embedded Processors, DaddyBASIC, CooCox CoOS, stlink, FreeRTOS, eCos, ChibiOS/RT, NuttX, scmRTOS, stm32flash, STM32 microcontroller, Wikipedia - ARM Cortex-M,

Linux development: STM32 Discovery Development On Linux, STM32/ARM Cortex-M3 HOWTO: Development under Ubuntu (Debian), STM32 LCD touch screen demo,

Projects / experiments: stm32-tutorial, Detect And Zero Rightmost One: ARM development, part 2, projectproto.blogspot.com: Cortex-M3 / STM32, STM32 Discovery tutorials, ARMv7 Cortex-M3 and Cortex-M4 Projects,

rust - Rust and STM32: A Quick Start Guide, Rust on STM32: Getting started,

local links

c2, c1,

History

2023-04-15: rust has the display-interface-parallel-gpio crate, which might be usable with the TFT LCD display.

2023-04-15: TFT LCD - the ILI9325 is configured for 16 bit parallel interface, according to schematics. Connections

DB00        PC0
DB01        PC1
DB02        PC2
DB03        PC3
DB04        PC4
DB05        PC5
DB06        PC6
DB07        PC7
DB08        PB8
DB09        PB9
DB10        PB10
DB11        PB11
DB12        PB12
DB13        PB13
DB14        PB14
DB15        PB15

CS          PC8
RS          PC9
WR          PC10
RD          PC11
BL_EN       PC12
LE          PB5

SD_CS       PB7
TP_CS       PA4
SPI_SCK     PA5
SPI_MISO    PA6
SPI_MOSI    PA7
TP_INT      PC13

SDcard (SD) and touch screen (TP) controller are on SPI interface.

2023-04-15: c1 - rust - updated dependecies in Cargo.toml, these are the newest that work with the example

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ cat Cargo.toml
[package]
name = "blink"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[profile.release]
opt-level = 'z' # turn on maximum optimizations. We only have 64kB
lto = true      # Link-time-optimizations for further size reduction

[dependencies]
#cortex-m = "^0.6.3"       # Access to the generic ARM peripherals
#cortex-m-rt = "^0.6.12"   # Startup code for the ARM Core
#embedded-hal = "^0.2.4"   # Access to generic embedded functions (`set_high`)
cortex-m = "0.7"       # Access to the generic ARM peripherals
#cortex-m-rt = "0.7"       # Startup code for the ARM Core
cortex-m-rt = "0.6"    # Startup code for the ARM Core
embedded-hal = "0.2"       # Access to generic embedded functions (`set_high`)
panic-halt = "^0.2.0"     # Panic handler

# Access to the STM32F103 HAL.
[dependencies.stm32f1xx-hal]
# STM32F103RB contains a 128kB flash variant which is called "medium density"
features = ["stm32f103", "rt", "medium"]
#version = "^0.6.1"
#version = "0.10"
version = "0.7"

2023-04-15: c1 - rust - the updated example, with both LEDs blinking looks like this

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ more src/main.rs 
// src/main.rs

// std and main are not available for bare metal software
#![no_std]
#![no_main]

use panic_halt as _;

use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal as hal;
use hal::{pac, delay::Delay, prelude::*};

#[entry]
fn main() -> ! {
    /* Get access to device and core peripherals */
    let dp = pac::Peripherals::take().unwrap();
    let cp = cortex_m::Peripherals::take().unwrap();

    /* Get access to RCC, AFIO and GPIOA */
    let mut rcc = dp.RCC.constrain();
    let mut flash = dp.FLASH.constrain();
    let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);

    /* Set up LED pin */
    let mut led1 = gpioa.pa2.into_push_pull_output(&mut gpioa.crl);
    let mut led2 = gpioa.pa3.into_push_pull_output(&mut gpioa.crl);

    /* Set up sysclk and freeze it */
    let clocks = rcc.cfgr.sysclk(8.mhz()).freeze(&mut flash.acr);

    /* Set up systick delay */
    let mut delay = Delay::new(cp.SYST, clocks);

    loop {
        /* Light show */
        led1.set_high().ok();
        led2.set_low().ok();
        delay.delay_ms(1_000_u16);
        led1.set_low().ok();
        led2.set_high().ok();
        delay.delay_ms(1_000_u16);
    }
}

2023-04-15: c1 - rust - build the updated example

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ cargo build --release

   Compiling blink v0.1.0 (/zs/tingo/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink)
    Finished release [optimized] target(s) in 0.50s
warning: the following packages contain code that will be rejected by a future version of Rust: stm32f1xx-hal v0.6.1
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 5`

convert to binary

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ cargo objcopy --target thumbv7m-none-eabi --release -- -O binary blinky.bin
    Finished release [optimized] target(s) in 0.03s
warning: the following packages contain code that will be rejected by a future version of Rust: stm32f1xx-hal v0.6.1
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 6`

flash and start

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ stm32flash -w ./blinky.bin -g 0x0 /dev/cuaU0
stm32flash 0.7

http://stm32flash.sourceforge.net/

Using Parser : Raw BINARY
Size         : 852
Interface serial_posix: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (STM32F10xxx Medium-density)
- RAM        : Up to 20KiB  (512b reserved by bootloader)
- Flash      : Up to 128KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
Wrote address 0x08000354 (100.00%) Done.

Starting execution at address 0x08000000... done.

and it worked. Nice.

2023-04-15: c1 - connect the Mini STM32 v3.0 board and check that stm32flash finds it

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ stm32flash /dev/cuaU0
stm32flash 0.7

http://stm32flash.sourceforge.net/

Interface serial_posix: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (STM32F10xxx Medium-density)
- RAM        : Up to 20KiB  (512b reserved by bootloader)
- Flash      : Up to 128KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB

try to write

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ stm32flash -w ./blinky.bin /dev/cuaU0
stm32flash 0.7

http://stm32flash.sourceforge.net/

Using Parser : Raw BINARY
Size         : 852
Interface serial_posix: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (STM32F10xxx Medium-density)
- RAM        : Up to 20KiB  (512b reserved by bootloader)
- Flash      : Up to 128KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
Wrote address 0x08000354 (100.00%) Done.

probably worked, but I need to fix the eaxmple first.

2023-04-15: c1 - rust - and I can use cargo objcopy as well

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ cargo objcopy --target thumbv7m-none-eabi --release -- -O binary blinky.bin
    Finished release [optimized] target(s) in 0.03s
warning: the following packages contain code that will be rejected by a future version of Rust: stm32f1xx-hal v0.6.1
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 4`

check

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ file ./blinky.bin
./blinky.bin: data

2023-04-15: c1 - rust - trying cargo readobj

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ cargo readobj --target thumbv7m-none-eabi  -- --file-header
   Compiling typenum v1.16.0
   Compiling semver-parser v0.7.0
   Compiling proc-macro2 v1.0.56
   Compiling version_check v0.9.4
   Compiling semver v0.9.0
   Compiling unicode-ident v1.0.8
   Compiling rustc_version v0.2.3
   Compiling generic-array v0.14.7
   Compiling quote v1.0.26
   Compiling semver v1.0.17
   Compiling bare-metal v0.2.5
   Compiling nb v1.1.0
   Compiling syn v1.0.109
   Compiling cortex-m v0.7.7
   Compiling nb v0.1.3
   Compiling generic-array v0.13.3
   Compiling generic-array v0.12.4
   Compiling vcell v0.1.3
   Compiling void v1.0.2
   Compiling cortex-m-rt v0.6.15
   Compiling stable_deref_trait v1.2.0
   Compiling embedded-hal v0.2.7
   Compiling volatile-register v0.2.1
   Compiling as-slice v0.1.5
   Compiling rustc_version v0.4.0
   Compiling cortex-m v0.6.7
   Compiling bitfield v0.13.2
   Compiling aligned v0.3.5
   Compiling r0 v0.2.2
   Compiling stm32f1 v0.11.0
   Compiling cast v0.2.7
   Compiling panic-halt v0.2.0
   Compiling cortex-m-rt-macros v0.6.15
   Compiling stm32f1xx-hal v0.6.1
   Compiling blink v0.1.0 (/zs/tingo/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink)
    Finished dev [unoptimized + debuginfo] target(s) in 40.41s
warning: the following packages contain code that will be rejected by a future version of Rust: stm32f1xx-hal v0.6.1
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 2`
Could not find tool: readobj
at: /usr/home/tingo/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/bin/llvm-readobj
Consider `rustup component add llvm-tools-preview`

ok, try to add the component

tingo@kg-core1:~ $ rustup component add llvm-tools-preview
info: downloading component 'llvm-tools'
info: installing component 'llvm-tools'
 13.5 MiB /  51.0 MiB ( 26 %)   0 B/s in  1s ETA: Unknown                                                          24.5 MiB /  51.0 MiB ( 48 %)  13.5 MiB/s in  2s ETA:  1s                                                          36.5 MiB /  51.0 MiB ( 72 %)  12.2 MiB/s in  3s ETA:  1s                                                          48.8 MiB /  51.0 MiB ( 96 %)  12.2 MiB/s in  4s ETA:  0s                                                          51.0 MiB /  51.0 MiB (100 %)  12.2 MiB/s in  4s ETA:  0s

and

tingo@kg-core1:~ $ l ~/.cargo/bin
./              cargo-cov*      cargo-objcopy*  cargo-size*     rust-ar*        rust-ld*        rust-objcopy*   rust-size*      rustfmt*
../             cargo-fmt*      cargo-objdump*  cargo-strip*    rust-cov*       rust-lld*       rust-objdump*   rust-strip*     rustup*
cargo*          cargo-miri*     cargo-profdata* clippy-driver*  rust-gdb*       rust-lldb*      rust-profdata*  rustc*
cargo-clippy*   cargo-nm*       cargo-readobj*  rls*            rust-gdbgui*    rust-nm*        rust-readobj*   rustdoc*

probably put into the $HOME/.rustup tree instead. Retry cargo readobj

tingo@kg-core1:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ cargo readobj --target thumbv7m-none-eabi  -- --file-header
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
warning: the following packages contain code that will be rejected by a future version of Rust: stm32f1xx-hal v0.6.1
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 3`
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x8000131
  Start of program headers:          52 (bytes into file)
  Start of section headers:          3028568 (bytes into file)
  Flags:                             0x5000200
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         5
  Size of section headers:           40 (bytes)
  Number of section headers:         22
  Section header string table index: 20

much better.

2023-04-15: c1 - rust - I installed rust via rustup, like so

tingo@kg-core1:~ $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/tingo/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/tingo/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /home/tingo/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile file located at:

  /home/tingo/.profile

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-freebsd
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

info: profile set to 'default'
info: default host triple is x86_64-unknown-freebsd
info: syncing channel updates for 'stable-x86_64-unknown-freebsd'
info: latest update on 2023-03-28, rust version 1.68.2 (9eb3afe9e 2023-03-27)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
  5.5 MiB /  19.5 MiB ( 28 %)   0 B/s in  1s ETA: Unknown                                                           7.3 MiB /  19.5 MiB ( 38 %)   5.5 MiB/s in  2s ETA:  2s                                                          11.9 MiB /  19.5 MiB ( 61 %)   3.7 MiB/s in  3s ETA:  2s                                                          19.5 MiB /  19.5 MiB (100 %)   4.0 MiB/s in  4s ETA:  0s
info: installing component 'rust-std'
 11.3 MiB /  29.3 MiB ( 39 %)   0 B/s in  1s ETA: Unknown                                                          21.9 MiB /  29.3 MiB ( 75 %)  11.3 MiB/s in  2s ETA:  0s                                                          29.3 MiB /  29.3 MiB (100 %)  10.9 MiB/s in  2s ETA:  0s
info: installing component 'rustc'
 14.1 MiB /  84.9 MiB ( 17 %)   0 B/s in  1s ETA: Unknown                                                          25.7 MiB /  84.9 MiB ( 30 %)  14.1 MiB/s in  2s ETA:  4s                                                          38.5 MiB /  84.9 MiB ( 45 %)  12.8 MiB/s in  3s ETA:  3s                                                          51.9 MiB /  84.9 MiB ( 61 %)  12.8 MiB/s in  4s ETA:  2s                                                          63.0 MiB /  84.9 MiB ( 74 %)  13.0 MiB/s in  5s ETA:  1s                                                          75.1 MiB /  84.9 MiB ( 88 %)  12.6 MiB/s in  6s ETA:  0s                                                          84.9 MiB /  84.9 MiB (100 %)  12.2 MiB/s in  6s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-freebsd'

  stable-x86_64-unknown-freebsd installed - rustc 1.68.2 (9eb3afe9e 2023-03-27)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"

and installed cargo-binutils via cargo install, cargo-flash fails to install as before. I used rustup to install correct target

tingo@kg-core1:~/personal/projects/2023 $ rustup target install thumbv7m-none-eabi
info: downloading component 'rust-std' for 'thumbv7m-none-eabi'
info: installing component 'rust-std' for 'thumbv7m-none-eabi'

and this make the example rust project build - nice.

2023-04-15: c2 - rust - install some prerequisites: $ cargo install cargo-binutils is ok, but cargo install cargo-flash blows up:

tingo@kg-core2:~/personal/projects/2023/rust/embedded/stm32/mini_stm32_v3/blink $ cargo install cargo-flash
    Updating crates.io index
  Downloaded cargo-flash v0.18.0
  Downloaded 1 crate (27.2 KB) in 0.36s
  Installing cargo-flash v0.18.0
  Downloaded clap v4.2.2
  Downloaded scroll_derive v0.11.0
  Downloaded jaylink v0.3.0
  Downloaded indexmap v1.9.3
  Downloaded serde_spanned v0.6.1
  Downloaded git-version-macro v0.3.5
  Downloaded enum-primitive-derive v0.2.2
  Downloaded defmt-json-schema v0.1.0
  Downloaded heck v0.4.1
  Downloaded radium v0.7.0
  Downloaded clap_lex v0.4.1
  Downloaded simplelog v0.12.1
  Downloaded humantime v2.1.0
  Downloaded anstyle v1.0.0
  Downloaded fallible-iterator v0.2.0
  Downloaded semver v1.0.17
  Downloaded toml_datetime v0.6.1
  Downloaded git-version v0.3.5
  Downloaded colorchoice v1.0.0
  Downloaded serde_derive v1.0.160
  Downloaded clap_derive v4.2.0
  Downloaded tracing-attributes v0.1.23
  Downloaded utf8-width v0.1.6
  Downloaded stable_deref_trait v1.2.0
  Downloaded tap v1.0.1
  Downloaded itoa v1.0.6
  Downloaded probe-rs-target v0.18.0
  Downloaded anstream v0.3.0
  Downloaded wyz v0.5.1
  Downloaded kmp v0.1.1
  Downloaded terminal_size v0.2.6
  Downloaded ihex v3.0.0
  Downloaded thiserror v1.0.40
  Downloaded thiserror-impl v1.0.40
  Downloaded utf8parse v0.2.1
  Downloaded io-lifetimes v1.0.10
  Downloaded unicode-ident v1.0.8
  Downloaded unsafe-libyaml v0.2.8
  Downloaded serde_yaml v0.9.21
  Downloaded serde v1.0.160
  Downloaded camino v1.1.4
  Downloaded toml_edit v0.19.8
  Downloaded winnow v0.4.1
  Downloaded serde_json v1.0.96
  Downloaded goblin v0.6.1
  Downloaded clap_builder v4.2.2
  Downloaded regex v1.7.3
  Downloaded syn v2.0.15
  Downloaded syn v1.0.109
  Downloaded object v0.30.3
  Downloaded hidapi v2.2.2
  Downloaded libusb1-sys v0.6.4
  Downloaded regex-syntax v0.6.29
  Downloaded bitvec v1.0.1
  Downloaded time v0.3.20
  Downloaded scroll v0.11.0
  Downloaded ryu v1.0.13
  Downloaded env_logger v0.10.0
  Downloaded dissimilar v1.0.6
  Downloaded base64 v0.21.0
  Downloaded libc v0.2.141
  Downloaded toml v0.7.3
  Downloaded time-macros v0.2.8
  Downloaded gimli v0.27.2
  Downloaded probe-rs v0.18.0
  Downloaded svg v0.13.1
  Downloaded rusb v0.9.2
  Downloaded once_cell v1.17.1
  Downloaded defmt-decoder v0.3.6
  Downloaded cargo_toml v0.15.2
  Downloaded probe-rs-cli-util v0.18.0
  Downloaded dunce v1.0.3
  Downloaded funty v2.0.0
  Downloaded bytesize v1.2.0
  Downloaded anyhow v1.0.70
  Downloaded anstyle-parse v0.2.0
  Downloaded quote v1.0.26
  Downloaded byteorder v1.4.3
  Downloaded bitfield v0.14.0
  Downloaded rustix v0.37.11
  Downloaded colored v2.0.0
  Downloaded cargo_metadata v0.15.4
  Downloaded proc-macro2 v1.0.56
  Downloaded errno v0.3.1
  Downloaded anstyle-query v1.0.0
  Downloaded byte-unit v4.0.19
  Downloaded atty v0.2.14
  Downloaded is-terminal v0.4.7
  Downloaded defmt-parser v0.3.2
  Downloaded cargo-platform v0.1.2
  Downloaded bincode v1.3.3
  Downloaded plain v0.2.3
  Downloaded jep106 v0.2.8
  Downloaded 93 crates (9.6 MB) in 0.97s (largest was `probe-rs` at 3.3 MB)
   Compiling proc-macro2 v1.0.56
   Compiling unicode-ident v1.0.8
   Compiling quote v1.0.26
   Compiling serde_derive v1.0.160
   Compiling serde v1.0.160
   Compiling libc v0.2.141
   Compiling autocfg v1.1.0
   Compiling syn v1.0.109
   Compiling cc v1.0.79
   Compiling pkg-config v0.3.26
   Compiling log v0.4.17
   Compiling cfg-if v1.0.0
   Compiling io-lifetimes v1.0.10
   Compiling bitflags v1.3.2
   Compiling rustix v0.37.11
   Compiling indexmap v1.9.3
   Compiling memchr v2.5.0
   Compiling itoa v1.0.6
   Compiling num-traits v0.2.15
   Compiling proc-macro-hack v0.5.20+deprecated
   Compiling hashbrown v0.12.3
   Compiling thiserror v1.0.40
   Compiling ryu v1.0.13
   Compiling rusb v0.9.2
   Compiling time-core v0.1.0
   Compiling once_cell v1.17.1
   Compiling unsafe-libyaml v0.2.8
   Compiling serde_json v1.0.96
   Compiling utf8parse v0.2.1
   Compiling radium v0.7.0
   Compiling lazy_static v1.4.0
   Compiling anyhow v1.0.70
   Compiling base64 v0.21.0
   Compiling syn v2.0.15
   Compiling libusb1-sys v0.6.4
   Compiling hidapi v2.2.2
   Compiling anstyle-parse v0.2.0
   Compiling time-macros v0.2.8
   Compiling anstyle-query v1.0.0
   Compiling winnow v0.4.1
   Compiling portable-atomic v0.3.19
   Compiling anstyle v1.0.0
   Compiling stable_deref_trait v1.2.0
   Compiling camino v1.1.4
   Compiling byteorder v1.4.3
   Compiling colorchoice v1.0.0
   Compiling tap v1.0.1
   Compiling semver v1.0.17
   Compiling fallible-iterator v0.2.0
   Compiling errno v0.3.1
   Compiling num_threads v0.1.6
   Compiling atty v0.2.14
   Compiling wyz v0.5.1
   Compiling gimli v0.27.2
   Compiling object v0.30.3
   Compiling aho-corasick v0.7.20
   Compiling tracing-core v0.1.30
   Compiling is-terminal v0.4.7
   Compiling anstream v0.3.0
   Compiling time v0.3.20
   Compiling unicode-width v0.1.10
   Compiling regex-syntax v0.6.29
   Compiling clap_lex v0.4.1
   Compiling strsim v0.10.0
   Compiling termcolor v1.1.3
   Compiling heck v0.4.1
   Compiling funty v2.0.0
   Compiling pin-project-lite v0.2.9
   Compiling clap_builder v4.2.2
   Compiling regex v1.7.3
   Compiling console v0.15.5
   Compiling bitvec v1.0.1
   Compiling colored v2.0.0
   Compiling thiserror-impl v1.0.40
   Compiling clap_derive v4.2.0
   Compiling humantime v2.1.0
   Compiling svg v0.13.1
   Compiling kmp v0.1.1
   Compiling ihex v3.0.0
   Compiling static_assertions v1.1.0
   Compiling plain v0.2.3
   Compiling number_prefix v0.4.0
   Compiling defmt-parser v0.3.2
   Compiling bitfield v0.14.0
   Compiling dissimilar v1.0.6
   Compiling utf8-width v0.1.6
   Compiling indicatif v0.17.3
   Compiling scroll_derive v0.11.0
   Compiling git-version-macro v0.3.5
   Compiling tracing-attributes v0.1.23
   Compiling scroll v0.11.0
   Compiling enum-primitive-derive v0.2.2
   Compiling git-version v0.3.5
   Compiling cargo-flash v0.18.0
   Compiling clap v4.2.2
   Compiling terminal_size v0.2.6
   Compiling dunce v1.0.3
   Compiling bytesize v1.2.0
   Compiling jep106 v0.2.8
   Compiling bincode v1.3.3
   Compiling serde_yaml v0.9.21
   Compiling toml_datetime v0.6.1
   Compiling serde_spanned v0.6.1
   Compiling cargo-platform v0.1.2
   Compiling toml_edit v0.19.8
   Compiling probe-rs-target v0.18.0
   Compiling defmt-json-schema v0.1.0
   Compiling tracing v0.1.37
   Compiling jaylink v0.3.0
   Compiling simplelog v0.12.1
   Compiling goblin v0.6.1
   Compiling env_logger v0.10.0
   Compiling byte-unit v4.0.19
   Compiling defmt-decoder v0.3.6
   Compiling cargo_metadata v0.15.4
   Compiling toml v0.7.3
   Compiling probe-rs v0.18.0
   Compiling cargo_toml v0.15.2
   Compiling probe-rs-cli-util v0.18.0
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/usr/local/lib/rustlib/x86_64-unknown-freebsd/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/tingo/bin:/home/tingo/.local/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustc3yQp9I/symbols.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.0.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.1.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.10.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.11.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.12.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.13.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.14.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.15.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.2.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.3.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.4.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.5.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.6.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.7.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.8.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.cargo_flash.a2cd0848-cgu.9.rcgu.o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6.1gkg4arytkwzk6ky.rcgu.o" "-Wl,--as-needed" "-L" "/tmp/cargo-installixy38e/release/deps" "-L" "/usr/local/lib" "-L" "/usr/lib" "-L" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib" "-Wl,-Bstatic" "/tmp/cargo-installixy38e/release/deps/libgit_version-90d47f114cd0e5d9.rlib" "/tmp/cargo-installixy38e/release/deps/libprobe_rs_cli_util-052b986ef5747f46.rlib" "/tmp/cargo-installixy38e/release/deps/libdunce-b025474c47969172.rlib" "/tmp/cargo-installixy38e/release/deps/libgoblin-d8a753f868adf698.rlib" "/tmp/cargo-installixy38e/release/deps/libplain-1fcd7f9be67db815.rlib" "/tmp/cargo-installixy38e/release/deps/libcargo_metadata-7fead633a4b0066c.rlib" "/tmp/cargo-installixy38e/release/deps/libcargo_platform-76abdd155a314a38.rlib" "/tmp/cargo-installixy38e/release/deps/libsemver-e0121ecd6a29f46d.rlib" "/tmp/cargo-installixy38e/release/deps/libcamino-d8352d4345331b07.rlib" "/tmp/cargo-installixy38e/release/deps/libcargo_toml-77b745c436db4cf6.rlib" "/tmp/cargo-installixy38e/release/deps/libtoml-d6e5738a742b41ec.rlib" "/tmp/cargo-installixy38e/release/deps/libtoml_edit-1e750526cbe95b61.rlib" "/tmp/cargo-installixy38e/release/deps/libserde_spanned-a65d157b0458eff5.rlib" "/tmp/cargo-installixy38e/release/deps/libwinnow-bf6d9b87bc82d848.rlib" "/tmp/cargo-installixy38e/release/deps/libtoml_datetime-73a689a3f1620c11.rlib" "/tmp/cargo-installixy38e/release/deps/libdefmt_decoder-94722e60e8cf79d3.rlib" "/tmp/cargo-installixy38e/release/deps/libserde_json-3494c1c1e0bc2d8a.rlib" "/tmp/cargo-installixy38e/release/deps/libdissimilar-8458f63f18afa3ad.rlib" "/tmp/cargo-installixy38e/release/deps/libdefmt_json_schema-13d91a473a2b9aaf.rlib" "/tmp/cargo-installixy38e/release/deps/libdefmt_parser-e1aed817a3fcae21.rlib" "/tmp/cargo-installixy38e/release/deps/libterminal_size-41887b623a00e29d.rlib" "/tmp/cargo-installixy38e/release/deps/libsimplelog-0092072f34422eaf.rlib" "/tmp/cargo-installixy38e/release/deps/libtime-2e3d4e117f8c6efa.rlib" "/tmp/cargo-installixy38e/release/deps/libnum_threads-a2f30da255406fbd.rlib" "/tmp/cargo-installixy38e/release/deps/libtime_core-c2ea6524fc684ebf.rlib" "/tmp/cargo-installixy38e/release/deps/libenv_logger-4372b215b1b24336.rlib" "/tmp/cargo-installixy38e/release/deps/libtermcolor-68062a7adf7cfc25.rlib" "/tmp/cargo-installixy38e/release/deps/libhumantime-6500c4bb3f9d22ca.rlib" "/tmp/cargo-installixy38e/release/deps/libregex-d27a571194c7393c.rlib" "/tmp/cargo-installixy38e/release/deps/libaho_corasick-07b862cd599c028b.rlib" "/tmp/cargo-installixy38e/release/deps/libregex_syntax-57eea25ee30ce778.rlib" "/tmp/cargo-installixy38e/release/deps/libindicatif-02b963e73e7e4f6a.rlib" "/tmp/cargo-installixy38e/release/deps/libportable_atomic-833962edc3fde3a3.rlib" "/tmp/cargo-installixy38e/release/deps/libnumber_prefix-453fb46c3e1e5f11.rlib" "/tmp/cargo-installixy38e/release/deps/libconsole-94f95bd24cbf2d8a.rlib" "/tmp/cargo-installixy38e/release/deps/libunicode_width-663cc2b377259818.rlib" "/tmp/cargo-installixy38e/release/deps/libclap-bfa467d7b4b19e18.rlib" "/tmp/cargo-installixy38e/release/deps/libclap_builder-3d6c856b09719fc9.rlib" "/tmp/cargo-installixy38e/release/deps/libstrsim-5e6decf6cf800997.rlib" "/tmp/cargo-installixy38e/release/deps/libanstream-48c5b624ce4350e3.rlib" "/tmp/cargo-installixy38e/release/deps/libanstyle_query-a3298bf4b22f856b.rlib" "/tmp/cargo-installixy38e/release/deps/libis_terminal-8e4a1fb476e1b806.rlib" "/tmp/cargo-installixy38e/release/deps/librustix-e40fac9429cc481b.rlib" "/tmp/cargo-installixy38e/release/deps/liberrno-7394e45e430db981.rlib" "/tmp/cargo-installixy38e/release/deps/libio_lifetimes-3a7b989594151d6e.rlib" "/tmp/cargo-installixy38e/release/deps/libanstyle-4eb40767dd36b39a.rlib" "/tmp/cargo-installixy38e/release/deps/libcolorchoice-71c904cf82730a06.rlib" "/tmp/cargo-installixy38e/release/deps/libanstyle_parse-8efa2ea8fedf0192.rlib" "/tmp/cargo-installixy38e/release/deps/libutf8parse-5c8ba7c9b1c48c57.rlib" "/tmp/cargo-installixy38e/release/deps/libclap_lex-882ab6bcf2cc6544.rlib" "/tmp/cargo-installixy38e/release/deps/libbyte_unit-4a2c47a789f68e72.rlib" "/tmp/cargo-installixy38e/release/deps/libutf8_width-0e033bc9c05b289f.rlib" "/tmp/cargo-installixy38e/release/deps/libprobe_rs-2e6cef03f3b56884.rlib" "/tmp/cargo-installixy38e/release/deps/libkmp-a6e06c1f002d8e81.rlib" "/tmp/cargo-installixy38e/release/deps/libbincode-d74953af25d50866.rlib" "/tmp/cargo-installixy38e/release/deps/libserde_yaml-c0c5f8b0652b016d.rlib" "/tmp/cargo-installixy38e/release/deps/libryu-73e4be0fd4c4572e.rlib" "/tmp/cargo-installixy38e/release/deps/libitoa-d74d3dec5847db3c.rlib" "/tmp/cargo-installixy38e/release/deps/libindexmap-48a76f7b2a01ef4e.rlib" "/tmp/cargo-installixy38e/release/deps/libhashbrown-27b3f95e6e81910c.rlib" "/tmp/cargo-installixy38e/release/deps/libunsafe_libyaml-3ffce42076732a18.rlib" "/tmp/cargo-installixy38e/release/deps/libstatic_assertions-0ed6df3421f210d8.rlib" "/tmp/cargo-installixy38e/release/deps/libthiserror-291e9d5dcf33a4be.rlib" "/tmp/cargo-installixy38e/release/deps/libjaylink-354246037d2e3056.rlib" "/tmp/cargo-installixy38e/release/deps/libbyteorder-65665858711d8769.rlib" "/tmp/cargo-installixy38e/release/deps/libbitflags-56154651ca245155.rlib" "/tmp/cargo-installixy38e/release/deps/librusb-c405dd09e0afd6e1.rlib" "/tmp/cargo-installixy38e/release/deps/liblibusb1_sys-f553d9a333faaaa1.rlib" "/tmp/cargo-installixy38e/release/deps/libhidapi-e687f5d6fc8c9893.rlib" "/tmp/cargo-installixy38e/release/deps/libscroll-a7c77662c1e47a13.rlib" "/tmp/cargo-installixy38e/release/deps/libsvg-8a4c499c167d1ebd.rlib" "/tmp/cargo-installixy38e/release/deps/libihex-afbe45a0eb3c3efe.rlib" "/tmp/cargo-installixy38e/release/deps/libtracing-e2495663bb9ba10a.rlib" "/tmp/cargo-installixy38e/release/deps/liblog-99ffe3175ce66d28.rlib" "/tmp/cargo-installixy38e/release/deps/libcfg_if-b4c990ca52e973f0.rlib" "/tmp/cargo-installixy38e/release/deps/libpin_project_lite-5fa458e13395a34f.rlib" "/tmp/cargo-installixy38e/release/deps/libtracing_core-1e34ef537d7e5499.rlib" "/tmp/cargo-installixy38e/release/deps/libobject-a39dd432bf58e04b.rlib" "/tmp/cargo-installixy38e/release/deps/libmemchr-1bf371181ccca0fd.rlib" "/tmp/cargo-installixy38e/release/deps/libgimli-4f8b7d1470aa4e82.rlib" "/tmp/cargo-installixy38e/release/deps/libfallible_iterator-9f38cd20d78e82e8.rlib" "/tmp/cargo-installixy38e/release/deps/libstable_deref_trait-5d0012a3fae094c9.rlib" "/tmp/cargo-installixy38e/release/deps/libonce_cell-4fbec61d2985fc8f.rlib" "/tmp/cargo-installixy38e/release/deps/libprobe_rs_target-d3c04ffe53f3f964.rlib" "/tmp/cargo-installixy38e/release/deps/libbase64-6bd4409e643efa44.rlib" "/tmp/cargo-installixy38e/release/deps/libanyhow-41529528ca66735d.rlib" "/tmp/cargo-installixy38e/release/deps/libbitfield-a6e2194c7ae9ac3d.rlib" "/tmp/cargo-installixy38e/release/deps/libjep106-7d120662fde7c03b.rlib" "/tmp/cargo-installixy38e/release/deps/libnum_traits-508966f93a78d487.rlib" "/tmp/cargo-installixy38e/release/deps/libserde-22267c9745297498.rlib" "/tmp/cargo-installixy38e/release/deps/libbytesize-64f820fc85b72f82.rlib" "/tmp/cargo-installixy38e/release/deps/libcolored-a6b92b9e942c531b.rlib" "/tmp/cargo-installixy38e/release/deps/liblazy_static-21fb74d17b834f99.rlib" "/tmp/cargo-installixy38e/release/deps/libatty-f7c77098b13e8e70.rlib" "/tmp/cargo-installixy38e/release/deps/liblibc-a19254cf9ebc8367.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libstd-7c7f3bd22bdaa9dd.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libpanic_unwind-43564f5c87df8622.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libobject-63ebf0257001e199.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libmemchr-5ebccec0eb7a2dbc.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libaddr2line-9718c7d03a37f6b8.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libgimli-76dde1840fb934bc.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_demangle-97c24b791629bd1c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libstd_detect-6655d156bdef4c15.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libhashbrown-f39b5a4ab6d03d30.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libminiz_oxide-2a31bb753fa834c6.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libadler-a86dc7eafa119ac1.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_alloc-b92afbd7b85f4529.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libunwind-c1808ffb153b7a2d.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libcfg_if-eb6a05031d339718.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/liblibc-4843838543d70c5d.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/liballoc-77ddc16017f002f2.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_core-3c1e7d54d70452a8.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libcore-db6e1a38a9546138.rlib" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib/libcompiler_builtins-a9c77aa633313fdc.rlib" "-Wl,-Bdynamic" "-lusb" "-lhidapi" "-lrt" "-lutil" "-lexecinfo" "-lkvm" "-lmemstat" "-lkvm" "-lutil" "-lprocstat" "-lrt" "-ldevstat" "-lexecinfo" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lrt" "-lutil" "-lexecinfo" "-lkvm" "-lmemstat" "-lkvm" "-lutil" "-lprocstat" "-lrt" "-ldevstat" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/local/lib/rustlib/x86_64-unknown-freebsd/lib" "-o" "/tmp/cargo-installixy38e/release/deps/cargo_flash-5fe0c9935856b5d6" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs"
  = note: ld: error: undefined symbol: libusb_set_option
          >>> referenced by hidapi.f791af44-cgu.8
          >>>               hidapi-e687f5d6fc8c9893.hidapi.f791af44-cgu.8.rcgu.o:(hidapi::lazy_init::h763c120ae93a814e) in archive /tmp/cargo-installixy38e/release/deps/libhidapi-e687f5d6fc8c9893.rlib
          cc: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `cargo-flash` due to previous error
error: failed to compile `cargo-flash v0.18.0`, intermediate artifacts can be found at `/tmp/cargo-installixy38e`

thyat's not good.

2023-04-14: c2 - rust, what do we have?

tingo@kg-core2:~ $ rustc --version
rustc 1.68.2 (9eb3afe9e 2023-03-27) (built from a source tarball)
tingo@kg-core2:~ $ cargo --version
cargo 1.68.2

Cortex M3 is thumbv7m, check for it

tingo@kg-core2:~ $ rustc --print target-list | grep thumbv7m
thumbv7m-none-eabi

great.

2023-04-14: c2 - connecting the right min USB port (ports facing away) mini stm32 V3 board to a FreeBSD workstation running

tingo@kg-core2:~ $ freebsd-version -ku
13.1-RELEASE-p6
13.1-RELEASE-p7

from /var/log/messages

Apr 14 22:52:25 kg-core2 kernel: ugen1.6: <Prolific Technology Inc. USB-Serial Controller> at usbus1
Apr 14 22:52:25 kg-core2 kernel: uplcom0 on uhub3
Apr 14 22:52:25 kg-core2 kernel: uplcom0: <Prolific Technology Inc. USB-Serial Controller, class 0/0, rev 1.10/3.00, addr 5> on usbus1

usbconfig

root@kg-core2:~ # usbconfig -d ugen1.6
ugen1.6: <Prolific Technology Inc. USB-Serial Controller> at usbus1, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (100mA)

find which tty port

root@kg-core2:~ # sysctl dev.uplcom.0.ttyname
dev.uplcom.0.ttyname: U0

tty ports

root@kg-core2:~ # ll /dev/cuaU0 /dev/ttyU0
crw-rw----  1 uucp  dialer  0x1d5 Apr 14 22:53 /dev/cuaU0
crw-------  1 root  wheel   0x1d2 Apr 14 22:52 /dev/ttyU0

try with stm32flash, normal power on (LED 1 and 2 blinking)

tingo@kg-core2:~ $ stm32flash /dev/cuaU0
stm32flash 0.7

http://stm32flash.sourceforge.net/

Interface serial_posix: 57600 8E1
Failed to init device, timeout.

after holding down BOOT0 button until after RESET has been pushed (LED 1 and 2 are off)

tingo@kg-core2:~ $ stm32flash /dev/cuaU0
stm32flash 0.7

http://stm32flash.sourceforge.net/

Interface serial_posix: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (STM32F10xxx Medium-density)
- RAM        : Up to 20KiB  (512b reserved by bootloader)
- Flash      : Up to 128KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB

nice.

2021-11-07: I re-created this page on my self-hosted web server.

2013-09-28: FreeBSD - messing around with git: add changed file

tingo@kg-core1$ git add serial_posix.c

local commit

tingo@kg-core1$  git commit

Check the log

tingo@kg-core1$ git log --pretty=oneline -3
617dd370a8086b4fd0b298d44fbbe5cc03436c60 Fix the serial_setup function so stm32flash works on FreeBSD
d8bbb25fca01ddd95cbe6b390bf4a28b6b4a4d79 Issue #15 - Fixed reading binary files under w32
46eb51eb068dd64ac7147f133939f0cbfa58dfd6 Issue #18 - Thanks bolmsted Patch for adding F2 and F4 to stm32flash. Only the F4 part has been tested on a STM32F4 discovery board. The serial timeout needed to be increased to accommodate the significant increase in the mass erase time.

Using git format-patch for a single commit:

tingo@kg-core1$ git format-patch -1 --stdout 617dd370a8086b4fd0b298d44fbbe5cc03436c60
From 617dd370a8086b4fd0b298d44fbbe5cc03436c60 Mon Sep 17 00:00:00 2001
From: Torfinn Ingolfsen <ti...@gmail.com>
Date: Sat, 28 Sep 2013 00:59:27 +0200
Subject: [PATCH] Fix the serial_setup function so stm32flash works on FreeBSD

Without this fix, stm32flash will only show
tingo@kg-core1$ ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

/dev/cuaU0: No such file or directory
when you try to query a device.
---
 serial_posix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/serial_posix.c b/serial_posix.c
index f4097b4..3cca7e1 100644
--- a/serial_posix.c
+++ b/serial_posix.c
@@ -105,8 +105,8 @@ serial_err_t serial_setup(serial_t *h, const serial_baud_t baud, const serial_bi

        switch(parity) {
                case SERIAL_PARITY_NONE: port_parity = 0;                       break;
-               case SERIAL_PARITY_EVEN: port_parity = INPCK | PARENB;          break;
-               case SERIAL_PARITY_ODD : port_parity = INPCK | PARENB | PARODD; break;
+               case SERIAL_PARITY_EVEN: port_parity = PARENB;          break;
+               case SERIAL_PARITY_ODD : port_parity = PARENB | PARODD; break;

                default:
                        return SERIAL_ERR_INVALID_PARITY;
-- 
1.8.3.4

That was all.

2013-09-27: FreeBSD - checking out the unofficial git tree for stm32flash:

tingo@kg-core1$ git clone https://git.gitorious.org/stm32flash/stm32flash.git stm32flash
Cloning into 'stm32flash'...
remote: Counting objects: 455, done
remote: Finding sources: 100% (455/455)
remote: Compressing objects: 100% (115/115)
remote: Compressing objects: 100% (114/114)
Receiving objects: 100% (455/455), 428.95 KiB | 0 bytes/s, done.
Resolving deltas: 100% (300/300), done.
Checking connectivity... done

Let's see if it builds

tingo@kg-core1$ cd stm32flash
tingo@kg-core1$ gmake
gmake -C parsers
gmake[1]: Entering directory `/zs/tingo/work/stm32flash/parsers'
gcc -g -Wall -c -I../ binary.c hex.c
ar r parsers.a        binary.o hex.o
ar: warning: creating parsers.a
gmake[1]: Leaving directory `/zs/tingo/work/stm32flash/parsers'
gcc -g -o stm32flash -I./ \
    main.c \
    utils.c \
    stm32.c \
    serial_common.c \
    serial_platform.c \
    parsers/parsers.a \
    stm32/stmreset_binary.c \
    -Wall
In file included from main.c:31:
serial.h:82: warning: type qualifiers ignored on function return type
serial.h:83: warning: type qualifiers ignored on function return type
serial.h:84: warning: type qualifiers ignored on function return type
serial.h:85: warning: type qualifiers ignored on function return type
In file included from stm32.h:25,
                 from stm32.c:24:
serial.h:82: warning: type qualifiers ignored on function return type
serial.h:83: warning: type qualifiers ignored on function return type
serial.h:84: warning: type qualifiers ignored on function return type
serial.h:85: warning: type qualifiers ignored on function return type
In file included from serial_common.c:20:
serial.h:82: warning: type qualifiers ignored on function return type
serial.h:83: warning: type qualifiers ignored on function return type
serial.h:84: warning: type qualifiers ignored on function return type
serial.h:85: warning: type qualifiers ignored on function return type
serial_common.c:39: warning: type qualifiers ignored on function return type
serial_common.c:57: warning: type qualifiers ignored on function return type
serial_common.c:69: warning: type qualifiers ignored on function return type
serial_common.c:80: warning: type qualifiers ignored on function return type
In file included from serial_posix.c:28,
                 from serial_platform.c:4:
serial.h:82: warning: type qualifiers ignored on function return type
serial.h:83: warning: type qualifiers ignored on function return type
serial.h:84: warning: type qualifiers ignored on function return type
serial.h:85: warning: type qualifiers ignored on function return type

build ok.

tingo@kg-core1$ ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

/dev/cuaU0: No such file or directory

Ok. Does it have the same problem as the old one? It does. After removing INPCK from the serial_setup function and recompiling:

tingo@kg-core1$ ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

Serial Config: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (Medium-density)
RAM          : 20KiB  (512b reserved by bootloader)
Flash        : 128KiB (sector size: 4x1024)
Option RAM   : 15b
System RAM   : 2KiB

Resetting device... done.

Now only need to

2013-09-27: FreeBSD - I forgot that you have to set the board to the correct mode by holding down the BOOT0 button while pressing and releasing the RESET button. After doing that , the stm32flash program says:

tingo@kg-core1$ ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

(read, written) iflag: 1, 1
(read, written) oflag: 0, 0
(read, written) cflag: db00, db00
(read, written) lflag: 0, 0
Serial Config: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (Medium-density)
RAM          : 20KiB  (512b reserved by bootloader)
Flash        : 128KiB (sector size: 4x1024)
Option RAM   : 15b
System RAM   : 2KiB

Resetting device... done.

OK, it works - nice.

2013-09-27: FreeBSD - debugging the termios flags in serial_setup:

tingo@kg-core1$ ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

(read, written) iflag: 1, 1
(read, written) oflag: 0, 0
(read, written) cflag: db00, db10
(read, written) lflag: 0, 0
/dev/cuaU0: No such file or directory
The control flags set in the code are different. For some reason, the code has
    switch(parity) {
        case SERIAL_PARITY_NONE: port_parity = 0;                       break;
        case SERIAL_PARITY_EVEN: port_parity = INPCK | PARENB;          break;
        case SERIAL_PARITY_ODD : port_parity = INPCK | PARENB | PARODD; break;

        default:
            return SERIAL_ERR_INVALID_PARITY;
    }

but INPCK is an input flag. Removing that flag gets the program a bit further:

tingo@kg-core1$ ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

(read, written) iflag: 1, 1
(read, written) oflag: 0, 0
(read, written) cflag: db00, db00
(read, written) lflag: 0, 0
Serial Config: 57600 8E1
read_byte: No such file or directory
Assertion failed: (0), function stm32_read_byte, file stm32.c, line 90.
Abort trap (core dumped)

With truss (in case it helps):

tingo@kg-core1$ LANG=C truss ./stm32flash /dev/cuaU0
__sysctl(0x7fffffffe080,0x2,0x7fffffffe09c,0x7fffffffe090,0x0,0x0) = 0 (0x0)
mmap(0x0,688,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365198336 (0x800535000)
munmap(0x800535000,688)                 = 0 (0x0)
__sysctl(0x7fffffffe0f0,0x2,0x80063f408,0x7fffffffe0e8,0x0,0x0) = 0 (0x0)
mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34365198336 (0x800535000)
issetugid(0x800536015,0x800530684,0x80064bb10,0x80064bae0,0x5991,0x0) = 0 (0x0)
open("/etc/libmap.conf",O_RDONLY,0666)         ERR#2 'No such file or directory'
open("/var/run/ld-elf.so.hints",O_RDONLY,057)     = 3 (0x3)
read(3,"Ehnt\^A\0\0\0\M^@\0\0\0002\^A\0"...,128) = 128 (0x80)
lseek(3,0x80,SEEK_SET)                 = 128 (0x80)
read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,306) = 306 (0x132)
close(3)                     = 0 (0x0)
access("/lib/libc.so.7",0)             = 0 (0x0)
open("/lib/libc.so.7",O_RDONLY,030771340)     = 3 (0x3)
fstat(3,{ mode=-r--r--r-- ,inode=5537727,size=1298464,blksize=32768 }) = 0 (0x0)
pread(0x3,0x80063e2c0,0x1000,0x0,0x101010101010101,0x8080808080808080) = 4096 (0x1000)
mmap(0x0,2371584,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) = 34366341120 (0x80064c000)
mmap(0x80064c000,1085440,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,3,0x0) = 34366341120 (0x80064c000)
mmap(0x800855000,126976,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,3,0x109000) = 34368475136 (0x800855000)
mmap(0x800874000,110592,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,-1,0x0) = 34368602112 (0x800874000)
close(3)                     = 0 (0x0)
mmap(0x0,656,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365231104 (0x80053d000)
munmap(0x80053d000,656)                 = 0 (0x0)
mmap(0x0,43904,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365231104 (0x80053d000)
munmap(0x80053d000,43904)             = 0 (0x0)
sysarch(0x81,0x7fffffffe170,0x800539088,0x0,0xffffffffffcde450,0x8080808080808080) = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)         = 0 (0x0)
__sysctl(0x7fffffffe100,0x2,0x80087a780,0x7fffffffe0f8,0x0,0x0) = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)         = 0 (0x0)
fstat(1,{ mode=crw--w---- ,inode=147,size=0,blksize=4096 }) = 0 (0x0)
__sysctl(0x7fffffffe0c0,0x2,0x800879dc8,0x7fffffffe0b8,0x0,0x0) = 0 (0x0)
__sysctl(0x7fffffffdfe0,0x2,0x7fffffffdf70,0x7fffffffdfd8,0x8007478c0,0xc) = 0 (0x0)
__sysctl(0x7fffffffdf70,0x2,0x800879fd0,0x7fffffffe038,0x0,0x0) = 0 (0x0)
readlink("/etc/malloc.conf",0x7fffffffe0e0,1024) ERR#2 'No such file or directory'
issetugid(0x800746581,0x7fffffffe0e0,0xffffffffffffffff,0x0,0x2,0x0) = 0 (0x0)
break(0x600000)                     = 0 (0x0)
__sysctl(0x7fffffffe370,0x2,0x7fffffffe38c,0x7fffffffe380,0x0,0x0) = 0 (0x0)
mmap(0x0,2097152,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34368712704 (0x80088f000)
mmap(0x800a8f000,1511424,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34370809856 (0x800a8f000)
munmap(0x80088f000,1511424)             = 0 (0x0)
ioctl(1,TIOCGETA,0xffffe550)             = 0 (0x0)
stm32flash - http://stm32flash.googlecode.com/
write(1,"stm32flash - http://stm32flash.g"...,47) = 47 (0x2f)

write(1,"\n",1)                     = 1 (0x1)
open("/dev/cuaU0",O_RDWR|O_NONBLOCK|O_NOCTTY,00) = 3 (0x3)
fcntl(3,F_SETFL,0x0)                 = 0 (0x0)
ioctl(3,TIOCGETA,0xa07084)             = 0 (0x0)
ioctl(3,TIOCGETA,0xa070b0)             = 0 (0x0)
ioctl(3,TIOCFLUSH,0xffffe5d4)             = 0 (0x0)
ioctl(3,TIOCSETA,0xa070b0)             = 0 (0x0)
ioctl(3,TIOCGETA,0xffffe630)             = 0 (0x0)
(read, written) iflag: 1, 1
write(2,"(read, written) iflag: 1, 1\n",28)     = 28 (0x1c)
(read, written) oflag: 0, 0
write(2,"(read, written) oflag: 0, 0\n",28)     = 28 (0x1c)
(read, written) cflag: db00, db00
write(2,"(read, written) cflag: db00, db0"...,34) = 34 (0x22)
(read, written) lflag: 0, 0
write(2,"(read, written) lflag: 0, 0\n",28)     = 28 (0x1c)
Serial Config: 57600 8E1
write(1,"Serial Config: 57600 8E1\n",25)     = 25 (0x19)
write(3,"\^?",1)                 = 1 (0x1)
read(3,0x7fffffffe62b,1)             = 0 (0x0)
stat("/usr/share/nls/C/libc.cat",0x7fffffffd850) ERR#2 'No such file or directory'
stat("/usr/share/nls/libc/C",0x7fffffffd850)     ERR#2 'No such file or directory'
stat("/usr/local/share/nls/C/libc.cat",0x7fffffffd850) ERR#2 'No such file or directory'
stat("/usr/local/share/nls/libc/C",0x7fffffffd850) ERR#2 'No such file or directory'
read_byte: No such file or directory
writev(0x2,0x7fffffffdd90,0x4,0x19,0x1b6664,0x800a00158) = 37 (0x25)
Assertion failed: (0), function stm32_read_byte, file stm32.c, line 90.
write(2,"Assertion failed: (0), function "...,72) = 72 (0x48)
sigprocmask(SIG_SETMASK,SIGHUP|SIGINT|SIGQUIT|SIGILL|SIGTRAP|SIGEMT|SIGFPE|SIGKILL|SIGBUS|SIGSEGV|SIGSYS|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
getpid()                     = 19636 (0x4cb4)
kill(19636,SIGABRT)                 = 0 (0x0)
SIGNAL 6 (SIGABRT)
process exit, rval = 0
That's it.

2013-09-18: FreeBSD - running truss(1) on stm32flash:
tingo@kg-core1$ truss ./stm32flash /dev/cuaU0
__sysctl(0x7fffffffe070,0x2,0x7fffffffe08c,0x7fffffffe080,0x0,0x0) = 0 (0x0)
mmap(0x0,688,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365198336 (0x800535000)
munmap(0x800535000,688)                 = 0 (0x0)
__sysctl(0x7fffffffe0e0,0x2,0x80063f408,0x7fffffffe0d8,0x0,0x0) = 0 (0x0)
mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34365198336 (0x800535000)
issetugid(0x800536015,0x800530684,0x80064bb10,0x80064bae0,0x5991,0x0) = 0 (0x0)
open("/etc/libmap.conf",O_RDONLY,0666)         ERR#2 'No such file or directory'
open("/var/run/ld-elf.so.hints",O_RDONLY,057)     = 3 (0x3)
read(3,"Ehnt\^A\0\0\0\M^@\0\0\0002\^A\0"...,128) = 128 (0x80)
lseek(3,0x80,SEEK_SET)                 = 128 (0x80)
read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,306) = 306 (0x132)
close(3)                     = 0 (0x0)
access("/lib/libc.so.7",0)             = 0 (0x0)
open("/lib/libc.so.7",O_RDONLY,030771340)     = 3 (0x3)
fstat(3,{ mode=-r--r--r-- ,inode=5537727,size=1298464,blksize=32768 }) = 0 (0x0)
pread(0x3,0x80063e2c0,0x1000,0x0,0x101010101010101,0x8080808080808080) = 4096 (0x1000)
mmap(0x0,2371584,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) = 34366341120 (0x80064c000)
mmap(0x80064c000,1085440,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,3,0x0) = 34366341120 (0x80064c000)
mmap(0x800855000,126976,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,3,0x109000) = 34368475136 (0x800855000)
mmap(0x800874000,110592,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,-1,0x0) = 34368602112 (0x800874000)
close(3)                     = 0 (0x0)
mmap(0x0,656,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365231104 (0x80053d000)
munmap(0x80053d000,656)                 = 0 (0x0)
mmap(0x0,43904,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365231104 (0x80053d000)
munmap(0x80053d000,43904)             = 0 (0x0)
sysarch(0x81,0x7fffffffe160,0x800539088,0x0,0xffffffffffcde450,0x8080808080808080) = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)         = 0 (0x0)
__sysctl(0x7fffffffe0f0,0x2,0x80087a780,0x7fffffffe0e8,0x0,0x0) = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)         = 0 (0x0)
fstat(1,{ mode=crw--w---- ,inode=147,size=0,blksize=4096 }) = 0 (0x0)
__sysctl(0x7fffffffe0b0,0x2,0x800879dc8,0x7fffffffe0a8,0x0,0x0) = 0 (0x0)
__sysctl(0x7fffffffdfd0,0x2,0x7fffffffdf60,0x7fffffffdfc8,0x8007478c0,0xc) = 0 (0x0)
__sysctl(0x7fffffffdf60,0x2,0x800879fd0,0x7fffffffe028,0x0,0x0) = 0 (0x0)
readlink("/etc/malloc.conf",0x7fffffffe0d0,1024) ERR#2 'No such file or directory'
issetugid(0x800746581,0x7fffffffe0d0,0xffffffffffffffff,0x0,0x2,0x0) = 0 (0x0)
break(0x600000)                     = 0 (0x0)
__sysctl(0x7fffffffe360,0x2,0x7fffffffe37c,0x7fffffffe370,0x0,0x0) = 0 (0x0)
mmap(0x0,2097152,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34368712704 (0x80088f000)
mmap(0x800a8f000,1511424,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34370809856 (0x800a8f000)
munmap(0x80088f000,1511424)             = 0 (0x0)
ioctl(1,TIOCGETA,0xffffe540)             = 0 (0x0)
stm32flash - http://stm32flash.googlecode.com/
write(1,"stm32flash - http://stm32flash.g"...,47) = 47 (0x2f)

write(1,"\n",1)                     = 1 (0x1)
open("/dev/cuaU0",O_RDWR|O_NONBLOCK|O_NOCTTY,00) = 3 (0x3)
fcntl(3,F_SETFL,0x0)                 = 0 (0x0)
ioctl(3,TIOCGETA,0xa07084)             = 0 (0x0)
ioctl(3,TIOCGETA,0xa070b0)             = 0 (0x0)
ioctl(3,TIOCFLUSH,0xffffe5c4)             = 0 (0x0)
ioctl(3,TIOCSETA,0xa070b0)             = 0 (0x0)
ioctl(3,TIOCGETA,0xffffe620)             = 0 (0x0)
stat("/usr/share/nls/C/libc.cat",0x7fffffffd8b0) ERR#2 'No such file or directory'
stat("/usr/share/nls/libc/C",0x7fffffffd8b0)     ERR#2 'No such file or directory'
stat("/usr/local/share/nls/C/libc.cat",0x7fffffffd8b0) ERR#2 'No such file or directory'
stat("/usr/local/share/nls/libc/C",0x7fffffffd8b0) ERR#2 'No such file or directory'
/dev/cuaU0: No such file or directory
writev(0x2,0x7fffffffddf0,0x4,0x19,0x1b4664,0x800a00128) = 38 (0x26)
ioctl(3,TIOCFLUSH,0xffffe624)             = 0 (0x0)
ioctl(3,TIOCSETA,0xa07084)             = 0 (0x0)
close(3)                     = 0 (0x0)

write(1,"\n",1)                     = 1 (0x1)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)         = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)         = 0 (0x0)
process exit, rval = 1

Now I need help to decode that.

2013-08-18: compiling stm32flash under FreeBSD; Version:

tingo@kg-core1$ uname -a
FreeBSD kg-core1.kg4.no 8.4-STABLE FreeBSD 8.4-STABLE #0 r253646: Thu Jul 25 10:12:31 UTC 2013
     root@kg-core1.kg4.no:/usr/obj/usr/src/sys/GENERIC  amd64

compile:

tingo@kg-core1$ pwd
/home/tingo/work/stm32flash
tingo@kg-core1$ gmake
gmake -C parsers
gmake[1]: Entering directory `/zs/tingo/work/stm32flash/parsers'
gcc -g -Wall -c -I../ binary.c hex.c
ar r parsers.a        binary.o hex.o
ar: warning: creating parsers.a
gmake[1]: Leaving directory `/zs/tingo/work/stm32flash/parsers'
gcc -g -o stm32flash -I./ \
    main.c \
    utils.c \
    stm32.c \
    serial_common.c \
    serial_platform.c \
    parsers/parsers.a \
    stm32/stmreset_binary.c \
    -Wall
In file included from main.c:31:
serial.h:82: warning: type qualifiers ignored on function return type
serial.h:83: warning: type qualifiers ignored on function return type
serial.h:84: warning: type qualifiers ignored on function return type
serial.h:85: warning: type qualifiers ignored on function return type
In file included from stm32.h:25,
                 from stm32.c:24:
serial.h:82: warning: type qualifiers ignored on function return type
serial.h:83: warning: type qualifiers ignored on function return type
serial.h:84: warning: type qualifiers ignored on function return type
serial.h:85: warning: type qualifiers ignored on function return type
In file included from serial_common.c:20:
serial.h:82: warning: type qualifiers ignored on function return type
serial.h:83: warning: type qualifiers ignored on function return type
serial.h:84: warning: type qualifiers ignored on function return type
serial.h:85: warning: type qualifiers ignored on function return type
serial_common.c:39: warning: type qualifiers ignored on function return type
serial_common.c:57: warning: type qualifiers ignored on function return type
serial_common.c:69: warning: type qualifiers ignored on function return type
serial_common.c:80: warning: type qualifiers ignored on function return type
In file included from serial_posix.c:28,
                 from serial_platform.c:4:
serial.h:82: warning: type qualifiers ignored on function return type
serial.h:83: warning: type qualifiers ignored on function return type
serial.h:84: warning: type qualifiers ignored on function return type
serial.h:85: warning: type qualifiers ignored on function return type
tingo@kg-core1$

Ok, it compiled at least. Does it work?

tingo@kg-core1$ ./stm32flash
stm32flash - http://stm32flash.googlecode.com/

ERROR: Device not specified
Usage: ./stm32flash [-bvngfhc] [-[rw] filename] /dev/ttyS0
    -b rate        Baud rate (default 57600)
    -r filename    Read flash to file
    -w filename    Write flash to file
    -u        Disable the flash write-protection
    -e n        Only erase n pages before writing the flash
    -v        Verify writes
    -n count    Retry failed writes up to count times (default 10)
    -g address    Start execution at specified address (0 = flash start)
    -f        Force binary parser
    -h        Show this help
    -c        Resume the connection (don't send initial INIT)
            *Baud rate must be kept the same as the first init*
            This is useful if the reset fails

Examples:
    Get device information:
        ./stm32flash /dev/ttyS0

    Write with verify and then start execution:
        ./stm32flash -w filename -v -g 0x0 /dev/ttyS0

    Read flash to file:
        ./stm32flash -r filename /dev/ttyS0

    Start execution:
        ./stm32flash -g 0x0 /dev/ttyS0

So far, so good. Next test:

tingo@kg-core1$ ll /dev/cuaU* /dev/ttyU*
crw-rw----  1 uucp  dialer  -   0, 159 Aug 18 17:26 /dev/cuaU0
crw-rw----  1 uucp  dialer  -   0, 160 Aug 18 17:26 /dev/cuaU0.init
crw-rw----  1 uucp  dialer  -   0, 161 Aug 18 17:26 /dev/cuaU0.lock
crw-------  1 root  wheel   -   0, 156 Aug 18 17:26 /dev/ttyU0
crw-------  1 root  wheel   -   0, 157 Aug 18 17:26 /dev/ttyU0.init
crw-------  1 root  wheel   -   0, 158 Aug 18 17:26 /dev/ttyU0.lock
tingo@kg-core1$ id
uid=1001(tingo) gid=1001(users) groups=1001(users),0(wheel),5(operator)
tingo@kg-core1$ ./stm32flash /dev/ttyU0
stm32flash - http://stm32flash.googlecode.com/

/dev/ttyU0: Permission denied

tingo@kg-core1$ ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

/dev/cuaU0: Permission denied

Ok, no access. Need to fix that. Testing now:

tingo@kg-core1$ su
Password:
root@kg-core1# ./stm32flash /dev/ttyU0
stm32flash - http://stm32flash.googlecode.com/

/dev/ttyU0: No such file or directory

Hmm, try the other one:

root@kg-core1# ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

/dev/cuaU0: No such file or directory

Ok, try with the RESET and BOOT0 button combo: No - the display blinks, but the behavior is the same:

root@kg-core1# ./stm32flash /dev/ttyU0
stm32flash - http://stm32flash.googlecode.com/

/dev/ttyU0: No such file or directory

root@kg-core1# ./stm32flash /dev/cuaU0
stm32flash - http://stm32flash.googlecode.com/

/dev/cuaU0: No such file or directory

I guess it doesn't work then.

2013-08-16: linux and stm32flash:

tingo@kg-u35jc:~/work/stm32flash$ ./stm32flash /dev/ttyUSB0
stm32flash - http://stm32flash.googlecode.com/

Serial Config: 57600 8E1
read_byte: Success
stm32flash: stm32.c:90: stm32_read_byte: Assertion `0' failed.
Aborted (core dumped)

So that doesn't work. But holding down the BOOT0 button until releasing the RESET button on the board gives this:

tingo@kg-u35jc:~/work/stm32flash$ ./stm32flash /dev/ttyUSB0
stm32flash - http://stm32flash.googlecode.com/

Serial Config: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (Medium-density)
RAM          : 20KiB  (512b reserved by bootloader)
Flash        : 128KiB (sector size: 4x1024)
Option RAM   : 15b
System RAM   : 2KiB

Resetting device... done.

Cool.

2013-08-16: right usb port connected to my Linux laptop:

tingo@kg-u35jc:~$ uname -a
Linux kg-u35jc 3.2.0-49-generic #75-Ubuntu SMP Tue Jun 18 17:39:32 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

From /var/log/messages:

Aug 16 21:04:22 kg-u35jc kernel: [2189723.823563] usb 2-1.3: new full-speed USB device number 7 using ehci_hcd
Aug 16 21:04:22 kg-u35jc mtp-probe: checking bus 2, device 7: "/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3"
Aug 16 21:04:22 kg-u35jc mtp-probe: bus: 2, device: 7 was not an MTP device
Aug 16 21:04:22 kg-u35jc kernel: [2189723.988715] usbcore: registered new interface driver usbserial
Aug 16 21:04:22 kg-u35jc kernel: [2189723.988734] USB Serial support registered for generic
Aug 16 21:04:22 kg-u35jc kernel: [2189723.988788] usbcore: registered new interface driver usbserial_generic
Aug 16 21:04:22 kg-u35jc kernel: [2189723.988790] usbserial: USB Serial Driver core
Aug 16 21:04:22 kg-u35jc kernel: [2189724.009069] USB Serial support registered for pl2303
Aug 16 21:04:22 kg-u35jc kernel: [2189724.009106] pl2303 2-1.3:1.0: pl2303 converter detected
Aug 16 21:04:22 kg-u35jc kernel: [2189724.010791] usb 2-1.3: pl2303 converter now attached to ttyUSB0
Aug 16 21:04:22 kg-u35jc kernel: [2189724.010831] usbcore: registered new interface driver pl2303
Aug 16 21:04:22 kg-u35jc kernel: [2189724.010837] pl2303: Prolific PL2303 USB to serial adaptor driver

device:

tingo@kg-u35jc:~$ ls -l /dev/ttyU*
crw-rw-r-- 1 root dialout 188, 0 Aug 16 21:04 /dev/ttyUSB0

lsusb output:

tingo@kg-u35jc:~$ lsusb -s 2:7
Bus 002 Device 007: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
tingo@kg-u35jc:~$ lsusb -s 2:7 -v

Bus 002 Device 007: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x067b Prolific Technology, Inc.
  idProduct          0x2303 PL2303 Serial Port
  bcdDevice            3.00
  iManufacturer           1 Prolific Technology Inc.
  iProduct                2 USB-Serial Controller
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           39
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x000a  1x 10 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0000
  (Bus Powered)

Nothing more.

2013-08-16: left usb port: with the buttons towards me, and the usb connectors and LEDs away from me I connected the leftmost usb port. The power LED (LD3, righmost) lights steady, and the user LEDs (LED1, LED2) blinks in an alternating pattern. LD4 is dark. The LCD shows a rolling demo (µC/GUI). Nothing shows up on the connected machine. right usb port: LD3 lights steady, LED1 and LED2 blinks, and the LCD shows a rolling demo (µC/GUI). On my machine it shows up in /var/log/messages:

Aug 16 16:30:00 kg-core1 kernel: ugen2.4: <Prolific Technology Inc.> at usbus2
Aug 16 16:30:00 kg-core1 kernel: uplcom0: <Prolific Technology Inc. USB-Serial Controller, class 0/0, rev 1.10/3.00, addr 4> on usbus2

Indeed, the ports show up:

root@kg-core1# ll /dev/cuaU* /dev/ttyU*
crw-rw----  1 uucp  dialer    0, 158 Aug 16 18:30 /dev/cuaU0
crw-rw----  1 uucp  dialer    0, 159 Aug 16 18:30 /dev/cuaU0.init
crw-rw----  1 uucp  dialer    0, 160 Aug 16 18:30 /dev/cuaU0.lock
crw-------  1 root  wheel     0, 155 Aug 16 18:30 /dev/ttyU0
crw-------  1 root  wheel     0, 156 Aug 16 18:30 /dev/ttyU0.init
crw-------  1 root  wheel     0, 157 Aug 16 18:30 /dev/ttyU0.lock

this is on

tingo@kg-core1$ uname -a
FreeBSD kg-core1.kg4.no 8.4-STABLE FreeBSD 8.4-STABLE #0 r253646: Thu Jul 25 10:12:31 UTC 2013
     root@kg-core1.kg4.no:/usr/obj/usr/src/sys/GENERIC  amd64

All now.