Skip to content

Commit b33d219

Browse files
committed
feat: STM32 reset, bootMode and endCommunication methods
1 parent ebce038 commit b33d219

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

firmware_updater.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
STM32_writeMEM("Blink_fast.bin")
1616
print("\nDONE")
1717
print("\nLower Boot0 and reset STM32")
18+
19+
STM32_endCommunication()

stm32_flash.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from time import sleep_ms
2-
from machine import UART
2+
from machine import UART, Pin
33

44
STM32_INIT = b'\x7F'
55
STM32_NACK = b'\x1F'
@@ -16,6 +16,12 @@
1616

1717
STM32_ADDRESS = bytes.fromhex('08000000') # [b'\x08',b'\x00',b'\x00',b'\x00']
1818

19+
# NANO ESP32 SETTINGS
20+
_D2 = 5 # ESP32 pin5 -> nano D2
21+
_D3 = 6 # ESP32 pin6 -> nano D3
22+
_Boot0 = Pin(_D2, Pin.OUT) # STM32 Boot0
23+
_NRST = Pin(_D3, Pin.OUT) # STM32 NRST
24+
1925
# UART SETTINGS
2026
_UART_ID = 1
2127
_TX_PIN = 43
@@ -37,10 +43,17 @@ def STM32_startCommunication() -> bytes:
3743
Starts communication with STM32 sending just 0x7F. Blocking
3844
:return:
3945
"""
46+
STM32_bootMode(bootloader=True)
47+
STM32_reset()
4048
uart.write(STM32_INIT)
4149
return _STM32_waitForAnswer()
4250

4351

52+
def STM32_endCommunication():
53+
STM32_bootMode(bootloader=False)
54+
STM32_reset()
55+
56+
4457
def _STM32_waitForAnswer() -> bytes:
4558
"""
4659
Blocking wait
@@ -57,6 +70,21 @@ def _STM32_waitForAnswer() -> bytes:
5770
return res
5871

5972

73+
def STM32_reset():
74+
"""
75+
Resets STM32 from the host pins _D3
76+
:return:
77+
"""
78+
_NRST.value(0)
79+
sleep_ms(100)
80+
_NRST.value(1)
81+
sleep_ms(500)
82+
83+
84+
def STM32_bootMode(bootloader: bool = False):
85+
_Boot0.value(bootloader)
86+
87+
6088
def STM32_sendCommand(cmd: bytes):
6189
"""
6290
Sends a command and its complement according to AN3155

0 commit comments

Comments
 (0)