flash

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBaud = 115200
View Source
var DefaultTTY = "/dev/ttyS1"
View Source
var ErrClosed = errors.New("serial port is closed")
View Source
var ErrSTMFailedToAck = errors.New("failed to read ack or nack from stm microcontroller")
View Source
var ErrSTMNACK = errors.New("received nack from stm microcontroller")
View Source
var ErrTimeout = errors.New("timed out reading from microcontroller")
View Source
var STMTimeout = 5 * time.Second

Functions

This section is empty.

Types

type CommandCode

type CommandCode int
const (
	CommandCodeSync             CommandCode = -1
	CommandCodeGet              CommandCode = 0
	CommandCodeGetVersion       CommandCode = 1
	CommandCodeGetID            CommandCode = 2
	CommandCodeReadMemory       CommandCode = 3
	CommandCodeGo               CommandCode = 4
	CommandCodeWriteMemory      CommandCode = 5
	CommandCodeErase            CommandCode = 6
	CommandCodeWriteProtect     CommandCode = 7
	CommandCodeWriteUnprotect   CommandCode = 8
	CommandCodeReadoutProtect   CommandCode = 9
	CommandCodeReadoutUnprotect CommandCode = 10
)

these must be the index of the bytes as received in the get data call

type Config

type Config struct {
	Boot0GPIO int
	Boot1GPIO int
	PowerGPIO int

	BootloaderBaud int
	TTY            string
}

Config defines configuration for communicating and flashing the microcontroller

type Microcontroller

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

Microcontroller represents an embedded microntroller chip that can be communicated with over UART

func NewMicrocontroller

func NewMicrocontroller(c *Config) (*Microcontroller, error)

NewMicrocontroller will create a new reference to a particular chip

func (*Microcontroller) BaudRate

func (mc *Microcontroller) BaudRate() int

BaudRate will return the baud rate used to connect to the TTY

func (*Microcontroller) Close

func (mc *Microcontroller) Close() error

Close will close the connection and reset the MCU

func (*Microcontroller) FlashPayload

func (mc *Microcontroller) FlashPayload(bs []byte, addr uint32) error

FlashPayload will flash the payload provided to the flash at the provided address

func (*Microcontroller) FlashPayloadFromFile

func (mc *Microcontroller) FlashPayloadFromFile(filePath string, addr uint32) error

FlashPayloadFromFile will flash the requested file to the flash memory at the provided address

func (*Microcontroller) Identify

func (mc *Microcontroller) Identify() (string, error)

Identify will report back a unique string with the ID of the chip

func (*Microcontroller) IsOpen

func (mc *Microcontroller) IsOpen() bool

func (*Microcontroller) Open

func (mc *Microcontroller) Open() (err error)

func (*Microcontroller) ReadN

func (mc *Microcontroller) ReadN(n int, to time.Duration) ([]byte, error)

ReadN will read exactly N bytes from the rx chan

func (*Microcontroller) Reset added in v0.0.2

func (mc *Microcontroller) Reset()

Reset will force a power cycle on the microcontroller

func (*Microcontroller) TTY

func (mc *Microcontroller) TTY() string

TTY will return the TTY that will be used

func (*Microcontroller) Write

func (mc *Microcontroller) Write(bs ...[]byte) (err error)

Write will write the specified bytes to the microcontroller

Jump to

Keyboard shortcuts

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