Skip to content

Commit ed8422c

Browse files
committed
v1.0.0 - Add proper support for compiling LOWMEM versions, add examples for ethernet usage, declare some things
1 parent cb3d0c2 commit ed8422c

File tree

17 files changed

+241
-638
lines changed

17 files changed

+241
-638
lines changed

.github/workflows/make_mpy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ jobs:
4040
make clean
4141
cd ../../
4242
done
43+
for board_dir in mcu/*/; do
44+
cd "$board_dir"
45+
make -j$(nproc) LOWMEM=1
46+
board_name=$(basename "$board_dir")
47+
mkdir -p release
48+
cp build/firmware.hex "release/${board_name}-LOWMEM.hex"
49+
make clean
50+
cd ../../
51+
done
4352
cd ../../
4453
4554
- name: Release version

LATEST.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
## Support
2-
This is information about latest release of firmware update. The firmware supports MikroE MCU card family for STM32.
3-
| Supported MCU(s) | Ethernet | SSL support | Test passed |
1+
# Support
2+
This is information about latest release of firmware update. Firmware supports MikroE MCU card family for STM32.
3+
| Supported MCU(s) | Tests passed |
4+
| :----------------: | :------:|
5+
| STM32F43 | Yes |
6+
| STM32F43-LOWMEM | Yes |
7+
| STM32F76 | No |
8+
| STM32F76-LOWMEM | N/A |
9+
10+
Version differences:
11+
| Version | Ethernet | MbedTLS (crypto, SSL) support | Typical out file size |
412
| :----------------: | :------:| :----:| :----: |
5-
| STM32F43 | Yes | Yes | Yes |
6-
| STM32F43-LOWMEM | Yes | No | Yes |
7-
| STM32F76 | Yes | Yes | No |
8-
## Default communications
13+
| NORMAL | Yes | Yes | ~1200 KB |
14+
| LOWMEM | Yes | No | ~900 KB |
15+
16+
The supported key features for it is built-in Ethernet, RTC clock, USB U(S)ART protocol, mikroBUS usage. You can check [examples](https://github.com/ukicomputers/Fusion_STM32/tree/main/examples) folder for all key feature usage.
17+
# Default communications
918
The prefered default communication is via USB UART with baud rate of 115200.
10-
## Credits
11-
Uglješa Lukešević (@ukicomputers) & other contributors. <br>
12-
Made for MikroE.
19+
# Credits
20+
Uglješa Lukešević (@ukicomputers) & other contributors.

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Port for MicroPython language on STM32 developed for Fusion for ARM v8.
55
[![Compile and Release MicroPython firmware](https://github.com/ukicomputers/Fusion_STM32/actions/workflows/make_mpy.yml/badge.svg)](https://github.com/ukicomputers/Fusion_STM32/actions/workflows/make_mpy.yml)
66

77
# Prepare
8-
You are required to init submodules and install required compilers. <br>
8+
You are required to init submodules and install required compilers. Required compilers are GCC/G++ (GNU SDK) for ARM. <br>
99
**Submodule initialization:**
1010
```sh
1111
git submodule update --init lib/micropython
@@ -20,21 +20,23 @@ make -C lib/micropython/mpy-cross
2020
To build a firmware for choosen development board, you need to do following. The firmware will be located at `boards/<dev_board>/build/firmware.hex`.
2121
```sh
2222
cd boards/<dev_board>
23-
make -j$(nproc) LTO=1 DEBUG=0
23+
make -j$(nproc) LTO=1 DEBUG=0 LOWMEM=1
2424
```
25-
`LTO` (Link Time Optimisation) usually shrinks .hex file for 2-3%.
25+
`LTO` (Link Time Optimisation) usually shrinks .hex file for 2-3%. Not recommended in usage when MbedTLS is enabled.
2626
`DEBUG` stands to enable debugging symbols for GDB.
27+
`LOWMEM` is used to build a firmware for Low Memory MCU or normal (> 1024KB flash size).
28+
Differences are explained in [LATEST.md](https://github.com/ukicomputers/Fusion_STM32/blob/main/LATEST.md).
2729

2830
# Alternate Function file generation
2931
To generate a Alternate Function file, and later use it for specific MCU port, execute following Python script:
3032
```
3133
python3 make_af.py <stm32_mcu_name>
3234
```
35+
The source for the script is from micropython main repository.
3336

34-
# Support
37+
# TODO, future releases, support
3538
Port currently **DOES NOT** support TFT SSD19603 controller.<br>
3639
However, plans are to add LVGL support. <br>
37-
Ethernet may work.
3840
## STM32 family
3941
This MPY port supports following STM32 families (some of them are ported):
4042
- F0
@@ -56,7 +58,7 @@ The ports are automatically built by GitHub Actions on every new commit. Check t
5658
# License
5759
MicroPython is licensed under MIT license by Damien P. George `Copyright (c) 2021 Damien P. George`<br>
5860
This port is licensed under CC BY-3.0 license under Uglješa Lukešević. <br>
59-
Made for **MikroE**.
61+
Full support written for **MikroE** MCU cards.
6062

6163
## Required header
6264
On every file that uses this port, please add this header:
@@ -73,6 +75,6 @@ MicroPython licensed with MIT license under Damien P. George
7375
"""
7476
```
7577

76-
It is also required when calling `help()` in MicroPython firmware to output show that port is written by me. If use this port in NECTO, also in About section, define that port is written by me, exactly like this:
78+
It is also required when calling `help()` in MicroPython firmware to output show that port is written by me. That is already set up. <br><br>If use this port in NECTO, also in About section, define that port is written by me, exactly like this:
7779
## MicroPython port
78-
Uglješa Lukešević
80+
Uglješa Lukešević

examples/eth_client.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/micropyserver.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
"""
2+
MicroPyServer is a simple HTTP server for MicroPython projects.
3+
4+
@see https://github.com/troublegum/micropyserver
5+
6+
The MIT License
7+
8+
Copyright (c) 2019 troublegum. https://github.com/troublegum/micropyserver
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in
18+
all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
THE SOFTWARE.
27+
"""
28+
import re
29+
import socket
30+
import sys
31+
import io
32+
33+
34+
class MicroPyServer(object):
35+
36+
def __init__(self, host="0.0.0.0", port=80):
37+
""" Constructor """
38+
self._host = host
39+
self._port = port
40+
self._routes = []
41+
self._connect = None
42+
self._on_request_handler = None
43+
self._on_not_found_handler = None
44+
self._on_error_handler = None
45+
self._sock = None
46+
47+
def start(self):
48+
""" Start server """
49+
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
50+
self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
51+
self._sock.bind((self._host, self._port))
52+
self._sock.listen(1)
53+
print("Server start")
54+
while True:
55+
if self._sock is None:
56+
break
57+
try:
58+
self._connect, address = self._sock.accept()
59+
request = self.get_request()
60+
if len(request) == 0:
61+
self._connect.close()
62+
continue
63+
if self._on_request_handler:
64+
if not self._on_request_handler(request, address):
65+
continue
66+
route = self.find_route(request)
67+
if route:
68+
route["handler"](request)
69+
else:
70+
self._route_not_found(request)
71+
except Exception as e:
72+
self._internal_error(e)
73+
finally:
74+
self._connect.close()
75+
76+
def stop(self):
77+
""" Stop the server """
78+
self._connect.close()
79+
self._sock.close()
80+
self._sock = None
81+
print("Server stop")
82+
83+
def add_route(self, path, handler, method="GET"):
84+
""" Add new route """
85+
self._routes.append(
86+
{"path": path, "handler": handler, "method": method})
87+
88+
def send(self, data):
89+
""" Send data to client """
90+
if self._connect is None:
91+
raise Exception("Can't send response, no connection instance")
92+
self._connect.sendall(data.encode())
93+
94+
def find_route(self, request):
95+
""" Find route """
96+
lines = request.split("\r\n")
97+
method = re.search("^([A-Z]+)", lines[0]).group(1)
98+
path = re.search("^[A-Z]+\\s+(/[-a-zA-Z0-9_.]*)", lines[0]).group(1)
99+
for route in self._routes:
100+
if method != route["method"]:
101+
continue
102+
if path == route["path"]:
103+
return route
104+
else:
105+
match = re.search("^" + route["path"] + "$", path)
106+
if match:
107+
print(method, path, route["path"])
108+
return route
109+
110+
def get_request(self, buffer_length=4096):
111+
""" Return request body """
112+
return str(self._connect.recv(buffer_length), "utf8")
113+
114+
def on_request(self, handler):
115+
""" Set request handler """
116+
self._on_request_handler = handler
117+
118+
def on_not_found(self, handler):
119+
""" Set not found handler """
120+
self._on_not_found_handler = handler
121+
122+
def on_error(self, handler):
123+
""" Set error handler """
124+
self._on_error_handler = handler
125+
126+
def _route_not_found(self, request):
127+
""" Route not found handler """
128+
if self._on_not_found_handler:
129+
self._on_not_found_handler(request)
130+
else:
131+
""" Default not found handler """
132+
self.send("HTTP/1.0 404 Not Found\r\n")
133+
self.send("Content-Type: text/plain\r\n\r\n")
134+
self.send("Not found")
135+
136+
def _internal_error(self, error):
137+
""" Internal error handler """
138+
if self._on_error_handler:
139+
self._on_error_handler(error)
140+
else:
141+
""" Default internal error handler """
142+
if "print_exception" in dir(sys):
143+
output = io.StringIO()
144+
sys.print_exception(error, output)
145+
str_error = output.getvalue()
146+
output.close()
147+
else:
148+
str_error = str(error)
149+
self.send("HTTP/1.0 500 Internal Server Error\r\n")
150+
self.send("Content-Type: text/plain\r\n\r\n")
151+
self.send("Error: " + str_error)
152+
print(str_error)
153+

examples/server.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from micropyserver import MicroPyServer
2+
from machine import Pin
3+
import time
4+
import network
5+
6+
nic = network.LAN()
7+
nic.active(True)
8+
nic.ifconfig("dhcp")
9+
print(nic.ifconfig())
10+
11+
def ukljuci(request):
12+
pin.value(1)
13+
server.send("UKLJUCENO! ukicomputers.")
14+
15+
def iskljuci(request):
16+
pin.value(0)
17+
server.send("ISKLJUCENO! ukicomputers.")
18+
19+
def poruka(request):
20+
server.send("/ukljuci za HIGH, /iskljuci za LOW. ukicomputers.")
21+
22+
pin = Pin("PA0", Pin.OUT)
23+
server = MicroPyServer()
24+
25+
server.add_route("/", poruka)
26+
server.add_route("/ukljuci", ukljuci)
27+
server.add_route("/iskljuci", iskljuci)
28+
29+
server.start()

mcu/STM32F43-LOWMEM/Makefile

Lines changed: 0 additions & 21 deletions
This file was deleted.

mcu/STM32F43-LOWMEM/help.c

Lines changed: 0 additions & 27 deletions
This file was deleted.

mcu/STM32F43-LOWMEM/linker.ld

Lines changed: 0 additions & 30 deletions
This file was deleted.

mcu/STM32F43-LOWMEM/manifest.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)