You can now create (singleton) objects representing the flash and SD
card, using:
flash = pyb.Flash()
sdcard = pyb.SDCard()
These objects provide the block protocol.
Per the previously discussed plan. mount() still stays backward-compatible,
and new mkfs() is rought and takes more args than needed. But is a step
in a forward direction.
Adds a lot of code, makes IRQs a bit less efficient, but is very useful
for debugging. Usage: pyb.irq_stats() returns a memory view that can be
read and written, eg:
list(pyb.irq_stats())
pyb.irq_stats()[0]
pyb.irq_stats()[0] = 0
The patch provides general IRQ_ENTER() and IRQ_EXIT() macros that can be
modified to provide further IRQ statistics if desired.
pyb.delay and pyb.udelay now use systick if IRQs are enabled, otherwise
they use a busy loop. Thus they work correctly when IRQs are disabled.
The busy loop is computed from the current CPU frequency, so works no
matter the CPU frequency.
Also restrict higher frequencies to have a VCO_OUT frequency below
432MHz, as specified in the datasheet.
Docs improved to list allowed frequencies, and explain about USB
stability.
Found these by compiling stmhal with mp_uint_t of type uint32_t instead
of unsigned int. This actually makes a difference to the code, but just
a curiosity.
Eg pyb.freq(120000000) sets the CPU to 120MHz. The frequency can be set
at any point in the code, and can be changed as many times as you like.
Note that any active timers will need to be reconfigured after a freq
change.
Valid range is 24MHz to 168MHz (but not all freqs are supported). The
code maintains a 48MHz clock for the USB at all times and it's possible
to change the frequency at a USB REPL and keep the REPL alive (well,
most of the time it stays, sometimes it resets the USB for some reason).
Note that USB does not work with pyb.freq of 24MHz.
I also removed trailing spaces from modpyb.c which affected a couple
of lines technically not part of this patch.
Tested using: https://github.com/dhylands/upy-examples/blob/master/micros_test.py
which eventually fails due to wraparound issues (I could fix the test to compensate
but didn't bother)
It's still "safe" because no scripts are run. Remove the SD card if you
want to access the internal flash filesystem. Addresses issue #616.
Also: remove obsolete pyb.source_dir setting, and reset pyb.main and
pyb.usb_mode settings on soft-reset.
Some important changes to the way the file system is structured on the
pyboard:
1. 0: and 1: drive names are now replaced with POSIX inspired
directories, namely /flash and /sd.
2. Filesystem now supports the notion of a current working directory.
Supports the standard Python way of manipulating it: os.chdir and
os.getcwd.
3. On boot up, current directory is /flash if no SD inserted, else /sd
if SD inserted. Then runs boot.py and main.py from the current dir.
This is the same as the old behaviour, but is much more consistent and
flexible (eg you can os.chdir in boot.py to change where main.py is run
from).
4. sys.path (for import) is now set to '' (current dir), plus /flash
and /flash/lib, and then /sd and /sd/lib if SD inserted. This, along
with CWD, means that import now works properly. You can import a file
from the current directory.
5. os.listdir is fixed to return just the basename, not the full path.
See issue #537 for background and discussion.
Before, pyb.stdin/pyb.stdout allowed some kind of access to the USB VCP
device, but it was basic access.
This patch adds a proper USB_VCP class and object with much more control
over the USB VCP device. Create an object with pyb.USB_VCP(), then use
this object as if it were a UART object. It has send, recv, read,
write, and other methods. send and recv allow a timeout to be specified.
Addresses issue 774.
Recent changes to builtin print meant that print was printing to the
mp_sys_stdout_obj, which was sending data raw to the USB CDC device.
The data should be cooked so that \n turns into \r\n.
This adds a hook to get/set pyb_uart_global_debug from Python, using
pyb.repl_uart(). You can set it to an arbitrary UART object, and then
the REPL (in and out) is repeated on this UART object (as well as on USB
CDC).
Ultimately, this will be replaced with a proper Pythonic interface to
set sys.stdin and sys.stdout.