Skip to content

Commit

Permalink
Improve ROM connection setup on ESP32
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Oct 22, 2021
1 parent 917564f commit 64925a7
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cli/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import (
"github.com/mongoose-os/mos/common/mgrpc/codec"
"github.com/mongoose-os/mos/common/mgrpc/frame"

"github.com/cesanta/go-serial/serial"
"github.com/juju/errors"
"github.com/mongoose-os/go-serial/serial"
flag "github.com/spf13/pflag"
)

Expand Down
5 changes: 3 additions & 2 deletions cli/flash/cc3200/flasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"fmt"
"sort"

"github.com/cesanta/go-serial/serial"
"github.com/juju/errors"
"github.com/mongoose-os/mos/common/fwbundle"
"github.com/mongoose-os/go-serial/serial"

"github.com/mongoose-os/mos/cli/flash/cc32xx"
"github.com/mongoose-os/mos/cli/flash/common"
"github.com/mongoose-os/mos/common/fwbundle"
)

type FlashOpts struct {
Expand Down
5 changes: 3 additions & 2 deletions cli/flash/cc3220/flasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
package cc3220

import (
"github.com/cesanta/go-serial/serial"
"github.com/juju/errors"
"github.com/mongoose-os/mos/common/fwbundle"
"github.com/mongoose-os/go-serial/serial"

"github.com/mongoose-os/mos/cli/flash/cc32xx"
"github.com/mongoose-os/mos/cli/flash/common"
"github.com/mongoose-os/mos/common/fwbundle"
)

type FlashOpts struct {
Expand Down
5 changes: 3 additions & 2 deletions cli/flash/cc32xx/rom_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
"io/ioutil"
"time"

"github.com/cesanta/go-serial/serial"
"github.com/juju/errors"
"github.com/mongoose-os/mos/cli/flash/common"
"github.com/mongoose-os/go-serial/serial"
glog "k8s.io/klog/v2"

"github.com/mongoose-os/mos/cli/flash/common"
)

type loaderCmd uint8
Expand Down
5 changes: 3 additions & 2 deletions cli/flash/esp/flasher/flasher_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import (
"time"
"unsafe"

"github.com/cesanta/go-serial/serial"
"github.com/juju/errors"
"github.com/mongoose-os/go-serial/serial"
glog "k8s.io/klog/v2"

"github.com/mongoose-os/mos/cli/flash/common"
"github.com/mongoose-os/mos/cli/flash/esp"
"github.com/mongoose-os/mos/cli/flash/esp/rom_client"
"github.com/mongoose-os/mos/cli/flash/esp32"
"github.com/mongoose-os/mos/cli/flash/esp8266"
glog "k8s.io/klog/v2"
)

const (
Expand Down
9 changes: 6 additions & 3 deletions cli/flash/esp/rom_client/rom_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import (
"math"
"time"

"github.com/cesanta/go-serial/serial"
"github.com/juju/errors"
"github.com/mongoose-os/go-serial/serial"
glog "k8s.io/klog/v2"

"github.com/mongoose-os/mos/cli/flash/common"
"github.com/mongoose-os/mos/cli/flash/esp"
"github.com/mongoose-os/mos/cli/flash/esp32"
"github.com/mongoose-os/mos/cli/flash/esp8266"
glog "k8s.io/klog/v2"
)

const (
Expand Down Expand Up @@ -199,6 +200,7 @@ func (rc *ROMClient) sendCommand(cmd romCmd, arg []byte, csum uint8) error {
binary.Write(cmdBuf, binary.LittleEndian, uint32(csum)) // Yes, uint8 -> uint32
cmdBuf.Write(arg)
_, err := rc.srw.Write(cmdBuf.Bytes())
rc.sd.Flush()
return err
}

Expand Down Expand Up @@ -278,6 +280,7 @@ func (rc *ROMClient) trySync() error {
if err := rc.sendCommand(cmdSync, argBuf.Bytes(), 0); err != nil {
return errors.Trace(err)
}
rc.sd.Flush()
for i := 1; i <= 8; i++ {
var r *romResponse
for {
Expand Down Expand Up @@ -305,7 +308,7 @@ func (rc *ROMClient) trySync() error {
func (rc *ROMClient) sync() error {
var err error
// Usually there is no response to the first command, and the second is successful.
for i := 0; i < 2; i++ {
for i := 0; i < 5; i++ {
err = rc.trySync()
if err == nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion common/mgrpc/codec/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"sync"
"time"

"github.com/cesanta/go-serial/serial"
"github.com/juju/errors"
"github.com/mongoose-os/go-serial/serial"
glog "k8s.io/klog/v2"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/Microsoft/hcsshim v0.9.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210920160938-87db9fbc61c7 // indirect
github.com/aws/aws-sdk-go v1.41.4
github.com/cesanta/go-serial v0.0.0-20170105152649-4dff7aff019e
github.com/cesanta/hid v0.0.0-20190304122332-79d86877855b
github.com/containerd/cgroups v1.0.2 // indirect
github.com/docker/docker v20.10.9+incompatible // indirect
Expand All @@ -32,6 +31,7 @@ require (
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-shellwords v1.0.6
github.com/mcuadros/go-version v0.0.0-20180611085657-6d5863ca60fa
github.com/mongoose-os/go-serial v0.0.0-20211022230256-bb7bd0b47c67
github.com/sergi/go-diff v1.2.0
github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c
github.com/smartystreets/goconvey v1.6.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8n
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cesanta/go-serial v0.0.0-20170105152649-4dff7aff019e h1:C++Ag/pucyWyaAN0ZVi1TQoVPLDXP8XElP0GR4DPDRY=
github.com/cesanta/go-serial v0.0.0-20170105152649-4dff7aff019e/go.mod h1:8NcZR8jUd1YKVUMGAzeu2cVpWHQAxeb1oVLFBapFwmQ=
github.com/cesanta/hid v0.0.0-20190304122332-79d86877855b h1:sis04aP3W+T6iw+rr1PtowTyzGk2C/uW4Yt5kxJGtoU=
github.com/cesanta/hid v0.0.0-20190304122332-79d86877855b/go.mod h1:TyHSqYNeVEvfBfk5Sg9kTkH7sH+yZSpnbhk+KOlqyS0=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand Down Expand Up @@ -602,6 +600,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mongoose-os/go-serial v0.0.0-20211022230256-bb7bd0b47c67 h1:jQ1TgzH8eS3e4F42kCE9NdCqRrbidJq+qTa5gVFM6E0=
github.com/mongoose-os/go-serial v0.0.0-20211022230256-bb7bd0b47c67/go.mod h1:HZ7dmippnLpPxYlKfmEyOhXr6eqwu/UtOcYICIE5SH0=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
Expand Down

0 comments on commit 64925a7

Please sign in to comment.