kopia lustrzana https://github.com/peterhinch/micropython-samples
Timed function and fastboot added
rodzic
6571dc8104
commit
8ba7da0f1a
38
README.md
38
README.md
|
@ -1,19 +1,39 @@
|
||||||
# micropython-samples
|
# micropython-samples
|
||||||
A place for assorted code ideas for MicroPython.
|
A place for assorted code ideas for MicroPython. Most are targeted at the Pyboard variants.
|
||||||
|
|
||||||
mutex: A class providing mutal exclusion enabling interrupt handlers and the main program to
|
## mutex
|
||||||
access shared data in a manner which ensures data integrity.
|
A class providing mutal exclusion enabling interrupt handlers and the main program to access shared
|
||||||
|
data in a manner which ensures data integrity.
|
||||||
|
|
||||||
watchdog: How to access the simpler of the Pyboard's watchdog timers.
|
## watchdog
|
||||||
|
Access the simpler of the Pyboard's watchdog timers.
|
||||||
|
|
||||||
reverse: Fast reverse a bytearray.
|
## reverse
|
||||||
|
Fast reverse a bytearray.
|
||||||
|
|
||||||
font: Convert a C file produced by GLCD Font Creator to Python for storage as persistent byte code.
|
## font
|
||||||
|
Convert a C file produced by GLCD Font Creator to Python for storage as persistent byte code.
|
||||||
|
|
||||||
ds3231_pb: Driver for the DS3231 low cost precison RTC, including a facility to calibrate the
|
## ds3231_pb
|
||||||
Pyboard's RTC from the DS3231
|
Driver for the DS3231 low cost precison RTC, including a facility to calibrate the Pyboard's RTC
|
||||||
|
from the DS3231.
|
||||||
|
|
||||||
Buildcheck: Raise an exception if a firmware build is earlier than a given date.
|
## Buildcheck
|
||||||
|
Raise an exception if a firmware build is earlier than a given date.
|
||||||
|
|
||||||
|
## timed_function
|
||||||
|
Time a function's execution using a decorator
|
||||||
|
|
||||||
|
## fastbuild - Pyboard use under Linux
|
||||||
|
Build MicroPython with your frozen bytecode, put the Pyboard into DFU mode, and deploy the build to
|
||||||
|
the board with a single command. Takes just over 60 seconds on a fast PC. Note the use of make's j
|
||||||
|
argument to use mutliple cores. Empirically 8 gave the fastest build on my core i7 4/8 core laptop:
|
||||||
|
adjust to suit your PC.
|
||||||
|
|
||||||
|
Includes udev rules to avoid jumps from /dev/ttyACM0 to /dev/ttyACM1: ensures Pyboards of all types
|
||||||
|
appear as /dev/pyboard. Also rules for USB connected WiPy and FTDI USB/serial adaptor.
|
||||||
|
|
||||||
|
# License
|
||||||
|
|
||||||
Any code placed here is released under the MIT License (MIT).
|
Any code placed here is released under the MIT License (MIT).
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# FTDI lead
|
||||||
|
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ENV{MTP_NO_PROBE}="1"
|
||||||
|
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", MODE:="0666"
|
||||||
|
KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", SYMLINK+="ftdi", MODE:="0666"
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
# 0403:6015 - WiPy board ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", ENV{ID_MM_DEVICE_IGNORE}="1"
|
||||||
|
# WiPy appears as /dev/wipy
|
||||||
|
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", ENV{MTP_NO_PROBE}="1"
|
||||||
|
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", MODE:="0666"
|
||||||
|
KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", SYMLINK+="wipy", MODE:="0666"
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
# f055:9800, 9801, 9802 MicroPython pyboard
|
||||||
|
# Instantiate Pyboard V1.0, V1.1 or Lite as /dev/pyoard
|
||||||
|
ATTRS{idVendor}=="f055", ENV{MTP_NO_PROBE}="1"
|
||||||
|
ATTRS{idVendor}=="f055", ENV{ID_MM_DEVICE_IGNORE}="1"
|
||||||
|
SUBSYSTEMS=="usb", ATTRS{idVendor}=="f055", MODE:="0666"
|
||||||
|
KERNEL=="ttyACM*", ATTRS{idVendor}=="f055", SYMLINK+="pyboard", MODE:="0666", GROUP="adminpete"
|
||||||
|
KERNEL=="ttyUSB*", ATTRS{idVendor}=="f055", SYMLINK+="pyboard", MODE:="0666", GROUP="adminpete"
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# Edit this to match the location of micropython/tools and the Pyboard device
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.append('/mnt/qnap2/data/Projects/MicroPython/micropython/tools')
|
||||||
|
import pyboard
|
||||||
|
def main():
|
||||||
|
pyb=pyboard.Pyboard('/dev/pyboard')
|
||||||
|
pyb.enter_raw_repl()
|
||||||
|
try:
|
||||||
|
pyb.exec_raw('pyb.bootloader()')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#! /bin/bash
|
||||||
|
# PYB V1.1 build script for 4/8 Core i7 and frozen bytecode
|
||||||
|
# Run from micropython/stmhal
|
||||||
|
# edit location of pyb_boot
|
||||||
|
make BOARD=PYBV10 clean && make -j 8 BOARD=PYBV10 FROZEN_MPY_DIR=scripts && /mnt/qnap2/Scripts/pyb_boot && make BOARD=PYBV10 deploy
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#! /bin/bash
|
||||||
|
# PYB V1.1 build script for 4/8 Core i7 and frozen bytecode
|
||||||
|
# Run from micropython/stmhal
|
||||||
|
# edit location of pyb_boot
|
||||||
|
make BOARD=PYBV11 clean && make -j 8 BOARD=PYBV11 FROZEN_MPY_DIR=scripts && /mnt/qnap2/Scripts/pyb_boot && make BOARD=PYBV11 deploy
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Time a function call by means of a decorator
|
||||||
|
|
||||||
|
import utime
|
||||||
|
|
||||||
|
def timed_function(f, *args, **kwargs):
|
||||||
|
myname = str(f).split(' ')[1]
|
||||||
|
def new_func(*args, **kwargs):
|
||||||
|
t = utime.ticks_us()
|
||||||
|
result = f(*args, **kwargs)
|
||||||
|
delta = utime.ticks_diff(t, utime.ticks_us())
|
||||||
|
print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000))
|
||||||
|
return result
|
||||||
|
return new_func
|
||||||
|
|
||||||
|
@timed_function
|
||||||
|
def test():
|
||||||
|
utime.sleep_us(10000)
|
||||||
|
|
Ładowanie…
Reference in New Issue