-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
42 lines (35 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2019 Michal Derkacz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Reboot shows the way to perform unsafe reboot of the ST32L746 MCU. Unsafe
// reboot simply restarts the software without reseting the hardware.
package main
import (
"embedded/rtos"
"time"
"unsafe"
"github.com/embeddedgo/stm32/hal/gpio"
"github.com/embeddedgo/stm32/hal/system"
"github.com/embeddedgo/stm32/hal/system/timer/rtcst"
"github.com/embeddedgo/stm32/p/rcc"
"github.com/embeddedgo/stm32/p/syscfg"
)
func main() {
system.Setup80(0, 0)
rtcst.Setup(rtcst.LSE, 1, 32768)
pa := gpio.PA()
pa.EnableClock(true)
led := pa.Pin(5)
led.Setup(&gpio.Config{Mode: gpio.Out, Speed: gpio.Low})
for i := 0; i < 10; i++ {
led.Set()
time.Sleep(time.Second / 8)
led.Clear()
time.Sleep(time.Second / 8)
}
RCC := rcc.RCC()
RCC.APB2ENR.SetBits(rcc.SYSCFGEN)
syscfg.SYSCFG().MEMRMP.StoreBits(syscfg.MEM_MODE, 1)
RCC.APB2ENR.ClearBits(rcc.SYSCFGEN)
rtos.Reset(rtos.UnsafeReboot, unsafe.Pointer(uintptr(0x1FFF0000)))
}