stmprog

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2021 License: MIT Imports: 9 Imported by: 0

README

stmprog

Stmprog is implementation of USART protocol used in the STM32 bootloader in Golang.

Usage

Please see example. Assumptions:

  • Boot0 pin of STM connected to pin 65 in RPi Compute Module (pin 19 according to BCM enumeration, please consult datasheet, chapter 5),
  • Rst pin of STM connected to pin 65 in compute module (pin 18 according to BCM enumeration),
  • 115200 baundrate,
  • /dev/ttyUSB0 serial port,
  • app_firmware.bin application file,
  • 0x8000000 application address

Documentation

Index

Constants

View Source
const (
	ACK                 byte    = 0x79
	NACK                byte    = 0x1F
	INIT                        = 0x7F
	GET                 Command = 0x00
	GET_VERSION_AND_RPS Command = 0x01
	READ_MEMORY         Command = 0x11
	WRITE_MEMORY        Command = 0x31
	ERASE               Command = 0x43
	EXTENDED_ERASE      Command = 0x44
	WRITE_PROTECT       Command = 0x63
	WRITE_UNPROTECT     Command = 0x73
	READOUT_PROTECT     Command = 0x82
	READOUT_UNPROTECT   Command = 0x92
)
View Source
const APPLICATION_ADDRESS = 0x8000000

Variables

This section is empty.

Functions

func ReadFile

func ReadFile(path string) (int, []byte, error)

Types

type Booter

type Booter interface {
	Boot() error
	Reset() error
}

Booter switches STM to bootloader mode and resets CPU.

type Bootloader

type Bootloader struct {
	Version  byte
	Commands []Command
}

type Command

type Command byte

type Flasher

type Flasher interface {
	io.ReadWriter
	Init() error
	Erase() error
}

Flasher initializes chip and reads, and writes to memory. It can erase memory too. Sector erase is not yet implemented.

type GpioBooter

type GpioBooter struct {
	BootPin gpio.PinOut
	RstPin  gpio.PinOut
}

func (*GpioBooter) Boot

func (dp *GpioBooter) Boot() error

func (*GpioBooter) Reset

func (dp *GpioBooter) Reset() error

type GpioSerialProgrammer

type GpioSerialProgrammer struct {
	*GpioBooter
	*SerialFlasher
}

type Programmer

type Programmer struct {
	Flasher
	Booter
}

func (*Programmer) Program

func (p *Programmer) Program(b []byte) error

func (*Programmer) ProgramVerify

func (p *Programmer) ProgramVerify(b []byte) error

type Rdp

type Rdp byte

Rdp - read protection

type RdpStatus

type RdpStatus struct {
	Rdp          byte
	RdpToggleCnt byte
	Version      byte
}

RdpStatus is not correctly reported, only Version is valid

type Sector

type Sector byte

type SerialFlasher

type SerialFlasher struct {
	// contains filtered or unexported fields
}

func NewSerialFlasher

func NewSerialFlasher(o SerialFlasherOpts) (*SerialFlasher, error)

NewSerialFlasher open selected port and flushes it.

func (*SerialFlasher) Erase

func (p *SerialFlasher) Erase() error

func (*SerialFlasher) EraseGlobal

func (p *SerialFlasher) EraseGlobal() error

func (*SerialFlasher) ExtendedEraseGlobal

func (p *SerialFlasher) ExtendedEraseGlobal() error

func (*SerialFlasher) Get

func (p *SerialFlasher) Get() (Bootloader, error)

func (*SerialFlasher) GetVersionAndReadProtectionStatus

func (p *SerialFlasher) GetVersionAndReadProtectionStatus() (RdpStatus, error)

func (*SerialFlasher) Init

func (p *SerialFlasher) Init() error

func (*SerialFlasher) Read

func (p *SerialFlasher) Read(b []byte) (int, error)

func (*SerialFlasher) ReadoutProtect

func (p *SerialFlasher) ReadoutProtect() error

func (*SerialFlasher) ReadoutUnprotect

func (p *SerialFlasher) ReadoutUnprotect() error

func (*SerialFlasher) Write

func (p *SerialFlasher) Write(b []byte) (int, error)

func (*SerialFlasher) WriteProtect

func (p *SerialFlasher) WriteProtect(sectors []byte) error

func (*SerialFlasher) WriteUnprotect

func (p *SerialFlasher) WriteUnprotect() error

type SerialFlasherOpts

type SerialFlasherOpts struct {
	serial.Config
	Addr      uint32
	ReadChunk uint8
}

func DefaultOptions

func DefaultOptions(port string) SerialFlasherOpts

DefaultOptions sets maximum baundrate for port (115200 bps). Use WithX to modify settings.

func (SerialFlasherOpts) WithApplicationAdress

func (o SerialFlasherOpts) WithApplicationAdress(addr uint32) SerialFlasherOpts

WithApplicationAdress returns new options with given application address.

func (SerialFlasherOpts) WithBaund

func (o SerialFlasherOpts) WithBaund(baund int) SerialFlasherOpts

WithBaund returns new options with given baundrate.

func (SerialFlasherOpts) WithReadChunk

func (o SerialFlasherOpts) WithReadChunk(chunk uint8) SerialFlasherOpts

WithReadChunk returns new options with selected read chunk size. Up to 256 bytes can be read in one command. When encountering issues with EEPROM reads, decrease chunk size.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL