diff --git a/.gitattributes b/.gitattributes
index 2d53b50e4..133e2625c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -15,16 +15,13 @@
# These should also not be modified by git.
tests/basics/string_cr_conversion.py -text
tests/basics/string_crlf_conversion.py -text
-stmhal/pybcdc.inf_template -text
-stmhal/usbd_* -text
-stmhal/boards/*/stm32f4xx_hal_conf.h -text
-stmhal/cmsis/** -text
-stmhal/hal/** -text
-stmhal/usbdev/** -text
-stmhal/usbhost/** -text
-cc3200/hal/aes.c -text
-cc3200/hal/aes.h -text
-cc3200/hal/des.c -text
-cc3200/hal/i2s.c -text
-cc3200/hal/i2s.h -text
-cc3200/version.h -text
+ports/stm32/pybcdc.inf_template -text
+ports/stm32/usbd_* -text
+ports/stm32/usbdev/** -text
+ports/stm32/usbhost/** -text
+ports/cc3200/hal/aes.c -text
+ports/cc3200/hal/aes.h -text
+ports/cc3200/hal/des.c -text
+ports/cc3200/hal/i2s.c -text
+ports/cc3200/hal/i2s.h -text
+ports/cc3200/version.h -text
diff --git a/.gitmodules b/.gitmodules
index 7735bc2d0..d2d8dd278 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -11,3 +11,7 @@
[submodule "lib/berkeley-db-1.xx"]
path = lib/berkeley-db-1.xx
url = https://github.com/pfalcon/berkeley-db-1.xx
+[submodule "lib/stm32lib"]
+ path = lib/stm32lib
+ url = https://github.com/micropython/stm32lib
+ branch = work-F4-1.13.1+F7-1.5.0+L4-1.3.0
diff --git a/.travis.yml b/.travis.yml
index 9915cdd00..fd23a3707 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,48 +19,48 @@ before_script:
- sudo apt-get install -y --force-yes gcc-arm-none-eabi
# For teensy build
- sudo apt-get install realpath
- # For coverage testing
- - sudo pip install cpp-coveralls
+ # For coverage testing (upgrade is used to get latest urllib3 version)
+ - sudo pip install --upgrade cpp-coveralls
- gcc --version
- arm-none-eabi-gcc --version
- python3 --version
script:
- make -C mpy-cross
- - make -C minimal CROSS=1 build/firmware.bin
- - ls -l minimal/build/firmware.bin
+ - make -C ports/minimal CROSS=1 build/firmware.bin
+ - ls -l ports/minimal/build/firmware.bin
- tools/check_code_size.sh
- mkdir -p ${HOME}/persist
# Save new firmware for reference, but only if building a main branch, not a pull request
- - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then cp minimal/build/firmware.bin ${HOME}/persist/; fi'
- - make -C unix deplibs
- - make -C unix
- - make -C unix nanbox
- - make -C bare-arm
- - make -C qemu-arm test
- - make -C stmhal
- - make -C stmhal BOARD=PYBV11 MICROPY_PY_WIZNET5K=1 MICROPY_PY_CC3K=1
- - make -C stmhal BOARD=STM32F769DISC
- - make -C stmhal BOARD=STM32L476DISC
- - make -C teensy
- - make -C cc3200 BTARGET=application BTYPE=release
- - make -C cc3200 BTARGET=bootloader BTYPE=release
- - make -C windows CROSS_COMPILE=i686-w64-mingw32-
+ - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then cp ports/minimal/build/firmware.bin ${HOME}/persist/; fi'
+ - make -C ports/unix deplibs
+ - make -C ports/unix
+ - make -C ports/unix nanbox
+ - make -C ports/bare-arm
+ - make -C ports/qemu-arm test
+ - make -C ports/stm32
+ - make -C ports/stm32 BOARD=PYBV11 MICROPY_PY_WIZNET5K=5200 MICROPY_PY_CC3K=1
+ - make -C ports/stm32 BOARD=STM32F769DISC
+ - make -C ports/stm32 BOARD=STM32L476DISC
+ - make -C ports/teensy
+ - make -C ports/cc3200 BTARGET=application BTYPE=release
+ - make -C ports/cc3200 BTARGET=bootloader BTYPE=release
+ - make -C ports/windows CROSS_COMPILE=i686-w64-mingw32-
# run tests without coverage info
#- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests)
#- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests --emit native)
# run tests with coverage info
- - make -C unix coverage
- - (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests)
- - (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests -d thread)
- - (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests --emit native)
- - (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests --via-mpy -d basics float)
+ - make -C ports/unix coverage
+ - (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests)
+ - (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -d thread)
+ - (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --emit native)
+ - (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --via-mpy -d basics float)
# run coveralls coverage analysis (try to, even if some builds/tests failed)
- - (cd unix && coveralls --root .. --build-root . --gcov $(which gcov) --gcov-options '\-o build-coverage/' --include py --include extmod)
+ - (cd ports/unix && coveralls --root ../.. --build-root . --gcov $(which gcov) --gcov-options '\-o build-coverage/' --include py --include extmod)
after_failure:
- (cd tests && for exp in *.exp; do testbase=$(basename $exp .exp); echo -e "\nFAILURE $testbase"; diff -u $testbase.exp $testbase.out; done)
- - (grep "FAIL" qemu-arm/build/console.out)
+ - (grep "FAIL" ports/qemu-arm/build/console.out)
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md
new file mode 100644
index 000000000..aaf16861f
--- /dev/null
+++ b/ISSUE_TEMPLATE.md
@@ -0,0 +1,6 @@
+**The ESP32 port has now been merged back into the
+[main MicroPython repository](https://github.com/micropython/micropython/)
+and this repository is maintained for historical purposes.**
+
+**Please make new issues and pull requests against the master branch of the
+main repository, linked above.**
diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 000000000..aaf16861f
--- /dev/null
+++ b/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,6 @@
+**The ESP32 port has now been merged back into the
+[main MicroPython repository](https://github.com/micropython/micropython/)
+and this repository is maintained for historical purposes.**
+
+**Please make new issues and pull requests against the master branch of the
+main repository, linked above.**
diff --git a/README.md b/README.md
index 29a65221f..725316203 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,3 @@
-[](https://travis-ci.org/micropython/micropython) [](https://coveralls.io/r/micropython/micropython?branch=master)
-
The MicroPython project
=======================
@@ -13,24 +11,12 @@ You can find the official website at [micropython.org](http://www.micropython.or
A note about this ESP32 repository
----------------------------------
-This repository is a clone of the main, upstream repository found at
-https://github.com/micropython/micropython. This repository adds a new
-branch called `esp32` which contains a port of MicroPython to the ESP32
-microcontroller, under the MIT license. Please see the `README.md` file
-in the `esp32/` subdirectory for details of this port.
-
-This `esp32` branch is the default branch and all pull requests should be
-made to this branch, and any issues should discuss only the code developed
-in the `esp32/` subdirectory.
-
-The `esp32` branch will not be rebased so it is safe to clone/fork it and
-base your work on it. New commits from the upstream repository will
-occasionally be merged in the `esp32` branch. Any additional branches in
-this repository (apart from `master`) may be rebased or deleted at any time.
+**The ESP32 port has now been merged back into the
+[main MicroPython repository](https://github.com/micropython/micropython/)
+and this repository is maintained for historical purposes.**
-If there is enough interest in the port to the ESP32 then this code can
-eventually be merged into the upstream repository. So please do let your
-interest be known!
+**This repository is now getting out of date and new pull requests should
+be made against the master branch of the main repository!**
About MicroPython
-----------------
@@ -59,10 +45,10 @@ Major components in this repository:
core library.
- mpy-cross/ -- the MicroPython cross-compiler which is used to turn scripts
into precompiled bytecode.
-- unix/ -- a version of MicroPython that runs on Unix.
-- stmhal/ -- a version of MicroPython that runs on the PyBoard and similar
+- ports/unix/ -- a version of MicroPython that runs on Unix.
+- ports/stm32/ -- a version of MicroPython that runs on the PyBoard and similar
STM32 boards (using ST's Cube HAL drivers).
-- minimal/ -- a minimal MicroPython port. Start with this if you want
+- ports/minimal/ -- a minimal MicroPython port. Start with this if you want
to port MicroPython to another microcontroller.
- tests/ -- test framework and test scripts.
- docs/ -- user documentation in Sphinx reStructuredText format. Rendered
@@ -70,13 +56,13 @@ Major components in this repository:
to select needed board/port at the bottom left corner).
Additional components:
-- bare-arm/ -- a bare minimum version of MicroPython for ARM MCUs. Used
+- ports/bare-arm/ -- a bare minimum version of MicroPython for ARM MCUs. Used
mostly to control code size.
-- teensy/ -- a version of MicroPython that runs on the Teensy 3.1
+- ports/teensy/ -- a version of MicroPython that runs on the Teensy 3.1
(preliminary but functional).
-- pic16bit/ -- a version of MicroPython for 16-bit PIC microcontrollers.
-- cc3200/ -- a version of MicroPython that runs on the CC3200 from TI.
-- esp8266/ -- an experimental port for ESP8266 WiFi modules.
+- ports/pic16bit/ -- a version of MicroPython for 16-bit PIC microcontrollers.
+- ports/cc3200/ -- a version of MicroPython that runs on the CC3200 from TI.
+- ports/esp8266/ -- an experimental port for ESP8266 WiFi modules.
- extmod/ -- additional (non-core) modules implemented in C.
- tools/ -- various tools, including the pyboard.py module.
- examples/ -- a few example Python scripts.
@@ -84,7 +70,7 @@ Additional components:
The subdirectories above may include READMEs with additional info.
"make" is used to build the components, or "gmake" on BSD-based systems.
-You will also need bash and Python (at least 2.7 or 3.3).
+You will also need bash, gcc, and Python (at least 2.7 or 3.3).
The Unix version
----------------
@@ -97,7 +83,8 @@ Alternatively, fallback implementation based on setjmp/longjmp can be used.
To build (see section below for required dependencies):
- $ cd unix
+ $ git submodule update --init
+ $ cd ports/unix
$ make axtls
$ make
@@ -129,44 +116,49 @@ Standard library modules come from
External dependencies
---------------------
-Building Unix version requires some dependencies installed. For
+Building MicroPython ports may require some dependencies installed.
+
+For Unix port, `libffi` library and `pkg-config` tool are required. On
Debian/Ubuntu/Mint derivative Linux distros, install `build-essential`
(includes toolchain and make), `libffi-dev`, and `pkg-config` packages.
-Other dependencies can be built together with MicroPython. Oftentimes,
-you need to do this to enable extra features or capabilities. To build
+Other dependencies can be built together with MicroPython. This may
+be required to enable extra features or capabilities, and in recent
+versions of MicroPython, these may be enabled by default. To build
these additional dependencies, first fetch git submodules for them:
$ git submodule update --init
-Use this same command to get the latest versions of dependencies, as
-they are updated from time to time. After that, in `unix/` dir, execute:
+Use the same command to get the latest versions of dependencies, as
+they are updated from time to time. After that, in the port directory
+(e.g. `ports/unix/`), execute:
$ make deplibs
This will build all available dependencies (regardless whether they
are used or not). If you intend to build MicroPython with additional
options (like cross-compiling), the same set of options should be passed
-to `make deplibs`. To actually enabled use of dependencies, edit
-`unix/mpconfigport.mk` file, which has inline descriptions of the options.
-For example, to build SSL module (required for `upip` tool described above),
-set `MICROPY_PY_USSL` to 1.
+to `make deplibs`. To actually enable/disable use of dependencies, edit
+`ports/unix/mpconfigport.mk` file, which has inline descriptions of the options.
+For example, to build SSL module (required for `upip` tool described above,
+and so enabled by dfeault), `MICROPY_PY_USSL` should be set to 1.
-In `unix/mpconfigport.mk`, you can also disable some dependencies enabled
-by default, like FFI support, which requires libffi development files to
-be installed.
+For some ports, building required dependences is transparent, and happens
+automatically. They still need to be fetched with the git submodule command
+above.
-The STM version
----------------
+The STM32 version
+-----------------
-The "stmhal" port requires an ARM compiler, arm-none-eabi-gcc, and associated
-bin-utils. For those using Arch Linux, you need arm-none-eabi-binutils and
-arm-none-eabi-gcc packages. Otherwise, try here:
+The "stm32" port requires an ARM compiler, arm-none-eabi-gcc, and associated
+bin-utils. For those using Arch Linux, you need arm-none-eabi-binutils,
+arm-none-eabi-gcc and arm-none-eabi-newlib packages. Otherwise, try here:
https://launchpad.net/gcc-arm-embedded
To build:
- $ cd stmhal
+ $ git submodule update --init
+ $ cd ports/stm32
$ make
You then need to get your board into DFU mode. On the pyboard, connect the
@@ -180,4 +172,14 @@ Then to flash the code via USB DFU to your device:
This will use the included `tools/pydfu.py` script. If flashing the firmware
does not work it may be because you don't have the correct permissions, and
need to use `sudo make deploy`.
-See the README.md file in the stmhal/ directory for further details.
+See the README.md file in the ports/stm32/ directory for further details.
+
+Contributing
+------------
+
+MicroPython is an open-source project and welcomes contributions. To be
+productive, please be sure to follow the
+[Contributors' Guidelines](https://github.com/micropython/micropython/wiki/ContributorGuidelines)
+and the [Code Conventions](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md).
+Note that MicroPython is licenced under the MIT license, and all contributions
+should follow this license.
diff --git a/cc3200/misc/mpexception.c b/cc3200/misc/mpexception.c
deleted file mode 100644
index 068adb70b..000000000
--- a/cc3200/misc/mpexception.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2013, 2014 Damien P. George
- * Copyright (c) 2015 Daniel Campora
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include
-#include
-
-#include "py/mpstate.h"
-#include "mpexception.h"
-
-
-/******************************************************************************
-DECLARE PRIVATE FUNCTIONS
- ******************************************************************************/
-STATIC void mpexception_set_user_interrupt (int chr, void *data);
-
-/******************************************************************************
-DECLARE EXPORTED DATA
- ******************************************************************************/
-const char mpexception_value_invalid_arguments[] = "invalid argument(s) value";
-const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type";
-const char mpexception_uncaught[] = "uncaught exception";
-
-int user_interrupt_char = -1;
-
-/******************************************************************************
-DECLARE PRIVATE DATA
- ******************************************************************************/
-STATIC void *user_interrupt_data = NULL;
-
-/******************************************************************************
-DEFINE PUBLIC FUNCTIONS
- ******************************************************************************/
-
-void mpexception_init0 (void) {
- // Create an exception object for interrupting through the stdin uart
- MP_STATE_PORT(mp_const_user_interrupt) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
- mpexception_set_user_interrupt (-1, MP_STATE_PORT(mp_const_user_interrupt));
-}
-
-void mpexception_set_interrupt_char (int c) {
- if (c != -1) {
- mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_const_user_interrupt));
- }
- mpexception_set_user_interrupt(c, MP_STATE_PORT(mp_const_user_interrupt));
-}
-
-// Call this function to raise a pending exception during an interrupt.
-// It will try to raise the exception "softly" by setting the
-// mp_pending_exception variable hoping that the VM will notice it.
-void mpexception_nlr_jump (void *o) {
- if (MP_STATE_PORT(mp_pending_exception) == MP_OBJ_NULL) {
- MP_STATE_PORT(mp_pending_exception) = o;
- }
-}
-
-void mpexception_keyboard_nlr_jump (void) {
- mpexception_nlr_jump (user_interrupt_data);
-}
-
-/******************************************************************************
-DEFINE PRIVATE FUNCTIONS
- ******************************************************************************/
-
-STATIC void mpexception_set_user_interrupt (int chr, void *data) {
- user_interrupt_char = chr;
- user_interrupt_data = data;
-}
diff --git a/docs/conf.py b/docs/conf.py
index 2c3423d99..a8df37315 100755
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -98,7 +98,7 @@
#
# We don't follow "The short X.Y version" vs "The full version, including alpha/beta/rc tags"
# breakdown, so use the same version identifier for both to avoid confusion.
-version = release = '1.9.1'
+version = release = '1.9.2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/docs/esp8266/quickref.rst b/docs/esp8266/quickref.rst
index ccf6365c8..c510e4064 100644
--- a/docs/esp8266/quickref.rst
+++ b/docs/esp8266/quickref.rst
@@ -223,6 +223,17 @@ and is accessed via the :ref:`machine.I2C ` class::
buf = bytearray(10) # create a buffer with 10 bytes
i2c.writeto(0x3a, buf) # write the given buffer to the slave
+Real time clock (RTC)
+---------------------
+
+See :ref:`machine.RTC ` ::
+
+ from machine import RTC
+
+ rtc = RTC()
+ rtc.datetime((2017, 8, 23, 1, 12, 48, 0, 0)) # set a specific date and time
+ rtc.datetime() # get date and time
+
Deep-sleep mode
---------------
diff --git a/docs/esp8266/tutorial/neopixel.rst b/docs/esp8266/tutorial/neopixel.rst
index 245aed6d4..a1537526f 100644
--- a/docs/esp8266/tutorial/neopixel.rst
+++ b/docs/esp8266/tutorial/neopixel.rst
@@ -20,6 +20,20 @@ To set the colour of pixels use::
>>> np[1] = (0, 128, 0) # set to green, half brightness
>>> np[2] = (0, 0, 64) # set to blue, quarter brightness
+For LEDs with more than 3 colours, such as RGBW pixels or RGBY pixels, the
+NeoPixel class takes a ``bpp`` parameter. To setup a NeoPixel object for an
+RGBW Pixel, do the following::
+
+ >>> import machine, neopixel
+ >>> np = neopixel.NeoPixel(machine.Pin(4), 8, bpp=4)
+
+In a 4-bpp mode, remember to use 4-tuples instead of 3-tuples to set the colour.
+For example to set the first three pixels use::
+
+ >>> np[0] = (255, 0, 0, 128) # Orange in an RGBY Setup
+ >>> np[1] = (0, 255, 0, 128) # Yellow-green in an RGBY Setup
+ >>> np[2] = (0, 0, 255, 128) # Green-blue in an RGBY Setup
+
Then use the ``write()`` method to output the colours to the LEDs::
>>> np.write()
diff --git a/docs/library/btree.rst b/docs/library/btree.rst
index 9322d32e6..8fac67e8d 100644
--- a/docs/library/btree.rst
+++ b/docs/library/btree.rst
@@ -76,20 +76,24 @@ Example::
Functions
---------
-.. function:: open(stream, \*, flags=0, cachesize=0, pagesize=0, minkeypage=0)
+.. function:: open(stream, \*, flags=0, pagesize=0, cachesize=0, minkeypage=0)
Open a database from a random-access `stream` (like an open file). All
other parameters are optional and keyword-only, and allow to tweak advanced
parameters of the database operation (most users will not need them):
* *flags* - Currently unused.
- * *cachesize* - Suggested maximum memory cache size in bytes. For a
- board with enough memory using larger values may improve performance.
- The value is only a recommendation, the module may use more memory if
- values set too low.
* *pagesize* - Page size used for the nodes in BTree. Acceptable range
- is 512-65536. If 0, underlying I/O block size will be used (the best
- compromise between memory usage and performance).
+ is 512-65536. If 0, a port-specific default will be used, optimized for
+ port's memory usage and/or performance.
+ * *cachesize* - Suggested memory cache size in bytes. For a
+ board with enough memory using larger values may improve performance.
+ Cache policy is as follows: entire cache is not allocated at once;
+ instead, accessing a new page in database will allocate a memory buffer
+ for it, until value specified by *cachesize* is reached. Then, these
+ buffers will be managed using LRU (least recently used) policy. More
+ buffers may still be allocated if needed (e.g., if a database contains
+ big keys and/or values). Allocated cache buffers aren't reclaimed.
* *minkeypage* - Minimum number of keys to store per page. Default value
of 0 equivalent to 2.
diff --git a/docs/library/framebuf.rst b/docs/library/framebuf.rst
index b92bd08ef..74c9f8564 100644
--- a/docs/library/framebuf.rst
+++ b/docs/library/framebuf.rst
@@ -38,9 +38,9 @@ Constructors
- *width* is the width of the FrameBuffer in pixels
- *height* is the height of the FrameBuffer in pixels
- *format* specifies the type of pixel used in the FrameBuffer;
- valid values are ``framebuf.MVLSB``, ``framebuf.RGB565``
- and ``framebuf.GS4_HMSB``. MVLSB is monochrome 1-bit color,
- RGB565 is RGB 16-bit color, and GS4_HMSB is grayscale 4-bit color.
+ permissible values are listed under Constants below. These set the
+ number of bits used to encode a color value and the layout of these
+ bits in *buffer*.
Where a color value c is passed to a method, c is a small integer
with an encoding that is dependent on the format of the FrameBuffer.
- *stride* is the number of pixels between each horizontal line
@@ -110,8 +110,9 @@ Other methods
corresponding color will be considered transparent: all pixels with that
color value will not be drawn.
- This method works between FrameBuffer's utilising different formats, but the
- resulting colors may be unexpected due to the mismatch in color formats.
+ This method works between FrameBuffer instances utilising different formats,
+ but the resulting colors may be unexpected due to the mismatch in color
+ formats.
Constants
---------
diff --git a/docs/library/index.rst b/docs/library/index.rst
index e884f266e..0789ea43d 100644
--- a/docs/library/index.rst
+++ b/docs/library/index.rst
@@ -40,8 +40,7 @@ information pertaining to a specific port.
Beyond the built-in libraries described in this documentation, many more
modules from the Python standard library, as well as further MicroPython
-extensions to it, can be found in the `micropython-lib repository
-`_.
+extensions to it, can be found in `micropython-lib`.
Python standard libraries and micro-libraries
---------------------------------------------
@@ -54,7 +53,7 @@ e.g. ``ujson`` instead of ``json``. This is to signify that such a module is
micro-library, i.e. implements only a subset of CPython module functionality.
By naming them differently, a user has a choice to write a Python-level module
to extend functionality for better compatibility with CPython (indeed, this is
-what done by micropython-lib project mentioned above).
+what done by the `micropython-lib` project mentioned above).
On some embedded platforms, where it may be cumbersome to add Python-level
wrapper modules to achieve naming compatibility with CPython, micro-modules
diff --git a/docs/library/machine.RTC.rst b/docs/library/machine.RTC.rst
index 2a53b9146..95fa2b4ce 100644
--- a/docs/library/machine.RTC.rst
+++ b/docs/library/machine.RTC.rst
@@ -38,7 +38,7 @@ Methods
Resets the RTC to the time of January 1, 2015 and starts running it again.
-.. method:: RTC.alarm(id, time, /*, repeat=False)
+.. method:: RTC.alarm(id, time, \*, repeat=False)
Set the RTC alarm. Time might be either a millisecond value to program the alarm to
current time + time_in_ms in the future, or a datetimetuple. If the time passed is in
diff --git a/docs/library/machine.Signal.rst b/docs/library/machine.Signal.rst
index 486908627..a1a29164b 100644
--- a/docs/library/machine.Signal.rst
+++ b/docs/library/machine.Signal.rst
@@ -4,17 +4,44 @@
class Signal -- control and sense external I/O devices
======================================================
-The Signal class is a simple extension of Pin class. Unlike Pin, which
+The Signal class is a simple extension of the `Pin` class. Unlike Pin, which
can be only in "absolute" 0 and 1 states, a Signal can be in "asserted"
(on) or "deasserted" (off) states, while being inverted (active-low) or
-not. Summing up, it adds logical inversion support to Pin functionality.
+not. In other words, it adds logical inversion support to Pin functionality.
While this may seem a simple addition, it is exactly what is needed to
support wide array of simple digital devices in a way portable across
different boards, which is one of the major MicroPython goals. Regardless
-whether different users have an active-high or active-low LED, a normally
-open or normally closed relay - you can develop single, nicely looking
+of whether different users have an active-high or active-low LED, a normally
+open or normally closed relay - you can develop a single, nicely looking
application which works with each of them, and capture hardware
-configuration differences in few lines on the config file of your app.
+configuration differences in few lines in the config file of your app.
+
+Example::
+
+ from machine import Pin, Signal
+
+ # Suppose you have an active-high LED on pin 0
+ led1_pin = Pin(0, Pin.OUT)
+ # ... and active-low LED on pin 1
+ led2_pin = Pin(1, Pin.OUT)
+
+ # Now to light up both of them using Pin class, you'll need to set
+ # them to different values
+ led1_pin.value(1)
+ led2_pin.value(0)
+
+ # Signal class allows to abstract away active-high/active-low
+ # difference
+ led1 = Signal(led1_pin, invert=False)
+ led2 = Signal(led2_pin, invert=True)
+
+ # Now lighting up them looks the same
+ led1.value(1)
+ led2.value(1)
+
+ # Even better:
+ led1.on()
+ led2.on()
Following is the guide when Signal vs Pin should be used:
@@ -33,11 +60,11 @@ architecture of MicroPython: Pin offers the lowest overhead, which may
be important when bit-banging protocols. But Signal adds additional
flexibility on top of Pin, at the cost of minor overhead (much smaller
than if you implemented active-high vs active-low device differences in
-Python manually!). Also, Pin is low-level object which needs to be
+Python manually!). Also, Pin is a low-level object which needs to be
implemented for each support board, while Signal is a high-level object
which comes for free once Pin is implemented.
-If in doubt, give the Signal a try! Once again, it is developed to save
+If in doubt, give the Signal a try! Once again, it is offered to save
developers from the need to handle unexciting differences like active-low
vs active-high signals, and allow other users to share and enjoy your
application, instead of being frustrated by the fact that it doesn't
diff --git a/docs/library/micropython.rst b/docs/library/micropython.rst
index 4ff0b0c15..c13a7391b 100644
--- a/docs/library/micropython.rst
+++ b/docs/library/micropython.rst
@@ -46,7 +46,7 @@ Functions
.. function:: mem_info([verbose])
- Print information about currently used memory. If the *verbose`* argument
+ Print information about currently used memory. If the *verbose* argument
is given then extra information is printed.
The information that is printed is implementation dependent, but currently
diff --git a/docs/library/network.rst b/docs/library/network.rst
index de93c0e01..99a7c242c 100644
--- a/docs/library/network.rst
+++ b/docs/library/network.rst
@@ -9,7 +9,7 @@ This module provides network drivers and routing configuration. To use this
module, a MicroPython variant/build with network capabilities must be installed.
Network drivers for specific hardware are available within this module and are
used to configure hardware network interface(s). Network services provided
-by configured interfaces are then available for use via the :mod:`socket`
+by configured interfaces are then available for use via the :mod:`usocket`
module.
For example::
@@ -39,9 +39,9 @@ Common network adapter interface
================================
This section describes an (implied) abstract base class for all network
-interface classes implemented by different ports of MicroPython for
-different hardware. This means that MicroPython does not actually
-provide `AbstractNIC` class, but any actual NIC class, as described
+interface classes implemented by `MicroPython ports `
+for different hardware. This means that MicroPython does not actually
+provide ``AbstractNIC`` class, but any actual NIC class, as described
in the following sections, implements methods as described here.
.. class:: AbstractNIC(id=None, ...)
@@ -72,8 +72,7 @@ parameter should be `id`.
connection parameters. For various medium types, there are different
sets of predefined/recommended parameters, among them:
- * WiFi: *bssid* keyword to connect by BSSID (MAC address) instead
- of access point name
+ * WiFi: *bssid* keyword to connect to a specific BSSID (MAC address)
.. method:: disconnect()
@@ -225,7 +224,9 @@ parameter should be `id`.
==============
This class allows you to control WIZnet5x00 Ethernet adaptors based on
- the W5200 and W5500 chipsets (only W5200 tested).
+ the W5200 and W5500 chipsets. The particular chipset that is supported
+ by the firmware is selected at compile-time via the MICROPY_PY_WIZNET5K
+ option.
Example usage::
@@ -269,6 +270,11 @@ parameter should be `id`.
Methods
-------
+ .. method:: wiznet5k.isconnected()
+
+ Returns ``True`` if the physical Ethernet link is connected and up.
+ Returns ``False`` otherwise.
+
.. method:: wiznet5k.ifconfig([(ip, subnet, gateway, dns)])
Get/set IP address, subnet mask, gateway and DNS.
@@ -333,9 +339,12 @@ parameter should be `id`.
argument is passed. Otherwise, query current state if no argument is
provided. Most other methods require active interface.
- .. method:: wlan.connect(ssid, password)
+ .. method:: wlan.connect(ssid=None, password=None, \*, bssid=None)
Connect to the specified wireless network, using the specified password.
+ If *bssid* is given then the connection will be restricted to the
+ access-point with that MAC address (the *ssid* must also be specified
+ in this case).
.. method:: wlan.disconnect()
@@ -411,18 +420,19 @@ parameter should be `id`.
print(ap.config('channel'))
Following are commonly supported parameters (availability of a specific parameter
- depends on network technology type, driver, and MicroPython port).
-
- ========= ===========
- Parameter Description
- ========= ===========
- mac MAC address (bytes)
- essid WiFi access point name (string)
- channel WiFi channel (integer)
- hidden Whether ESSID is hidden (boolean)
- authmode Authentication mode supported (enumeration, see module constants)
- password Access password (string)
- ========= ===========
+ depends on network technology type, driver, and `MicroPython port`).
+
+ ============= ===========
+ Parameter Description
+ ============= ===========
+ mac MAC address (bytes)
+ essid WiFi access point name (string)
+ channel WiFi channel (integer)
+ hidden Whether ESSID is hidden (boolean)
+ authmode Authentication mode supported (enumeration, see module constants)
+ password Access password (string)
+ dhcp_hostname The DHCP hostname to use
+ ============= ===========
diff --git a/docs/library/pyb.Accel.rst b/docs/library/pyb.Accel.rst
index 061996485..9ade5c5c8 100644
--- a/docs/library/pyb.Accel.rst
+++ b/docs/library/pyb.Accel.rst
@@ -1,4 +1,5 @@
.. currentmodule:: pyb
+.. _pyb.Accel:
class Accel -- accelerometer control
====================================
diff --git a/docs/library/pyb.CAN.rst b/docs/library/pyb.CAN.rst
index 9e71f12b0..232d04d96 100644
--- a/docs/library/pyb.CAN.rst
+++ b/docs/library/pyb.CAN.rst
@@ -1,4 +1,5 @@
.. currentmodule:: pyb
+.. _pyb.CAN:
class CAN -- controller area network communication bus
======================================================
diff --git a/docs/library/pyb.LCD.rst b/docs/library/pyb.LCD.rst
index 83cf890b6..5ab127edc 100644
--- a/docs/library/pyb.LCD.rst
+++ b/docs/library/pyb.LCD.rst
@@ -1,4 +1,5 @@
.. currentmodule:: pyb
+.. _pyb.LCD:
class LCD -- LCD control for the LCD touch-sensor pyskin
========================================================
diff --git a/docs/library/pyb.Switch.rst b/docs/library/pyb.Switch.rst
index 0d5dc63b7..e5ab6bd84 100644
--- a/docs/library/pyb.Switch.rst
+++ b/docs/library/pyb.Switch.rst
@@ -1,4 +1,5 @@
.. currentmodule:: pyb
+.. _pyb.Switch:
class Switch -- switch object
=============================
diff --git a/docs/library/pyb.USB_HID.rst b/docs/library/pyb.USB_HID.rst
index 7d17c3099..702704435 100644
--- a/docs/library/pyb.USB_HID.rst
+++ b/docs/library/pyb.USB_HID.rst
@@ -1,4 +1,5 @@
.. currentmodule:: pyb
+.. _pyb.USB_HID:
class USB_HID -- USB Human Interface Device (HID)
=================================================
diff --git a/docs/library/pyb.USB_VCP.rst b/docs/library/pyb.USB_VCP.rst
index 4c4fe4516..80cc40cdd 100644
--- a/docs/library/pyb.USB_VCP.rst
+++ b/docs/library/pyb.USB_VCP.rst
@@ -1,4 +1,5 @@
.. currentmodule:: pyb
+.. _pyb.USB_VCP:
class USB_VCP -- USB virtual comm port
======================================
diff --git a/docs/library/sys.rst b/docs/library/sys.rst
index 0bec35cc9..d49577306 100644
--- a/docs/library/sys.rst
+++ b/docs/library/sys.rst
@@ -28,7 +28,7 @@ Functions
this function takes just exception value instead of exception type,
exception value, and traceback object; *file* argument should be
positional; further arguments are not supported. CPython-compatible
- ``traceback`` module can be found in micropython-lib.
+ ``traceback`` module can be found in `micropython-lib`.
Constants
---------
diff --git a/docs/library/ubinascii.rst b/docs/library/ubinascii.rst
index 0664d5b09..192d34514 100644
--- a/docs/library/ubinascii.rst
+++ b/docs/library/ubinascii.rst
@@ -29,8 +29,12 @@ Functions
.. function:: a2b_base64(data)
- Convert Base64-encoded data to binary representation. Returns bytes string.
+ Decode base64-encoded data, ignoring invalid characters in the input.
+ Conforms to `RFC 2045 s.6.8 `_.
+ Returns a bytes object.
.. function:: b2a_base64(data)
- Encode binary data in Base64 format. Returns string.
+ Encode binary data in base64 format, as in `RFC 3548
+ `_. Returns the encoded data
+ followed by a newline character, as a bytes object.
diff --git a/docs/library/uos.rst b/docs/library/uos.rst
index 7c52c1eea..43bf69cc0 100644
--- a/docs/library/uos.rst
+++ b/docs/library/uos.rst
@@ -89,8 +89,22 @@ Functions
Return a bytes object with n random bytes. Whenever possible, it is
generated by the hardware random number generator.
-.. function:: dupterm(stream_object)
+.. function:: dupterm(stream_object, index=0)
- Duplicate or switch MicroPython terminal (the REPL) on the passed stream-like
- object. The given object must implement the ``readinto()`` and ``write()``
- methods. If ``None`` is passed, previously set redirection is cancelled.
+ Duplicate or switch the MicroPython terminal (the REPL) on the given stream-like
+ object. The *stream_object* argument must implement the ``readinto()`` and
+ ``write()`` methods. The stream should be in non-blocking mode and
+ ``readinto()`` should return ``None`` if there is no data available for reading.
+
+ After calling this function all terminal output is repeated on this stream,
+ and any input that is available on the stream is passed on to the terminal input.
+
+ The *index* parameter should be a non-negative integer and specifies which
+ duplication slot is set. A given port may implement more than one slot (slot 0
+ will always be available) and in that case terminal input and output is
+ duplicated on all the slots that are set.
+
+ If ``None`` is passed as the *stream_object* then duplication is cancelled on
+ the slot given by *index*.
+
+ The function returns the previous stream-like object in the given slot.
diff --git a/docs/library/uselect.rst b/docs/library/uselect.rst
index e330207db..beffce69a 100644
--- a/docs/library/uselect.rst
+++ b/docs/library/uselect.rst
@@ -66,12 +66,18 @@ Methods
Tuples returned may contain more than 2 elements as described above.
-.. method:: poll.ipoll([timeout])
+.. method:: poll.ipoll(timeout=-1, flags=0)
Like :meth:`poll.poll`, but instead returns an iterator which yields
- callee-owned tuples. This function provides efficient, allocation-free
+ `callee-owned tuples`. This function provides efficient, allocation-free
way to poll on streams.
+ If *flags* is 1, one-shot behavior for events is employed: streams for
+ which events happened, event mask will be automatically reset (equivalent
+ to ``poll.modify(obj, 0)``), so new events for such a stream won't be
+ processed until new mask is set with `poll.modify()`. This behavior is
+ useful for asynchronous I/O schedulers.
+
.. admonition:: Difference to CPython
:class: attention
diff --git a/docs/library/usocket.rst b/docs/library/usocket.rst
index 70d4f49fc..53936505b 100644
--- a/docs/library/usocket.rst
+++ b/docs/library/usocket.rst
@@ -9,12 +9,6 @@
This module provides access to the BSD socket interface.
-.. admonition:: Difference to CPython
- :class: attention
-
- CPython used to have a ``socket.error`` exception which is now deprecated,
- and is an alias of `OSError`. In MicroPython, use `OSError` directly.
-
.. admonition:: Difference to CPython
:class: attention
@@ -27,18 +21,63 @@ This module provides access to the BSD socket interface.
Socket address format(s)
------------------------
-The functions below which expect a network address, accept it in the format of
-*(ipv4_address, port)*, where *ipv4_address* is a string with dot-notation numeric
-IPv4 address, e.g. ``"8.8.8.8"``, and port is integer port number in the range
-1-65535. Note the domain names are not accepted as *ipv4_address*, they should be
-resolved first using `usocket.getaddrinfo()`.
+The native socket address format of the ``usocket`` module is an opaque data type
+returned by `getaddrinfo` function, which must be used to resolve textual address
+(including numeric addresses)::
+
+ sockaddr = usocket.getaddrinfo('www.micropython.org', 80)[0][-1]
+ # You must use getaddrinfo() even for numeric addresses
+ sockaddr = usocket.getaddrinfo('127.0.0.1', 80)[0][-1]
+ # Now you can use that address
+ sock.connect(addr)
+
+Using `getaddrinfo` is the most efficient (both in terms of memory and processing
+power) and portable way to work with addresses.
+
+However, ``socket`` module (note the difference with native MicroPython
+``usocket`` module described here) provides CPython-compatible way to specify
+addresses using tuples, as described below. Note that depending on a
+`MicroPython port`, ``socket`` module can be builtin or need to be
+installed from `micropython-lib` (as in the case of `MicroPython Unix port`),
+and some ports still accept only numeric addresses in the tuple format,
+and require to use `getaddrinfo` function to resolve domain names.
+
+Summing up:
+
+* Always use `getaddrinfo` when writing portable applications.
+* Tuple addresses described below can be used as a shortcut for
+ quick hacks and interactive use, if your port supports them.
+
+Tuple address format for ``socket`` module:
+
+* IPv4: *(ipv4_address, port)*, where *ipv4_address* is a string with
+ dot-notation numeric IPv4 address, e.g. ``"8.8.8.8"``, and *port* is and
+ integer port number in the range 1-65535. Note the domain names are not
+ accepted as *ipv4_address*, they should be resolved first using
+ `usocket.getaddrinfo()`.
+* IPv6: *(ipv6_address, port, flowinfo, scopeid)*, where *ipv6_address*
+ is a string with colon-notation numeric IPv6 address, e.g. ``"2001:db8::1"``,
+ and *port* is an integer port number in the range 1-65535. *flowinfo*
+ must be 0. *scopeid* is the interface scope identifier for link-local
+ addresses. Note the domain names are not accepted as *ipv6_address*,
+ they should be resolved first using `usocket.getaddrinfo()`. Availability
+ of IPv6 support depends on a `MicroPython port`.
Functions
---------
.. function:: socket(af=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP)
- Create a new socket using the given address family, socket type and protocol number.
+ Create a new socket using the given address family, socket type and
+ protocol number. Note that specifying *proto* in most cases is not
+ required (and not recommended, as some MicroPython ports may omit
+ ``IPPROTO_*`` constants). Instead, *type* argument will select needed
+ protocol automatically::
+
+ # Create STREAM TCP socket
+ socket(AF_INET, SOCK_STREAM)
+ # Create DGRAM UDP socket
+ socket(AF_INET, SOCK_DGRAM)
.. function:: getaddrinfo(host, port)
@@ -50,8 +89,8 @@ Functions
The following example shows how to connect to a given url::
- s = socket.socket()
- s.connect(socket.getaddrinfo('www.micropython.org', 80)[0][-1])
+ s = usocket.socket()
+ s.connect(usocket.getaddrinfo('www.micropython.org', 80)[0][-1])
.. admonition:: Difference to CPython
:class: attention
@@ -66,13 +105,29 @@ Functions
from an exception object). The use of negative values is a provisional
detail which may change in the future.
+.. function:: inet_ntop(af, bin_addr)
+
+ Convert a binary network address *bin_addr* of the given address family *af*
+ to a textual representation::
+
+ >>> usocket.inet_ntop(usocket.AF_INET, b"\x7f\0\0\1")
+ '127.0.0.1'
+
+.. function:: inet_pton(af, txt_addr)
+
+ Convert a textual network address *txt_addr* of the given address family *af*
+ to a binary representation::
+
+ >>> usocket.inet_pton(usocket.AF_INET, "1.2.3.4")
+ b'\x01\x02\x03\x04'
+
Constants
---------
.. data:: AF_INET
AF_INET6
- Address family types. Availability depends on a particular board.
+ Address family types. Availability depends on a particular `MicroPython port`.
.. data:: SOCK_STREAM
SOCK_DGRAM
@@ -82,17 +137,21 @@ Constants
.. data:: IPPROTO_UDP
IPPROTO_TCP
- IP protocol numbers.
+ IP protocol numbers. Availability depends on a particular `MicroPython port`.
+ Note that you don't need to specify these in a call to `usocket.socket()`,
+ because `SOCK_STREAM` socket type automatically selects `IPPROTO_TCP`, and
+ `SOCK_DGRAM` - `IPPROTO_UDP`. Thus, the only real use of these constants
+ is as an argument to `setsockopt()`.
.. data:: usocket.SOL_*
Socket option levels (an argument to `setsockopt()`). The exact
- inventory depends on a MicroPython port.
+ inventory depends on a `MicroPython port`.
.. data:: usocket.SO_*
Socket options (an argument to `setsockopt()`). The exact
- inventory depends on a MicroPython port.
+ inventory depends on a `MicroPython port`.
Constants specific to WiPy:
@@ -250,3 +309,13 @@ Methods
the length of *buf*.
Return value: number of bytes written.
+
+.. exception:: usocket.error
+
+ MicroPython does NOT have this exception.
+
+ .. admonition:: Difference to CPython
+ :class: attention
+
+ CPython used to have a ``socket.error`` exception which is now deprecated,
+ and is an alias of `OSError`. In MicroPython, use `OSError` directly.
diff --git a/docs/pyboard/quickref.rst b/docs/pyboard/quickref.rst
index 5690dddb0..48798aad3 100644
--- a/docs/pyboard/quickref.rst
+++ b/docs/pyboard/quickref.rst
@@ -39,17 +39,32 @@ Use the :mod:`time ` module::
start = time.ticks_ms() # get value of millisecond counter
delta = time.ticks_diff(time.ticks_ms(), start) # compute time difference
-LEDs
-----
+Internal LEDs
+-------------
See :ref:`pyb.LED `. ::
from pyb import LED
- led = LED(1) # red led
+ led = LED(1) # 1=red, 2=green, 3=yellow, 4=blue
led.toggle()
led.on()
led.off()
+
+ # LEDs 3 and 4 support PWM intensity (0-255)
+ LED(4).intensity() # get intensity
+ LED(4).intensity(128) # set intensity to half
+
+Internal switch
+---------------
+
+See :ref:`pyb.Switch `. ::
+
+ from pyb import Switch
+
+ sw = Switch()
+ sw.value() # returns True or False
+ sw.callback(lambda: pyb.LED(1).toggle())
Pins and GPIO
-------------
@@ -99,6 +114,17 @@ See :ref:`pyb.Timer `. ::
tim.freq(0.5) # 0.5 Hz
tim.callback(lambda t: pyb.LED(1).toggle())
+RTC (real time clock)
+---------------------
+
+See :ref:`pyb.RTC ` ::
+
+ from pyb import RTC
+
+ rtc = RTC()
+ rtc.datetime((2017, 8, 23, 1, 12, 48, 0, 0)) # set a specific date and time
+ rtc.datetime() # get date and time
+
PWM (pulse width modulation)
----------------------------
@@ -167,3 +193,25 @@ See :ref:`pyb.I2C `. ::
i2c.recv(5, 0x42) # receive 5 bytes from slave
i2c.mem_read(2, 0x42, 0x10) # read 2 bytes from slave 0x42, slave memory 0x10
i2c.mem_write('xy', 0x42, 0x10) # write 2 bytes to slave 0x42, slave memory 0x10
+
+CAN bus (controller area network)
+---------------------------------
+
+See :ref:`pyb.CAN `. ::
+
+ from pyb import CAN
+
+ can = CAN(1, CAN.LOOPBACK)
+ can.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))
+ can.send('message!', 123) # send a message with id 123
+ can.recv(0) # receive message on FIFO 0
+
+Internal accelerometer
+----------------------
+
+See :ref:`pyb.Accel `. ::
+
+ from pyb import Accel
+
+ accel = Accel()
+ print(accel.x(), accel.y(), accel.z(), accel.tilt())
diff --git a/docs/pyboard/tutorial/leds.rst b/docs/pyboard/tutorial/leds.rst
index 763eedf01..6b05f5db0 100644
--- a/docs/pyboard/tutorial/leds.rst
+++ b/docs/pyboard/tutorial/leds.rst
@@ -60,10 +60,10 @@ One problem you might find is that if you stop the script and then start it agai
for l in leds:
l.off()
-The Fourth Special LED
-----------------------
+The Special LEDs
+----------------
-The blue LED is special. As well as turning it on and off, you can control the intensity using the intensity() method. This takes a number between 0 and 255 that determines how bright it is. The following script makes the blue LED gradually brighter then turns it off again. ::
+The yellow and blue LEDs are special. As well as turning them on and off, you can control their intensity using the intensity() method. This takes a number between 0 and 255 that determines how bright it is. The following script makes the blue LED gradually brighter then turns it off again. ::
led = pyb.LED(4)
intensity = 0
@@ -72,4 +72,4 @@ The blue LED is special. As well as turning it on and off, you can control the i
led.intensity(intensity)
pyb.delay(20)
-You can call intensity() on the other LEDs but they can only be off or on. 0 sets them off and any other number up to 255 turns them on.
+You can call intensity() on LEDs 1 and 2 but they can only be off or on. 0 sets them off and any other number up to 255 turns them on.
diff --git a/docs/pyboard/tutorial/pass_through.rst b/docs/pyboard/tutorial/pass_through.rst
index a94e7363d..012a90764 100644
--- a/docs/pyboard/tutorial/pass_through.rst
+++ b/docs/pyboard/tutorial/pass_through.rst
@@ -15,4 +15,4 @@ It's as simple as::
if uart.any():
usb.write(uart.read(256))
- pass_through(pyb.USB_VCP(), pyb.UART(1, 9600))
+ pass_through(pyb.USB_VCP(), pyb.UART(1, 9600, timeout=0))
diff --git a/docs/reference/constrained.rst b/docs/reference/constrained.rst
index 14286aa26..e7de459bc 100644
--- a/docs/reference/constrained.rst
+++ b/docs/reference/constrained.rst
@@ -279,7 +279,7 @@ After importing the modules, execute:
Then copy and paste all the Q(xxx) lines into a text editor. Check for and
remove lines which are obviously invalid. Open the file qstrdefsport.h which
-will be found in stmhal (or the equivalent directory for the architecture in
+will be found in ports/stm32 (or the equivalent directory for the architecture in
use). Copy and paste the corrected lines at the end of the file. Save the file,
rebuild and flash the firmware. The outcome can be checked by importing the
modules and again issuing:
diff --git a/docs/reference/glossary.rst b/docs/reference/glossary.rst
index 4099ae951..4cd3d84cc 100644
--- a/docs/reference/glossary.rst
+++ b/docs/reference/glossary.rst
@@ -54,11 +54,11 @@ Glossary
separate project
`micropython-lib `_
which provides implementations for many modules from CPython's
- standard library. However, large subset of these modules required
+ standard library. However, large subset of these modules require
POSIX-like environment (Linux, MacOS, Windows may be partially
- supported), and thus would work or make sense only with MicroPython
- Unix port. Some subset of modules however usable for baremetal ports
- too.
+ supported), and thus would work or make sense only with
+ `MicroPython Unix port`. Some subset of modules is however usable
+ for `baremetal` ports too.
Unlike monolithic :term:`CPython` stdlib, micropython-lib modules
are intended to be installed individually - either using manual
@@ -68,7 +68,13 @@ Glossary
MicroPython supports different :term:`boards `, RTOSes,
and OSes, and can be relatively easily adapted to new systems.
MicroPython with support for a particular system is called a
- "port" to that system.
+ "port" to that system. Different ports may have widely different
+ functionality. This documentation is intended to be a reference
+ of the generic APIs available across different ports ("MicroPython
+ core"). Note that some ports may still omit some APIs described
+ here (e.g. due to resource constraints). Any such differences,
+ and port-specific extensions beyond MicroPython core functionality,
+ would be described in the separate port-specific documentation.
MicroPython Unix port
Unix port is one of the major :term:`MicroPython ports `.
diff --git a/docs/reference/isr_rules.rst b/docs/reference/isr_rules.rst
index 23dcfd01f..2db261c09 100644
--- a/docs/reference/isr_rules.rst
+++ b/docs/reference/isr_rules.rst
@@ -21,6 +21,7 @@ This summarises the points detailed below and lists the principal recommendation
* Keep the code as short and simple as possible.
* Avoid memory allocation: no appending to lists or insertion into dictionaries, no floating point.
+* Consider using ``micropython.schedule`` to work around the above constraint.
* Where an ISR returns multiple bytes use a pre-allocated ``bytearray``. If multiple integers are to be
shared between an ISR and the main program consider an array (``array.array``).
* Where data is shared between the main program and an ISR, consider disabling interrupts prior to accessing
@@ -79,7 +80,7 @@ example causes two LED's to flash at different rates.
self.led.toggle()
red = Foo(pyb.Timer(4, freq=1), pyb.LED(1))
- greeen = Foo(pyb.Timer(2, freq=0.8), pyb.LED(2))
+ green = Foo(pyb.Timer(2, freq=0.8), pyb.LED(2))
In this example the ``red`` instance associates timer 4 with LED 1: when a timer 4 interrupt occurs ``red.cb()``
is called causing LED 1 to change state. The ``green`` instance operates similarly: a timer 2 interrupt
@@ -158,6 +159,26 @@ On platforms with hardware floating point (such as the Pyboard) the inline ARM T
round this limitation. This is because the processor stores float values in a machine word; values can be shared
between the ISR and main program code via an array of floats.
+Using micropython.schedule
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This function enables an ISR to schedule a callback for execution "very soon". The callback is queued for
+execution which will take place at a time when the heap is not locked. Hence it can create Python objects
+and use floats. The callback is also guaranteed to run at a time when the main program has completed any
+update of Python objects, so the callback will not encounter partially updated objects.
+
+Typical usage is to handle sensor hardware. The ISR acquires data from the hardware and enables it to
+issue a further interrupt. It then schedules a callback to process the data.
+
+Scheduled callbacks should comply with the principles of interrupt handler design outlined below. This is to
+avoid problems resulting from I/O activity and the modification of shared data which can arise in any code
+which pre-empts the main program loop.
+
+Execution time needs to be considered in relation to the frequency with which interrupts can occur. If an
+interrupt occurs while the previous callback is executing, a further instance of the callback will be queued
+for execution; this will run after the current instance has completed. A sustained high interrupt repetition
+rate therefore carries a risk of unconstrained queue growth and eventual failure with a ``RuntimeError``.
+
Exceptions
----------
diff --git a/drivers/cc3000/src/ccspi.c b/drivers/cc3000/src/ccspi.c
index 64900efe4..820be809b 100644
--- a/drivers/cc3000/src/ccspi.c
+++ b/drivers/cc3000/src/ccspi.c
@@ -34,8 +34,6 @@
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "pin.h"
#include "led.h"
diff --git a/drivers/dht/dht.c b/drivers/dht/dht.c
index 6bdda44b4..5d92ae39a 100644
--- a/drivers/dht/dht.c
+++ b/drivers/dht/dht.c
@@ -40,7 +40,7 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) {
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE);
if (bufinfo.len < 5) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "buffer too small"));
+ mp_raise_ValueError("buffer too small");
}
// issue start command
diff --git a/drivers/display/ssd1306.py b/drivers/display/ssd1306.py
index 53bcb0d2d..cd358d00e 100644
--- a/drivers/display/ssd1306.py
+++ b/drivers/display/ssd1306.py
@@ -1,7 +1,6 @@
# MicroPython SSD1306 OLED driver, I2C and SPI interfaces
from micropython import const
-import time
import framebuf
@@ -32,8 +31,21 @@ def __init__(self, width, height, external_vcc):
self.external_vcc = external_vcc
self.pages = self.height // 8
self.buffer = bytearray(self.pages * self.width)
- self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MVLSB)
- self.poweron()
+ fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
+ self.framebuf = fb
+ # Provide methods for accessing FrameBuffer graphics primitives. This is a
+ # workround because inheritance from a native class is currently unsupported.
+ # http://docs.micropython.org/en/latest/pyboard/library/framebuf.html
+ self.fill = fb.fill
+ self.pixel = fb.pixel
+ self.hline = fb.hline
+ self.vline = fb.vline
+ self.line = fb.line
+ self.rect = fb.rect
+ self.fill_rect = fb.fill_rect
+ self.text = fb.text
+ self.scroll = fb.scroll
+ self.blit = fb.blit
self.init_display()
def init_display(self):
@@ -66,6 +78,9 @@ def init_display(self):
def poweroff(self):
self.write_cmd(SET_DISP | 0x00)
+ def poweron(self):
+ self.write_cmd(SET_DISP | 0x01)
+
def contrast(self, contrast):
self.write_cmd(SET_CONTRAST)
self.write_cmd(contrast)
@@ -88,18 +103,6 @@ def show(self):
self.write_cmd(self.pages - 1)
self.write_data(self.buffer)
- def fill(self, col):
- self.framebuf.fill(col)
-
- def pixel(self, x, y, col):
- self.framebuf.pixel(x, y, col)
-
- def scroll(self, dx, dy):
- self.framebuf.scroll(dx, dy)
-
- def text(self, string, x, y, col=1):
- self.framebuf.text(string, x, y, col)
-
class SSD1306_I2C(SSD1306):
def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False):
@@ -121,9 +124,6 @@ def write_data(self, buf):
self.i2c.write(buf)
self.i2c.stop()
- def poweron(self):
- pass
-
class SSD1306_SPI(SSD1306):
def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):
@@ -135,6 +135,12 @@ def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):
self.dc = dc
self.res = res
self.cs = cs
+ import time
+ self.res(1)
+ time.sleep_ms(1)
+ self.res(0)
+ time.sleep_ms(10)
+ self.res(1)
super().__init__(width, height, external_vcc)
def write_cmd(self, cmd):
@@ -152,10 +158,3 @@ def write_data(self, buf):
self.cs(0)
self.spi.write(buf)
self.cs(1)
-
- def poweron(self):
- self.res(1)
- time.sleep_ms(1)
- self.res(0)
- time.sleep_ms(10)
- self.res(1)
diff --git a/drivers/memory/spiflash.c b/drivers/memory/spiflash.c
index 214610e0a..08564d054 100644
--- a/drivers/memory/spiflash.c
+++ b/drivers/memory/spiflash.c
@@ -49,10 +49,8 @@ STATIC uint8_t buf[SECTOR_SIZE];
void mp_spiflash_init(mp_spiflash_t *self) {
mp_hal_pin_write(self->cs, 1);
mp_hal_pin_output(self->cs);
- mp_hal_pin_write(self->spi.sck, 0);
- mp_hal_pin_output(self->spi.sck);
- mp_hal_pin_output(self->spi.mosi);
- mp_hal_pin_input(self->spi.miso);
+ const mp_machine_spi_p_t *protocol = self->spi->type->protocol;
+ protocol->init(self->spi, 0, NULL, (mp_map_t*)&mp_const_empty_map);
}
STATIC void mp_spiflash_acquire_bus(mp_spiflash_t *self) {
@@ -66,7 +64,8 @@ STATIC void mp_spiflash_release_bus(mp_spiflash_t *self) {
}
STATIC void mp_spiflash_transfer(mp_spiflash_t *self, size_t len, const uint8_t *src, uint8_t *dest) {
- mp_machine_soft_spi_transfer(&self->spi.base, len, src, dest);
+ const mp_machine_spi_p_t *protocol = self->spi->type->protocol;
+ protocol->transfer(self->spi, len, src, dest);
}
STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) {
diff --git a/drivers/memory/spiflash.h b/drivers/memory/spiflash.h
index 967352b04..cd96b16f3 100644
--- a/drivers/memory/spiflash.h
+++ b/drivers/memory/spiflash.h
@@ -30,8 +30,7 @@
typedef struct _mp_spiflash_t {
mp_hal_pin_obj_t cs;
- // TODO replace with generic SPI object
- mp_machine_soft_spi_obj_t spi;
+ mp_obj_base_t *spi; // object must have protocol pointing to mp_machine_spi_p_t struct
} mp_spiflash_t;
void mp_spiflash_init(mp_spiflash_t *self);
diff --git a/drivers/nrf24l01/nrf24l01.py b/drivers/nrf24l01/nrf24l01.py
index b45c137c6..7274a7927 100644
--- a/drivers/nrf24l01/nrf24l01.py
+++ b/drivers/nrf24l01/nrf24l01.py
@@ -1,4 +1,4 @@
-"""NRF24L01 driver for Micro Python
+"""NRF24L01 driver for MicroPython
"""
from micropython import const
diff --git a/drivers/nrf24l01/nrf24l01test.py b/drivers/nrf24l01/nrf24l01test.py
index a25194d38..5413511c3 100644
--- a/drivers/nrf24l01/nrf24l01test.py
+++ b/drivers/nrf24l01/nrf24l01test.py
@@ -1,8 +1,8 @@
"""Test for nrf24l01 module."""
import struct
-import pyb
-from pyb import Pin, SPI
+import utime
+from machine import Pin, SPI
from nrf24l01 import NRF24L01
pipes = (b'\xf0\xf0\xf0\xf0\xe1', b'\xf0\xf0\xf0\xf0\xd2')
@@ -24,7 +24,7 @@ def master():
while num_successes < num_needed and num_failures < num_needed:
# stop listening and send packet
nrf.stop_listening()
- millis = pyb.millis()
+ millis = utime.ticks_ms()
led_state = max(1, (led_state << 1) & 0x0f)
print('sending:', millis, led_state)
try:
@@ -36,10 +36,10 @@ def master():
nrf.start_listening()
# wait for response, with 250ms timeout
- start_time = pyb.millis()
+ start_time = utime.ticks_ms()
timeout = False
while not nrf.any() and not timeout:
- if pyb.elapsed_millis(start_time) > 250:
+ if utime.ticks_diff(utime.ticks_ms(), start_time) > 250:
timeout = True
if timeout:
@@ -51,11 +51,11 @@ def master():
got_millis, = struct.unpack('i', nrf.recv())
# print response and round-trip delay
- print('got response:', got_millis, '(delay', pyb.millis() - got_millis, 'ms)')
+ print('got response:', got_millis, '(delay', utime.ticks_diff(utime.ticks_ms(), got_millis), 'ms)')
num_successes += 1
# delay then loop
- pyb.delay(250)
+ utime.sleep_ms(250)
print('master finished sending; successes=%d, failures=%d' % (num_successes, num_failures))
@@ -69,18 +69,19 @@ def slave():
print('NRF24L01 slave mode, waiting for packets... (ctrl-C to stop)')
while True:
- pyb.wfi()
+ machine.idle()
if nrf.any():
while nrf.any():
buf = nrf.recv()
millis, led_state = struct.unpack('ii', buf)
print('received:', millis, led_state)
- for i in range(4):
- if led_state & (1 << i):
- pyb.LED(i + 1).on()
+ for led in leds:
+ if led_state & 1:
+ led.on()
else:
- pyb.LED(i + 1).off()
- pyb.delay(15)
+ led.off()
+ led_state >>= 1
+ utime.sleep_ms(15)
nrf.stop_listening()
try:
@@ -90,6 +91,12 @@ def slave():
print('sent response')
nrf.start_listening()
+try:
+ import pyb
+ leds = [pyb.LED(i + 1) for i in range(4)]
+except:
+ leds = []
+
print('NRF24L01 test module loaded')
print('NRF24L01 pinout for test:')
print(' CE on Y4')
diff --git a/drivers/sdcard/sdcard.py b/drivers/sdcard/sdcard.py
index e749d5376..75a0c501e 100644
--- a/drivers/sdcard/sdcard.py
+++ b/drivers/sdcard/sdcard.py
@@ -1,5 +1,5 @@
"""
-Micro Python driver for SD cards using SPI bus.
+MicroPython driver for SD cards using SPI bus.
Requires an SPI bus and a CS pin. Provides readblocks and writeblocks
methods so the device can be mounted as a filesystem.
diff --git a/drivers/wiznet5k/README.md b/drivers/wiznet5k/README.md
index 4f907e0b1..88f25a2b8 100644
--- a/drivers/wiznet5k/README.md
+++ b/drivers/wiznet5k/README.md
@@ -1,6 +1,6 @@
This is the driver for the WIZnet5x00 series of Ethernet controllers.
-Adapted for Micro Python.
+Adapted for MicroPython.
Original source: https://github.com/Wiznet/W5500_EVB/tree/master/ioLibrary
Taken on: 30 August 2014
diff --git a/drivers/wiznet5k/ethernet/socket.c b/drivers/wiznet5k/ethernet/socket.c
index 129473ad4..ec25fcc79 100644
--- a/drivers/wiznet5k/ethernet/socket.c
+++ b/drivers/wiznet5k/ethernet/socket.c
@@ -52,10 +52,9 @@
#include
+#include "py/mpthread.h"
#include "socket.h"
-extern void HAL_Delay(uint32_t);
-
#define SOCK_ANY_PORT_NUM 0xC000;
static uint16_t sock_any_port = SOCK_ANY_PORT_NUM;
@@ -242,7 +241,7 @@ int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port)
#endif
return SOCKERR_TIMEOUT;
}
- HAL_Delay(1);
+ MICROPY_THREAD_YIELD();
}
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
@@ -317,6 +316,7 @@ int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len)
}
if( (sock_io_mode & (1< freesize) ) return SOCK_BUSY;
if(len <= freesize) break;
+ MICROPY_THREAD_YIELD();
}
wiz_send_data(sn, buf, len);
#if _WIZCHIP_ == 5200
@@ -368,7 +368,7 @@ int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
}
if((sock_io_mode & (1< freesize) ) return SOCK_BUSY;
if(len <= freesize) break;
- HAL_Delay(1);
+ MICROPY_THREAD_YIELD();
};
wiz_send_data(sn, buf, len);
@@ -446,7 +446,7 @@ int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t
return SOCKERR_TIMEOUT;
}
////////////
- HAL_Delay(1);
+ MICROPY_THREAD_YIELD();
}
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
@@ -486,6 +486,7 @@ int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_
if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
if( (sock_io_mode & (1<
#include "../wizchip_conf.h"
-#include "board.h"
#define _W5500_IO_BASE_ 0x00000000
diff --git a/drivers/wiznet5k/ethernet/wizchip_conf.h b/drivers/wiznet5k/ethernet/wizchip_conf.h
index 55c79ae0a..4a7a7bd69 100644
--- a/drivers/wiznet5k/ethernet/wizchip_conf.h
+++ b/drivers/wiznet5k/ethernet/wizchip_conf.h
@@ -56,7 +56,9 @@
* @todo You should select one, \b 5100, \b 5200 ,\b 5500 or etc. \n\n
* ex> #define \_WIZCHIP_ 5500
*/
+#ifndef _WIZCHIP_
#define _WIZCHIP_ 5200 // 5100, 5200, 5500
+#endif
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
#define _WIZCHIP_IO_MODE_BUS_ 0x0100 /**< Bus interface mode */
diff --git a/esp32/modules/upip.py b/esp32/modules/upip.py
deleted file mode 120000
index 20d52a4ab..000000000
--- a/esp32/modules/upip.py
+++ /dev/null
@@ -1 +0,0 @@
-../../tools/upip.py
\ No newline at end of file
diff --git a/esp32/modules/upip_utarfile.py b/esp32/modules/upip_utarfile.py
deleted file mode 120000
index 149886291..000000000
--- a/esp32/modules/upip_utarfile.py
+++ /dev/null
@@ -1 +0,0 @@
-../../tools/upip_utarfile.py
\ No newline at end of file
diff --git a/esp32/modules/upysh.py b/esp32/modules/upysh.py
deleted file mode 120000
index be89874aa..000000000
--- a/esp32/modules/upysh.py
+++ /dev/null
@@ -1 +0,0 @@
-../../../micropython-lib/upysh/upysh.py
\ No newline at end of file
diff --git a/esp32/modules/urequests.py b/esp32/modules/urequests.py
deleted file mode 120000
index 1c73a4e28..000000000
--- a/esp32/modules/urequests.py
+++ /dev/null
@@ -1 +0,0 @@
-../../../micropython-lib/urequests/urequests.py
\ No newline at end of file
diff --git a/esp8266/modules/ds18x20.py b/esp8266/modules/ds18x20.py
deleted file mode 120000
index faae59d90..000000000
--- a/esp8266/modules/ds18x20.py
+++ /dev/null
@@ -1 +0,0 @@
-../../drivers/onewire/ds18x20.py
\ No newline at end of file
diff --git a/esp8266/modules/onewire.py b/esp8266/modules/onewire.py
deleted file mode 120000
index f6ec745e8..000000000
--- a/esp8266/modules/onewire.py
+++ /dev/null
@@ -1 +0,0 @@
-../../drivers/onewire/onewire.py
\ No newline at end of file
diff --git a/esp8266/modules/upip.py b/esp8266/modules/upip.py
deleted file mode 120000
index 20d52a4ab..000000000
--- a/esp8266/modules/upip.py
+++ /dev/null
@@ -1 +0,0 @@
-../../tools/upip.py
\ No newline at end of file
diff --git a/esp8266/modules/upip_utarfile.py b/esp8266/modules/upip_utarfile.py
deleted file mode 120000
index 149886291..000000000
--- a/esp8266/modules/upip_utarfile.py
+++ /dev/null
@@ -1 +0,0 @@
-../../tools/upip_utarfile.py
\ No newline at end of file
diff --git a/examples/embedding/Makefile.upylib b/examples/embedding/Makefile.upylib
index bb48fd507..a9b653517 100644
--- a/examples/embedding/Makefile.upylib
+++ b/examples/embedding/Makefile.upylib
@@ -55,7 +55,7 @@ CFLAGS += -U _FORTIFY_SOURCE
endif
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
-# The unix port of micropython on OSX must be compiled with clang,
+# The unix port of MicroPython on OSX must be compiled with clang,
# while cross-compile ports require gcc, so we test here for OSX and
# if necessary override the value of 'CC' set in py/mkenv.mk
ifeq ($(UNAME_S),Darwin)
diff --git a/examples/embedding/hello-embed.c b/examples/embedding/hello-embed.c
index e3a484783..3473e5bcd 100644
--- a/examples/embedding/hello-embed.c
+++ b/examples/embedding/hello-embed.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/examples/embedding/mpconfigport_minimal.h b/examples/embedding/mpconfigport_minimal.h
index 87c87fa97..fa52be4ad 100644
--- a/examples/embedding/mpconfigport_minimal.h
+++ b/examples/embedding/mpconfigport_minimal.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_ALLOC_PATH_MAX (PATH_MAX)
#define MICROPY_ENABLE_GC (1)
@@ -89,7 +89,7 @@
extern const struct _mp_obj_module_t mp_module_os;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_os }, \
+ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \
#define MICROPY_PORT_ROOT_POINTERS \
diff --git a/examples/hwapi/hwconfig_console.py b/examples/hwapi/hwconfig_console.py
index 4b0b0d79b..bbcc0e816 100644
--- a/examples/hwapi/hwconfig_console.py
+++ b/examples/hwapi/hwconfig_console.py
@@ -8,6 +8,12 @@ def __init__(self, id):
def value(self, v):
print(self.id, v)
+ def on(self):
+ self.value(1)
+
+ def off(self):
+ self.value(0)
+
LED = LEDClass(1)
LED2 = LEDClass(12)
diff --git a/examples/pins.py b/examples/pins.py
index ab359f692..aafdb4813 100644
--- a/examples/pins.py
+++ b/examples/pins.py
@@ -1,5 +1,5 @@
# Print a nice list of pins, their current settings, and available afs.
-# Requires pins_af.py from stmhal/build-PYBV10/ directory.
+# Requires pins_af.py from ports/stm32/build-PYBV10/ directory.
import pyb
import pins_af
diff --git a/extmod/machine_i2c.c b/extmod/machine_i2c.c
index c0a51a6e7..5d441b1ba 100644
--- a/extmod/machine_i2c.c
+++ b/extmod/machine_i2c.c
@@ -269,7 +269,7 @@ int mp_machine_soft_i2c_readfrom(mp_obj_base_t *self_in, uint16_t addr, uint8_t
/******************************************************************************/
// MicroPython bindings for I2C
-STATIC void machine_i2c_obj_init_helper(machine_i2c_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC void machine_i2c_obj_init_helper(machine_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_scl, ARG_sda, ARG_freq, ARG_timeout };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
diff --git a/extmod/machine_mem.c b/extmod/machine_mem.c
index 88c176803..b9f16507c 100644
--- a/extmod/machine_mem.c
+++ b/extmod/machine_mem.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,8 +24,8 @@
* THE SOFTWARE.
*/
+#include "py/runtime.h"
#include "extmod/machine_mem.h"
-#include "py/nlr.h"
#if MICROPY_PY_MACHINE
diff --git a/extmod/machine_mem.h b/extmod/machine_mem.h
index 4bc9ac127..a48a52c82 100644
--- a/extmod/machine_mem.h
+++ b/extmod/machine_mem.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/extmod/machine_pinbase.c b/extmod/machine_pinbase.c
index 3c1f09483..070c5cde9 100644
--- a/extmod/machine_pinbase.c
+++ b/extmod/machine_pinbase.c
@@ -30,6 +30,7 @@
#include "py/obj.h"
#include "py/runtime.h"
#include "extmod/virtpin.h"
+#include "extmod/machine_pinbase.h"
// PinBase class
@@ -40,10 +41,8 @@ typedef struct _mp_pinbase_t {
mp_obj_base_t base;
} mp_pinbase_t;
-STATIC const mp_obj_type_t pinbase_type;
-
-STATIC mp_pinbase_t pinbase_singleton = {
- .base = { &pinbase_type },
+STATIC const mp_pinbase_t pinbase_singleton = {
+ .base = { &machine_pinbase_type },
};
STATIC mp_obj_t pinbase_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
diff --git a/extmod/machine_signal.c b/extmod/machine_signal.c
index d08931296..78d0c3fee 100644
--- a/extmod/machine_signal.c
+++ b/extmod/machine_signal.c
@@ -96,7 +96,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
if (n_args == 1) {
if (n_kw == 0) {
} else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
- invert = mp_obj_is_true(args[1]);
+ invert = mp_obj_is_true(args[2]);
} else {
goto error;
}
diff --git a/extmod/misc.h b/extmod/misc.h
index 6c13592c7..d6f6d859c 100644
--- a/extmod/misc.h
+++ b/extmod/misc.h
@@ -35,8 +35,9 @@
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj);
#if MICROPY_PY_OS_DUPTERM
+int mp_uos_dupterm_rx_chr(void);
void mp_uos_dupterm_tx_strn(const char *str, size_t len);
-void mp_uos_deactivate(const char *msg, mp_obj_t exc);
+void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc);
#else
#define mp_uos_dupterm_tx_strn(s, l)
#endif
diff --git a/extmod/modbtree.c b/extmod/modbtree.c
index 229daaf0f..5c1311532 100644
--- a/extmod/modbtree.c
+++ b/extmod/modbtree.c
@@ -29,9 +29,7 @@
#include // for declaration of global errno variable
#include
-#include "py/nlr.h"
#include "py/runtime.h"
-#include "py/runtime0.h"
#include "py/stream.h"
#if MICROPY_PY_BTREE
@@ -281,7 +279,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
}
}
-STATIC mp_obj_t btree_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_btree_t *self = MP_OBJ_TO_PTR(lhs_in);
switch (op) {
case MP_BINARY_OP_IN: {
diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c
index 779214bb7..20e40d579 100644
--- a/extmod/modframebuf.c
+++ b/extmod/modframebuf.c
@@ -27,13 +27,11 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/runtime.h"
#if MICROPY_PY_FRAMEBUF
-#include "stmhal/font_petme128_8x8.h"
+#include "ports/stm32/font_petme128_8x8.h"
typedef struct _mp_obj_framebuf_t {
mp_obj_base_t base;
@@ -549,7 +547,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
.name = MP_QSTR_FrameBuffer,
.make_new = framebuf_make_new,
.buffer_p = { .get_buffer = framebuf_get_buffer },
- .locals_dict = (mp_obj_t)&framebuf_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&framebuf_locals_dict,
};
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
@@ -578,12 +576,12 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebuf) },
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) },
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) },
- { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) },
- { MP_ROM_QSTR(MP_QSTR_MONO_VLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) },
- { MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) },
- { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_GS4_HMSB) },
- { MP_ROM_QSTR(MP_QSTR_MONO_HLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHLSB) },
- { MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHMSB) },
+ { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_ROM_INT(FRAMEBUF_MVLSB) },
+ { MP_ROM_QSTR(MP_QSTR_MONO_VLSB), MP_ROM_INT(FRAMEBUF_MVLSB) },
+ { MP_ROM_QSTR(MP_QSTR_RGB565), MP_ROM_INT(FRAMEBUF_RGB565) },
+ { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_ROM_INT(FRAMEBUF_GS4_HMSB) },
+ { MP_ROM_QSTR(MP_QSTR_MONO_HLSB), MP_ROM_INT(FRAMEBUF_MHLSB) },
+ { MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_ROM_INT(FRAMEBUF_MHMSB) },
};
STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table);
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index 01190d200..bbb01b5d7 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -5,7 +5,7 @@
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2015 Galen Hazelwood
- * Copyright (c) 2015-2016 Paul Sokolovsky
+ * Copyright (c) 2015-2017 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/objlist.h"
#include "py/runtime.h"
#include "py/stream.h"
@@ -45,6 +44,7 @@
//#include "lwip/raw.h"
#include "lwip/dns.h"
#include "lwip/tcp_impl.h"
+#include "lwip/igmp.h"
#if 0 // print debugging info
#define DEBUG_printf DEBUG_printf
@@ -52,6 +52,10 @@
#define DEBUG_printf(...) (void)0
#endif
+// All socket options should be globally distinct,
+// because we ignore option levels for efficiency.
+#define IP_ADD_MEMBERSHIP 0x400
+
// For compatibilily with older lwIP versions.
#ifndef ip_set_option
#define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt))
@@ -124,15 +128,15 @@ STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw,
ip_addr_t iplocal, ipremote;
if (!ipaddr_aton(mp_obj_str_get_str(args[1]), &iplocal)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "not a valid local IP"));
+ mp_raise_ValueError("not a valid local IP");
}
if (!ipaddr_aton(mp_obj_str_get_str(args[2]), &ipremote)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "not a valid remote IP"));
+ mp_raise_ValueError("not a valid remote IP");
}
struct netif *n = &lwip_slip_obj.lwip_netif;
if (netif_add(n, &iplocal, IP_ADDR_BROADCAST, &ipremote, NULL, slipif_init, ip_input) == NULL) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "out of memory"));
+ mp_raise_ValueError("out of memory");
}
netif_set_up(n);
netif_set_default(n);
@@ -148,8 +152,8 @@ STATIC mp_obj_t lwip_slip_status(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(lwip_slip_status_obj, lwip_slip_status);
-STATIC const mp_map_elem_t lwip_slip_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&lwip_slip_status_obj },
+STATIC const mp_rom_map_elem_t lwip_slip_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lwip_slip_status_obj) },
};
STATIC MP_DEFINE_CONST_DICT(lwip_slip_locals_dict, lwip_slip_locals_dict_table);
@@ -158,7 +162,7 @@ STATIC const mp_obj_type_t lwip_slip_type = {
{ &mp_type_type },
.name = MP_QSTR_slip,
.make_new = lwip_slip_make_new,
- .locals_dict = (mp_obj_t)&lwip_slip_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&lwip_slip_locals_dict,
};
#endif // MICROPY_PY_LWIP_SLIP
@@ -1028,7 +1032,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
break;
}
case MOD_NETWORK_SOCK_DGRAM:
- mp_not_implemented("");
+ mp_raise_NotImplementedError(NULL);
break;
}
@@ -1065,7 +1069,7 @@ STATIC mp_obj_t lwip_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_setblocking_obj, lwip_socket_setblocking);
-STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) {
(void)n_args; // always 4
lwip_socket_obj_t *socket = args[0];
@@ -1079,10 +1083,10 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
- // Integer options
- mp_int_t val = mp_obj_get_int(args[3]);
switch (opt) {
- case SOF_REUSEADDR:
+ // level: SOL_SOCKET
+ case SOF_REUSEADDR: {
+ mp_int_t val = mp_obj_get_int(args[3]);
// Options are common for UDP and TCP pcb's.
if (val) {
ip_set_option(socket->pcb.tcp, SOF_REUSEADDR);
@@ -1090,6 +1094,24 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
ip_reset_option(socket->pcb.tcp, SOF_REUSEADDR);
}
break;
+ }
+
+ // level: IPPROTO_IP
+ case IP_ADD_MEMBERSHIP: {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
+ if (bufinfo.len != sizeof(ip_addr_t) * 2) {
+ mp_raise_ValueError(NULL);
+ }
+
+ // POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
+ err_t err = igmp_joingroup((ip_addr_t*)bufinfo.buf + 1, bufinfo.buf);
+ if (err != ERR_OK) {
+ mp_raise_OSError(error_lookup_table[-err]);
+ }
+ break;
+ }
+
default:
printf("Warning: lwip.setsockopt() not implemented\n");
}
@@ -1097,7 +1119,7 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_setsockopt_obj, 4, 4, lwip_socket_setsockopt);
-STATIC mp_obj_t lwip_socket_makefile(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t lwip_socket_makefile(size_t n_args, const mp_obj_t *args) {
(void)n_args;
return args[0];
}
@@ -1160,27 +1182,27 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
return ret;
}
-STATIC const mp_map_elem_t lwip_socket_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&lwip_socket_close_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&lwip_socket_close_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_bind), (mp_obj_t)&lwip_socket_bind_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_listen), (mp_obj_t)&lwip_socket_listen_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_accept), (mp_obj_t)&lwip_socket_accept_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&lwip_socket_connect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&lwip_socket_send_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&lwip_socket_recv_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sendto), (mp_obj_t)&lwip_socket_sendto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_recvfrom), (mp_obj_t)&lwip_socket_recvfrom_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sendall), (mp_obj_t)&lwip_socket_sendall_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_settimeout), (mp_obj_t)&lwip_socket_settimeout_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_setblocking), (mp_obj_t)&lwip_socket_setblocking_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_setsockopt), (mp_obj_t)&lwip_socket_setsockopt_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&lwip_socket_makefile_obj },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
+STATIC const mp_rom_map_elem_t lwip_socket_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&lwip_socket_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&lwip_socket_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&lwip_socket_bind_obj) },
+ { MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&lwip_socket_listen_obj) },
+ { MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&lwip_socket_accept_obj) },
+ { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&lwip_socket_connect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&lwip_socket_send_obj) },
+ { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&lwip_socket_recv_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&lwip_socket_sendto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_recvfrom), MP_ROM_PTR(&lwip_socket_recvfrom_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sendall), MP_ROM_PTR(&lwip_socket_sendall_obj) },
+ { MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&lwip_socket_settimeout_obj) },
+ { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&lwip_socket_setblocking_obj) },
+ { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&lwip_socket_setsockopt_obj) },
+ { MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&lwip_socket_makefile_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
};
STATIC MP_DEFINE_CONST_DICT(lwip_socket_locals_dict, lwip_socket_locals_dict_table);
@@ -1196,7 +1218,7 @@ STATIC const mp_obj_type_t lwip_socket_type = {
.print = lwip_socket_print,
.make_new = lwip_socket_make_new,
.protocol = &lwip_socket_stream_p,
- .locals_dict = (mp_obj_t)&lwip_socket_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&lwip_socket_locals_dict,
};
/******************************************************************************/
@@ -1321,27 +1343,30 @@ MP_DEFINE_CONST_FUN_OBJ_0(lwip_print_pcbs_obj, lwip_print_pcbs);
#ifdef MICROPY_PY_LWIP
-STATIC const mp_map_elem_t mp_module_lwip_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_lwip) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&mod_lwip_reset_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&mod_lwip_callback_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&lwip_getaddrinfo_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_print_pcbs), (mp_obj_t)&lwip_print_pcbs_obj },
+STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_lwip) },
+ { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&mod_lwip_reset_obj) },
+ { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&mod_lwip_callback_obj) },
+ { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&lwip_getaddrinfo_obj) },
+ { MP_ROM_QSTR(MP_QSTR_print_pcbs), MP_ROM_PTR(&lwip_print_pcbs_obj) },
// objects
- { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&lwip_socket_type },
+ { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&lwip_socket_type) },
#ifdef MICROPY_PY_LWIP_SLIP
- { MP_OBJ_NEW_QSTR(MP_QSTR_slip), (mp_obj_t)&lwip_slip_type },
+ { MP_ROM_QSTR(MP_QSTR_slip), MP_ROM_PTR(&lwip_slip_type) },
#endif
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET6), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET6) },
+ { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) },
+ { MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(MOD_NETWORK_AF_INET6) },
+
+ { MP_ROM_QSTR(MP_QSTR_SOCK_STREAM), MP_ROM_INT(MOD_NETWORK_SOCK_STREAM) },
+ { MP_ROM_QSTR(MP_QSTR_SOCK_DGRAM), MP_ROM_INT(MOD_NETWORK_SOCK_DGRAM) },
+ { MP_ROM_QSTR(MP_QSTR_SOCK_RAW), MP_ROM_INT(MOD_NETWORK_SOCK_RAW) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_DGRAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_RAW), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_RAW) },
+ { MP_ROM_QSTR(MP_QSTR_SOL_SOCKET), MP_ROM_INT(1) },
+ { MP_ROM_QSTR(MP_QSTR_SO_REUSEADDR), MP_ROM_INT(SOF_REUSEADDR) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOL_SOCKET), MP_OBJ_NEW_SMALL_INT(1) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SO_REUSEADDR), MP_OBJ_NEW_SMALL_INT(SOF_REUSEADDR) },
+ { MP_ROM_QSTR(MP_QSTR_IPPROTO_IP), MP_ROM_INT(0) },
+ { MP_ROM_QSTR(MP_QSTR_IP_ADD_MEMBERSHIP), MP_ROM_INT(IP_ADD_MEMBERSHIP) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table);
diff --git a/extmod/modonewire.c b/extmod/modonewire.c
index 8583cc1c2..53c9456c2 100644
--- a/extmod/modonewire.c
+++ b/extmod/modonewire.c
@@ -143,15 +143,15 @@ STATIC mp_obj_t onewire_crc8(mp_obj_t data) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_crc8_obj, onewire_crc8);
-STATIC const mp_map_elem_t onewire_module_globals_table[] = {
+STATIC const mp_rom_map_elem_t onewire_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_onewire) },
- { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR((mp_obj_t)&onewire_reset_obj) },
- { MP_ROM_QSTR(MP_QSTR_readbit), MP_ROM_PTR((mp_obj_t)&onewire_readbit_obj) },
- { MP_ROM_QSTR(MP_QSTR_readbyte), MP_ROM_PTR((mp_obj_t)&onewire_readbyte_obj) },
- { MP_ROM_QSTR(MP_QSTR_writebit), MP_ROM_PTR((mp_obj_t)&onewire_writebit_obj) },
- { MP_ROM_QSTR(MP_QSTR_writebyte), MP_ROM_PTR((mp_obj_t)&onewire_writebyte_obj) },
- { MP_ROM_QSTR(MP_QSTR_crc8), MP_ROM_PTR((mp_obj_t)&onewire_crc8_obj) },
+ { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&onewire_reset_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readbit), MP_ROM_PTR(&onewire_readbit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readbyte), MP_ROM_PTR(&onewire_readbyte_obj) },
+ { MP_ROM_QSTR(MP_QSTR_writebit), MP_ROM_PTR(&onewire_writebit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_writebyte), MP_ROM_PTR(&onewire_writebyte_obj) },
+ { MP_ROM_QSTR(MP_QSTR_crc8), MP_ROM_PTR(&onewire_crc8_obj) },
};
STATIC MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table);
diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c
index 4dda3c442..8256a50cf 100644
--- a/extmod/modubinascii.c
+++ b/extmod/modubinascii.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,13 +28,10 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "extmod/modubinascii.h"
-#include "uzlib/tinf.h"
-
mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) {
// Second argument is for an extension to allow a separator to be used
// between values.
@@ -105,54 +102,64 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
}
MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_unhexlify_obj, mod_binascii_unhexlify);
+// If ch is a character in the base64 alphabet, and is not a pad character, then
+// the corresponding integer between 0 and 63, inclusively, is returned.
+// Otherwise, -1 is returned.
+static int mod_binascii_sextet(byte ch) {
+ if (ch >= 'A' && ch <= 'Z') {
+ return ch - 'A';
+ } else if (ch >= 'a' && ch <= 'z') {
+ return ch - 'a' + 26;
+ } else if (ch >= '0' && ch <= '9') {
+ return ch - '0' + 52;
+ } else if (ch == '+') {
+ return 62;
+ } else if (ch == '/') {
+ return 63;
+ } else {
+ return -1;
+ }
+}
+
mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
- if (bufinfo.len % 4 != 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "incorrect padding"));
- }
+ byte *in = bufinfo.buf;
vstr_t vstr;
- byte *in = bufinfo.buf;
- if (bufinfo.len == 0) {
- vstr_init_len(&vstr, 0);
- }
- else {
- vstr_init_len(&vstr, ((bufinfo.len / 4) * 3) - ((in[bufinfo.len-1] == '=') ? ((in[bufinfo.len-2] == '=') ? 2 : 1 ) : 0));
- }
- byte *out = (byte*)vstr.buf;
- for (mp_uint_t i = bufinfo.len; i; i -= 4) {
- char hold[4];
- for (int j = 4; j--;) {
- if (in[j] >= 'A' && in[j] <= 'Z') {
- hold[j] = in[j] - 'A';
- } else if (in[j] >= 'a' && in[j] <= 'z') {
- hold[j] = in[j] - 'a' + 26;
- } else if (in[j] >= '0' && in[j] <= '9') {
- hold[j] = in[j] - '0' + 52;
- } else if (in[j] == '+') {
- hold[j] = 62;
- } else if (in[j] == '/') {
- hold[j] = 63;
- } else if (in[j] == '=') {
- if (j < 2 || i > 4) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "incorrect padding"));
- }
- hold[j] = 64;
- } else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid character"));
+ vstr_init(&vstr, (bufinfo.len / 4) * 3 + 1); // Potentially over-allocate
+ byte *out = (byte *)vstr.buf;
+
+ uint shift = 0;
+ int nbits = 0; // Number of meaningful bits in shift
+ bool hadpad = false; // Had a pad character since last valid character
+ for (size_t i = 0; i < bufinfo.len; i++) {
+ if (in[i] == '=') {
+ if ((nbits == 2) || ((nbits == 4) && hadpad)) {
+ nbits = 0;
+ break;
}
+ hadpad = true;
}
- in += 4;
- *out++ = (hold[0]) << 2 | (hold[1]) >> 4;
- if (hold[2] != 64) {
- *out++ = (hold[1] & 0x0F) << 4 | hold[2] >> 2;
- if (hold[3] != 64) {
- *out++ = (hold[2] & 0x03) << 6 | hold[3];
- }
+ int sextet = mod_binascii_sextet(in[i]);
+ if (sextet == -1) {
+ continue;
+ }
+ hadpad = false;
+ shift = (shift << 6) | sextet;
+ nbits += 6;
+
+ if (nbits >= 8) {
+ nbits -= 8;
+ out[vstr.len++] = (shift >> nbits) & 0xFF;
}
}
+
+ if (nbits) {
+ mp_raise_ValueError("incorrect padding");
+ }
+
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj, mod_binascii_a2b_base64);
@@ -184,7 +191,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
*out++ = (in[0] & 0x03) << 4;
*out++ = 64;
}
- *out++ = 64;
+ *out = 64;
}
// Second pass, we convert number base 64 values to actual base64 ascii encoding
@@ -211,6 +218,8 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj, mod_binascii_b2a_base64);
#if MICROPY_PY_UBINASCII_CRC32
+#include "uzlib/tinf.h"
+
mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
diff --git a/extmod/modubinascii.h b/extmod/modubinascii.h
index 6c0156fc4..fb3169267 100644
--- a/extmod/modubinascii.h
+++ b/extmod/modubinascii.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/extmod/moductypes.c b/extmod/moductypes.c
index d2d2e85de..c3da083cf 100644
--- a/extmod/moductypes.c
+++ b/extmod/moductypes.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/objtuple.h"
#include "py/binary.h"
@@ -118,7 +117,7 @@ typedef struct _mp_obj_uctypes_struct_t {
} mp_obj_uctypes_struct_t;
STATIC NORETURN void syntax_error(void) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "syntax error in uctypes descriptor"));
+ mp_raise_TypeError("syntax error in uctypes descriptor");
}
STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
@@ -215,7 +214,7 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
// but scalar structure field is lowered into native Python int, so all
// type info is lost. So, we cannot say if it's scalar type description,
// or such lowered scalar.
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Cannot unambiguously get sizeof scalar"));
+ mp_raise_TypeError("Cannot unambiguously get sizeof scalar");
}
syntax_error();
}
@@ -281,13 +280,13 @@ STATIC mp_obj_t uctypes_struct_sizeof(mp_obj_t obj_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_sizeof_obj, uctypes_struct_sizeof);
-STATIC inline mp_obj_t get_unaligned(uint val_type, byte *p, int big_endian) {
+static inline mp_obj_t get_unaligned(uint val_type, byte *p, int big_endian) {
char struct_type = big_endian ? '>' : '<';
static const char type2char[16] = "BbHhIiQq------fd";
return mp_binary_get_val(struct_type, type2char[val_type], &p);
}
-STATIC inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_t val) {
+static inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_t val) {
char struct_type = big_endian ? '>' : '<';
static const char type2char[16] = "BbHhIiQq------fd";
mp_binary_set_val(struct_type, type2char[val_type], val, &p);
@@ -393,7 +392,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
// TODO: Support at least OrderedDict in addition
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "struct: no fields"));
+ mp_raise_TypeError("struct: no fields");
}
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
@@ -526,7 +525,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
} else {
// load / store
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_tuple)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "struct: cannot index"));
+ mp_raise_TypeError("struct: cannot index");
}
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c
index 13525cc3f..3fad69247 100644
--- a/extmod/moduhashlib.c
+++ b/extmod/moduhashlib.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#if MICROPY_PY_UHASHLIB
diff --git a/extmod/moduheapq.c b/extmod/moduheapq.c
index 567ee83da..71c15368b 100644
--- a/extmod/moduheapq.c
+++ b/extmod/moduheapq.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,9 +24,7 @@
* THE SOFTWARE.
*/
-#include "py/nlr.h"
#include "py/objlist.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#if MICROPY_PY_UHEAPQ
@@ -35,7 +33,7 @@
STATIC mp_obj_list_t *get_heap(mp_obj_t heap_in) {
if (!MP_OBJ_IS_TYPE(heap_in, &mp_type_list)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "heap must be a list"));
+ mp_raise_TypeError("heap must be a list");
}
return MP_OBJ_TO_PTR(heap_in);
}
diff --git a/extmod/modujson.c b/extmod/modujson.c
index f94ec7db8..f14682d26 100644
--- a/extmod/modujson.c
+++ b/extmod/modujson.c
@@ -26,7 +26,6 @@
#include
-#include "py/nlr.h"
#include "py/objlist.h"
#include "py/objstringio.h"
#include "py/parsenum.h"
@@ -269,7 +268,7 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
return stack_top;
fail:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "syntax error in JSON"));
+ mp_raise_ValueError("syntax error in JSON");
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load);
diff --git a/extmod/modurandom.c b/extmod/modurandom.c
index 4b63dace4..1512a3fd4 100644
--- a/extmod/modurandom.c
+++ b/extmod/modurandom.c
@@ -27,7 +27,6 @@
#include
#include
-//#include "py/nlr.h"
#include "py/runtime.h"
#if MICROPY_PY_URANDOM
diff --git a/extmod/modure.c b/extmod/modure.c
index b4c7a364f..78de4706d 100644
--- a/extmod/modure.c
+++ b/extmod/modure.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,13 +28,15 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/objstr.h"
+#include "py/stackctrl.h"
#if MICROPY_PY_URE
+#define re1_5_stack_chk() MP_STACK_CHECK()
+
#include "re1.5/re1.5.h"
#define FLAG_DEBUG 0x1000
@@ -156,7 +158,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, caps[0] - subj.begin);
mp_obj_list_append(retval, s);
if (self->re.sub > 0) {
- mp_not_implemented("Splitting with sub-captures");
+ mp_raise_NotImplementedError("Splitting with sub-captures");
}
subj.begin = caps[1];
if (maxsplit > 0 && --maxsplit == 0) {
@@ -200,7 +202,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
int error = re1_5_compilecode(&o->re, re_str);
if (error != 0) {
error:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Error in regex"));
+ mp_raise_ValueError("Error in regex");
}
if (flags & FLAG_DEBUG) {
re1_5_dumpcode(&o->re);
diff --git a/extmod/moduselect.c b/extmod/moduselect.c
index 88dd29a49..a9f25c195 100644
--- a/extmod/moduselect.c
+++ b/extmod/moduselect.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -362,10 +362,10 @@ STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uselect) },
{ MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) },
{ MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mp_select_poll_obj) },
- { MP_ROM_QSTR(MP_QSTR_POLLIN), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_RD) },
- { MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_WR) },
- { MP_ROM_QSTR(MP_QSTR_POLLERR), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_ERR) },
- { MP_ROM_QSTR(MP_QSTR_POLLHUP), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_HUP) },
+ { MP_ROM_QSTR(MP_QSTR_POLLIN), MP_ROM_INT(MP_STREAM_POLL_RD) },
+ { MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_ROM_INT(MP_STREAM_POLL_WR) },
+ { MP_ROM_QSTR(MP_QSTR_POLLERR), MP_ROM_INT(MP_STREAM_POLL_ERR) },
+ { MP_ROM_QSTR(MP_QSTR_POLLHUP), MP_ROM_INT(MP_STREAM_POLL_HUP) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table);
diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c
index be1aa0359..3ad65ebf3 100644
--- a/extmod/modussl_axtls.c
+++ b/extmod/modussl_axtls.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
@@ -52,7 +51,11 @@ struct ssl_args {
STATIC const mp_obj_type_t ussl_socket_type;
STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
+#if MICROPY_PY_USSL_FINALISER
+ mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
+#else
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
+#endif
o->base.type = &ussl_socket_type;
o->buf = NULL;
o->bytes_left = 0;
@@ -153,7 +156,7 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
// Currently supports only blocking mode
(void)self_in;
if (!mp_obj_is_true(flag_in)) {
- mp_not_implemented("");
+ mp_raise_NotImplementedError(NULL);
}
return mp_const_none;
}
@@ -179,6 +182,9 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&socket_close_obj) },
+#if MICROPY_PY_USSL_FINALISER
+ { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&socket_close_obj) },
+#endif
};
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c
index 597eaee73..197a0651c 100644
--- a/extmod/modussl_mbedtls.c
+++ b/extmod/modussl_mbedtls.c
@@ -31,7 +31,6 @@
#include
#include // needed because mp_is_nonblocking_error uses system error codes
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
@@ -66,23 +65,30 @@ struct ssl_args {
STATIC const mp_obj_type_t ussl_socket_type;
-static void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) {
+#ifdef MBEDTLS_DEBUG_C
+STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) {
+ (void)ctx;
+ (void)level;
printf("DBG:%s:%04d: %s\n", file, line, str);
}
+#endif
// TODO: FIXME!
-int null_entropy_func(void *data, unsigned char *output, size_t len) {
+STATIC int null_entropy_func(void *data, unsigned char *output, size_t len) {
+ (void)data;
+ (void)output;
+ (void)len;
// enjoy random bytes
return 0;
}
-int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
+STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
mp_obj_t sock = *(mp_obj_t*)ctx;
const mp_stream_p_t *sock_stream = mp_get_stream_raise(sock, MP_STREAM_OP_WRITE);
int err;
- int out_sz = sock_stream->write(sock, buf, len, &err);
+ mp_uint_t out_sz = sock_stream->write(sock, buf, len, &err);
if (out_sz == MP_STREAM_ERROR) {
if (mp_is_nonblocking_error(err)) {
return MBEDTLS_ERR_SSL_WANT_WRITE;
@@ -93,13 +99,13 @@ int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
}
}
-int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
+STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
mp_obj_t sock = *(mp_obj_t*)ctx;
const mp_stream_p_t *sock_stream = mp_get_stream_raise(sock, MP_STREAM_OP_READ);
int err;
- int out_sz = sock_stream->read(sock, buf, len, &err);
+ mp_uint_t out_sz = sock_stream->read(sock, buf, len, &err);
if (out_sz == MP_STREAM_ERROR) {
if (mp_is_nonblocking_error(err)) {
return MBEDTLS_ERR_SSL_WANT_READ;
@@ -112,7 +118,11 @@ int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
+#if MICROPY_PY_USSL_FINALISER
+ mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
+#else
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
+#endif
o->base.type = &ussl_socket_type;
int ret;
@@ -122,15 +132,16 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
mbedtls_x509_crt_init(&o->cert);
mbedtls_pk_init(&o->pkey);
mbedtls_ctr_drbg_init(&o->ctr_drbg);
+ #ifdef MBEDTLS_DEBUG_C
// Debug level (0-4)
mbedtls_debug_set_threshold(0);
+ #endif
mbedtls_entropy_init(&o->entropy);
const byte seed[] = "upy";
ret = mbedtls_ctr_drbg_seed(&o->ctr_drbg, null_entropy_func/*mbedtls_entropy_func*/, &o->entropy, seed, sizeof(seed));
if (ret != 0) {
- printf("ret=%d\n", ret);
- assert(0);
+ goto cleanup;
}
ret = mbedtls_ssl_config_defaults(&o->conf,
@@ -138,23 +149,25 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT);
if (ret != 0) {
- assert(0);
+ goto cleanup;
}
mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_NONE);
mbedtls_ssl_conf_rng(&o->conf, mbedtls_ctr_drbg_random, &o->ctr_drbg);
+ #ifdef MBEDTLS_DEBUG_C
mbedtls_ssl_conf_dbg(&o->conf, mbedtls_debug, NULL);
+ #endif
ret = mbedtls_ssl_setup(&o->ssl, &o->conf);
if (ret != 0) {
- assert(0);
+ goto cleanup;
}
if (args->server_hostname.u_obj != mp_const_none) {
const char *sni = mp_obj_str_get_str(args->server_hostname.u_obj);
ret = mbedtls_ssl_set_hostname(&o->ssl, sni);
if (ret != 0) {
- assert(0);
+ goto cleanup;
}
}
@@ -180,14 +193,38 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
while ((ret = mbedtls_ssl_handshake(&o->ssl)) != 0) {
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
- //assert(0);
printf("mbedtls_ssl_handshake error: -%x\n", -ret);
- mp_raise_OSError(MP_EIO);
+ goto cleanup;
}
}
return o;
+
+cleanup:
+ mbedtls_pk_free(&o->pkey);
+ mbedtls_x509_crt_free(&o->cert);
+ mbedtls_x509_crt_free(&o->cacert);
+ mbedtls_ssl_free(&o->ssl);
+ mbedtls_ssl_config_free(&o->conf);
+ mbedtls_ctr_drbg_free(&o->ctr_drbg);
+ mbedtls_entropy_free(&o->entropy);
+
+ if (ret == MBEDTLS_ERR_SSL_ALLOC_FAILED) {
+ mp_raise_OSError(MP_ENOMEM);
+ } else {
+ mp_raise_OSError(MP_EIO);
+ }
+}
+
+STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) {
+ mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
+ if (!mp_obj_is_true(binary_form)) {
+ mp_raise_NotImplementedError(NULL);
+ }
+ const mbedtls_x509_crt* peer_cert = mbedtls_ssl_get_peer_cert(&o->ssl);
+ return mp_obj_new_bytes(peer_cert->raw.p, peer_cert->raw.len);
}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ssl_getpeercert_obj, mod_ssl_getpeercert);
STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind;
@@ -259,6 +296,10 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&socket_close_obj) },
+#if MICROPY_PY_USSL_FINALISER
+ { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&socket_close_obj) },
+#endif
+ { MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) },
};
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
diff --git a/extmod/modutimeq.c b/extmod/modutimeq.c
index a19b3fda9..620e7484b 100644
--- a/extmod/modutimeq.c
+++ b/extmod/modutimeq.c
@@ -27,9 +27,7 @@
#include
-#include "py/nlr.h"
#include "py/objlist.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/smallint.h"
@@ -148,7 +146,7 @@ STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
}
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);
if (!MP_OBJ_IS_TYPE(list_ref, &mp_type_list) || ret->len < 3) {
- mp_raise_TypeError("");
+ mp_raise_TypeError(NULL);
}
struct qentry *item = &heap->items[0];
@@ -189,7 +187,7 @@ STATIC mp_obj_t mod_utimeq_dump(mp_obj_t heap_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_dump_obj, mod_utimeq_dump);
#endif
-STATIC mp_obj_t utimeq_unary_op(mp_uint_t op, mp_obj_t self_in) {
+STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
mp_obj_utimeq_t *self = MP_OBJ_TO_PTR(self_in);
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c
index 6e045c403..e9af07370 100644
--- a/extmod/moduzlib.c
+++ b/extmod/moduzlib.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "py/mperrno.h"
@@ -92,7 +91,7 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size
dict_opt = uzlib_zlib_parse_header(&o->decomp);
if (dict_opt < 0) {
header_error:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "compression header"));
+ mp_raise_ValueError("compression header");
}
dict_sz = 1 << dict_opt;
} else {
diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c
index 9e3f16fe7..3aba5c0f1 100644
--- a/extmod/modwebrepl.c
+++ b/extmod/modwebrepl.c
@@ -28,8 +28,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "py/builtin.h"
@@ -310,18 +308,18 @@ STATIC mp_obj_t webrepl_set_password(mp_obj_t passwd_in) {
size_t len;
const char *passwd = mp_obj_str_get_data(passwd_in, &len);
if (len > sizeof(webrepl_passwd) - 1) {
- mp_raise_ValueError("");
+ mp_raise_ValueError(NULL);
}
strcpy(webrepl_passwd, passwd);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(webrepl_set_password_obj, webrepl_set_password);
-STATIC const mp_map_elem_t webrepl_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&webrepl_close_obj },
+STATIC const mp_rom_map_elem_t webrepl_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
+ { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&webrepl_close_obj) },
};
STATIC MP_DEFINE_CONST_DICT(webrepl_locals_dict, webrepl_locals_dict_table);
@@ -335,13 +333,13 @@ STATIC const mp_obj_type_t webrepl_type = {
.name = MP_QSTR__webrepl,
.make_new = webrepl_make_new,
.protocol = &webrepl_stream_p,
- .locals_dict = (mp_obj_t)&webrepl_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&webrepl_locals_dict,
};
-STATIC const mp_map_elem_t webrepl_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR__webrepl) },
- { MP_OBJ_NEW_QSTR(MP_QSTR__webrepl), (mp_obj_t)&webrepl_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_password), (mp_obj_t)&webrepl_set_password_obj },
+STATIC const mp_rom_map_elem_t webrepl_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__webrepl) },
+ { MP_ROM_QSTR(MP_QSTR__webrepl), MP_ROM_PTR(&webrepl_type) },
+ { MP_ROM_QSTR(MP_QSTR_password), MP_ROM_PTR(&webrepl_set_password_obj) },
};
STATIC MP_DEFINE_CONST_DICT(webrepl_module_globals, webrepl_module_globals_table);
diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c
index 6c6e32c1a..a651164b2 100644
--- a/extmod/modwebsocket.c
+++ b/extmod/modwebsocket.c
@@ -28,8 +28,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "extmod/modwebsocket.h"
diff --git a/extmod/re1.5/compilecode.c b/extmod/re1.5/compilecode.c
index e4635f034..3267a4190 100644
--- a/extmod/re1.5/compilecode.c
+++ b/extmod/re1.5/compilecode.c
@@ -55,7 +55,7 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
for (cnt = 0; *re != ']'; re++, cnt++) {
if (!*re) return NULL;
EMIT(PC++, *re);
- if (re[1] == '-') {
+ if (re[1] == '-' && re[2] != ']') {
re += 2;
}
EMIT(PC++, *re);
diff --git a/extmod/re1.5/re1.5.h b/extmod/re1.5/re1.5.h
index 815c5d33d..ba6f97b74 100644
--- a/extmod/re1.5/re1.5.h
+++ b/extmod/re1.5/re1.5.h
@@ -48,6 +48,9 @@ void printre(Regexp*);
#ifndef re1_5_fatal
void re1_5_fatal(char*);
#endif
+#ifndef re1_5_stack_chk
+#define re1_5_stack_chk()
+#endif
void *mal(int);
struct Prog
diff --git a/extmod/re1.5/recursiveloop.c b/extmod/re1.5/recursiveloop.c
index e8fef0304..bb337decf 100644
--- a/extmod/re1.5/recursiveloop.c
+++ b/extmod/re1.5/recursiveloop.c
@@ -9,7 +9,9 @@ recursiveloop(char *pc, const char *sp, Subject *input, const char **subp, int n
{
const char *old;
int off;
-
+
+ re1_5_stack_chk();
+
for(;;) {
if(inst_is_consumer(*pc)) {
// If we need to match a character, but there's none left, it's fail
diff --git a/extmod/uos_dupterm.c b/extmod/uos_dupterm.c
index 29a62ab89..f77cff577 100644
--- a/extmod/uos_dupterm.c
+++ b/extmod/uos_dupterm.c
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2016 Paul Sokolovsky
+ * Copyright (c) 2017 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,66 +28,118 @@
#include
#include "py/mpconfig.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/objtuple.h"
#include "py/objarray.h"
#include "py/stream.h"
+#include "lib/utils/interrupt_char.h"
#if MICROPY_PY_OS_DUPTERM
-void mp_uos_deactivate(const char *msg, mp_obj_t exc) {
- mp_obj_t term = MP_STATE_PORT(term_obj);
- MP_STATE_PORT(term_obj) = NULL;
+void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) {
+ mp_obj_t term = MP_STATE_VM(dupterm_objs[dupterm_idx]);
+ MP_STATE_VM(dupterm_objs[dupterm_idx]) = MP_OBJ_NULL;
mp_printf(&mp_plat_print, msg);
if (exc != MP_OBJ_NULL) {
mp_obj_print_exception(&mp_plat_print, exc);
}
- mp_stream_close(term);
+ nlr_buf_t nlr;
+ if (nlr_push(&nlr) == 0) {
+ mp_stream_close(term);
+ nlr_pop();
+ } else {
+ // Ignore any errors during stream closing
+ }
+}
+
+int mp_uos_dupterm_rx_chr(void) {
+ for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) {
+ if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) {
+ continue;
+ }
+
+ nlr_buf_t nlr;
+ if (nlr_push(&nlr) == 0) {
+ mp_obj_t readinto_m[3];
+ mp_load_method(MP_STATE_VM(dupterm_objs[idx]), MP_QSTR_readinto, readinto_m);
+ readinto_m[2] = MP_STATE_VM(dupterm_arr_obj);
+ mp_obj_t res = mp_call_method_n_kw(1, 0, readinto_m);
+ if (res == mp_const_none) {
+ nlr_pop();
+ } else if (res == MP_OBJ_NEW_SMALL_INT(0)) {
+ nlr_pop();
+ mp_uos_deactivate(idx, "dupterm: EOF received, deactivating\n", MP_OBJ_NULL);
+ } else {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(MP_STATE_VM(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ);
+ nlr_pop();
+ if (*(byte*)bufinfo.buf == mp_interrupt_char) {
+ // Signal keyboard interrupt to be raised as soon as the VM resumes
+ mp_keyboard_interrupt();
+ return -2;
+ }
+ return *(byte*)bufinfo.buf;
+ }
+ } else {
+ mp_uos_deactivate(idx, "dupterm: Exception in read() method, deactivating: ", nlr.ret_val);
+ }
+ }
+
+ // No chars available
+ return -1;
}
void mp_uos_dupterm_tx_strn(const char *str, size_t len) {
- if (MP_STATE_PORT(term_obj) != MP_OBJ_NULL) {
+ for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) {
+ if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) {
+ continue;
+ }
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_obj_t write_m[3];
- mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_write, write_m);
+ mp_load_method(MP_STATE_VM(dupterm_objs[idx]), MP_QSTR_write, write_m);
- mp_obj_array_t *arr = MP_OBJ_TO_PTR(MP_STATE_PORT(dupterm_arr_obj));
+ mp_obj_array_t *arr = MP_OBJ_TO_PTR(MP_STATE_VM(dupterm_arr_obj));
void *org_items = arr->items;
arr->items = (void*)str;
arr->len = len;
- write_m[2] = MP_STATE_PORT(dupterm_arr_obj);
+ write_m[2] = MP_STATE_VM(dupterm_arr_obj);
mp_call_method_n_kw(1, 0, write_m);
- arr = MP_OBJ_TO_PTR(MP_STATE_PORT(dupterm_arr_obj));
+ arr = MP_OBJ_TO_PTR(MP_STATE_VM(dupterm_arr_obj));
arr->items = org_items;
arr->len = 1;
nlr_pop();
} else {
- mp_uos_deactivate("dupterm: Exception in write() method, deactivating: ", nlr.ret_val);
+ mp_uos_deactivate(idx, "dupterm: Exception in write() method, deactivating: ", nlr.ret_val);
}
}
}
-STATIC mp_obj_t mp_uos_dupterm(mp_uint_t n_args, const mp_obj_t *args) {
- if (n_args == 0) {
- if (MP_STATE_PORT(term_obj) == MP_OBJ_NULL) {
- return mp_const_none;
- } else {
- return MP_STATE_PORT(term_obj);
- }
+STATIC mp_obj_t mp_uos_dupterm(size_t n_args, const mp_obj_t *args) {
+ mp_int_t idx = 0;
+ if (n_args == 2) {
+ idx = mp_obj_get_int(args[1]);
+ }
+
+ if (idx < 0 || idx >= MICROPY_PY_OS_DUPTERM) {
+ mp_raise_ValueError("invalid dupterm index");
+ }
+
+ mp_obj_t previous_obj = MP_STATE_VM(dupterm_objs[idx]);
+ if (previous_obj == MP_OBJ_NULL) {
+ previous_obj = mp_const_none;
+ }
+ if (args[0] == mp_const_none) {
+ MP_STATE_VM(dupterm_objs[idx]) = MP_OBJ_NULL;
} else {
- if (args[0] == mp_const_none) {
- MP_STATE_PORT(term_obj) = MP_OBJ_NULL;
- } else {
- MP_STATE_PORT(term_obj) = args[0];
- if (MP_STATE_PORT(dupterm_arr_obj) == MP_OBJ_NULL) {
- MP_STATE_PORT(dupterm_arr_obj) = mp_obj_new_bytearray(1, "");
- }
+ MP_STATE_VM(dupterm_objs[idx]) = args[0];
+ if (MP_STATE_VM(dupterm_arr_obj) == MP_OBJ_NULL) {
+ MP_STATE_VM(dupterm_arr_obj) = mp_obj_new_bytearray(1, "");
}
- return mp_const_none;
}
+
+ return previous_obj;
}
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj, 0, 1, mp_uos_dupterm);
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj, 1, 2, mp_uos_dupterm);
#endif
diff --git a/extmod/vfs.c b/extmod/vfs.c
index 3bdce80db..44ad8ffad 100644
--- a/extmod/vfs.c
+++ b/extmod/vfs.c
@@ -27,7 +27,6 @@
#include
#include
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/objstr.h"
#include "py/mperrno.h"
@@ -39,6 +38,10 @@
#include "extmod/vfs_fat.h"
#endif
+// For mp_vfs_proxy_call, the maximum number of additional args that can be passed.
+// A fixed maximum size is used to avoid the need for a costly variable array.
+#define PROXY_MAX_ARGS (2)
+
// path is the path to lookup and *path_out holds the path within the VFS
// object (starts with / if an absolute path).
// Returns MP_VFS_ROOT for root dir (and then path_out is undefined) and
@@ -98,6 +101,7 @@ STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) {
}
STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) {
+ assert(n_args <= PROXY_MAX_ARGS);
if (vfs == MP_VFS_NONE) {
// mount point not found
mp_raise_OSError(MP_ENODEV);
@@ -106,7 +110,7 @@ STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_
// can't do operation on root dir
mp_raise_OSError(MP_EPERM);
}
- mp_obj_t meth[n_args + 2];
+ mp_obj_t meth[2 + PROXY_MAX_ARGS];
mp_load_method(vfs->obj, meth_name, meth);
if (args != NULL) {
memcpy(meth + 2, args, n_args * sizeof(*args));
diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c
index 0ec3fe6d2..22346bdf1 100644
--- a/extmod/vfs_fat.c
+++ b/extmod/vfs_fat.c
@@ -33,7 +33,6 @@
#endif
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "lib/oofatfs/ff.h"
@@ -243,7 +242,7 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
t->items[3] = MP_OBJ_NEW_SMALL_INT(0); // st_nlink
t->items[4] = MP_OBJ_NEW_SMALL_INT(0); // st_uid
t->items[5] = MP_OBJ_NEW_SMALL_INT(0); // st_gid
- t->items[6] = MP_OBJ_NEW_SMALL_INT(fno.fsize); // st_size
+ t->items[6] = mp_obj_new_int_from_uint(fno.fsize); // st_size
t->items[7] = MP_OBJ_NEW_SMALL_INT(seconds); // st_atime
t->items[8] = MP_OBJ_NEW_SMALL_INT(seconds); // st_mtime
t->items[9] = MP_OBJ_NEW_SMALL_INT(seconds); // st_ctime
diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h
index 63c4abb82..443e4eda8 100644
--- a/extmod/vfs_fat.h
+++ b/extmod/vfs_fat.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c
index 24c00ffba..ff23c6b0c 100644
--- a/extmod/vfs_fat_diskio.c
+++ b/extmod/vfs_fat_diskio.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* Original template for this file comes from:
* Low level disk I/O module skeleton for FatFs, (C)ChaN, 2013
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index 22907c12a..1fcbb253d 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,7 +29,6 @@
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "py/mperrno.h"
diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c
index 7c16db7e5..9a26b4a2f 100644
--- a/extmod/vfs_fat_misc.c
+++ b/extmod/vfs_fat_misc.c
@@ -28,7 +28,6 @@
#if MICROPY_VFS_FAT
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "lib/oofatfs/ff.h"
#include "extmod/vfs_fat.h"
diff --git a/lib/axtls b/lib/axtls
index 9b3092eb3..dac9176ca 160000
--- a/lib/axtls
+++ b/lib/axtls
@@ -1 +1 @@
-Subproject commit 9b3092eb3b4b230a63c0c389bfbd3c55682c620f
+Subproject commit dac9176cac58cc5e49669a9a4d404a6f6dd7cc10
diff --git a/lib/berkeley-db-1.xx b/lib/berkeley-db-1.xx
index dab957dac..35aaec441 160000
--- a/lib/berkeley-db-1.xx
+++ b/lib/berkeley-db-1.xx
@@ -1 +1 @@
-Subproject commit dab957dacddcbf6cbc85d42df62e189e4877bb72
+Subproject commit 35aaec4418ad78628a3b935885dd189d41ce779b
diff --git a/lib/embed/abort_.c b/lib/embed/abort_.c
index a6df8143c..2fba0de4e 100644
--- a/lib/embed/abort_.c
+++ b/lib/embed/abort_.c
@@ -3,5 +3,5 @@
NORETURN void abort_(void);
NORETURN void abort_(void) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "abort() called"));
+ mp_raise_msg(&mp_type_RuntimeError, "abort() called");
}
diff --git a/lib/libc/string0.c b/lib/libc/string0.c
index 1b37169ed..c2f2abd0f 100644
--- a/lib/libc/string0.c
+++ b/lib/libc/string0.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/lib/libm/ef_rem_pio2.c b/lib/libm/ef_rem_pio2.c
index f7a695e17..ca55243fb 100644
--- a/lib/libm/ef_rem_pio2.c
+++ b/lib/libm/ef_rem_pio2.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/erf_lgamma.c b/lib/libm/erf_lgamma.c
index a0da86b8d..877816a0c 100644
--- a/lib/libm/erf_lgamma.c
+++ b/lib/libm/erf_lgamma.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/fdlibm.h b/lib/libm/fdlibm.h
index 529a3975a..ace3b2da2 100644
--- a/lib/libm/fdlibm.h
+++ b/lib/libm/fdlibm.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* This file is adapted from from newlib-nano-2, the newlib/libm/common/fdlib.h,
* available from https://github.com/32bitmicro/newlib-nano-2. The main change
diff --git a/lib/libm/kf_cos.c b/lib/libm/kf_cos.c
index f1f883ced..691f9842f 100644
--- a/lib/libm/kf_cos.c
+++ b/lib/libm/kf_cos.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/kf_rem_pio2.c b/lib/libm/kf_rem_pio2.c
index e267b65f9..c7e947957 100644
--- a/lib/libm/kf_rem_pio2.c
+++ b/lib/libm/kf_rem_pio2.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/kf_sin.c b/lib/libm/kf_sin.c
index 81390b4eb..07ea99344 100644
--- a/lib/libm/kf_sin.c
+++ b/lib/libm/kf_sin.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/kf_tan.c b/lib/libm/kf_tan.c
index 68254c682..6da9bd817 100644
--- a/lib/libm/kf_tan.c
+++ b/lib/libm/kf_tan.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/math.c b/lib/libm/math.c
index d7e27e775..6b65202cf 100644
--- a/lib/libm/math.c
+++ b/lib/libm/math.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -48,20 +48,15 @@ float copysignf(float x, float y) {
}
#endif
-// some compilers define log2f in terms of logf
-#ifdef log2f
-#undef log2f
-#endif
-// some compilers have _M_LN2 defined in math.h, some don't
-#ifndef _M_LN2
-#define _M_LN2 (0.69314718055994530942)
-#endif
-float log2f(float x) { return logf(x) / (float)_M_LN2; }
-
static const float _M_LN10 = 2.30258509299404; // 0x40135d8e
float log10f(float x) { return logf(x) / (float)_M_LN10; }
-float tanhf(float x) { return sinhf(x) / coshf(x); }
+float tanhf(float x) {
+ if (isinf(x)) {
+ return copysignf(1, x);
+ }
+ return sinhf(x) / coshf(x);
+}
/*****************************************************************************/
/*****************************************************************************/
diff --git a/lib/libm/sf_cos.c b/lib/libm/sf_cos.c
index 33cde50e2..fabb129cd 100644
--- a/lib/libm/sf_cos.c
+++ b/lib/libm/sf_cos.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/sf_erf.c b/lib/libm/sf_erf.c
index 00ac4baf1..3f0172c6e 100644
--- a/lib/libm/sf_erf.c
+++ b/lib/libm/sf_erf.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/sf_frexp.c b/lib/libm/sf_frexp.c
index 397373fde..df50fb773 100644
--- a/lib/libm/sf_frexp.c
+++ b/lib/libm/sf_frexp.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/sf_ldexp.c b/lib/libm/sf_ldexp.c
index a0941df9f..37968d475 100644
--- a/lib/libm/sf_ldexp.c
+++ b/lib/libm/sf_ldexp.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/sf_modf.c b/lib/libm/sf_modf.c
index 4fcae057a..410db2a37 100644
--- a/lib/libm/sf_modf.c
+++ b/lib/libm/sf_modf.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/common
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/sf_sin.c b/lib/libm/sf_sin.c
index 585ab8d8c..d27050778 100644
--- a/lib/libm/sf_sin.c
+++ b/lib/libm/sf_sin.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/sf_tan.c b/lib/libm/sf_tan.c
index a9296d8bf..148b16d61 100644
--- a/lib/libm/sf_tan.c
+++ b/lib/libm/sf_tan.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/wf_lgamma.c b/lib/libm/wf_lgamma.c
index 7d2f42c54..d86ede790 100644
--- a/lib/libm/wf_lgamma.c
+++ b/lib/libm/wf_lgamma.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/libm/wf_tgamma.c b/lib/libm/wf_tgamma.c
index afd16bf67..64b2488d1 100644
--- a/lib/libm/wf_tgamma.c
+++ b/lib/libm/wf_tgamma.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* These math functions are taken from newlib-nano-2, the newlib/libm/math
* directory, available from https://github.com/32bitmicro/newlib-nano-2.
diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c
index 5b35c8660..9d254d8cf 100644
--- a/lib/mp-readline/readline.c
+++ b/lib/mp-readline/readline.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/lib/mp-readline/readline.h b/lib/mp-readline/readline.h
index f53fdeaa8..00aa9622a 100644
--- a/lib/mp-readline/readline.h
+++ b/lib/mp-readline/readline.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/lib/netutils/netutils.c b/lib/netutils/netutils.c
index a2ea31cf3..06c3ff9b0 100644
--- a/lib/netutils/netutils.c
+++ b/lib/netutils/netutils.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,8 +29,7 @@
#include
#include
-#include "py/obj.h"
-#include "py/nlr.h"
+#include "py/runtime.h"
#include "lib/netutils/netutils.h"
// Takes an array with a raw IPv4 address and returns something like '192.168.0.1'.
@@ -80,7 +79,7 @@ void netutils_parse_ipv4_addr(mp_obj_t addr_in, uint8_t *out_ip, netutils_endian
} else if (i > 0 && s < s_top && *s == '.') {
s++;
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid arguments"));
+ mp_raise_ValueError("invalid arguments");
}
}
}
diff --git a/lib/netutils/netutils.h b/lib/netutils/netutils.h
index 1e147afa9..4befc90db 100644
--- a/lib/netutils/netutils.h
+++ b/lib/netutils/netutils.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/lib/stm32lib b/lib/stm32lib
new file mode 160000
index 000000000..d2bcfda54
--- /dev/null
+++ b/lib/stm32lib
@@ -0,0 +1 @@
+Subproject commit d2bcfda543d3b99361e44112aca929225bdcc07f
diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c
index 06915f25a..eb3dc80d4 100644
--- a/lib/timeutils/timeutils.c
+++ b/lib/timeutils/timeutils.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -67,7 +67,7 @@ mp_uint_t timeutils_year_day(mp_uint_t year, mp_uint_t month, mp_uint_t date) {
void timeutils_seconds_since_2000_to_struct_time(mp_uint_t t, timeutils_struct_time_t *tm) {
// The following algorithm was adapted from musl's __secs_to_tm and adapted
- // for differences in Micro Python's timebase.
+ // for differences in MicroPython's timebase.
mp_int_t seconds = t - LEAPOCH;
diff --git a/lib/timeutils/timeutils.h b/lib/timeutils/timeutils.h
index 1dc486e2e..9b1abeb8f 100644
--- a/lib/timeutils/timeutils.h
+++ b/lib/timeutils/timeutils.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/lib/utils/printf.c b/lib/utils/printf.c
index 303edfcca..51dfa5b96 100644
--- a/lib/utils/printf.c
+++ b/lib/utils/printf.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c
index 7d0d1cc38..1e99aa649 100644
--- a/lib/utils/pyexec.c
+++ b/lib/utils/pyexec.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,7 +29,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
diff --git a/lib/utils/pyexec.h b/lib/utils/pyexec.h
index 69cdb4762..bc98ba94a 100644
--- a/lib/utils/pyexec.h
+++ b/lib/utils/pyexec.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/logo/FONT-LICENSE.txt b/logo/FONT-LICENSE.txt
index 18ac0379f..69c49d84c 100644
--- a/logo/FONT-LICENSE.txt
+++ b/logo/FONT-LICENSE.txt
@@ -1,4 +1,4 @@
-The font used for the Micro Python logo is "Exo",
+The font used for the MicroPython logo is "Exo",
http://www.google.com/fonts/specimen/Exo.
Copyright (c) 2013, Natanael Gama (https://plus.google.com/u/0/+NatanaelGama),
diff --git a/minimal/frozentest.mpy b/minimal/frozentest.mpy
deleted file mode 100644
index 87f9581bf..000000000
Binary files a/minimal/frozentest.mpy and /dev/null differ
diff --git a/mpy-cross/Makefile b/mpy-cross/Makefile
index c04adaf6a..53ce50c7f 100644
--- a/mpy-cross/Makefile
+++ b/mpy-cross/Makefile
@@ -23,10 +23,10 @@ QSTR_DEFS = qstrdefsport.h
UNAME_S := $(shell uname -s)
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
INC += -I.
-INC += -I..
+INC += -I$(TOP)
INC += -I$(BUILD)
# compiler settings
@@ -44,7 +44,7 @@ COPT = -Os #-DNDEBUG
endif
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
-# The unix port of micropython on OSX must be compiled with clang,
+# The unix port of MicroPython on OSX must be compiled with clang,
# while cross-compile ports require gcc, so we test here for OSX and
# if necessary override the value of 'CC' set in py/mkenv.mk
ifeq ($(UNAME_S),Darwin)
@@ -65,10 +65,10 @@ SRC_C = \
# Add fmode when compiling with mingw gcc
COMPILER_TARGET := $(shell $(CC) -dumpmachine)
ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
- SRC_C += windows/fmode.c
+ SRC_C += ports/windows/fmode.c
endif
OBJ = $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/mpy-cross/main.c b/mpy-cross/main.c
index ca8d9633f..d819f74f1 100644
--- a/mpy-cross/main.c
+++ b/mpy-cross/main.c
@@ -29,14 +29,13 @@
#include
#include
-#include "py/mpstate.h"
#include "py/compile.h"
#include "py/persistentcode.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/stackctrl.h"
#ifdef _WIN32
-#include "windows/fmode.h"
+#include "ports/windows/fmode.h"
#endif
// Command line options, with their defaults
diff --git a/bare-arm/Makefile b/ports/bare-arm/Makefile
similarity index 90%
rename from bare-arm/Makefile
rename to ports/bare-arm/Makefile
index cfd427c60..0fcd5d027 100644
--- a/bare-arm/Makefile
+++ b/ports/bare-arm/Makefile
@@ -1,15 +1,15 @@
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
CROSS_COMPILE = arm-none-eabi-
INC += -I.
-INC += -I..
+INC += -I$(TOP)
INC += -I$(BUILD)
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
@@ -45,4 +45,4 @@ $(BUILD)/firmware.elf: $(OBJ)
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
$(Q)$(SIZE) $@
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/bare-arm/main.c b/ports/bare-arm/main.c
similarity index 99%
rename from bare-arm/main.c
rename to ports/bare-arm/main.c
index 938414dfe..b96fb47ac 100644
--- a/bare-arm/main.c
+++ b/ports/bare-arm/main.c
@@ -2,7 +2,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
diff --git a/bare-arm/mpconfigport.h b/ports/bare-arm/mpconfigport.h
similarity index 95%
rename from bare-arm/mpconfigport.h
rename to ports/bare-arm/mpconfigport.h
index 97e866bdb..3fbd3769f 100644
--- a/bare-arm/mpconfigport.h
+++ b/ports/bare-arm/mpconfigport.h
@@ -1,6 +1,6 @@
#include
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_QSTR_BYTES_IN_HASH (1)
#define MICROPY_ALLOC_PATH_MAX (512)
@@ -60,7 +60,7 @@ typedef long mp_off_t;
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
// We need to provide a declaration/definition of alloca()
#include
diff --git a/bare-arm/mphalport.h b/ports/bare-arm/mphalport.h
similarity index 100%
rename from bare-arm/mphalport.h
rename to ports/bare-arm/mphalport.h
diff --git a/bare-arm/qstrdefsport.h b/ports/bare-arm/qstrdefsport.h
similarity index 100%
rename from bare-arm/qstrdefsport.h
rename to ports/bare-arm/qstrdefsport.h
diff --git a/bare-arm/stm32f405.ld b/ports/bare-arm/stm32f405.ld
similarity index 100%
rename from bare-arm/stm32f405.ld
rename to ports/bare-arm/stm32f405.ld
diff --git a/cc3200/FreeRTOS/FreeRTOSConfig.h b/ports/cc3200/FreeRTOS/FreeRTOSConfig.h
similarity index 100%
rename from cc3200/FreeRTOS/FreeRTOSConfig.h
rename to ports/cc3200/FreeRTOS/FreeRTOSConfig.h
diff --git a/cc3200/FreeRTOS/License/license.txt b/ports/cc3200/FreeRTOS/License/license.txt
similarity index 100%
rename from cc3200/FreeRTOS/License/license.txt
rename to ports/cc3200/FreeRTOS/License/license.txt
diff --git a/cc3200/FreeRTOS/Source/croutine.c b/ports/cc3200/FreeRTOS/Source/croutine.c
similarity index 100%
rename from cc3200/FreeRTOS/Source/croutine.c
rename to ports/cc3200/FreeRTOS/Source/croutine.c
diff --git a/cc3200/FreeRTOS/Source/event_groups.c b/ports/cc3200/FreeRTOS/Source/event_groups.c
similarity index 100%
rename from cc3200/FreeRTOS/Source/event_groups.c
rename to ports/cc3200/FreeRTOS/Source/event_groups.c
diff --git a/cc3200/FreeRTOS/Source/include/FreeRTOS.h b/ports/cc3200/FreeRTOS/Source/include/FreeRTOS.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/FreeRTOS.h
rename to ports/cc3200/FreeRTOS/Source/include/FreeRTOS.h
diff --git a/cc3200/FreeRTOS/Source/include/StackMacros.h b/ports/cc3200/FreeRTOS/Source/include/StackMacros.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/StackMacros.h
rename to ports/cc3200/FreeRTOS/Source/include/StackMacros.h
diff --git a/cc3200/FreeRTOS/Source/include/croutine.h b/ports/cc3200/FreeRTOS/Source/include/croutine.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/croutine.h
rename to ports/cc3200/FreeRTOS/Source/include/croutine.h
diff --git a/cc3200/FreeRTOS/Source/include/deprecated_definitions.h b/ports/cc3200/FreeRTOS/Source/include/deprecated_definitions.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/deprecated_definitions.h
rename to ports/cc3200/FreeRTOS/Source/include/deprecated_definitions.h
diff --git a/cc3200/FreeRTOS/Source/include/event_groups.h b/ports/cc3200/FreeRTOS/Source/include/event_groups.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/event_groups.h
rename to ports/cc3200/FreeRTOS/Source/include/event_groups.h
diff --git a/cc3200/FreeRTOS/Source/include/list.h b/ports/cc3200/FreeRTOS/Source/include/list.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/list.h
rename to ports/cc3200/FreeRTOS/Source/include/list.h
diff --git a/cc3200/FreeRTOS/Source/include/mpu_prototypes.h b/ports/cc3200/FreeRTOS/Source/include/mpu_prototypes.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/mpu_prototypes.h
rename to ports/cc3200/FreeRTOS/Source/include/mpu_prototypes.h
diff --git a/cc3200/FreeRTOS/Source/include/mpu_wrappers.h b/ports/cc3200/FreeRTOS/Source/include/mpu_wrappers.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/mpu_wrappers.h
rename to ports/cc3200/FreeRTOS/Source/include/mpu_wrappers.h
diff --git a/cc3200/FreeRTOS/Source/include/portable.h b/ports/cc3200/FreeRTOS/Source/include/portable.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/portable.h
rename to ports/cc3200/FreeRTOS/Source/include/portable.h
diff --git a/cc3200/FreeRTOS/Source/include/projdefs.h b/ports/cc3200/FreeRTOS/Source/include/projdefs.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/projdefs.h
rename to ports/cc3200/FreeRTOS/Source/include/projdefs.h
diff --git a/cc3200/FreeRTOS/Source/include/queue.h b/ports/cc3200/FreeRTOS/Source/include/queue.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/queue.h
rename to ports/cc3200/FreeRTOS/Source/include/queue.h
diff --git a/cc3200/FreeRTOS/Source/include/semphr.h b/ports/cc3200/FreeRTOS/Source/include/semphr.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/semphr.h
rename to ports/cc3200/FreeRTOS/Source/include/semphr.h
diff --git a/cc3200/FreeRTOS/Source/include/task.h b/ports/cc3200/FreeRTOS/Source/include/task.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/task.h
rename to ports/cc3200/FreeRTOS/Source/include/task.h
diff --git a/cc3200/FreeRTOS/Source/include/timers.h b/ports/cc3200/FreeRTOS/Source/include/timers.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/include/timers.h
rename to ports/cc3200/FreeRTOS/Source/include/timers.h
diff --git a/cc3200/FreeRTOS/Source/list.c b/ports/cc3200/FreeRTOS/Source/list.c
similarity index 100%
rename from cc3200/FreeRTOS/Source/list.c
rename to ports/cc3200/FreeRTOS/Source/list.c
diff --git a/cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c b/ports/cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
similarity index 100%
rename from cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
rename to ports/cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
diff --git a/cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h b/ports/cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h
similarity index 100%
rename from cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h
rename to ports/cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h
diff --git a/cc3200/FreeRTOS/Source/portable/MemMang/heap_4.c b/ports/cc3200/FreeRTOS/Source/portable/MemMang/heap_4.c
similarity index 100%
rename from cc3200/FreeRTOS/Source/portable/MemMang/heap_4.c
rename to ports/cc3200/FreeRTOS/Source/portable/MemMang/heap_4.c
diff --git a/cc3200/FreeRTOS/Source/queue.c b/ports/cc3200/FreeRTOS/Source/queue.c
similarity index 100%
rename from cc3200/FreeRTOS/Source/queue.c
rename to ports/cc3200/FreeRTOS/Source/queue.c
diff --git a/cc3200/FreeRTOS/Source/tasks.c b/ports/cc3200/FreeRTOS/Source/tasks.c
similarity index 100%
rename from cc3200/FreeRTOS/Source/tasks.c
rename to ports/cc3200/FreeRTOS/Source/tasks.c
diff --git a/cc3200/FreeRTOS/Source/timers.c b/ports/cc3200/FreeRTOS/Source/timers.c
similarity index 100%
rename from cc3200/FreeRTOS/Source/timers.c
rename to ports/cc3200/FreeRTOS/Source/timers.c
diff --git a/cc3200/Makefile b/ports/cc3200/Makefile
similarity index 95%
rename from cc3200/Makefile
rename to ports/cc3200/Makefile
index 663496435..81531b108 100644
--- a/cc3200/Makefile
+++ b/ports/cc3200/Makefile
@@ -14,7 +14,7 @@ PORT ?= /dev/ttyUSB1
# If the build directory is not given, make it reflect the board name.
BUILD ?= build/$(BOARD)/$(BTYPE)
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
-include ../../localconfig.mk
CROSS_COMPILE ?= arm-none-eabi-
@@ -34,7 +34,7 @@ ifeq ($(BTARGET), application)
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
# include MicroPython make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
include application.mk
else
ifeq ($(BTARGET), bootloader)
@@ -45,7 +45,7 @@ endif
endif
# always include MicroPython make rules
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
erase:
cc3200tool -p $(PORT) format_flash --size $(FLASH_SIZE_$(BOARD))
diff --git a/cc3200/README.md b/ports/cc3200/README.md
similarity index 100%
rename from cc3200/README.md
rename to ports/cc3200/README.md
diff --git a/cc3200/application.lds b/ports/cc3200/application.lds
similarity index 92%
rename from cc3200/application.lds
rename to ports/cc3200/application.lds
index 22ad1968d..3f5e72f8b 100644
--- a/cc3200/application.lds
+++ b/ports/cc3200/application.lds
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -37,7 +37,7 @@ ENTRY(ResetISR)
SECTIONS
{
- /* place the FreeRTOS heap (the micropython stack will live here) */
+ /* place the FreeRTOS heap (the MicroPython stack will live here) */
.rtos_heap (NOLOAD) :
{
. = ALIGN(8);
@@ -83,7 +83,7 @@ SECTIONS
} > SRAM
/* place here functions that are only called during boot up, */
- /* that way, we can re-use this area for the micropython heap */
+ /* that way, we can re-use this area for the MicroPython heap */
.boot :
{
. = ALIGN(8);
@@ -93,7 +93,7 @@ SECTIONS
_eboot = .;
} > SRAM
- /* allocate the micropython heap */
+ /* allocate the MicroPython heap */
.heap :
{
. = ALIGN(8);
diff --git a/cc3200/application.mk b/ports/cc3200/application.mk
similarity index 97%
rename from cc3200/application.mk
rename to ports/cc3200/application.mk
index c6b91ed0e..19abe6616 100644
--- a/cc3200/application.mk
+++ b/ports/cc3200/application.mk
@@ -1,5 +1,5 @@
APP_INC = -I.
-APP_INC += -I..
+APP_INC += -I$(TOP)
APP_INC += -Ifatfs/src
APP_INC += -Ifatfs/src/drivers
APP_INC += -IFreeRTOS
@@ -10,7 +10,7 @@ APP_INC += -Ihal
APP_INC += -Ihal/inc
APP_INC += -Imisc
APP_INC += -Imods
-APP_INC += -I../drivers/cc3100/inc
+APP_INC += -I$(TOP)/drivers/cc3100/inc
APP_INC += -Isimplelink
APP_INC += -Isimplelink/oslib
APP_INC += -Itelnet
@@ -18,7 +18,7 @@ APP_INC += -Iutil
APP_INC += -Ibootmgr
APP_INC += -I$(BUILD)
APP_INC += -I$(BUILD)/genhdr
-APP_INC += -I../stmhal
+APP_INC += -I$(TOP)/ports/stm32
APP_CPPDEFINES = -Dgcc -DTARGET_IS_CC3200 -DSL_FULL -DUSE_FREERTOS
@@ -147,10 +147,11 @@ APP_LIB_SRC_C = $(addprefix lib/,\
netutils/netutils.c \
timeutils/timeutils.c \
utils/pyexec.c \
+ utils/interrupt_char.c \
utils/sys_stdio_mphal.c \
)
-APP_STM_SRC_C = $(addprefix stmhal/,\
+APP_STM_SRC_C = $(addprefix ports/stm32/,\
bufhelper.c \
irq.c \
)
diff --git a/cc3200/appsign.sh b/ports/cc3200/appsign.sh
similarity index 100%
rename from cc3200/appsign.sh
rename to ports/cc3200/appsign.sh
diff --git a/cc3200/boards/LAUNCHXL/mpconfigboard.h b/ports/cc3200/boards/LAUNCHXL/mpconfigboard.h
similarity index 96%
rename from cc3200/boards/LAUNCHXL/mpconfigboard.h
rename to ports/cc3200/boards/LAUNCHXL/mpconfigboard.h
index 32ef5290b..b3d766d1e 100644
--- a/cc3200/boards/LAUNCHXL/mpconfigboard.h
+++ b/ports/cc3200/boards/LAUNCHXL/mpconfigboard.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/boards/LAUNCHXL/pins.csv b/ports/cc3200/boards/LAUNCHXL/pins.csv
similarity index 100%
rename from cc3200/boards/LAUNCHXL/pins.csv
rename to ports/cc3200/boards/LAUNCHXL/pins.csv
diff --git a/cc3200/boards/WIPY/mpconfigboard.h b/ports/cc3200/boards/WIPY/mpconfigboard.h
similarity index 96%
rename from cc3200/boards/WIPY/mpconfigboard.h
rename to ports/cc3200/boards/WIPY/mpconfigboard.h
index 9f04dbf23..af15cca35 100644
--- a/cc3200/boards/WIPY/mpconfigboard.h
+++ b/ports/cc3200/boards/WIPY/mpconfigboard.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/boards/WIPY/pins.csv b/ports/cc3200/boards/WIPY/pins.csv
similarity index 100%
rename from cc3200/boards/WIPY/pins.csv
rename to ports/cc3200/boards/WIPY/pins.csv
diff --git a/cc3200/boards/cc3200_af.csv b/ports/cc3200/boards/cc3200_af.csv
similarity index 100%
rename from cc3200/boards/cc3200_af.csv
rename to ports/cc3200/boards/cc3200_af.csv
diff --git a/cc3200/boards/cc3200_prefix.c b/ports/cc3200/boards/cc3200_prefix.c
similarity index 96%
rename from cc3200/boards/cc3200_prefix.c
rename to ports/cc3200/boards/cc3200_prefix.c
index 971285745..d03efe024 100644
--- a/cc3200/boards/cc3200_prefix.c
+++ b/ports/cc3200/boards/cc3200_prefix.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/boards/make-pins.py b/ports/cc3200/boards/make-pins.py
similarity index 97%
rename from cc3200/boards/make-pins.py
rename to ports/cc3200/boards/make-pins.py
index 26ca5a0b9..30db4ac9e 100644
--- a/cc3200/boards/make-pins.py
+++ b/ports/cc3200/boards/make-pins.py
@@ -133,10 +133,10 @@ def parse_board_file(self, filename, cpu_pin_col):
def print_named(self, label, pins):
print('')
- print('STATIC const mp_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{'.format(label))
+ print('STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{'.format(label))
for pin in pins:
if pin.board_pin:
- print(' {{ MP_OBJ_NEW_QSTR(MP_QSTR_{:6s}), (mp_obj_t)&pin_{:6s} }},'.format(pin.name, pin.name))
+ print(' {{ MP_ROM_QSTR(MP_QSTR_{:6s}), MP_ROM_PTR(&pin_{:6s}) }},'.format(pin.name, pin.name))
print('};')
print('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);'.format(label, label));
diff --git a/cc3200/bootmgr/bootgen.sh b/ports/cc3200/bootmgr/bootgen.sh
similarity index 100%
rename from cc3200/bootmgr/bootgen.sh
rename to ports/cc3200/bootmgr/bootgen.sh
diff --git a/cc3200/bootmgr/bootloader.mk b/ports/cc3200/bootmgr/bootloader.mk
similarity index 96%
rename from cc3200/bootmgr/bootloader.mk
rename to ports/cc3200/bootmgr/bootloader.mk
index ee5236913..44f1b7f42 100644
--- a/cc3200/bootmgr/bootloader.mk
+++ b/ports/cc3200/bootmgr/bootloader.mk
@@ -4,13 +4,13 @@ BOOT_INC = -Ibootmgr
BOOT_INC += -Ibootmgr/sl
BOOT_INC += -Ihal
BOOT_INC += -Ihal/inc
-BOOT_INC += -I../drivers/cc3100/inc
+BOOT_INC += -I$(TOP)/drivers/cc3100/inc
BOOT_INC += -Imisc
BOOT_INC += -Imods
BOOT_INC += -Isimplelink
BOOT_INC += -Isimplelink/oslib
BOOT_INC += -Iutil
-BOOT_INC += -I..
+BOOT_INC += -I$(TOP)
BOOT_INC += -I.
BOOT_INC += -I$(BUILD)
@@ -98,7 +98,7 @@ $(BUILD)/misc/%.o: CFLAGS += -Os
$(BUILD)/simplelink/%.o: CFLAGS += -Os
$(BUILD)/drivers/cc3100/%.o: CFLAGS += -Os
$(BUILD)/py/%.o: CFLAGS += -Os
-$(BUILD)/stmhal/%.o: CFLAGS += -Os
+$(BUILD)/ports/stm32/%.o: CFLAGS += -Os
else
$(error Invalid BTYPE specified)
endif
diff --git a/cc3200/bootmgr/bootmgr.h b/ports/cc3200/bootmgr/bootmgr.h
similarity index 97%
rename from cc3200/bootmgr/bootmgr.h
rename to ports/cc3200/bootmgr/bootmgr.h
index e5285d4e4..5a370f8c9 100644
--- a/cc3200/bootmgr/bootmgr.h
+++ b/ports/cc3200/bootmgr/bootmgr.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/bootmgr/bootmgr.lds b/ports/cc3200/bootmgr/bootmgr.lds
similarity index 96%
rename from cc3200/bootmgr/bootmgr.lds
rename to ports/cc3200/bootmgr/bootmgr.lds
index e67fe23ae..9c911a0d0 100644
--- a/cc3200/bootmgr/bootmgr.lds
+++ b/ports/cc3200/bootmgr/bootmgr.lds
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/bootmgr/flc.h b/ports/cc3200/bootmgr/flc.h
similarity index 98%
rename from cc3200/bootmgr/flc.h
rename to ports/cc3200/bootmgr/flc.h
index 7c04c7b05..8f05bb320 100644
--- a/cc3200/bootmgr/flc.h
+++ b/ports/cc3200/bootmgr/flc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/bootmgr/main.c b/ports/cc3200/bootmgr/main.c
similarity index 99%
rename from cc3200/bootmgr/main.c
rename to ports/cc3200/bootmgr/main.c
index 0d9ab35f8..cfb8dec21 100644
--- a/cc3200/bootmgr/main.c
+++ b/ports/cc3200/bootmgr/main.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/bootmgr/relocator/relocator.bin b/ports/cc3200/bootmgr/relocator/relocator.bin
similarity index 100%
rename from cc3200/bootmgr/relocator/relocator.bin
rename to ports/cc3200/bootmgr/relocator/relocator.bin
diff --git a/cc3200/bootmgr/runapp.s b/ports/cc3200/bootmgr/runapp.s
similarity index 100%
rename from cc3200/bootmgr/runapp.s
rename to ports/cc3200/bootmgr/runapp.s
diff --git a/cc3200/bootmgr/sl/user.h b/ports/cc3200/bootmgr/sl/user.h
similarity index 100%
rename from cc3200/bootmgr/sl/user.h
rename to ports/cc3200/bootmgr/sl/user.h
diff --git a/cc3200/fatfs/src/drivers/sd_diskio.c b/ports/cc3200/fatfs/src/drivers/sd_diskio.c
similarity index 100%
rename from cc3200/fatfs/src/drivers/sd_diskio.c
rename to ports/cc3200/fatfs/src/drivers/sd_diskio.c
diff --git a/cc3200/fatfs/src/drivers/sd_diskio.h b/ports/cc3200/fatfs/src/drivers/sd_diskio.h
similarity index 100%
rename from cc3200/fatfs/src/drivers/sd_diskio.h
rename to ports/cc3200/fatfs/src/drivers/sd_diskio.h
diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.c b/ports/cc3200/fatfs/src/drivers/sflash_diskio.c
similarity index 100%
rename from cc3200/fatfs/src/drivers/sflash_diskio.c
rename to ports/cc3200/fatfs/src/drivers/sflash_diskio.c
diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.h b/ports/cc3200/fatfs/src/drivers/sflash_diskio.h
similarity index 100%
rename from cc3200/fatfs/src/drivers/sflash_diskio.h
rename to ports/cc3200/fatfs/src/drivers/sflash_diskio.h
diff --git a/cc3200/fatfs/src/drivers/stdcmd.h b/ports/cc3200/fatfs/src/drivers/stdcmd.h
similarity index 100%
rename from cc3200/fatfs/src/drivers/stdcmd.h
rename to ports/cc3200/fatfs/src/drivers/stdcmd.h
diff --git a/cc3200/fatfs_port.c b/ports/cc3200/fatfs_port.c
similarity index 100%
rename from cc3200/fatfs_port.c
rename to ports/cc3200/fatfs_port.c
diff --git a/cc3200/ftp/ftp.c b/ports/cc3200/ftp/ftp.c
similarity index 99%
rename from cc3200/ftp/ftp.c
rename to ports/cc3200/ftp/ftp.c
index b56e3f4ce..ee80e51f5 100644
--- a/cc3200/ftp/ftp.c
+++ b/ports/cc3200/ftp/ftp.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,8 +27,7 @@
#include
#include
-#include "py/mpstate.h"
-#include "py/obj.h"
+#include "py/runtime.h"
#include "lib/timeutils/timeutils.h"
#include "lib/oofatfs/ff.h"
#include "extmod/vfs.h"
diff --git a/cc3200/ftp/ftp.h b/ports/cc3200/ftp/ftp.h
similarity index 95%
rename from cc3200/ftp/ftp.h
rename to ports/cc3200/ftp/ftp.h
index 7d16002e4..af4c14fa3 100644
--- a/cc3200/ftp/ftp.h
+++ b/ports/cc3200/ftp/ftp.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/ftp/updater.c b/ports/cc3200/ftp/updater.c
similarity index 99%
rename from cc3200/ftp/updater.c
rename to ports/cc3200/ftp/updater.c
index fece70095..5be2c6063 100644
--- a/cc3200/ftp/updater.c
+++ b/ports/cc3200/ftp/updater.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/ftp/updater.h b/ports/cc3200/ftp/updater.h
similarity index 95%
rename from cc3200/ftp/updater.h
rename to ports/cc3200/ftp/updater.h
index dcca70472..51248e4bf 100644
--- a/cc3200/ftp/updater.h
+++ b/ports/cc3200/ftp/updater.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/hal/adc.c b/ports/cc3200/hal/adc.c
similarity index 100%
rename from cc3200/hal/adc.c
rename to ports/cc3200/hal/adc.c
diff --git a/cc3200/hal/adc.h b/ports/cc3200/hal/adc.h
similarity index 100%
rename from cc3200/hal/adc.h
rename to ports/cc3200/hal/adc.h
diff --git a/cc3200/hal/aes.c b/ports/cc3200/hal/aes.c
similarity index 100%
rename from cc3200/hal/aes.c
rename to ports/cc3200/hal/aes.c
diff --git a/cc3200/hal/aes.h b/ports/cc3200/hal/aes.h
similarity index 100%
rename from cc3200/hal/aes.h
rename to ports/cc3200/hal/aes.h
diff --git a/cc3200/hal/cc3200_asm.h b/ports/cc3200/hal/cc3200_asm.h
similarity index 97%
rename from cc3200/hal/cc3200_asm.h
rename to ports/cc3200/hal/cc3200_asm.h
index dcaaf57e1..742c9a6f7 100644
--- a/cc3200/hal/cc3200_asm.h
+++ b/ports/cc3200/hal/cc3200_asm.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/hal/cc3200_hal.c b/ports/cc3200/hal/cc3200_hal.c
similarity index 97%
rename from cc3200/hal/cc3200_hal.c
rename to ports/cc3200/hal/cc3200_hal.c
index 5c0e9c30f..0285d0585 100644
--- a/cc3200/hal/cc3200_hal.c
+++ b/ports/cc3200/hal/cc3200_hal.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -33,7 +33,6 @@
#include
-#include "py/mpstate.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "py/objstr.h"
@@ -143,10 +142,6 @@ void mp_hal_delay_ms(mp_uint_t delay) {
}
}
-void mp_hal_set_interrupt_char (int c) {
- mpexception_set_interrupt_char (c);
-}
-
void mp_hal_stdout_tx_str(const char *str) {
mp_hal_stdout_tx_strn(str, strlen(str));
}
diff --git a/cc3200/hal/cc3200_hal.h b/ports/cc3200/hal/cc3200_hal.h
similarity index 97%
rename from cc3200/hal/cc3200_hal.h
rename to ports/cc3200/hal/cc3200_hal.h
index 9953f0e5a..71e245eeb 100644
--- a/cc3200/hal/cc3200_hal.h
+++ b/ports/cc3200/hal/cc3200_hal.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/hal/cpu.c b/ports/cc3200/hal/cpu.c
similarity index 100%
rename from cc3200/hal/cpu.c
rename to ports/cc3200/hal/cpu.c
diff --git a/cc3200/hal/cpu.h b/ports/cc3200/hal/cpu.h
similarity index 100%
rename from cc3200/hal/cpu.h
rename to ports/cc3200/hal/cpu.h
diff --git a/cc3200/hal/crc.c b/ports/cc3200/hal/crc.c
similarity index 100%
rename from cc3200/hal/crc.c
rename to ports/cc3200/hal/crc.c
diff --git a/cc3200/hal/crc.h b/ports/cc3200/hal/crc.h
similarity index 100%
rename from cc3200/hal/crc.h
rename to ports/cc3200/hal/crc.h
diff --git a/cc3200/hal/debug.h b/ports/cc3200/hal/debug.h
similarity index 100%
rename from cc3200/hal/debug.h
rename to ports/cc3200/hal/debug.h
diff --git a/cc3200/hal/des.c b/ports/cc3200/hal/des.c
similarity index 100%
rename from cc3200/hal/des.c
rename to ports/cc3200/hal/des.c
diff --git a/cc3200/hal/des.h b/ports/cc3200/hal/des.h
similarity index 100%
rename from cc3200/hal/des.h
rename to ports/cc3200/hal/des.h
diff --git a/cc3200/hal/fault_registers.h b/ports/cc3200/hal/fault_registers.h
similarity index 96%
rename from cc3200/hal/fault_registers.h
rename to ports/cc3200/hal/fault_registers.h
index 739745e92..ade516b9e 100644
--- a/cc3200/hal/fault_registers.h
+++ b/ports/cc3200/hal/fault_registers.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/hal/gpio.c b/ports/cc3200/hal/gpio.c
similarity index 100%
rename from cc3200/hal/gpio.c
rename to ports/cc3200/hal/gpio.c
diff --git a/cc3200/hal/gpio.h b/ports/cc3200/hal/gpio.h
similarity index 100%
rename from cc3200/hal/gpio.h
rename to ports/cc3200/hal/gpio.h
diff --git a/cc3200/hal/i2c.c b/ports/cc3200/hal/i2c.c
similarity index 100%
rename from cc3200/hal/i2c.c
rename to ports/cc3200/hal/i2c.c
diff --git a/cc3200/hal/i2c.h b/ports/cc3200/hal/i2c.h
similarity index 100%
rename from cc3200/hal/i2c.h
rename to ports/cc3200/hal/i2c.h
diff --git a/cc3200/hal/i2s.c b/ports/cc3200/hal/i2s.c
similarity index 100%
rename from cc3200/hal/i2s.c
rename to ports/cc3200/hal/i2s.c
diff --git a/cc3200/hal/i2s.h b/ports/cc3200/hal/i2s.h
similarity index 100%
rename from cc3200/hal/i2s.h
rename to ports/cc3200/hal/i2s.h
diff --git a/cc3200/hal/inc/asmdefs.h b/ports/cc3200/hal/inc/asmdefs.h
similarity index 100%
rename from cc3200/hal/inc/asmdefs.h
rename to ports/cc3200/hal/inc/asmdefs.h
diff --git a/cc3200/hal/inc/hw_adc.h b/ports/cc3200/hal/inc/hw_adc.h
similarity index 100%
rename from cc3200/hal/inc/hw_adc.h
rename to ports/cc3200/hal/inc/hw_adc.h
diff --git a/cc3200/hal/inc/hw_aes.h b/ports/cc3200/hal/inc/hw_aes.h
similarity index 100%
rename from cc3200/hal/inc/hw_aes.h
rename to ports/cc3200/hal/inc/hw_aes.h
diff --git a/cc3200/hal/inc/hw_apps_config.h b/ports/cc3200/hal/inc/hw_apps_config.h
similarity index 100%
rename from cc3200/hal/inc/hw_apps_config.h
rename to ports/cc3200/hal/inc/hw_apps_config.h
diff --git a/cc3200/hal/inc/hw_apps_rcm.h b/ports/cc3200/hal/inc/hw_apps_rcm.h
similarity index 100%
rename from cc3200/hal/inc/hw_apps_rcm.h
rename to ports/cc3200/hal/inc/hw_apps_rcm.h
diff --git a/cc3200/hal/inc/hw_camera.h b/ports/cc3200/hal/inc/hw_camera.h
similarity index 100%
rename from cc3200/hal/inc/hw_camera.h
rename to ports/cc3200/hal/inc/hw_camera.h
diff --git a/cc3200/hal/inc/hw_common_reg.h b/ports/cc3200/hal/inc/hw_common_reg.h
similarity index 100%
rename from cc3200/hal/inc/hw_common_reg.h
rename to ports/cc3200/hal/inc/hw_common_reg.h
diff --git a/cc3200/hal/inc/hw_des.h b/ports/cc3200/hal/inc/hw_des.h
similarity index 100%
rename from cc3200/hal/inc/hw_des.h
rename to ports/cc3200/hal/inc/hw_des.h
diff --git a/cc3200/hal/inc/hw_dthe.h b/ports/cc3200/hal/inc/hw_dthe.h
similarity index 100%
rename from cc3200/hal/inc/hw_dthe.h
rename to ports/cc3200/hal/inc/hw_dthe.h
diff --git a/cc3200/hal/inc/hw_flash_ctrl.h b/ports/cc3200/hal/inc/hw_flash_ctrl.h
similarity index 100%
rename from cc3200/hal/inc/hw_flash_ctrl.h
rename to ports/cc3200/hal/inc/hw_flash_ctrl.h
diff --git a/cc3200/hal/inc/hw_gpio.h b/ports/cc3200/hal/inc/hw_gpio.h
similarity index 100%
rename from cc3200/hal/inc/hw_gpio.h
rename to ports/cc3200/hal/inc/hw_gpio.h
diff --git a/cc3200/hal/inc/hw_gprcm.h b/ports/cc3200/hal/inc/hw_gprcm.h
similarity index 100%
rename from cc3200/hal/inc/hw_gprcm.h
rename to ports/cc3200/hal/inc/hw_gprcm.h
diff --git a/cc3200/hal/inc/hw_hib1p2.h b/ports/cc3200/hal/inc/hw_hib1p2.h
similarity index 100%
rename from cc3200/hal/inc/hw_hib1p2.h
rename to ports/cc3200/hal/inc/hw_hib1p2.h
diff --git a/cc3200/hal/inc/hw_hib3p3.h b/ports/cc3200/hal/inc/hw_hib3p3.h
similarity index 100%
rename from cc3200/hal/inc/hw_hib3p3.h
rename to ports/cc3200/hal/inc/hw_hib3p3.h
diff --git a/cc3200/hal/inc/hw_i2c.h b/ports/cc3200/hal/inc/hw_i2c.h
similarity index 100%
rename from cc3200/hal/inc/hw_i2c.h
rename to ports/cc3200/hal/inc/hw_i2c.h
diff --git a/cc3200/hal/inc/hw_ints.h b/ports/cc3200/hal/inc/hw_ints.h
similarity index 100%
rename from cc3200/hal/inc/hw_ints.h
rename to ports/cc3200/hal/inc/hw_ints.h
diff --git a/cc3200/hal/inc/hw_mcasp.h b/ports/cc3200/hal/inc/hw_mcasp.h
similarity index 100%
rename from cc3200/hal/inc/hw_mcasp.h
rename to ports/cc3200/hal/inc/hw_mcasp.h
diff --git a/cc3200/hal/inc/hw_mcspi.h b/ports/cc3200/hal/inc/hw_mcspi.h
similarity index 100%
rename from cc3200/hal/inc/hw_mcspi.h
rename to ports/cc3200/hal/inc/hw_mcspi.h
diff --git a/cc3200/hal/inc/hw_memmap.h b/ports/cc3200/hal/inc/hw_memmap.h
similarity index 100%
rename from cc3200/hal/inc/hw_memmap.h
rename to ports/cc3200/hal/inc/hw_memmap.h
diff --git a/cc3200/hal/inc/hw_mmchs.h b/ports/cc3200/hal/inc/hw_mmchs.h
similarity index 100%
rename from cc3200/hal/inc/hw_mmchs.h
rename to ports/cc3200/hal/inc/hw_mmchs.h
diff --git a/cc3200/hal/inc/hw_nvic.h b/ports/cc3200/hal/inc/hw_nvic.h
similarity index 100%
rename from cc3200/hal/inc/hw_nvic.h
rename to ports/cc3200/hal/inc/hw_nvic.h
diff --git a/cc3200/hal/inc/hw_ocp_shared.h b/ports/cc3200/hal/inc/hw_ocp_shared.h
similarity index 100%
rename from cc3200/hal/inc/hw_ocp_shared.h
rename to ports/cc3200/hal/inc/hw_ocp_shared.h
diff --git a/cc3200/hal/inc/hw_shamd5.h b/ports/cc3200/hal/inc/hw_shamd5.h
similarity index 100%
rename from cc3200/hal/inc/hw_shamd5.h
rename to ports/cc3200/hal/inc/hw_shamd5.h
diff --git a/cc3200/hal/inc/hw_stack_die_ctrl.h b/ports/cc3200/hal/inc/hw_stack_die_ctrl.h
similarity index 100%
rename from cc3200/hal/inc/hw_stack_die_ctrl.h
rename to ports/cc3200/hal/inc/hw_stack_die_ctrl.h
diff --git a/cc3200/hal/inc/hw_timer.h b/ports/cc3200/hal/inc/hw_timer.h
similarity index 100%
rename from cc3200/hal/inc/hw_timer.h
rename to ports/cc3200/hal/inc/hw_timer.h
diff --git a/cc3200/hal/inc/hw_types.h b/ports/cc3200/hal/inc/hw_types.h
similarity index 100%
rename from cc3200/hal/inc/hw_types.h
rename to ports/cc3200/hal/inc/hw_types.h
diff --git a/cc3200/hal/inc/hw_uart.h b/ports/cc3200/hal/inc/hw_uart.h
similarity index 100%
rename from cc3200/hal/inc/hw_uart.h
rename to ports/cc3200/hal/inc/hw_uart.h
diff --git a/cc3200/hal/inc/hw_udma.h b/ports/cc3200/hal/inc/hw_udma.h
similarity index 100%
rename from cc3200/hal/inc/hw_udma.h
rename to ports/cc3200/hal/inc/hw_udma.h
diff --git a/cc3200/hal/inc/hw_wdt.h b/ports/cc3200/hal/inc/hw_wdt.h
similarity index 100%
rename from cc3200/hal/inc/hw_wdt.h
rename to ports/cc3200/hal/inc/hw_wdt.h
diff --git a/cc3200/hal/interrupt.c b/ports/cc3200/hal/interrupt.c
similarity index 100%
rename from cc3200/hal/interrupt.c
rename to ports/cc3200/hal/interrupt.c
diff --git a/cc3200/hal/interrupt.h b/ports/cc3200/hal/interrupt.h
similarity index 100%
rename from cc3200/hal/interrupt.h
rename to ports/cc3200/hal/interrupt.h
diff --git a/cc3200/hal/pin.c b/ports/cc3200/hal/pin.c
similarity index 100%
rename from cc3200/hal/pin.c
rename to ports/cc3200/hal/pin.c
diff --git a/cc3200/hal/pin.h b/ports/cc3200/hal/pin.h
similarity index 100%
rename from cc3200/hal/pin.h
rename to ports/cc3200/hal/pin.h
diff --git a/cc3200/hal/prcm.c b/ports/cc3200/hal/prcm.c
similarity index 100%
rename from cc3200/hal/prcm.c
rename to ports/cc3200/hal/prcm.c
diff --git a/cc3200/hal/prcm.h b/ports/cc3200/hal/prcm.h
similarity index 100%
rename from cc3200/hal/prcm.h
rename to ports/cc3200/hal/prcm.h
diff --git a/cc3200/hal/rom.h b/ports/cc3200/hal/rom.h
similarity index 100%
rename from cc3200/hal/rom.h
rename to ports/cc3200/hal/rom.h
diff --git a/cc3200/hal/rom_map.h b/ports/cc3200/hal/rom_map.h
similarity index 100%
rename from cc3200/hal/rom_map.h
rename to ports/cc3200/hal/rom_map.h
diff --git a/cc3200/hal/rom_patch.h b/ports/cc3200/hal/rom_patch.h
similarity index 100%
rename from cc3200/hal/rom_patch.h
rename to ports/cc3200/hal/rom_patch.h
diff --git a/cc3200/hal/sdhost.c b/ports/cc3200/hal/sdhost.c
similarity index 100%
rename from cc3200/hal/sdhost.c
rename to ports/cc3200/hal/sdhost.c
diff --git a/cc3200/hal/sdhost.h b/ports/cc3200/hal/sdhost.h
similarity index 100%
rename from cc3200/hal/sdhost.h
rename to ports/cc3200/hal/sdhost.h
diff --git a/cc3200/hal/shamd5.c b/ports/cc3200/hal/shamd5.c
similarity index 100%
rename from cc3200/hal/shamd5.c
rename to ports/cc3200/hal/shamd5.c
diff --git a/cc3200/hal/shamd5.h b/ports/cc3200/hal/shamd5.h
similarity index 100%
rename from cc3200/hal/shamd5.h
rename to ports/cc3200/hal/shamd5.h
diff --git a/cc3200/hal/spi.c b/ports/cc3200/hal/spi.c
similarity index 100%
rename from cc3200/hal/spi.c
rename to ports/cc3200/hal/spi.c
diff --git a/cc3200/hal/spi.h b/ports/cc3200/hal/spi.h
similarity index 100%
rename from cc3200/hal/spi.h
rename to ports/cc3200/hal/spi.h
diff --git a/cc3200/hal/startup_gcc.c b/ports/cc3200/hal/startup_gcc.c
similarity index 100%
rename from cc3200/hal/startup_gcc.c
rename to ports/cc3200/hal/startup_gcc.c
diff --git a/cc3200/hal/systick.c b/ports/cc3200/hal/systick.c
similarity index 100%
rename from cc3200/hal/systick.c
rename to ports/cc3200/hal/systick.c
diff --git a/cc3200/hal/systick.h b/ports/cc3200/hal/systick.h
similarity index 100%
rename from cc3200/hal/systick.h
rename to ports/cc3200/hal/systick.h
diff --git a/cc3200/hal/timer.c b/ports/cc3200/hal/timer.c
similarity index 100%
rename from cc3200/hal/timer.c
rename to ports/cc3200/hal/timer.c
diff --git a/cc3200/hal/timer.h b/ports/cc3200/hal/timer.h
similarity index 100%
rename from cc3200/hal/timer.h
rename to ports/cc3200/hal/timer.h
diff --git a/cc3200/hal/uart.c b/ports/cc3200/hal/uart.c
similarity index 100%
rename from cc3200/hal/uart.c
rename to ports/cc3200/hal/uart.c
diff --git a/cc3200/hal/uart.h b/ports/cc3200/hal/uart.h
similarity index 100%
rename from cc3200/hal/uart.h
rename to ports/cc3200/hal/uart.h
diff --git a/cc3200/hal/utils.c b/ports/cc3200/hal/utils.c
similarity index 100%
rename from cc3200/hal/utils.c
rename to ports/cc3200/hal/utils.c
diff --git a/cc3200/hal/utils.h b/ports/cc3200/hal/utils.h
similarity index 100%
rename from cc3200/hal/utils.h
rename to ports/cc3200/hal/utils.h
diff --git a/cc3200/hal/wdt.c b/ports/cc3200/hal/wdt.c
similarity index 100%
rename from cc3200/hal/wdt.c
rename to ports/cc3200/hal/wdt.c
diff --git a/cc3200/hal/wdt.h b/ports/cc3200/hal/wdt.h
similarity index 100%
rename from cc3200/hal/wdt.h
rename to ports/cc3200/hal/wdt.h
diff --git a/cc3200/main.c b/ports/cc3200/main.c
similarity index 98%
rename from cc3200/main.c
rename to ports/cc3200/main.c
index 1ffb98188..e2299e146 100644
--- a/cc3200/main.c
+++ b/ports/cc3200/main.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/misc/FreeRTOSHooks.c b/ports/cc3200/misc/FreeRTOSHooks.c
similarity index 97%
rename from cc3200/misc/FreeRTOSHooks.c
rename to ports/cc3200/misc/FreeRTOSHooks.c
index dac9a9282..c618279b7 100644
--- a/cc3200/misc/FreeRTOSHooks.c
+++ b/ports/cc3200/misc/FreeRTOSHooks.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/misc/antenna.c b/ports/cc3200/misc/antenna.c
similarity index 98%
rename from cc3200/misc/antenna.c
rename to ports/cc3200/misc/antenna.c
index 0fbf79f0f..afeed85e1 100644
--- a/cc3200/misc/antenna.c
+++ b/ports/cc3200/misc/antenna.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/misc/antenna.h b/ports/cc3200/misc/antenna.h
similarity index 95%
rename from cc3200/misc/antenna.h
rename to ports/cc3200/misc/antenna.h
index 3bb87e32b..c9d845453 100644
--- a/cc3200/misc/antenna.h
+++ b/ports/cc3200/misc/antenna.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/misc/help.c b/ports/cc3200/misc/help.c
similarity index 91%
rename from cc3200/misc/help.c
rename to ports/cc3200/misc/help.c
index cce515898..ea0c9501d 100644
--- a/cc3200/misc/help.c
+++ b/ports/cc3200/misc/help.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,6 +27,6 @@
#include "py/builtin.h"
-const char *cc3200_help_text = "Welcome to MicroPython!\n"
+const char cc3200_help_text[] = "Welcome to MicroPython!\n"
"For online help please visit http://micropython.org/help/.\n"
"For further help on a specific object, type help(obj)\n";
diff --git a/cc3200/misc/mperror.c b/ports/cc3200/misc/mperror.c
similarity index 99%
rename from cc3200/misc/mperror.c
rename to ports/cc3200/misc/mperror.c
index 81b853b48..082d940e2 100644
--- a/cc3200/misc/mperror.c
+++ b/ports/cc3200/misc/mperror.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/misc/mperror.h b/ports/cc3200/misc/mperror.h
similarity index 95%
rename from cc3200/misc/mperror.h
rename to ports/cc3200/misc/mperror.h
index 46a9b8cb0..1c3eb6269 100644
--- a/cc3200/misc/mperror.h
+++ b/ports/cc3200/misc/mperror.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/ports/cc3200/misc/mpexception.c b/ports/cc3200/misc/mpexception.c
new file mode 100644
index 000000000..72d4a155f
--- /dev/null
+++ b/ports/cc3200/misc/mpexception.c
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2015 Daniel Campora
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+#include
+
+#include "mpexception.h"
+
+
+/******************************************************************************
+DECLARE EXPORTED DATA
+ ******************************************************************************/
+const char mpexception_value_invalid_arguments[] = "invalid argument(s) value";
+const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type";
+const char mpexception_uncaught[] = "uncaught exception";
diff --git a/cc3200/misc/mpexception.h b/ports/cc3200/misc/mpexception.h
similarity index 83%
rename from cc3200/misc/mpexception.h
rename to ports/cc3200/misc/mpexception.h
index d23381caf..e84a1edb2 100644
--- a/cc3200/misc/mpexception.h
+++ b/ports/cc3200/misc/mpexception.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -31,12 +31,4 @@ extern const char mpexception_value_invalid_arguments[];
extern const char mpexception_num_type_invalid_arguments[];
extern const char mpexception_uncaught[];
-extern int user_interrupt_char;
-
-
-extern void mpexception_init0 (void);
-extern void mpexception_set_interrupt_char (int c);
-extern void mpexception_nlr_jump (void *o);
-extern void mpexception_keyboard_nlr_jump (void);
-
#endif // MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H
diff --git a/cc3200/misc/mpirq.c b/ports/cc3200/misc/mpirq.c
similarity index 92%
rename from cc3200/misc/mpirq.c
rename to ports/cc3200/misc/mpirq.c
index 37149089f..d54e7465b 100644
--- a/cc3200/misc/mpirq.c
+++ b/ports/cc3200/misc/mpirq.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -143,9 +143,9 @@ void mp_irq_handler (mp_obj_t self_in) {
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
-STATIC mp_obj_t mp_irq_init (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t mp_irq_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_irq_obj_t *self = pos_args[0];
// this is a bit of a hack, but it let us reuse the callback_create method from our parent
((mp_obj_t *)pos_args)[0] = self->parent;
@@ -182,12 +182,12 @@ STATIC mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
return mp_const_none;
}
-STATIC const mp_map_elem_t mp_irq_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&mp_irq_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&mp_irq_enable_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&mp_irq_disable_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flags), (mp_obj_t)&mp_irq_flags_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mp_irq_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&mp_irq_enable_obj) },
+ { MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&mp_irq_disable_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flags), MP_ROM_PTR(&mp_irq_flags_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table);
diff --git a/cc3200/misc/mpirq.h b/ports/cc3200/misc/mpirq.h
similarity index 94%
rename from cc3200/misc/mpirq.h
rename to ports/cc3200/misc/mpirq.h
index 8b4ab2f1b..223a34cae 100644
--- a/cc3200/misc/mpirq.h
+++ b/ports/cc3200/misc/mpirq.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -34,7 +34,7 @@
/******************************************************************************
DEFINE TYPES
******************************************************************************/
-typedef mp_obj_t (*mp_irq_init_t) (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
+typedef mp_obj_t (*mp_irq_init_t) (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
typedef void (*mp_irq_void_method_t) (mp_obj_t self);
typedef int (*mp_irq_int_method_t) (mp_obj_t self);
diff --git a/cc3200/mods/modmachine.c b/ports/cc3200/mods/modmachine.c
similarity index 62%
rename from cc3200/mods/modmachine.c
rename to ports/cc3200/mods/modmachine.c
index fd1485607..6051497e3 100644
--- a/cc3200/mods/modmachine.c
+++ b/ports/cc3200/mods/modmachine.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "irq.h"
@@ -72,7 +71,7 @@ extern OsiTaskHandle xSimpleLinkSpawnTaskHndl;
///
/******************************************************************************/
-// Micro Python bindings;
+// MicroPython bindings;
STATIC mp_obj_t machine_reset(void) {
// disable wlan
@@ -160,49 +159,49 @@ STATIC mp_obj_t machine_wake_reason (void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason);
-STATIC const mp_map_elem_t machine_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_umachine) },
+STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&machine_reset_obj },
+ { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
#ifdef DEBUG
- { MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&machine_info_obj },
+ { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) },
#endif
- { MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&machine_freq_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&machine_unique_id_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_main), (mp_obj_t)&machine_main_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&machine_rng_get_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_idle), (mp_obj_t)&machine_idle_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&machine_sleep_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&machine_deepsleep_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_reset_cause), (mp_obj_t)&machine_reset_cause_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_wake_reason), (mp_obj_t)&machine_wake_reason_obj },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_disable_irq), (mp_obj_t)&pyb_disable_irq_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_enable_irq), (mp_obj_t)&pyb_enable_irq_obj },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SPI), (mp_obj_t)&pyb_spi_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },
+ { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) },
+ { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) },
+ { MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&machine_main_obj) },
+ { MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&machine_rng_get_obj) },
+ { MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_sleep_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) },
+ { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
+ { MP_ROM_QSTR(MP_QSTR_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&pyb_disable_irq_obj) },
+ { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&pyb_enable_irq_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&pyb_rtc_type) },
+ { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) },
+ { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&pyb_adc_type) },
+ { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&pyb_i2c_type) },
+ { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&pyb_spi_type) },
+ { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) },
+ { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&pyb_timer_type) },
+ { MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&pyb_wdt_type) },
+ { MP_ROM_QSTR(MP_QSTR_SD), MP_ROM_PTR(&pyb_sd_type) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_IDLE), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_ACTIVE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_LPDS) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_DEEPSLEEP), MP_OBJ_NEW_SMALL_INT(PYB_PWR_MODE_HIBERNATE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_POWER_ON), MP_OBJ_NEW_SMALL_INT(PYB_SLP_PWRON_RESET) }, // legacy constant
- { MP_OBJ_NEW_QSTR(MP_QSTR_PWRON_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_PWRON_RESET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_HARD_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_HARD_RESET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WDT_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WDT_RESET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_DEEPSLEEP_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_HIB_RESET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOFT_RESET), MP_OBJ_NEW_SMALL_INT(PYB_SLP_SOFT_RESET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WLAN_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_WLAN) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PIN_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_GPIO) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_RTC_WAKE), MP_OBJ_NEW_SMALL_INT(PYB_SLP_WAKED_BY_RTC) },
+ { MP_ROM_QSTR(MP_QSTR_IDLE), MP_ROM_INT(PYB_PWR_MODE_ACTIVE) },
+ { MP_ROM_QSTR(MP_QSTR_SLEEP), MP_ROM_INT(PYB_PWR_MODE_LPDS) },
+ { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP), MP_ROM_INT(PYB_PWR_MODE_HIBERNATE) },
+ { MP_ROM_QSTR(MP_QSTR_POWER_ON), MP_ROM_INT(PYB_SLP_PWRON_RESET) }, // legacy constant
+ { MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(PYB_SLP_PWRON_RESET) },
+ { MP_ROM_QSTR(MP_QSTR_HARD_RESET), MP_ROM_INT(PYB_SLP_HARD_RESET) },
+ { MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(PYB_SLP_WDT_RESET) },
+ { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP_RESET), MP_ROM_INT(PYB_SLP_HIB_RESET) },
+ { MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(PYB_SLP_SOFT_RESET) },
+ { MP_ROM_QSTR(MP_QSTR_WLAN_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_WLAN) },
+ { MP_ROM_QSTR(MP_QSTR_PIN_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_GPIO) },
+ { MP_ROM_QSTR(MP_QSTR_RTC_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_RTC) },
};
STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);
diff --git a/cc3200/mods/modnetwork.c b/ports/cc3200/mods/modnetwork.c
similarity index 84%
rename from cc3200/mods/modnetwork.c
rename to ports/cc3200/mods/modnetwork.c
index d44f75aca..37dffe731 100644
--- a/cc3200/mods/modnetwork.c
+++ b/ports/cc3200/mods/modnetwork.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -25,9 +25,6 @@
* THE SOFTWARE.
*/
-#include "py/mpstate.h"
-#include "py/obj.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "py/mphal.h"
@@ -112,7 +109,7 @@ STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args
return (mp_obj_t)self;
}
-STATIC mp_obj_t network_server_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t network_server_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(network_server_args) - 1];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &network_server_args[1], args);
@@ -121,7 +118,7 @@ STATIC mp_obj_t network_server_init(mp_uint_t n_args, const mp_obj_t *pos_args,
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_server_init_obj, 1, network_server_init);
// timeout value given in seconds
-STATIC mp_obj_t network_server_timeout(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t network_server_timeout(size_t n_args, const mp_obj_t *args) {
if (n_args > 1) {
uint32_t timeout = mp_obj_get_int(args[1]);
servers_set_timeout(timeout * 1000);
@@ -147,12 +144,12 @@ STATIC mp_obj_t network_server_deinit(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_server_deinit_obj, network_server_deinit);
#endif
-STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&mod_network_nic_type_wlan },
+STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
+ { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_wlan) },
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
- { MP_OBJ_NEW_QSTR(MP_QSTR_Server), (mp_obj_t)&network_server_type },
+ { MP_ROM_QSTR(MP_QSTR_Server), MP_ROM_PTR(&network_server_type) },
#endif
};
@@ -164,11 +161,11 @@ const mp_obj_module_t mp_module_network = {
};
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
-STATIC const mp_map_elem_t network_server_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&network_server_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&network_server_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&network_server_timeout_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_isrunning), (mp_obj_t)&network_server_running_obj },
+STATIC const mp_rom_map_elem_t network_server_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&network_server_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&network_server_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_timeout), MP_ROM_PTR(&network_server_timeout_obj) },
+ { MP_ROM_QSTR(MP_QSTR_isrunning), MP_ROM_PTR(&network_server_running_obj) },
};
STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table);
diff --git a/cc3200/mods/modnetwork.h b/ports/cc3200/mods/modnetwork.h
similarity index 97%
rename from cc3200/mods/modnetwork.h
rename to ports/cc3200/mods/modnetwork.h
index 8e1196e86..6ec90a2ba 100644
--- a/cc3200/mods/modnetwork.h
+++ b/ports/cc3200/mods/modnetwork.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/modubinascii.c b/ports/cc3200/mods/modubinascii.c
similarity index 73%
rename from cc3200/mods/modubinascii.c
rename to ports/cc3200/mods/modubinascii.c
index 09f4b1e10..6b020ab39 100644
--- a/cc3200/mods/modubinascii.c
+++ b/ports/cc3200/mods/modubinascii.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -25,8 +25,6 @@
* THE SOFTWARE.
*/
-#include "py/mpconfig.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "extmod/modubinascii.h"
@@ -44,14 +42,14 @@
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
-STATIC const mp_map_elem_t mp_module_binascii_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ubinascii) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_hexlify), (mp_obj_t)&mod_binascii_hexlify_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_unhexlify), (mp_obj_t)&mod_binascii_unhexlify_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_a2b_base64), (mp_obj_t)&mod_binascii_a2b_base64_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_b2a_base64), (mp_obj_t)&mod_binascii_b2a_base64_obj },
+STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubinascii) },
+ { MP_ROM_QSTR(MP_QSTR_hexlify), MP_ROM_PTR(&mod_binascii_hexlify_obj) },
+ { MP_ROM_QSTR(MP_QSTR_unhexlify), MP_ROM_PTR(&mod_binascii_unhexlify_obj) },
+ { MP_ROM_QSTR(MP_QSTR_a2b_base64), MP_ROM_PTR(&mod_binascii_a2b_base64_obj) },
+ { MP_ROM_QSTR(MP_QSTR_b2a_base64), MP_ROM_PTR(&mod_binascii_b2a_base64_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table);
diff --git a/cc3200/mods/modubinascii.h b/ports/cc3200/mods/modubinascii.h
similarity index 94%
rename from cc3200/mods/modubinascii.h
rename to ports/cc3200/mods/modubinascii.h
index 3e784e9ae..eb9fc4f21 100644
--- a/cc3200/mods/modubinascii.h
+++ b/ports/cc3200/mods/modubinascii.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/moduhashlib.c b/ports/cc3200/mods/moduhashlib.c
similarity index 90%
rename from cc3200/mods/moduhashlib.c
rename to ports/cc3200/mods/moduhashlib.c
index e1145e4d8..96f514927 100644
--- a/cc3200/mods/moduhashlib.c
+++ b/ports/cc3200/mods/moduhashlib.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -30,7 +30,6 @@
#include "py/mpconfig.h"
#include MICROPY_HAL_H
-#include "py/nlr.h"
#include "py/runtime.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
@@ -117,7 +116,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) {
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
/// \classmethod \constructor([data[, block_size]])
/// initial data must be given if block_size wants to be passed
@@ -165,9 +164,9 @@ STATIC mp_obj_t hash_digest(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(hash_digest_obj, hash_digest);
-STATIC const mp_map_elem_t hash_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_update), (mp_obj_t) &hash_update_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_digest), (mp_obj_t) &hash_digest_obj },
+STATIC const mp_rom_map_elem_t hash_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hash_update_obj) },
+ { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hash_digest_obj) },
};
STATIC MP_DEFINE_CONST_DICT(hash_locals_dict, hash_locals_dict_table);
@@ -193,11 +192,11 @@ STATIC const mp_obj_type_t sha256_type = {
.locals_dict = (mp_obj_t)&hash_locals_dict,
};
-STATIC const mp_map_elem_t mp_module_hashlib_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uhashlib) },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_md5), (mp_obj_t)&md5_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sha1), (mp_obj_t)&sha1_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sha256), (mp_obj_t)&sha256_type },
+STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uhashlib) },
+ //{ MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&md5_type) },
+ { MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&sha1_type) },
+ { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&sha256_type) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table);
diff --git a/cc3200/mods/moduos.c b/ports/cc3200/mods/moduos.c
similarity index 77%
rename from cc3200/mods/moduos.c
rename to ports/cc3200/mods/moduos.c
index ed8879bf3..7d99c8e80 100644
--- a/cc3200/mods/moduos.c
+++ b/ports/cc3200/mods/moduos.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,8 +28,6 @@
#include
#include
-#include "py/mpstate.h"
-#include "py/nlr.h"
#include "py/objtuple.h"
#include "py/objstr.h"
#include "py/runtime.h"
@@ -78,7 +76,7 @@ void osmount_unmount_all (void) {
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
//
STATIC const qstr os_uname_info_fields[] = {
@@ -148,32 +146,32 @@ STATIC mp_obj_t os_dupterm(uint n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_dupterm_obj, 0, 1, os_dupterm);
-STATIC const mp_map_elem_t os_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uos) },
+STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_uname), (mp_obj_t)&os_uname_obj },
+ { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&mp_vfs_chdir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&mp_vfs_getcwd_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ilistdir), (mp_obj_t)&mp_vfs_ilistdir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_listdir), (mp_obj_t)&mp_vfs_listdir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mkdir), (mp_obj_t)&mp_vfs_mkdir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_rename), (mp_obj_t)&mp_vfs_rename_obj},
- { MP_OBJ_NEW_QSTR(MP_QSTR_remove), (mp_obj_t)&mp_vfs_remove_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_rmdir), (mp_obj_t)&mp_vfs_rmdir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&mp_vfs_stat_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_unlink), (mp_obj_t)&mp_vfs_remove_obj }, // unlink aliases to remove
+ { MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_vfs_mkdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&mp_vfs_rename_obj) },
+ { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_vfs_remove_obj) },
+ { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_vfs_stat_obj) },
+ { MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&mp_vfs_remove_obj) }, // unlink aliases to remove
- { MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&os_sync_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_urandom), (mp_obj_t)&os_urandom_obj },
+ { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&os_sync_obj) },
+ { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&os_urandom_obj) },
// MicroPython additions
// removed: mkfs
// renamed: unmount -> umount
- { MP_OBJ_NEW_QSTR(MP_QSTR_mount), (mp_obj_t)&mp_vfs_mount_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_umount), (mp_obj_t)&mp_vfs_umount_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_VfsFat), (mp_obj_t)&mp_fat_vfs_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_dupterm), (mp_obj_t)&os_dupterm_obj },
+ { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
+ { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
+ { MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
+ { MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&os_dupterm_obj) },
};
STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
diff --git a/cc3200/mods/moduos.h b/ports/cc3200/mods/moduos.h
similarity index 96%
rename from cc3200/mods/moduos.h
rename to ports/cc3200/mods/moduos.h
index 148cddf2e..f183715c9 100644
--- a/cc3200/mods/moduos.h
+++ b/ports/cc3200/mods/moduos.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/modusocket.c b/ports/cc3200/mods/modusocket.c
similarity index 90%
rename from cc3200/mods/modusocket.c
rename to ports/cc3200/mods/modusocket.c
index 4e17bbae6..f587e765a 100644
--- a/cc3200/mods/modusocket.c
+++ b/ports/cc3200/mods/modusocket.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -492,7 +492,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
// method socket.listen([backlog])
-STATIC mp_obj_t socket_listen(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) {
mod_network_socket_obj_t *self = args[0];
int32_t backlog = 0;
@@ -639,7 +639,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
// method socket.setsockopt(level, optname, value)
-STATIC mp_obj_t socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
mod_network_socket_obj_t *self = args[0];
mp_int_t level = mp_obj_get_int(args[1]);
@@ -697,34 +697,34 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
-STATIC mp_obj_t socket_makefile(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) {
(void)n_args;
return args[0];
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 6, socket_makefile);
-STATIC const mp_map_elem_t socket_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&socket_close_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&socket_close_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_bind), (mp_obj_t)&socket_bind_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_listen), (mp_obj_t)&socket_listen_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_accept), (mp_obj_t)&socket_accept_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&socket_connect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&socket_send_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sendall), (mp_obj_t)&socket_send_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&socket_recv_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sendto), (mp_obj_t)&socket_sendto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_recvfrom), (mp_obj_t)&socket_recvfrom_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_setsockopt), (mp_obj_t)&socket_setsockopt_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_settimeout), (mp_obj_t)&socket_settimeout_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_setblocking), (mp_obj_t)&socket_setblocking_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&socket_makefile_obj },
+STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&socket_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&socket_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) },
+ { MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&socket_listen_obj) },
+ { MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&socket_accept_obj) },
+ { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&socket_connect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&socket_send_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sendall), MP_ROM_PTR(&socket_send_obj) },
+ { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&socket_recv_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socket_sendto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_recvfrom), MP_ROM_PTR(&socket_recvfrom_obj) },
+ { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socket_setsockopt_obj) },
+ { MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&socket_settimeout_obj) },
+ { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
+ { MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&socket_makefile_obj) },
// stream methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read1_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read1_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
};
MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
@@ -799,21 +799,21 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_usocket_getaddrinfo_obj, mod_usocket_getaddrinfo);
-STATIC const mp_map_elem_t mp_module_usocket_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usocket) },
+STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&socket_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_usocket_getaddrinfo_obj },
+ { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) },
+ { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_usocket_getaddrinfo_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(SL_AF_INET) },
+ { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(SL_AF_INET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(SL_SOCK_STREAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(SL_SOCK_DGRAM) },
+ { MP_ROM_QSTR(MP_QSTR_SOCK_STREAM), MP_ROM_INT(SL_SOCK_STREAM) },
+ { MP_ROM_QSTR(MP_QSTR_SOCK_DGRAM), MP_ROM_INT(SL_SOCK_DGRAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_SEC), MP_OBJ_NEW_SMALL_INT(SL_SEC_SOCKET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_TCP), MP_OBJ_NEW_SMALL_INT(SL_IPPROTO_TCP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_UDP), MP_OBJ_NEW_SMALL_INT(SL_IPPROTO_UDP) },
+ { MP_ROM_QSTR(MP_QSTR_IPPROTO_SEC), MP_ROM_INT(SL_SEC_SOCKET) },
+ { MP_ROM_QSTR(MP_QSTR_IPPROTO_TCP), MP_ROM_INT(SL_IPPROTO_TCP) },
+ { MP_ROM_QSTR(MP_QSTR_IPPROTO_UDP), MP_ROM_INT(SL_IPPROTO_UDP) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table);
diff --git a/cc3200/mods/modusocket.h b/ports/cc3200/mods/modusocket.h
similarity index 95%
rename from cc3200/mods/modusocket.h
rename to ports/cc3200/mods/modusocket.h
index 80c1f24cd..6e7758662 100644
--- a/cc3200/mods/modusocket.h
+++ b/ports/cc3200/mods/modusocket.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/modussl.c b/ports/cc3200/mods/modussl.c
similarity index 83%
rename from cc3200/mods/modussl.c
rename to ports/cc3200/mods/modussl.c
index 95ecdbce7..321157049 100644
--- a/cc3200/mods/modussl.c
+++ b/ports/cc3200/mods/modussl.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -57,7 +57,7 @@ typedef struct _mp_obj_ssl_socket_t {
STATIC const mp_obj_type_t ssl_socket_type;
/******************************************************************************/
-// Micro Python bindings; SSL class
+// MicroPython bindings; SSL class
// ssl sockets inherit from normal socket, so we take its
// locals and stream methods
@@ -70,7 +70,7 @@ STATIC const mp_obj_type_t ssl_socket_type = {
.locals_dict = (mp_obj_t)&socket_locals_dict,
};
-STATIC mp_obj_t mod_ssl_wrap_socket(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t allowed_args[] = {
{ MP_QSTR_sock, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_keyfile, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -137,22 +137,22 @@ STATIC mp_obj_t mod_ssl_wrap_socket(mp_uint_t n_args, const mp_obj_t *pos_args,
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket);
-STATIC const mp_map_elem_t mp_module_ussl_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ussl) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_wrap_socket), (mp_obj_t)&mod_ssl_wrap_socket_obj },
+STATIC const mp_rom_map_elem_t mp_module_ussl_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ussl) },
+ { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) },
// class exceptions
- { MP_OBJ_NEW_QSTR(MP_QSTR_SSLError), (mp_obj_t)&mp_type_OSError },
+ { MP_ROM_QSTR(MP_QSTR_SSLError), MP_ROM_PTR(&mp_type_OSError) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_CERT_NONE), MP_OBJ_NEW_SMALL_INT(SSL_CERT_NONE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_CERT_OPTIONAL), MP_OBJ_NEW_SMALL_INT(SSL_CERT_OPTIONAL) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_CERT_REQUIRED), MP_OBJ_NEW_SMALL_INT(SSL_CERT_REQUIRED) },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_PROTOCOL_SSLv3), MP_OBJ_NEW_SMALL_INT(SL_SO_SEC_METHOD_SSLV3) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PROTOCOL_TLSv1), MP_OBJ_NEW_SMALL_INT(SL_SO_SEC_METHOD_TLSV1) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PROTOCOL_TLSv1_1), MP_OBJ_NEW_SMALL_INT(SL_SO_SEC_METHOD_TLSV1_1) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PROTOCOL_TLSv1_2), MP_OBJ_NEW_SMALL_INT(SL_SO_SEC_METHOD_TLSV1_2) },
+ { MP_ROM_QSTR(MP_QSTR_CERT_NONE), MP_ROM_INT(SSL_CERT_NONE) },
+ { MP_ROM_QSTR(MP_QSTR_CERT_OPTIONAL), MP_ROM_INT(SSL_CERT_OPTIONAL) },
+ { MP_ROM_QSTR(MP_QSTR_CERT_REQUIRED), MP_ROM_INT(SSL_CERT_REQUIRED) },
+
+ { MP_ROM_QSTR(MP_QSTR_PROTOCOL_SSLv3), MP_ROM_INT(SL_SO_SEC_METHOD_SSLV3) },
+ { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLSv1), MP_ROM_INT(SL_SO_SEC_METHOD_TLSV1) },
+ { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLSv1_1), MP_ROM_INT(SL_SO_SEC_METHOD_TLSV1_1) },
+ { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLSv1_2), MP_ROM_INT(SL_SO_SEC_METHOD_TLSV1_2) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_ussl_globals, mp_module_ussl_globals_table);
diff --git a/cc3200/mods/modutime.c b/ports/cc3200/mods/modutime.c
similarity index 80%
rename from cc3200/mods/modutime.c
rename to ports/cc3200/mods/modutime.c
index 48fde67e7..13750f96b 100644
--- a/cc3200/mods/modutime.c
+++ b/ports/cc3200/mods/modutime.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -51,7 +51,7 @@
/// and for sleeping.
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
/// \function localtime([secs])
/// Convert a time expressed in seconds since Jan 1, 2000 into an 8-tuple which
@@ -65,7 +65,7 @@
/// second is 0-59
/// weekday is 0-6 for Mon-Sun.
/// yearday is 1-366
-STATIC mp_obj_t time_localtime(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
if (n_args == 0 || args[0] == mp_const_none) {
timeutils_struct_time_t tm;
@@ -131,22 +131,22 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
}
MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);
-STATIC const mp_map_elem_t time_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_utime) },
+STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_localtime), (mp_obj_t)&time_localtime_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mktime), (mp_obj_t)&time_mktime_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_time_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&time_sleep_obj },
+ { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) },
+ { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&time_sleep_obj) },
// MicroPython additions
- { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&mp_utime_sleep_ms_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&mp_utime_sleep_us_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&mp_utime_ticks_ms_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&mp_utime_ticks_us_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&mp_utime_ticks_cpu_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_add), (mp_obj_t)&mp_utime_ticks_add_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&mp_utime_ticks_diff_obj },
+ { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
};
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
diff --git a/cc3200/mods/modwipy.c b/ports/cc3200/mods/modwipy.c
similarity index 67%
rename from cc3200/mods/modwipy.c
rename to ports/cc3200/mods/modwipy.c
index b4c18d153..0f16e7301 100644
--- a/cc3200/mods/modwipy.c
+++ b/ports/cc3200/mods/modwipy.c
@@ -5,9 +5,9 @@
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
-STATIC mp_obj_t mod_wipy_heartbeat (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t mod_wipy_heartbeat(size_t n_args, const mp_obj_t *args) {
if (n_args) {
mperror_enable_heartbeat (mp_obj_is_true(args[0]));
return mp_const_none;
@@ -17,9 +17,9 @@ STATIC mp_obj_t mod_wipy_heartbeat (mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_wipy_heartbeat_obj, 0, 1, mod_wipy_heartbeat);
-STATIC const mp_map_elem_t wipy_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_wipy) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_heartbeat), (mp_obj_t)&mod_wipy_heartbeat_obj },
+STATIC const mp_rom_map_elem_t wipy_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wipy) },
+ { MP_ROM_QSTR(MP_QSTR_heartbeat), MP_ROM_PTR(&mod_wipy_heartbeat_obj) },
};
STATIC MP_DEFINE_CONST_DICT(wipy_module_globals, wipy_module_globals_table);
diff --git a/cc3200/mods/modwlan.c b/ports/cc3200/mods/modwlan.c
similarity index 93%
rename from cc3200/mods/modwlan.c
rename to ports/cc3200/mods/modwlan.c
index 68d892364..f9c7111b3 100644
--- a/cc3200/mods/modwlan.c
+++ b/ports/cc3200/mods/modwlan.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -763,7 +763,7 @@ STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid) {
}
/******************************************************************************/
-// Micro Python bindings; WLAN class
+// MicroPython bindings; WLAN class
/// \class WLAN - WiFi driver
@@ -845,7 +845,7 @@ STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
return (mp_obj_t)self;
}
-STATIC mp_obj_t wlan_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t wlan_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(wlan_init_args) - 1];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &wlan_init_args[1], args);
@@ -904,7 +904,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan);
-STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t allowed_args[] = {
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_auth, MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -981,7 +981,7 @@ STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_isconnected_obj, wlan_isconnected);
-STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t wlan_ifconfig(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t wlan_ifconfig_args[] = {
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_config, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
@@ -1058,7 +1058,7 @@ STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_ifconfig_obj, 1, wlan_ifconfig);
-STATIC mp_obj_t wlan_mode (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t wlan_mode(size_t n_args, const mp_obj_t *args) {
wlan_obj_t *self = args[0];
if (n_args == 1) {
return mp_obj_new_int(self->mode);
@@ -1072,7 +1072,7 @@ STATIC mp_obj_t wlan_mode (mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mode_obj, 1, 2, wlan_mode);
-STATIC mp_obj_t wlan_ssid (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) {
wlan_obj_t *self = args[0];
if (n_args == 1) {
return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid), false);
@@ -1087,7 +1087,7 @@ STATIC mp_obj_t wlan_ssid (mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_ssid_obj, 1, 2, wlan_ssid);
-STATIC mp_obj_t wlan_auth (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) {
wlan_obj_t *self = args[0];
if (n_args == 1) {
if (self->auth == SL_SEC_TYPE_OPEN) {
@@ -1117,7 +1117,7 @@ STATIC mp_obj_t wlan_auth (mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_auth_obj, 1, 2, wlan_auth);
-STATIC mp_obj_t wlan_channel (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t wlan_channel(size_t n_args, const mp_obj_t *args) {
wlan_obj_t *self = args[0];
if (n_args == 1) {
return mp_obj_new_int(self->channel);
@@ -1131,7 +1131,7 @@ STATIC mp_obj_t wlan_channel (mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_channel_obj, 1, 2, wlan_channel);
-STATIC mp_obj_t wlan_antenna (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t wlan_antenna(size_t n_args, const mp_obj_t *args) {
wlan_obj_t *self = args[0];
if (n_args == 1) {
return mp_obj_new_int(self->antenna);
@@ -1146,7 +1146,7 @@ STATIC mp_obj_t wlan_antenna (mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_antenna_obj, 1, 2, wlan_antenna);
-STATIC mp_obj_t wlan_mac (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t wlan_mac(size_t n_args, const mp_obj_t *args) {
wlan_obj_t *self = args[0];
if (n_args == 1) {
return mp_obj_new_bytes((const byte *)self->mac, SL_BSSID_LENGTH);
@@ -1164,7 +1164,7 @@ STATIC mp_obj_t wlan_mac (mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mac_obj, 1, 2, wlan_mac);
-STATIC mp_obj_t wlan_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t wlan_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
@@ -1254,35 +1254,35 @@ STATIC mp_obj_t wlan_print_ver(void) {
STATIC MP_DEFINE_CONST_FUN_OBJ_0(wlan_print_ver_fun_obj, wlan_print_ver);
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(wlan_print_ver_obj, MP_ROM_PTR(&wlan_print_ver_fun_obj));
-STATIC const mp_map_elem_t wlan_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&wlan_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&wlan_scan_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&wlan_connect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)&wlan_disconnect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_isconnected), (mp_obj_t)&wlan_isconnected_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ifconfig), (mp_obj_t)&wlan_ifconfig_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&wlan_mode_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ssid), (mp_obj_t)&wlan_ssid_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_auth), (mp_obj_t)&wlan_auth_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_channel), (mp_obj_t)&wlan_channel_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_antenna), (mp_obj_t)&wlan_antenna_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mac), (mp_obj_t)&wlan_mac_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&wlan_irq_obj },
- // { MP_OBJ_NEW_QSTR(MP_QSTR_connections), (mp_obj_t)&wlan_connections_obj },
- // { MP_OBJ_NEW_QSTR(MP_QSTR_urn), (mp_obj_t)&wlan_urn_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_print_ver), (mp_obj_t)&wlan_print_ver_obj },
+STATIC const mp_rom_map_elem_t wlan_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&wlan_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&wlan_scan_obj) },
+ { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wlan_connect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&wlan_disconnect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&wlan_isconnected_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&wlan_ifconfig_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&wlan_mode_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ssid), MP_ROM_PTR(&wlan_ssid_obj) },
+ { MP_ROM_QSTR(MP_QSTR_auth), MP_ROM_PTR(&wlan_auth_obj) },
+ { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wlan_channel_obj) },
+ { MP_ROM_QSTR(MP_QSTR_antenna), MP_ROM_PTR(&wlan_antenna_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mac), MP_ROM_PTR(&wlan_mac_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&wlan_irq_obj) },
+ //{ MP_ROM_QSTR(MP_QSTR_connections), MP_ROM_PTR(&wlan_connections_obj) },
+ //{ MP_ROM_QSTR(MP_QSTR_urn), MP_ROM_PTR(&wlan_urn_obj) },
+ { MP_ROM_QSTR(MP_QSTR_print_ver), MP_ROM_PTR(&wlan_print_ver_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_STA), MP_OBJ_NEW_SMALL_INT(ROLE_STA) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AP), MP_OBJ_NEW_SMALL_INT(ROLE_AP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WEP), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WEP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WPA), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WPA_WPA2) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WPA2), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_WPA_WPA2) },
+ { MP_ROM_QSTR(MP_QSTR_STA), MP_ROM_INT(ROLE_STA) },
+ { MP_ROM_QSTR(MP_QSTR_AP), MP_ROM_INT(ROLE_AP) },
+ { MP_ROM_QSTR(MP_QSTR_WEP), MP_ROM_INT(SL_SEC_TYPE_WEP) },
+ { MP_ROM_QSTR(MP_QSTR_WPA), MP_ROM_INT(SL_SEC_TYPE_WPA_WPA2) },
+ { MP_ROM_QSTR(MP_QSTR_WPA2), MP_ROM_INT(SL_SEC_TYPE_WPA_WPA2) },
#if MICROPY_HW_ANTENNA_DIVERSITY
- { MP_OBJ_NEW_QSTR(MP_QSTR_INT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_INTERNAL) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_EXT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_EXTERNAL) },
+ { MP_ROM_QSTR(MP_QSTR_INT_ANT), MP_ROM_INT(ANTENNA_TYPE_INTERNAL) },
+ { MP_ROM_QSTR(MP_QSTR_EXT_ANT), MP_ROM_INT(ANTENNA_TYPE_EXTERNAL) },
#endif
- { MP_OBJ_NEW_QSTR(MP_QSTR_ANY_EVENT), MP_OBJ_NEW_SMALL_INT(MODWLAN_WIFI_EVENT_ANY) },
+ { MP_ROM_QSTR(MP_QSTR_ANY_EVENT), MP_ROM_INT(MODWLAN_WIFI_EVENT_ANY) },
};
STATIC MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table);
diff --git a/cc3200/mods/modwlan.h b/ports/cc3200/mods/modwlan.h
similarity index 98%
rename from cc3200/mods/modwlan.h
rename to ports/cc3200/mods/modwlan.h
index d37d276e8..b806644f5 100644
--- a/cc3200/mods/modwlan.h
+++ b/ports/cc3200/mods/modwlan.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybadc.c b/ports/cc3200/mods/pybadc.c
similarity index 91%
rename from cc3200/mods/pybadc.c
rename to ports/cc3200/mods/pybadc.c
index 696e7650b..c73b8c149 100644
--- a/cc3200/mods/pybadc.c
+++ b/ports/cc3200/mods/pybadc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,8 +28,6 @@
#include
#include
-#include "py/mpconfig.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/gc.h"
@@ -126,7 +124,7 @@ STATIC void pyb_adc_deinit_all_channels (void) {
}
/******************************************************************************/
-/* Micro Python bindings : adc object */
+/* MicroPython bindings : adc object */
STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_adc_obj_t *self = self_in;
@@ -168,7 +166,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
return self;
}
-STATIC mp_obj_t adc_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t adc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_adc_init_args) - 1];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_adc_init_args[1], args);
@@ -193,7 +191,7 @@ STATIC mp_obj_t adc_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_deinit_obj, adc_deinit);
-STATIC mp_obj_t adc_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t adc_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t pyb_adc_channel_args[] = {
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -228,10 +226,10 @@ STATIC mp_obj_t adc_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_channel_obj, 1, adc_channel);
-STATIC const mp_map_elem_t adc_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&adc_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&adc_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_channel), (mp_obj_t)&adc_channel_obj },
+STATIC const mp_rom_map_elem_t adc_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&adc_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&adc_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&adc_channel_obj) },
};
STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table);
@@ -295,10 +293,10 @@ STATIC mp_obj_t adc_channel_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c
return adc_channel_value (self_in);
}
-STATIC const mp_map_elem_t adc_channel_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&adc_channel_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&adc_channel_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&adc_channel_value_obj },
+STATIC const mp_rom_map_elem_t adc_channel_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&adc_channel_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&adc_channel_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&adc_channel_value_obj) },
};
STATIC MP_DEFINE_CONST_DICT(adc_channel_locals_dict, adc_channel_locals_dict_table);
diff --git a/cc3200/mods/pybadc.h b/ports/cc3200/mods/pybadc.h
similarity index 94%
rename from cc3200/mods/pybadc.h
rename to ports/cc3200/mods/pybadc.h
index 50640ee60..db04b006b 100644
--- a/cc3200/mods/pybadc.h
+++ b/ports/cc3200/mods/pybadc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybflash.c b/ports/cc3200/mods/pybflash.c
similarity index 93%
rename from cc3200/mods/pybflash.c
rename to ports/cc3200/mods/pybflash.c
index f5af79dbf..51f4cb517 100644
--- a/cc3200/mods/pybflash.c
+++ b/ports/cc3200/mods/pybflash.c
@@ -79,10 +79,10 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl);
-STATIC const mp_map_elem_t pyb_flash_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_readblocks), (mp_obj_t)&pyb_flash_readblocks_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_writeblocks), (mp_obj_t)&pyb_flash_writeblocks_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&pyb_flash_ioctl_obj },
+STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&pyb_flash_readblocks_obj) },
+ { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&pyb_flash_writeblocks_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_flash_ioctl_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table);
diff --git a/cc3200/mods/pybflash.h b/ports/cc3200/mods/pybflash.h
similarity index 100%
rename from cc3200/mods/pybflash.h
rename to ports/cc3200/mods/pybflash.h
diff --git a/cc3200/mods/pybi2c.c b/ports/cc3200/mods/pybi2c.c
similarity index 92%
rename from cc3200/mods/pybi2c.c
rename to ports/cc3200/mods/pybi2c.c
index 9fc97d914..d08627fa4 100644
--- a/cc3200/mods/pybi2c.c
+++ b/ports/cc3200/mods/pybi2c.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "py/mphal.h"
@@ -281,7 +280,7 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
/******************************************************************************/
STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_i2c_obj_t *self = self_in;
@@ -380,7 +379,7 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan);
-STATIC mp_obj_t pyb_i2c_readfrom(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t pyb_i2c_readfrom_args[] = {
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
{ MP_QSTR_nbytes, MP_ARG_REQUIRED | MP_ARG_OBJ, },
@@ -398,7 +397,7 @@ STATIC mp_obj_t pyb_i2c_readfrom(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_obj, 3, pyb_i2c_readfrom);
-STATIC mp_obj_t pyb_i2c_readfrom_into(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t pyb_i2c_readfrom_into_args[] = {
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
{ MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, },
@@ -416,7 +415,7 @@ STATIC mp_obj_t pyb_i2c_readfrom_into(mp_uint_t n_args, const mp_obj_t *pos_args
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_into_obj, 1, pyb_i2c_readfrom_into);
-STATIC mp_obj_t pyb_i2c_writeto(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t pyb_i2c_writeto_args[] = {
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
{ MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, },
@@ -444,7 +443,7 @@ STATIC mp_obj_t pyb_i2c_writeto(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_obj, 1, pyb_i2c_writeto);
-STATIC mp_obj_t pyb_i2c_readfrom_mem(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t pyb_i2c_readfrom_mem_args[] = {
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
{ MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, },
@@ -469,7 +468,7 @@ STATIC const mp_arg_t pyb_i2c_readfrom_mem_into_args[] = {
{ MP_QSTR_addrsize, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
};
-STATIC mp_obj_t pyb_i2c_readfrom_mem_into(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), pyb_i2c_readfrom_mem_into_args, args);
@@ -481,7 +480,7 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem_into(mp_uint_t n_args, const mp_obj_t *pos_
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into);
-STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args), pyb_i2c_readfrom_mem_into_args, args);
@@ -508,17 +507,17 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args,
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem);
-STATIC const mp_map_elem_t pyb_i2c_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_i2c_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_i2c_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&pyb_i2c_scan_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readfrom), (mp_obj_t)&pyb_i2c_readfrom_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_into), (mp_obj_t)&pyb_i2c_readfrom_into_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_writeto), (mp_obj_t)&pyb_i2c_writeto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_mem), (mp_obj_t)&pyb_i2c_readfrom_mem_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readfrom_mem_into), (mp_obj_t)&pyb_i2c_readfrom_mem_into_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_writeto_mem), (mp_obj_t)&pyb_i2c_writeto_mem_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_i2c_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_i2c_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&pyb_i2c_scan_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readfrom), MP_ROM_PTR(&pyb_i2c_readfrom_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readfrom_into), MP_ROM_PTR(&pyb_i2c_readfrom_into_obj) },
+ { MP_ROM_QSTR(MP_QSTR_writeto), MP_ROM_PTR(&pyb_i2c_writeto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readfrom_mem), MP_ROM_PTR(&pyb_i2c_readfrom_mem_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readfrom_mem_into), MP_ROM_PTR(&pyb_i2c_readfrom_mem_into_obj) },
+ { MP_ROM_QSTR(MP_QSTR_writeto_mem), MP_ROM_PTR(&pyb_i2c_writeto_mem_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table);
diff --git a/cc3200/mods/pybi2c.h b/ports/cc3200/mods/pybi2c.h
similarity index 94%
rename from cc3200/mods/pybi2c.h
rename to ports/cc3200/mods/pybi2c.h
index d547f6330..dcc3f0468 100644
--- a/cc3200/mods/pybi2c.h
+++ b/ports/cc3200/mods/pybi2c.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybpin.c b/ports/cc3200/mods/pybpin.c
similarity index 91%
rename from cc3200/mods/pybpin.c
rename to ports/cc3200/mods/pybpin.c
index c2a469117..c877433e9 100644
--- a/cc3200/mods/pybpin.c
+++ b/ports/cc3200/mods/pybpin.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,11 +29,8 @@
#include
#include
-#include "py/mpconfig.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "py/gc.h"
-#include "py/mpstate.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
@@ -519,7 +516,7 @@ STATIC void EXTI_Handler(uint port) {
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
STATIC const mp_arg_t pin_init_args[] = {
{ MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
@@ -530,7 +527,7 @@ STATIC const mp_arg_t pin_init_args[] = {
};
#define pin_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args)
-STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[pin_INIT_NUM_ARGS];
mp_arg_parse_all(n_args, pos_args, kw_args, pin_INIT_NUM_ARGS, pin_init_args, args);
@@ -660,12 +657,12 @@ STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
return (mp_obj_t)pin;
}
-STATIC mp_obj_t pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
-STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
pin_obj_t *self = args[0];
if (n_args == 1) {
// get the value
@@ -690,7 +687,7 @@ STATIC mp_obj_t pin_id(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_id_obj, pin_id);
-STATIC mp_obj_t pin_mode(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pin_mode(size_t n_args, const mp_obj_t *args) {
pin_obj_t *self = args[0];
if (n_args == 1) {
return mp_obj_new_int(self->mode);
@@ -704,7 +701,7 @@ STATIC mp_obj_t pin_mode(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mode_obj, 1, 2, pin_mode);
-STATIC mp_obj_t pin_pull(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pin_pull(size_t n_args, const mp_obj_t *args) {
pin_obj_t *self = args[0];
if (n_args == 1) {
if (self->pull == PIN_TYPE_STD) {
@@ -726,7 +723,7 @@ STATIC mp_obj_t pin_pull(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_pull_obj, 1, 2, pin_pull);
-STATIC mp_obj_t pin_drive(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pin_drive(size_t n_args, const mp_obj_t *args) {
pin_obj_t *self = args[0];
if (n_args == 1) {
return mp_obj_new_int(self->strength);
@@ -761,7 +758,7 @@ STATIC mp_obj_t pin_alt_list(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_alt_list_obj, pin_alt_list);
/// \method irq(trigger, priority, handler, wake)
-STATIC mp_obj_t pin_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
pin_obj_t *self = pos_args[0];
@@ -902,35 +899,35 @@ STATIC mp_obj_t pin_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *k
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
-STATIC const mp_map_elem_t pin_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pin_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pin_value_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_id), (mp_obj_t)&pin_id_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&pin_mode_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_pull), (mp_obj_t)&pin_pull_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_drive), (mp_obj_t)&pin_drive_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_alt_list), (mp_obj_t)&pin_alt_list_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pin_irq_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) },
+ { MP_ROM_QSTR(MP_QSTR_id), MP_ROM_PTR(&pin_id_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&pin_mode_obj) },
+ { MP_ROM_QSTR(MP_QSTR_pull), MP_ROM_PTR(&pin_pull_obj) },
+ { MP_ROM_QSTR(MP_QSTR_drive), MP_ROM_PTR(&pin_drive_obj) },
+ { MP_ROM_QSTR(MP_QSTR_alt_list), MP_ROM_PTR(&pin_alt_list_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pin_irq_obj) },
// class attributes
- { MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&pin_board_pins_obj_type },
+ { MP_ROM_QSTR(MP_QSTR_board), MP_ROM_PTR(&pin_board_pins_obj_type) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_IN), MP_OBJ_NEW_SMALL_INT(GPIO_DIR_MODE_IN) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OUT), MP_OBJ_NEW_SMALL_INT(GPIO_DIR_MODE_OUT) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OPEN_DRAIN), MP_OBJ_NEW_SMALL_INT(PIN_TYPE_OD) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ALT), MP_OBJ_NEW_SMALL_INT(GPIO_DIR_MODE_ALT) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ALT_OPEN_DRAIN), MP_OBJ_NEW_SMALL_INT(GPIO_DIR_MODE_ALT_OD) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PULL_UP), MP_OBJ_NEW_SMALL_INT(PIN_TYPE_STD_PU) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PULL_DOWN), MP_OBJ_NEW_SMALL_INT(PIN_TYPE_STD_PD) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_LOW_POWER), MP_OBJ_NEW_SMALL_INT(PIN_STRENGTH_2MA) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_MED_POWER), MP_OBJ_NEW_SMALL_INT(PIN_STRENGTH_4MA) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_HIGH_POWER), MP_OBJ_NEW_SMALL_INT(PIN_STRENGTH_6MA) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_FALLING), MP_OBJ_NEW_SMALL_INT(PYB_PIN_FALLING_EDGE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_RISING), MP_OBJ_NEW_SMALL_INT(PYB_PIN_RISING_EDGE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_LOW_LEVEL), MP_OBJ_NEW_SMALL_INT(PYB_PIN_LOW_LEVEL) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_HIGH_LEVEL), MP_OBJ_NEW_SMALL_INT(PYB_PIN_HIGH_LEVEL) },
+ { MP_ROM_QSTR(MP_QSTR_IN), MP_ROM_INT(GPIO_DIR_MODE_IN) },
+ { MP_ROM_QSTR(MP_QSTR_OUT), MP_ROM_INT(GPIO_DIR_MODE_OUT) },
+ { MP_ROM_QSTR(MP_QSTR_OPEN_DRAIN), MP_ROM_INT(PIN_TYPE_OD) },
+ { MP_ROM_QSTR(MP_QSTR_ALT), MP_ROM_INT(GPIO_DIR_MODE_ALT) },
+ { MP_ROM_QSTR(MP_QSTR_ALT_OPEN_DRAIN), MP_ROM_INT(GPIO_DIR_MODE_ALT_OD) },
+ { MP_ROM_QSTR(MP_QSTR_PULL_UP), MP_ROM_INT(PIN_TYPE_STD_PU) },
+ { MP_ROM_QSTR(MP_QSTR_PULL_DOWN), MP_ROM_INT(PIN_TYPE_STD_PD) },
+ { MP_ROM_QSTR(MP_QSTR_LOW_POWER), MP_ROM_INT(PIN_STRENGTH_2MA) },
+ { MP_ROM_QSTR(MP_QSTR_MED_POWER), MP_ROM_INT(PIN_STRENGTH_4MA) },
+ { MP_ROM_QSTR(MP_QSTR_HIGH_POWER), MP_ROM_INT(PIN_STRENGTH_6MA) },
+ { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(PYB_PIN_FALLING_EDGE) },
+ { MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(PYB_PIN_RISING_EDGE) },
+ { MP_ROM_QSTR(MP_QSTR_IRQ_LOW_LEVEL), MP_ROM_INT(PYB_PIN_LOW_LEVEL) },
+ { MP_ROM_QSTR(MP_QSTR_IRQ_HIGH_LEVEL), MP_ROM_INT(PYB_PIN_HIGH_LEVEL) },
};
STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
diff --git a/cc3200/mods/pybpin.h b/ports/cc3200/mods/pybpin.h
similarity index 98%
rename from cc3200/mods/pybpin.h
rename to ports/cc3200/mods/pybpin.h
index 6b4b7b1ed..74f0af2b3 100644
--- a/cc3200/mods/pybpin.h
+++ b/ports/cc3200/mods/pybpin.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybrtc.c b/ports/cc3200/mods/pybrtc.c
similarity index 92%
rename from cc3200/mods/pybrtc.c
rename to ports/cc3200/mods/pybrtc.c
index 134bd440e..e7b9cf258 100644
--- a/cc3200/mods/pybrtc.c
+++ b/ports/cc3200/mods/pybrtc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -278,7 +278,7 @@ STATIC void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) {
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
STATIC const mp_arg_t pyb_rtc_init_args[] = {
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
@@ -310,7 +310,7 @@ STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_
return (mp_obj_t)&pyb_rtc_obj;
}
-STATIC mp_obj_t pyb_rtc_init (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_rtc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_rtc_init_args) - 1];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_rtc_init_args[1], args);
@@ -347,7 +347,7 @@ STATIC mp_obj_t pyb_rtc_deinit (mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_deinit_obj, pyb_rtc_deinit);
-STATIC mp_obj_t pyb_rtc_alarm (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t allowed_args[] = {
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_time, MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -388,7 +388,7 @@ STATIC mp_obj_t pyb_rtc_alarm (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_alarm_obj, 1, pyb_rtc_alarm);
-STATIC mp_obj_t pyb_rtc_alarm_left (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) {
pyb_rtc_obj_t *self = args[0];
int32_t ms_left;
uint32_t c_seconds;
@@ -411,7 +411,7 @@ STATIC mp_obj_t pyb_rtc_alarm_left (mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left);
-STATIC mp_obj_t pyb_rtc_alarm_cancel (mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) {
// only alarm id 0 is available
if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
mp_raise_OSError(MP_ENODEV);
@@ -423,7 +423,7 @@ STATIC mp_obj_t pyb_rtc_alarm_cancel (mp_uint_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_cancel_obj, 1, 2, pyb_rtc_alarm_cancel);
/// \method irq(trigger, priority, handler, wake)
-STATIC mp_obj_t pyb_rtc_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
pyb_rtc_obj_t *self = pos_args[0];
@@ -456,17 +456,17 @@ STATIC mp_obj_t pyb_rtc_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq);
-STATIC const mp_map_elem_t pyb_rtc_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_rtc_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_rtc_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_now), (mp_obj_t)&pyb_rtc_now_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_alarm), (mp_obj_t)&pyb_rtc_alarm_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_left), (mp_obj_t)&pyb_rtc_alarm_left_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_cancel), (mp_obj_t)&pyb_rtc_alarm_cancel_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_rtc_irq_obj },
+STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_rtc_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_rtc_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_now), MP_ROM_PTR(&pyb_rtc_now_obj) },
+ { MP_ROM_QSTR(MP_QSTR_alarm), MP_ROM_PTR(&pyb_rtc_alarm_obj) },
+ { MP_ROM_QSTR(MP_QSTR_alarm_left), MP_ROM_PTR(&pyb_rtc_alarm_left_obj) },
+ { MP_ROM_QSTR(MP_QSTR_alarm_cancel), MP_ROM_PTR(&pyb_rtc_alarm_cancel_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_rtc_irq_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_ALARM0), MP_OBJ_NEW_SMALL_INT(PYB_RTC_ALARM0) },
+ { MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(PYB_RTC_ALARM0) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
diff --git a/cc3200/mods/pybrtc.h b/ports/cc3200/mods/pybrtc.h
similarity index 96%
rename from cc3200/mods/pybrtc.h
rename to ports/cc3200/mods/pybrtc.h
index 3fd11ecd6..f73de3f5a 100644
--- a/cc3200/mods/pybrtc.h
+++ b/ports/cc3200/mods/pybrtc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybsd.c b/ports/cc3200/mods/pybsd.c
similarity index 92%
rename from cc3200/mods/pybsd.c
rename to ports/cc3200/mods/pybsd.c
index 306baea8b..c47d4e945 100644
--- a/cc3200/mods/pybsd.c
+++ b/ports/cc3200/mods/pybsd.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -118,7 +118,7 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args)
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
//
STATIC const mp_arg_t pyb_sd_init_args[] = {
@@ -144,7 +144,7 @@ STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t
return self;
}
-STATIC mp_obj_t pyb_sd_init (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_sd_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_sd_init_args) - 1];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_sd_init_args[1], args);
@@ -202,13 +202,13 @@ STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_ioctl_obj, pyb_sd_ioctl);
-STATIC const mp_map_elem_t pyb_sd_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_sd_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_sd_deinit_obj },
+STATIC const mp_rom_map_elem_t pyb_sd_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_sd_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_sd_deinit_obj) },
// block device protocol
- { MP_OBJ_NEW_QSTR(MP_QSTR_readblocks), (mp_obj_t)&pyb_sd_readblocks_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_writeblocks), (mp_obj_t)&pyb_sd_writeblocks_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&pyb_sd_ioctl_obj },
+ { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&pyb_sd_readblocks_obj) },
+ { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&pyb_sd_writeblocks_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_sd_ioctl_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table);
diff --git a/cc3200/mods/pybsd.h b/ports/cc3200/mods/pybsd.h
similarity index 96%
rename from cc3200/mods/pybsd.h
rename to ports/cc3200/mods/pybsd.h
index 084d7caaf..af942084d 100644
--- a/cc3200/mods/pybsd.h
+++ b/ports/cc3200/mods/pybsd.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybsleep.c b/ports/cc3200/mods/pybsleep.c
similarity index 99%
rename from cc3200/mods/pybsleep.c
rename to ports/cc3200/mods/pybsleep.c
index ced7fef85..798c6538b 100644
--- a/cc3200/mods/pybsleep.c
+++ b/ports/cc3200/mods/pybsleep.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "inc/hw_types.h"
diff --git a/cc3200/mods/pybsleep.h b/ports/cc3200/mods/pybsleep.h
similarity index 97%
rename from cc3200/mods/pybsleep.h
rename to ports/cc3200/mods/pybsleep.h
index 513e6fa95..e98636178 100644
--- a/cc3200/mods/pybsleep.h
+++ b/ports/cc3200/mods/pybsleep.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybspi.c b/ports/cc3200/mods/pybspi.c
similarity index 91%
rename from cc3200/mods/pybspi.c
rename to ports/cc3200/mods/pybspi.c
index 3cd384266..27591e4f4 100644
--- a/cc3200/mods/pybspi.c
+++ b/ports/cc3200/mods/pybspi.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "bufhelper.h"
@@ -144,7 +143,7 @@ STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxda
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
/******************************************************************************/
STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_spi_obj_t *self = self_in;
@@ -248,7 +247,7 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
return self;
}
-STATIC mp_obj_t pyb_spi_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_spi_init_args) - 1];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_spi_init_args[1], args);
@@ -287,7 +286,7 @@ STATIC mp_obj_t pyb_spi_write (mp_obj_t self_in, mp_obj_t buf) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_spi_write_obj, pyb_spi_write);
-STATIC mp_obj_t pyb_spi_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_spi_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_nbytes, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_write, MP_ARG_INT, {.u_int = 0x00} },
@@ -311,7 +310,7 @@ STATIC mp_obj_t pyb_spi_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_read_obj, 1, pyb_spi_read);
-STATIC mp_obj_t pyb_spi_readinto(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_write, MP_ARG_INT, {.u_int = 0x00} },
@@ -364,17 +363,17 @@ STATIC mp_obj_t pyb_spi_write_readinto (mp_obj_t self, mp_obj_t writebuf, mp_obj
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_spi_write_readinto_obj, pyb_spi_write_readinto);
-STATIC const mp_map_elem_t pyb_spi_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_spi_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_spi_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&pyb_spi_write_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&pyb_spi_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&pyb_spi_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_write_readinto), (mp_obj_t)&pyb_spi_write_readinto_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_spi_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_spi_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&pyb_spi_write_obj) },
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&pyb_spi_read_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&pyb_spi_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_write_readinto), MP_ROM_PTR(&pyb_spi_write_readinto_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_MSB), MP_OBJ_NEW_SMALL_INT(PYBSPI_FIRST_BIT_MSB) },
+ { MP_ROM_QSTR(MP_QSTR_MSB), MP_ROM_INT(PYBSPI_FIRST_BIT_MSB) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table);
diff --git a/cc3200/mods/pybspi.h b/ports/cc3200/mods/pybspi.h
similarity index 94%
rename from cc3200/mods/pybspi.h
rename to ports/cc3200/mods/pybspi.h
index b533b6056..b0fce8870 100644
--- a/cc3200/mods/pybspi.h
+++ b/ports/cc3200/mods/pybspi.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybtimer.c b/ports/cc3200/mods/pybtimer.c
similarity index 90%
rename from cc3200/mods/pybtimer.c
rename to ports/cc3200/mods/pybtimer.c
index d25ac6c2b..ea795b848 100644
--- a/cc3200/mods/pybtimer.c
+++ b/ports/cc3200/mods/pybtimer.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,9 +29,6 @@
#include
#include
-#include "py/mpconfig.h"
-#include "py/obj.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mperrno.h"
@@ -111,7 +108,7 @@ STATIC const mp_obj_t pyb_timer_pwm_pin[8] = {&pin_GP24, MP_OBJ_NULL, &pin_GP25,
/******************************************************************************
DECLARE PRIVATE FUNCTIONS
******************************************************************************/
-STATIC mp_obj_t pyb_timer_channel_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
+STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
STATIC void timer_disable (pyb_timer_obj_t *tim);
STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch);
STATIC void TIMER0AIntHandler(void);
@@ -264,7 +261,7 @@ STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_timer_obj_t *tim = self_in;
@@ -285,7 +282,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
mp_printf(print, "Timer(%u, mode=Timer.%q)", tim->id, mode_qst);
}
-STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, },
{ MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16} },
@@ -346,7 +343,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
return (mp_obj_t)tim;
}
-STATIC mp_obj_t pyb_timer_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_timer_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init);
@@ -358,7 +355,7 @@ STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);
-STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
@@ -445,22 +442,22 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel);
-STATIC const mp_map_elem_t pyb_timer_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_timer_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_timer_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_channel), (mp_obj_t)&pyb_timer_channel_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_timer_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_timer_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&pyb_timer_channel_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_A), MP_OBJ_NEW_SMALL_INT(TIMER_A) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_B), MP_OBJ_NEW_SMALL_INT(TIMER_B) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ONE_SHOT), MP_OBJ_NEW_SMALL_INT(TIMER_CFG_A_ONE_SHOT_UP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PERIODIC), MP_OBJ_NEW_SMALL_INT(TIMER_CFG_A_PERIODIC_UP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PWM), MP_OBJ_NEW_SMALL_INT(TIMER_CFG_A_PWM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_POSITIVE), MP_OBJ_NEW_SMALL_INT(PYBTIMER_POLARITY_POS) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_NEGATIVE), MP_OBJ_NEW_SMALL_INT(PYBTIMER_POLARITY_NEG) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_TIMEOUT), MP_OBJ_NEW_SMALL_INT(PYBTIMER_TIMEOUT_TRIGGER) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_MATCH), MP_OBJ_NEW_SMALL_INT(PYBTIMER_MATCH_TRIGGER) },
+ { MP_ROM_QSTR(MP_QSTR_A), MP_ROM_INT(TIMER_A) },
+ { MP_ROM_QSTR(MP_QSTR_B), MP_ROM_INT(TIMER_B) },
+ { MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(TIMER_CFG_A_ONE_SHOT_UP) },
+ { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(TIMER_CFG_A_PERIODIC_UP) },
+ { MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_INT(TIMER_CFG_A_PWM) },
+ { MP_ROM_QSTR(MP_QSTR_POSITIVE), MP_ROM_INT(PYBTIMER_POLARITY_POS) },
+ { MP_ROM_QSTR(MP_QSTR_NEGATIVE), MP_ROM_INT(PYBTIMER_POLARITY_NEG) },
+ { MP_ROM_QSTR(MP_QSTR_TIMEOUT), MP_ROM_INT(PYBTIMER_TIMEOUT_TRIGGER) },
+ { MP_ROM_QSTR(MP_QSTR_MATCH), MP_ROM_INT(PYBTIMER_MATCH_TRIGGER) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table);
@@ -552,7 +549,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m
mp_printf(print, ")");
}
-STATIC mp_obj_t pyb_timer_channel_freq(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_channel_freq(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *ch = args[0];
if (n_args == 1) {
// get
@@ -571,7 +568,7 @@ STATIC mp_obj_t pyb_timer_channel_freq(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_freq_obj, 1, 2, pyb_timer_channel_freq);
-STATIC mp_obj_t pyb_timer_channel_period(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_channel_period(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *ch = args[0];
if (n_args == 1) {
// get
@@ -590,7 +587,7 @@ STATIC mp_obj_t pyb_timer_channel_period(mp_uint_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_period_obj, 1, 2, pyb_timer_channel_period);
-STATIC mp_obj_t pyb_timer_channel_duty_cycle(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_channel_duty_cycle(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *ch = args[0];
if (n_args == 1) {
// get
@@ -614,7 +611,7 @@ STATIC mp_obj_t pyb_timer_channel_duty_cycle(mp_uint_t n_args, const mp_obj_t *a
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_duty_cycle_obj, 1, 3, pyb_timer_channel_duty_cycle);
-STATIC mp_obj_t pyb_timer_channel_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
pyb_timer_channel_obj_t *ch = pos_args[0];
@@ -717,12 +714,12 @@ STATIC mp_obj_t pyb_timer_channel_irq (mp_uint_t n_args, const mp_obj_t *pos_arg
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_irq_obj, 1, pyb_timer_channel_irq);
-STATIC const mp_map_elem_t pyb_timer_channel_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_timer_channel_freq_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_period), (mp_obj_t)&pyb_timer_channel_period_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_duty_cycle), (mp_obj_t)&pyb_timer_channel_duty_cycle_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_timer_channel_irq_obj },
+ { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&pyb_timer_channel_freq_obj) },
+ { MP_ROM_QSTR(MP_QSTR_period), MP_ROM_PTR(&pyb_timer_channel_period_obj) },
+ { MP_ROM_QSTR(MP_QSTR_duty_cycle), MP_ROM_PTR(&pyb_timer_channel_duty_cycle_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_timer_channel_irq_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table);
diff --git a/cc3200/mods/pybtimer.h b/ports/cc3200/mods/pybtimer.h
similarity index 96%
rename from cc3200/mods/pybtimer.h
rename to ports/cc3200/mods/pybtimer.h
index a1b30cd2b..0af0864ca 100644
--- a/cc3200/mods/pybtimer.h
+++ b/ports/cc3200/mods/pybtimer.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybuart.c b/ports/cc3200/mods/pybuart.c
similarity index 94%
rename from cc3200/mods/pybuart.c
rename to ports/cc3200/mods/pybuart.c
index 06938bdd4..35c0de9f9 100644
--- a/cc3200/mods/pybuart.c
+++ b/ports/cc3200/mods/pybuart.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,12 +29,11 @@
#include
#include
-#include "py/mpconfig.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "py/objlist.h"
#include "py/stream.h"
#include "py/mphal.h"
+#include "lib/utils/interrupt_char.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
@@ -47,7 +46,6 @@
#include "mpirq.h"
#include "pybsleep.h"
#include "mpexception.h"
-#include "py/mpstate.h"
#include "osi.h"
#include "utils.h"
#include "pin.h"
@@ -251,9 +249,9 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) {
MAP_UARTIntClear(self->reg, UART_INT_RX | UART_INT_RT);
while (UARTCharsAvail(self->reg)) {
int data = MAP_UARTCharGetNonBlocking(self->reg);
- if (MP_STATE_PORT(os_term_dup_obj) && MP_STATE_PORT(os_term_dup_obj)->stream_o == self && data == user_interrupt_char) {
+ if (MP_STATE_PORT(os_term_dup_obj) && MP_STATE_PORT(os_term_dup_obj)->stream_o == self && data == mp_interrupt_char) {
// raise an exception when interrupts are finished
- mpexception_keyboard_nlr_jump();
+ mp_keyboard_interrupt();
} else { // there's always a read buffer available
uint16_t next_head = (self->read_buf_head + 1) % PYBUART_RX_BUFFER_LEN;
if (next_head != self->read_buf_tail) {
@@ -311,7 +309,7 @@ STATIC int uart_irq_flags (mp_obj_t self_in) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_uart_obj_t *self = self_in;
@@ -487,7 +485,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
return self;
}
-STATIC mp_obj_t pyb_uart_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_uart_init_args) - 1];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_uart_init_args[1], args);
@@ -530,7 +528,7 @@ STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_sendbreak_obj, pyb_uart_sendbreak);
/// \method irq(trigger, priority, handler, wake)
-STATIC mp_obj_t pyb_uart_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
@@ -561,25 +559,25 @@ STATIC mp_obj_t pyb_uart_irq (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_irq_obj, 1, pyb_uart_irq);
-STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_uart_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_uart_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_any), (mp_obj_t)&pyb_uart_any_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sendbreak), (mp_obj_t)&pyb_uart_sendbreak_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_uart_irq_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_uart_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_uart_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(&pyb_uart_any_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sendbreak), MP_ROM_PTR(&pyb_uart_sendbreak_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_uart_irq_obj) },
/// \method read([nbytes])
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
/// \method readline()
- { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
+ { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
/// \method readinto(buf[, nbytes])
- { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
+ { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
/// \method write(buf)
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_RX_ANY), MP_OBJ_NEW_SMALL_INT(UART_TRIGGER_RX_ANY) },
+ { MP_ROM_QSTR(MP_QSTR_RX_ANY), MP_ROM_INT(UART_TRIGGER_RX_ANY) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table);
diff --git a/cc3200/mods/pybuart.h b/ports/cc3200/mods/pybuart.h
similarity index 95%
rename from cc3200/mods/pybuart.h
rename to ports/cc3200/mods/pybuart.h
index 56440987f..d481242f1 100644
--- a/cc3200/mods/pybuart.h
+++ b/ports/cc3200/mods/pybuart.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mods/pybwdt.c b/ports/cc3200/mods/pybwdt.c
similarity index 96%
rename from cc3200/mods/pybwdt.c
rename to ports/cc3200/mods/pybwdt.c
index 76c701ca0..4a9fafc4a 100644
--- a/cc3200/mods/pybwdt.c
+++ b/ports/cc3200/mods/pybwdt.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -87,7 +87,7 @@ void pybwdt_sl_alive (void) {
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
STATIC const mp_arg_t pyb_wdt_init_args[] = {
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -146,8 +146,8 @@ STATIC mp_obj_t pyb_wdt_feed(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_wdt_feed_obj, pyb_wdt_feed);
-STATIC const mp_map_elem_t pybwdt_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&pyb_wdt_feed_obj },
+STATIC const mp_rom_map_elem_t pybwdt_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_feed), MP_ROM_PTR(&pyb_wdt_feed_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pybwdt_locals_dict, pybwdt_locals_dict_table);
diff --git a/cc3200/mods/pybwdt.h b/ports/cc3200/mods/pybwdt.h
similarity index 95%
rename from cc3200/mods/pybwdt.h
rename to ports/cc3200/mods/pybwdt.h
index 2844587cb..275c49435 100644
--- a/cc3200/mods/pybwdt.h
+++ b/ports/cc3200/mods/pybwdt.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h
similarity index 83%
rename from cc3200/mpconfigport.h
rename to ports/cc3200/mpconfigport.h
index 78f8c0948..29ae9092b 100644
--- a/cc3200/mpconfigport.h
+++ b/ports/cc3200/mpconfigport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -32,7 +32,7 @@
#include "semphr.h"
#endif
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_ALLOC_PATH_MAX (128)
#define MICROPY_PERSISTENT_CODE_LOAD (1)
@@ -120,6 +120,7 @@
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
+#define MICROPY_KBD_EXCEPTION (1)
// We define our own list of errno constants to include in uerrno module
#define MICROPY_PY_UERRNO_LIST \
@@ -140,7 +141,7 @@
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, \
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t machine_module;
@@ -156,32 +157,32 @@ extern const struct _mp_obj_module_t mp_module_ubinascii;
extern const struct _mp_obj_module_t mp_module_ussl;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_umachine), (mp_obj_t)&machine_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_wipy), (mp_obj_t)&wipy_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_uselect), (mp_obj_t)&mp_module_uselect }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mp_module_network }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_ubinascii), (mp_obj_t)&mp_module_ubinascii }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_ussl), (mp_obj_t)&mp_module_ussl }, \
+ { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&machine_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_wipy), MP_ROM_PTR(&wipy_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
+ { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
+ { MP_ROM_QSTR(MP_QSTR_uselect), MP_ROM_PTR(&mp_module_uselect) }, \
+ { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_usocket) }, \
+ { MP_ROM_QSTR(MP_QSTR_network), MP_ROM_PTR(&mp_module_network) }, \
+ { MP_ROM_QSTR(MP_QSTR_ubinascii), MP_ROM_PTR(&mp_module_ubinascii) }, \
+ { MP_ROM_QSTR(MP_QSTR_ussl), MP_ROM_PTR(&mp_module_ussl) }, \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_re), (mp_obj_t)&mp_module_ure }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&mp_module_uos }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_utime }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_binascii), (mp_obj_t)&mp_module_ubinascii }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_ssl), (mp_obj_t)&mp_module_ussl }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
+ { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \
+ { MP_ROM_QSTR(MP_QSTR_struct), MP_ROM_PTR(&mp_module_ustruct) }, \
+ { MP_ROM_QSTR(MP_QSTR_re), MP_ROM_PTR(&mp_module_ure) }, \
+ { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) }, \
+ { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&mp_module_uos) }, \
+ { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_utime) }, \
+ { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_module_uselect) }, \
+ { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_module_usocket) }, \
+ { MP_ROM_QSTR(MP_QSTR_binascii), MP_ROM_PTR(&mp_module_ubinascii) }, \
+ { MP_ROM_QSTR(MP_QSTR_ssl), MP_ROM_PTR(&mp_module_ussl) }, \
+ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
// extra constants
#define MICROPY_PORT_CONSTANTS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_umachine), (mp_obj_t)&machine_module }, \
+ { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&machine_module) }, \
// vm state and root pointers for the gc
#define MP_STATE_PORT MP_STATE_VM
diff --git a/cc3200/mptask.c b/ports/cc3200/mptask.c
similarity index 99%
rename from cc3200/mptask.c
rename to ports/cc3200/mptask.c
index 50c3c769d..6143f72a7 100644
--- a/cc3200/mptask.c
+++ b/ports/cc3200/mptask.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -61,7 +61,6 @@
#include "telnet.h"
#include "debug.h"
#include "sflash_diskio.h"
-#include "mpexception.h"
#include "random.h"
#include "pybi2c.h"
#include "pins.h"
@@ -143,7 +142,6 @@ void TASK_MicroPython (void *pvParameters) {
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
// execute all basic initializations
- mpexception_init0();
mp_irq_init0();
pyb_sleep_init0();
pin_init0();
diff --git a/cc3200/mptask.h b/ports/cc3200/mptask.h
similarity index 96%
rename from cc3200/mptask.h
rename to ports/cc3200/mptask.h
index 5345ecfda..a1c3eb2cb 100644
--- a/cc3200/mptask.h
+++ b/ports/cc3200/mptask.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/mpthreadport.c b/ports/cc3200/mpthreadport.c
similarity index 99%
rename from cc3200/mpthreadport.c
rename to ports/cc3200/mpthreadport.c
index e77ac4ae5..9dbc518e0 100644
--- a/cc3200/mpthreadport.c
+++ b/ports/cc3200/mpthreadport.c
@@ -26,8 +26,6 @@
#include
-#include "py/mpconfig.h"
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mpthread.h"
diff --git a/cc3200/mpthreadport.h b/ports/cc3200/mpthreadport.h
similarity index 100%
rename from cc3200/mpthreadport.h
rename to ports/cc3200/mpthreadport.h
diff --git a/cc3200/qstrdefsport.h b/ports/cc3200/qstrdefsport.h
similarity index 94%
rename from cc3200/qstrdefsport.h
rename to ports/cc3200/qstrdefsport.h
index 2fc56668c..d5f22d70a 100644
--- a/cc3200/qstrdefsport.h
+++ b/ports/cc3200/qstrdefsport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/serverstask.c b/ports/cc3200/serverstask.c
similarity index 98%
rename from cc3200/serverstask.c
rename to ports/cc3200/serverstask.c
index 6b5899e18..100b8d33b 100644
--- a/cc3200/serverstask.c
+++ b/ports/cc3200/serverstask.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/serverstask.h b/ports/cc3200/serverstask.h
similarity index 97%
rename from cc3200/serverstask.h
rename to ports/cc3200/serverstask.h
index 77a3af2f3..c4533d717 100644
--- a/cc3200/serverstask.h
+++ b/ports/cc3200/serverstask.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/simplelink/cc_pal.c b/ports/cc3200/simplelink/cc_pal.c
similarity index 100%
rename from cc3200/simplelink/cc_pal.c
rename to ports/cc3200/simplelink/cc_pal.c
diff --git a/cc3200/simplelink/cc_pal.h b/ports/cc3200/simplelink/cc_pal.h
similarity index 100%
rename from cc3200/simplelink/cc_pal.h
rename to ports/cc3200/simplelink/cc_pal.h
diff --git a/cc3200/simplelink/oslib/osi.h b/ports/cc3200/simplelink/oslib/osi.h
similarity index 100%
rename from cc3200/simplelink/oslib/osi.h
rename to ports/cc3200/simplelink/oslib/osi.h
diff --git a/cc3200/simplelink/oslib/osi_freertos.c b/ports/cc3200/simplelink/oslib/osi_freertos.c
similarity index 100%
rename from cc3200/simplelink/oslib/osi_freertos.c
rename to ports/cc3200/simplelink/oslib/osi_freertos.c
diff --git a/cc3200/simplelink/user.h b/ports/cc3200/simplelink/user.h
similarity index 100%
rename from cc3200/simplelink/user.h
rename to ports/cc3200/simplelink/user.h
diff --git a/cc3200/telnet/telnet.c b/ports/cc3200/telnet/telnet.c
similarity index 99%
rename from cc3200/telnet/telnet.c
rename to ports/cc3200/telnet/telnet.c
index 26e45a75f..dbb77cd6d 100644
--- a/cc3200/telnet/telnet.c
+++ b/ports/cc3200/telnet/telnet.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,6 +29,7 @@
#include "py/mpconfig.h"
#include "py/obj.h"
#include "py/mphal.h"
+#include "lib/utils/interrupt_char.h"
#include "telnet.h"
#include "simplelink.h"
#include "modnetwork.h"
@@ -445,9 +446,9 @@ static void telnet_parse_input (uint8_t *str, int16_t *len) {
for (uint8_t *_str = b_str; _str < b_str + b_len; ) {
if (*_str <= 127) {
- if (telnet_data.state == E_TELNET_STE_LOGGED_IN && *_str == user_interrupt_char) {
+ if (telnet_data.state == E_TELNET_STE_LOGGED_IN && *_str == mp_interrupt_char) {
// raise a keyboard exception
- mpexception_keyboard_nlr_jump();
+ mp_keyboard_interrupt();
(*len)--;
_str++;
}
diff --git a/cc3200/telnet/telnet.h b/ports/cc3200/telnet/telnet.h
similarity index 96%
rename from cc3200/telnet/telnet.h
rename to ports/cc3200/telnet/telnet.h
index 1e3173b11..51c569104 100644
--- a/cc3200/telnet/telnet.h
+++ b/ports/cc3200/telnet/telnet.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/tools/smoke.py b/ports/cc3200/tools/smoke.py
similarity index 100%
rename from cc3200/tools/smoke.py
rename to ports/cc3200/tools/smoke.py
diff --git a/cc3200/tools/smoke.py.exp b/ports/cc3200/tools/smoke.py.exp
similarity index 100%
rename from cc3200/tools/smoke.py.exp
rename to ports/cc3200/tools/smoke.py.exp
diff --git a/cc3200/tools/uniflash.py b/ports/cc3200/tools/uniflash.py
similarity index 100%
rename from cc3200/tools/uniflash.py
rename to ports/cc3200/tools/uniflash.py
diff --git a/cc3200/tools/update-wipy.py b/ports/cc3200/tools/update-wipy.py
similarity index 100%
rename from cc3200/tools/update-wipy.py
rename to ports/cc3200/tools/update-wipy.py
diff --git a/cc3200/util/cryptohash.c b/ports/cc3200/util/cryptohash.c
similarity index 97%
rename from cc3200/util/cryptohash.c
rename to ports/cc3200/util/cryptohash.c
index d2d6222ff..909dadc8c 100644
--- a/cc3200/util/cryptohash.c
+++ b/ports/cc3200/util/cryptohash.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/cryptohash.h b/ports/cc3200/util/cryptohash.h
similarity index 95%
rename from cc3200/util/cryptohash.h
rename to ports/cc3200/util/cryptohash.h
index df3a8475c..15d46b705 100644
--- a/cc3200/util/cryptohash.h
+++ b/ports/cc3200/util/cryptohash.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/fifo.c b/ports/cc3200/util/fifo.c
similarity index 98%
rename from cc3200/util/fifo.c
rename to ports/cc3200/util/fifo.c
index 166f99d98..421f83710 100644
--- a/cc3200/util/fifo.c
+++ b/ports/cc3200/util/fifo.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/fifo.h b/ports/cc3200/util/fifo.h
similarity index 96%
rename from cc3200/util/fifo.h
rename to ports/cc3200/util/fifo.h
index ee7571c26..6ede57e1e 100644
--- a/cc3200/util/fifo.h
+++ b/ports/cc3200/util/fifo.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/gccollect.c b/ports/cc3200/util/gccollect.c
similarity index 94%
rename from cc3200/util/gccollect.c
rename to ports/cc3200/util/gccollect.c
index 8963852f7..6e2a9081c 100644
--- a/cc3200/util/gccollect.c
+++ b/ports/cc3200/util/gccollect.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,8 +28,6 @@
#include
#include
-#include "py/mpconfig.h"
-#include "py/mpstate.h"
#include "py/gc.h"
#include "py/mpthread.h"
#include "gccollect.h"
diff --git a/cc3200/util/gccollect.h b/ports/cc3200/util/gccollect.h
similarity index 95%
rename from cc3200/util/gccollect.h
rename to ports/cc3200/util/gccollect.h
index 3c4232b84..08d43d283 100644
--- a/cc3200/util/gccollect.h
+++ b/ports/cc3200/util/gccollect.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/gchelper.h b/ports/cc3200/util/gchelper.h
similarity index 95%
rename from cc3200/util/gchelper.h
rename to ports/cc3200/util/gchelper.h
index 0277a754b..48e81bc61 100644
--- a/cc3200/util/gchelper.h
+++ b/ports/cc3200/util/gchelper.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/gchelper.s b/ports/cc3200/util/gchelper.s
similarity index 100%
rename from cc3200/util/gchelper.s
rename to ports/cc3200/util/gchelper.s
diff --git a/cc3200/util/random.c b/ports/cc3200/util/random.c
similarity index 97%
rename from cc3200/util/random.c
rename to ports/cc3200/util/random.c
index 54aaa829c..f8e9cdf0c 100644
--- a/cc3200/util/random.c
+++ b/ports/cc3200/util/random.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -67,7 +67,7 @@ STATIC uint32_t lfsr (uint32_t input) {
}
/******************************************************************************/
-// Micro Python bindings;
+// MicroPython bindings;
STATIC mp_obj_t machine_rng_get(void) {
return mp_obj_new_int(rng_get());
diff --git a/cc3200/util/random.h b/ports/cc3200/util/random.h
similarity index 94%
rename from cc3200/util/random.h
rename to ports/cc3200/util/random.h
index 60b0b8663..02cde6b52 100644
--- a/cc3200/util/random.h
+++ b/ports/cc3200/util/random.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/sleeprestore.h b/ports/cc3200/util/sleeprestore.h
similarity index 94%
rename from cc3200/util/sleeprestore.h
rename to ports/cc3200/util/sleeprestore.h
index 1c5509db0..e178f4c2d 100644
--- a/cc3200/util/sleeprestore.h
+++ b/ports/cc3200/util/sleeprestore.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/sleeprestore.s b/ports/cc3200/util/sleeprestore.s
similarity index 100%
rename from cc3200/util/sleeprestore.s
rename to ports/cc3200/util/sleeprestore.s
diff --git a/cc3200/util/socketfifo.c b/ports/cc3200/util/socketfifo.c
similarity index 97%
rename from cc3200/util/socketfifo.c
rename to ports/cc3200/util/socketfifo.c
index eb25f3be3..d0a715048 100644
--- a/cc3200/util/socketfifo.c
+++ b/ports/cc3200/util/socketfifo.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/util/socketfifo.h b/ports/cc3200/util/socketfifo.h
similarity index 96%
rename from cc3200/util/socketfifo.h
rename to ports/cc3200/util/socketfifo.h
index 1309201ee..e6cf851b1 100644
--- a/cc3200/util/socketfifo.h
+++ b/ports/cc3200/util/socketfifo.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/cc3200/version.h b/ports/cc3200/version.h
similarity index 92%
rename from cc3200/version.h
rename to ports/cc3200/version.h
index 83e3f8c07..fccb95c52 100644
--- a/cc3200/version.h
+++ b/ports/cc3200/version.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp32/Makefile b/ports/esp32/Makefile
similarity index 92%
rename from esp32/Makefile
rename to ports/esp32/Makefile
index 1d0adf660..48d4b9d5c 100644
--- a/esp32/Makefile
+++ b/ports/esp32/Makefile
@@ -1,4 +1,4 @@
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
@@ -12,7 +12,7 @@ MICROPY_PY_BTREE = 1
FROZEN_MPY_DIR = modules
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
PORT ?= /dev/ttyUSB0
BAUD ?= 460800
@@ -29,7 +29,7 @@ ESPCOMP = $(ESPIDF)/components
ESPTOOL ?= $(ESPCOMP)/esptool_py/esptool/esptool.py
# verify the ESP IDF version
-ESPIDF_SUPHASH := 4ec2abbf23084ac060679e4136fa222a2d0ab0e8
+ESPIDF_SUPHASH := 2c95a77cf93781f296883d5dbafcdc18e4389656
ESPIDF_CURHASH := $(shell git -C $(ESPIDF) show -s --pretty=format:'%H')
ifneq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH))
$(info ** WARNING **)
@@ -44,10 +44,10 @@ endif
IDF_VER := $(shell git -C $(ESPIDF) describe)
INC += -I.
-INC += -I..
-INC += -I../lib/mp-readline
-INC += -I../lib/netutils
-INC += -I../lib/timeutils
+INC += -I$(TOP)
+INC += -I$(TOP)/lib/mp-readline
+INC += -I$(TOP)/lib/netutils
+INC += -I$(TOP)/lib/timeutils
INC += -I$(BUILD)
INC_ESPCOMP += -I$(ESPCOMP)/bootloader_support/include
@@ -93,9 +93,14 @@ CXXFLAGS = -std=gnu++11 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sec
LDFLAGS = -nostdlib -Map=$(@:.elf=.map) --cref
LDFLAGS += --gc-sections -static -EL
-LDFLAGS += -u call_user_start_cpu0 -u uxTopUsedPriority
+LDFLAGS += -u call_user_start_cpu0 -u uxTopUsedPriority -u ld_include_panic_highint_hdl
LDFLAGS += -u __cxa_guard_dummy # so that implementation of static guards is taken from cxx_guards.o instead of libstdc++.a
-LDFLAGS += -L$(ESPCOMP)/esp32/ld -T $(BUILD)/esp32_out.ld -T ./esp32.custom_common.ld -T esp32.rom.ld -T esp32.rom.spiflash.ld -T esp32.peripherals.ld
+LDFLAGS += -L$(ESPCOMP)/esp32/ld
+LDFLAGS += -T $(BUILD)/esp32_out.ld
+LDFLAGS += -T ./esp32.custom_common.ld
+LDFLAGS += -T esp32.rom.ld
+LDFLAGS += -T esp32.rom.spiram_incompatible_fns.ld
+LDFLAGS += -T esp32.peripherals.ld
LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LIBSTDCXX_FILE_NAME = $(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)
@@ -131,11 +136,13 @@ SRC_C = \
machine_uart.c \
modmachine.c \
modnetwork.c \
+ network_lan.c \
modsocket.c \
modesp.c \
moduhashlib.c \
espneopixel.c \
machine_hw_spi.c \
+ machine_wdt.c \
mpthreadport.c \
$(SRC_MOD)
@@ -208,8 +215,13 @@ ESPIDF_DRIVER_O = $(addprefix $(ESPCOMP)/driver/,\
$(BUILD)/$(ESPCOMP)/esp32/dport_access.o: CFLAGS += -Wno-array-bounds
ESPIDF_ESP32_O = $(addprefix $(ESPCOMP)/esp32/,\
+ brownout.o \
panic.o \
+ esp_timer.o \
+ esp_timer_esp32.o \
+ ets_timer_legacy.o \
event_default_handlers.o \
+ fast_crypto_ops.o \
task_wdt.o \
cache_err_int.o \
clk.o \
@@ -217,7 +229,6 @@ ESPIDF_ESP32_O = $(addprefix $(ESPCOMP)/esp32/,\
cpu_start.o \
gdbstub.o \
crosscore_int.o \
- deep_sleep.o \
ipc.o \
int_wdt.o \
event_loop.o \
@@ -230,6 +241,8 @@ ESPIDF_ESP32_O = $(addprefix $(ESPCOMP)/esp32/,\
phy_init.o \
intr_alloc.o \
dport_access.o \
+ wifi_init.o \
+ wifi_internal.o \
)
ESPIDF_HEAP_O = $(addprefix $(ESPCOMP)/heap/,\
@@ -255,6 +268,9 @@ ESPIDF_CXX_O = $(addprefix $(ESPCOMP)/cxx/,\
ESPIDF_ETHERNET_O = $(addprefix $(ESPCOMP)/ethernet/,\
emac_dev.o \
emac_main.o \
+ eth_phy/phy_tlk110.o \
+ eth_phy/phy_lan8720.o \
+ eth_phy/phy_common.o \
)
$(BUILD)/$(ESPCOMP)/expat/%.o: CFLAGS += -Wno-unused-function
@@ -269,6 +285,11 @@ ESPIDF_EXPAT_O = $(addprefix $(ESPCOMP)/expat/,\
port/chardata.o \
)
+ESPIDF_PTHREAD_O = $(addprefix $(ESPCOMP)/pthread/,\
+ pthread.o \
+ pthread_local_storage.o \
+ )
+
# Assembler .S files need only basic flags, and in particular should not have
# -Os because that generates subtly different code.
# We also need custom CFLAGS for .c files because FreeRTOS has headers with
@@ -295,6 +316,7 @@ ESPIDF_FREERTOS_O = $(addprefix $(ESPCOMP)/freertos/,\
xtensa_intr_asm.o \
xtensa_intr.o \
xtensa_overlay_os_hook.o \
+ xtensa_vector_defaults.o \
xtensa_vectors.o \
)
@@ -432,11 +454,11 @@ ESPIDF_LWIP_O = $(addprefix $(ESPCOMP)/lwip/,\
port/freertos/sys_arch.o \
port/netif/wlanif.o \
port/netif/ethernetif.o \
+ port/vfs_lwip.o \
)
ESPIDF_MBEDTLS_O = $(addprefix $(ESPCOMP)/mbedtls/,\
library/entropy.o \
- library/net.o \
library/pkcs12.o \
library/ccm.o \
library/pk.o \
@@ -505,7 +527,6 @@ ESPIDF_MBEDTLS_O = $(addprefix $(ESPCOMP)/mbedtls/,\
library/ctr_drbg.o \
library/x509write_crt.o \
library/pk_wrap.o \
- port/net.o \
port/esp_bignum.o \
port/esp_hardware.o \
port/esp_sha1.o \
@@ -536,6 +557,10 @@ ESPIDF_WPA_SUPPLICANT_O = $(addprefix $(ESPCOMP)/wpa_supplicant/,\
src/crypto/bignum.o \
src/crypto/crypto_internal-modexp.o \
src/crypto/crypto_internal-cipher.o \
+ src/fast_crypto/fast_aes-unwrap.o \
+ src/fast_crypto/fast_aes-wrap.o \
+ src/fast_crypto/fast_sha256.o \
+ src/fast_crypto/fast_sha256-internal.o \
port/os_xtensa.o \
)
@@ -548,6 +573,7 @@ OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_SOC_O))
OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_CXX_O))
OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_ETHERNET_O))
OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_EXPAT_O))
+OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_PTHREAD_O))
OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_FREERTOS_O))
OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_VFS_O))
OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_JSON_O))
@@ -597,7 +623,7 @@ APP_LD_ARGS += -L$(dir $(LIBSTDCXX_FILE_NAME)) -lstdc++
APP_LD_ARGS += $(ESPCOMP)/newlib/lib/libc.a
APP_LD_ARGS += $(ESPCOMP)/newlib/lib/libm.a
APP_LD_ARGS += $(ESPCOMP)/esp32/libhal.a
-APP_LD_ARGS += -L$(ESPCOMP)/esp32/lib -lcore -lnet80211 -lphy -lrtc -lpp -lwpa -lsmartconfig -lcoexist
+APP_LD_ARGS += -L$(ESPCOMP)/esp32/lib -lcore -lnet80211 -lphy -lrtc -lpp -lwpa -lsmartconfig -lcoexist -lwps -lwpa2
APP_LD_ARGS += $(OBJ)
APP_LD_ARGS += --end-group
@@ -636,6 +662,7 @@ $(BUILD)/bootloader/$(ESPCOMP)/%.o: CFLAGS += -DBOOTLOADER_BUILD=1 -I$(ESPCOMP)/
BOOTLOADER_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
bootloader_support/src/bootloader_flash.o \
bootloader_support/src/bootloader_random.o \
+ bootloader_support/src/bootloader_sha.o \
bootloader_support/src/secure_boot_signatures.o \
bootloader_support/src/secure_boot.o \
bootloader_support/src/esp_image_format.o \
@@ -646,7 +673,7 @@ BOOTLOADER_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
soc/esp32/rtc_clk.o \
soc/esp32/rtc_time.o \
micro-ecc/micro-ecc/uECC.o \
- bootloader/src/main/bootloader_start.o \
+ bootloader/subproject/main/bootloader_start.o \
)
BOOTLOADER_LIBS =
@@ -665,10 +692,10 @@ BOOTLOADER_LDFLAGS += -Wl,--gc-sections
BOOTLOADER_LDFLAGS += -static
BOOTLOADER_LDFLAGS += -Wl,-EL
BOOTLOADER_LDFLAGS += -Wl,-Map=$(@:.elf=.map) -Wl,--cref
-BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/src/main/esp32.bootloader.ld
-BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/src/main/esp32.bootloader.rom.ld
+BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.ld
+BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.rom.ld
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.ld
-BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.spiflash.ld
+BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.spiram_incompatible_fns.ld
BOOTLOADER_OBJ_DIRS = $(sort $(dir $(BOOTLOADER_OBJ)))
$(BOOTLOADER_OBJ): | $(BOOTLOADER_OBJ_DIRS)
@@ -698,4 +725,4 @@ $(BUILD)/partitions.bin: $(PART_SRC)
################################################################################
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/esp32/README.md b/ports/esp32/README.md
similarity index 83%
rename from esp32/README.md
rename to ports/esp32/README.md
index 9ee4bf6cb..5c0eb813d 100644
--- a/esp32/README.md
+++ b/ports/esp32/README.md
@@ -7,12 +7,14 @@ a task under FreeRTOS.
Supported features include:
- REPL (Python prompt) over UART0.
-- 16k stack for the MicroPython task and 64k Python heap.
+- 16k stack for the MicroPython task and 96k Python heap.
- Many of MicroPython's features are enabled: unicode, arbitrary-precision
integers, single-precision floats, complex numbers, frozen bytecode, as
well as many of the internal modules.
-- Internal filesystem using the flash (currently 256k in size).
-- The machine module with basic GPIO and bit-banging I2C, SPI support.
+- Internal filesystem using the flash (currently 2M in size).
+- The machine module with GPIO, UART, SPI, software I2C, ADC, DAC, PWM,
+ TouchPad, WDT and Timer.
+- The network module with WLAN (WiFi) support.
Development of this ESP32 port was sponsored in part by Microbric Pty Ltd.
@@ -30,6 +32,13 @@ Follow the guide "Setting Up ESP-IDF", for Windows, Mac or Linux. You
only need to perform up to "Step 2" of the guide, by which stage you
should have installed the cross-compile and cloned the ESP-IDF repository.
+If you are on a Windows machine then the
+[Windows Subsystem for Linux](https://msdn.microsoft.com/en-au/commandline/wsl/install_guide)
+is the most efficient way to install the ESP32 toolchain and build the project.
+If you use WSL then follow the
+[Linux guidelines](http://esp-idf.readthedocs.io/en/latest/get-started/linux-setup.html)
+for the ESP-IDF instead of the Windows ones.
+
Be advised that the ESP-IDF is still undergoing changes and only some
versions are supported. To find which build is compatible refer to the line
in the makefile containing the following:
@@ -37,13 +46,22 @@ in the makefile containing the following:
ESPIDF_SUPHASH :=
```
After finishing "Step 2" you can roll back your current build of
-the ESP-IDF using:
+the ESP-IDF (and update the submodules accordingly) using:
```
$ git checkout
+$ git submodule update --recursive
```
Note that you will get a warning when building the code if the ESP-IDF
version is incorrect.
+The Espressif ESP-IDF instructions above only install pyserial for Python 2,
+so if you're running Python 3 or a non-system Python you'll also need to
+install `pyserial` (or `esptool`) so that the Makefile can flash the board
+and set parameters:
+```bash
+$ pip install pyserial
+```
+
Once everything is set up you should have a functioning toolchain with
prefix xtensa-esp32-elf- (or otherwise if you configured it differently)
as well as a copy of the ESP-IDF repository.
@@ -93,7 +111,7 @@ $ git submodule update
Then to build MicroPython for the ESP32 run:
```bash
-$ cd esp32
+$ cd ports/esp32
$ make
```
This will produce binary firmware images in the `build/` subdirectory
@@ -105,6 +123,13 @@ for your particular ESP32 module for how to do this. The serial port and
flash settings are set in the `Makefile`, and can be overridden in your
local `makefile`; see above for more details.
+You will also need to have user permissions to access the /dev/ttyUSB0 device.
+On Linux, you can enable this by adding your user to the `dialout` group,
+and rebooting or logging out and in again.
+```bash
+$ sudo adduser dialout
+```
+
If you are installing MicroPython to your module for the first time, or
after installing any other firmware, you should first erase the flash
completely:
@@ -126,7 +151,7 @@ You can get a prompt via the serial port, via UART0, which is the same UART
that is used for programming the firmware. The baudrate for the REPL is
115200 and you can use a command such as:
```bash
-$ picocom /dev/ttyUSB0
+$ picocom -b 115200 /dev/ttyUSB0
```
Configuring the WiFi and using the board
diff --git a/esp32/esp32.custom_common.ld b/ports/esp32/esp32.custom_common.ld
similarity index 83%
rename from esp32/esp32.custom_common.ld
rename to ports/esp32/esp32.custom_common.ld
index 363b6b53c..eb1dee3c0 100644
--- a/esp32/esp32.custom_common.ld
+++ b/ports/esp32/esp32.custom_common.ld
@@ -83,15 +83,20 @@ SECTIONS
_iram_text_start = ABSOLUTE(.);
*(.iram1 .iram1.*)
*freertos/*(.literal .text .literal.* .text.*)
+ *heap/multi_heap.o(.literal .text .literal.* .text.*)
+ *heap/multi_heap_poisoning.o(.literal .text .literal.* .text.*)
*esp32/panic.o(.literal .text .literal.* .text.*)
*esp32/core_dump.o(.literal .text .literal.* .text.*)
- *esp32/heap_alloc_caps.o(.literal .text .literal.* .text.*)
- *esp32/app_trace.o(.literal .text .literal.* .text.*)
+ *app_trace/*(.literal .text .literal.* .text.*)
+ *xtensa-debug-module/eri.o(.literal .text .literal.* .text.*)
*libphy.a:(.literal .text .literal.* .text.*)
*librtc.a:(.literal .text .literal.* .text.*)
*libsoc.a:(.literal .text .literal.* .text.*)
*libhal.a:(.literal .text .literal.* .text.*)
+ *libgcc.a:lib2funcs.o(.literal .text .literal.* .text.*)
*spi_flash/spi_flash_rom_patch.o(.literal .text .literal.* .text.*)
+ *libgcov.a:(.literal .text .literal.* .text.*)
+ INCLUDE esp32.spiram.rom-functions-iram.ld
*py/scheduler.o*(.literal .text .literal.* .text.*)
_iram_text_end = ABSOLUTE(.);
} > iram0_0_seg
@@ -99,21 +104,26 @@ SECTIONS
.dram0.data :
{
_data_start = ABSOLUTE(.);
- KEEP(*(.data))
- KEEP(*(.data.*))
- KEEP(*(.gnu.linkonce.d.*))
- KEEP(*(.data1))
- KEEP(*(.sdata))
- KEEP(*(.sdata.*))
- KEEP(*(.gnu.linkonce.s.*))
- KEEP(*(.sdata2))
- KEEP(*(.sdata2.*))
- KEEP(*(.gnu.linkonce.s2.*))
- KEEP(*(.jcr))
+ *(.data)
+ *(.data.*)
+ *(.gnu.linkonce.d.*)
+ *(.data1)
+ *(.sdata)
+ *(.sdata.*)
+ *(.gnu.linkonce.s.*)
+ *(.sdata2)
+ *(.sdata2.*)
+ *(.gnu.linkonce.s2.*)
+ *(.jcr)
*(.dram1 .dram1.*)
*esp32/panic.o(.rodata .rodata.*)
- *esp32/app_trace.o(.rodata .rodata.*)
*libphy.a:(.rodata .rodata.*)
+ *soc/esp32/rtc_clk.o(.rodata .rodata.*)
+ *app_trace/app_trace.o(.rodata .rodata.*)
+ *libgcov.a:(.rodata .rodata.*)
+ *heap/multi_heap.o(.rodata .rodata.*)
+ *heap/multi_heap_poisoning.o(.rodata .rodata.*)
+ INCLUDE esp32.spiram.rom-functions-dram.ld
_data_end = ABSOLUTE(.);
. = ALIGN(4);
} >dram0_0_seg
@@ -152,11 +162,13 @@ SECTIONS
*(.rodata1)
__XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
*(.xt_except_table)
- *(.gcc_except_table)
+ *(.gcc_except_table .gcc_except_table.*)
*(.gnu.linkonce.e.*)
*(.gnu.version_r)
- *(.eh_frame)
. = (. + 3) & ~ 3;
+ __eh_frame = ABSOLUTE(.);
+ KEEP(*(.eh_frame))
+ . = (. + 7) & ~ 3;
/* C++ constructor and destructor tables, properly ordered: */
__init_array_start = ABSOLUTE(.);
KEEP (*crtbegin.o(.ctors))
diff --git a/esp32/espneopixel.c b/ports/esp32/espneopixel.c
similarity index 100%
rename from esp32/espneopixel.c
rename to ports/esp32/espneopixel.c
diff --git a/esp32/esponewire.c b/ports/esp32/esponewire.c
similarity index 100%
rename from esp32/esponewire.c
rename to ports/esp32/esponewire.c
diff --git a/esp32/fatfs_port.c b/ports/esp32/fatfs_port.c
similarity index 100%
rename from esp32/fatfs_port.c
rename to ports/esp32/fatfs_port.c
diff --git a/esp32/gccollect.c b/ports/esp32/gccollect.c
similarity index 100%
rename from esp32/gccollect.c
rename to ports/esp32/gccollect.c
diff --git a/esp32/gccollect.h b/ports/esp32/gccollect.h
similarity index 100%
rename from esp32/gccollect.h
rename to ports/esp32/gccollect.h
diff --git a/esp32/help.c b/ports/esp32/help.c
similarity index 98%
rename from esp32/help.c
rename to ports/esp32/help.c
index c18ca7282..95d115c56 100644
--- a/esp32/help.c
+++ b/ports/esp32/help.c
@@ -28,7 +28,7 @@
#include "py/builtin.h"
-const char *esp32_help_text =
+const char esp32_help_text[] =
"Welcome to MicroPython on the ESP32!\n"
"\n"
"For generic online docs please visit http://docs.micropython.org/\n"
diff --git a/esp32/machine_adc.c b/ports/esp32/machine_adc.c
similarity index 97%
rename from esp32/machine_adc.c
rename to ports/esp32/machine_adc.c
index 659702ae2..d62f362e9 100644
--- a/esp32/machine_adc.c
+++ b/ports/esp32/machine_adc.c
@@ -68,7 +68,7 @@ STATIC mp_obj_t madc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
for (int i = 0; i < MP_ARRAY_SIZE(madc_obj); i++) {
if (pin_id == madc_obj[i].gpio_id) { self = &madc_obj[i]; break; }
}
- if (!self) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid Pin for ADC"));
+ if (!self) mp_raise_ValueError("invalid Pin for ADC");
esp_err_t err = adc1_config_channel_atten(self->adc1_id, ADC_ATTEN_0db);
if (err == ESP_OK) return MP_OBJ_FROM_PTR(self);
mp_raise_ValueError("Parameter Error");
@@ -81,7 +81,7 @@ STATIC void madc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
STATIC mp_obj_t madc_read(mp_obj_t self_in) {
madc_obj_t *self = self_in;
- int val = adc1_get_voltage(self->adc1_id);
+ int val = adc1_get_raw(self->adc1_id);
if (val == -1) mp_raise_ValueError("Parameter Error");
return MP_OBJ_NEW_SMALL_INT(val);
}
diff --git a/esp32/machine_dac.c b/ports/esp32/machine_dac.c
similarity index 97%
rename from esp32/machine_dac.c
rename to ports/esp32/machine_dac.c
index 10152c657..bd0804ec4 100644
--- a/esp32/machine_dac.c
+++ b/ports/esp32/machine_dac.c
@@ -56,7 +56,7 @@ STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
for (int i = 0; i < MP_ARRAY_SIZE(mdac_obj); i++) {
if (pin_id == mdac_obj[i].gpio_id) { self = &mdac_obj[i]; break; }
}
- if (!self) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid Pin for DAC"));
+ if (!self) mp_raise_ValueError("invalid Pin for DAC");
esp_err_t err = dac_output_enable(self->dac_id);
if (err == ESP_OK) {
diff --git a/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c
similarity index 100%
rename from esp32/machine_hw_spi.c
rename to ports/esp32/machine_hw_spi.c
diff --git a/esp32/machine_pin.c b/ports/esp32/machine_pin.c
similarity index 97%
rename from esp32/machine_pin.c
rename to ports/esp32/machine_pin.c
index 22205aeb3..493dff3f5 100644
--- a/esp32/machine_pin.c
+++ b/ports/esp32/machine_pin.c
@@ -151,7 +151,12 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
// configure mode
if (args[ARG_mode].u_obj != mp_const_none) {
- gpio_set_direction(self->id, mp_obj_get_int(args[ARG_mode].u_obj));
+ mp_int_t pin_io_mode = mp_obj_get_int(args[ARG_mode].u_obj);
+ if (self->id >= 34 && (pin_io_mode & GPIO_MODE_DEF_OUTPUT)) {
+ mp_raise_ValueError("pin can only be input");
+ } else {
+ gpio_set_direction(self->id, pin_io_mode);
+ }
}
// configure pull
@@ -173,7 +178,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
self = (machine_pin_obj_t*)&machine_pin_obj[wanted_pin];
}
if (self == NULL || self->base.type == NULL) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid pin"));
+ mp_raise_ValueError("invalid pin");
}
if (n_args > 1 || n_kw > 0) {
diff --git a/esp32/machine_pwm.c b/ports/esp32/machine_pwm.c
similarity index 99%
rename from esp32/machine_pwm.c
rename to ports/esp32/machine_pwm.c
index 489833e7c..4d6c59f0f 100644
--- a/esp32/machine_pwm.c
+++ b/ports/esp32/machine_pwm.c
@@ -131,6 +131,7 @@ STATIC void esp32_pwm_init_helper(esp32_pwm_obj_t *self,
}
channel = avail;
}
+ self->channel = channel;
// New PWM assignment
self->active = 1;
@@ -148,7 +149,6 @@ STATIC void esp32_pwm_init_helper(esp32_pwm_obj_t *self,
"PWM not supported on pin %d", self->pin));
}
chan_gpio[channel] = self->pin;
- self->channel = channel;
}
// Maybe change PWM timer
diff --git a/esp32/machine_timer.c b/ports/esp32/machine_timer.c
similarity index 100%
rename from esp32/machine_timer.c
rename to ports/esp32/machine_timer.c
diff --git a/esp32/machine_touchpad.c b/ports/esp32/machine_touchpad.c
similarity index 97%
rename from esp32/machine_touchpad.c
rename to ports/esp32/machine_touchpad.c
index 2770b17b1..96de1a2a1 100644
--- a/esp32/machine_touchpad.c
+++ b/ports/esp32/machine_touchpad.c
@@ -64,7 +64,7 @@ STATIC mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
for (int i = 0; i < MP_ARRAY_SIZE(touchpad_obj); i++) {
if (pin_id == touchpad_obj[i].gpio_id) { self = &touchpad_obj[i]; break; }
}
- if (!self) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid pin for touchpad"));
+ if (!self) mp_raise_ValueError("invalid pin for touchpad");
static int initialized = 0;
if (!initialized) {
diff --git a/esp32/machine_uart.c b/ports/esp32/machine_uart.c
similarity index 95%
rename from esp32/machine_uart.c
rename to ports/esp32/machine_uart.c
index 16ed97405..0b303d424 100644
--- a/esp32/machine_uart.c
+++ b/ports/esp32/machine_uart.c
@@ -42,7 +42,6 @@ typedef struct _machine_uart_obj_t {
uint8_t bits;
uint8_t parity;
uint8_t stop;
- uint32_t baudrate;
int8_t tx;
int8_t rx;
int8_t rts;
@@ -60,8 +59,10 @@ QueueHandle_t UART_QUEUE[UART_NUM_MAX] = {};
STATIC void machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ uint32_t baudrate;
+ uart_get_baudrate(self->uart_num, &baudrate);
mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, tx=%d, rx=%d, rts=%d, cts=%d, timeout=%u, timeout_char=%u)",
- self->uart_num, self->baudrate, self->bits, _parity_name[self->parity],
+ self->uart_num, baudrate, self->bits, _parity_name[self->parity],
self->stop, self->tx, self->rx, self->rts, self->cts, self->timeout, self->timeout_char);
}
@@ -82,10 +83,14 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+ // wait for all data to be transmitted before changing settings
+ uart_wait_tx_done(self->uart_num, pdMS_TO_TICKS(1000));
+
// set baudrate
+ uint32_t baudrate = 115200;
if (args[ARG_baudrate].u_int > 0) {
- self->baudrate = args[ARG_baudrate].u_int;
- uart_set_baudrate(self->uart_num, self->baudrate);
+ uart_set_baudrate(self->uart_num, args[ARG_baudrate].u_int);
+ uart_get_baudrate(self->uart_num, &baudrate);
}
uart_set_pin(self->uart_num, args[ARG_tx].u_int, args[ARG_rx].u_int, args[ARG_rts].u_int, args[ARG_cts].u_int);
@@ -126,7 +131,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
self->bits = 8;
break;
default:
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid data bits"));
+ mp_raise_ValueError("invalid data bits");
break;
}
@@ -161,7 +166,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
self->stop = 2;
break;
default:
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid stop bits"));
+ mp_raise_ValueError("invalid stop bits");
break;
}
@@ -171,7 +176,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
// set timeout_char
// make sure it is at least as long as a whole character (13 bits to be safe)
self->timeout_char = args[ARG_timeout_char].u_int;
- uint32_t min_timeout_char = 13000 / self->baudrate + 1;
+ uint32_t min_timeout_char = 13000 / baudrate + 1;
if (self->timeout_char < min_timeout_char) {
self->timeout_char = min_timeout_char;
}
@@ -206,7 +211,6 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
machine_uart_obj_t *self = m_new_obj(machine_uart_obj_t);
self->base.type = &machine_uart_type;
self->uart_num = uart_num;
- self->baudrate = 115200;
self->bits = 8;
self->parity = 0;
self->stop = 1;
diff --git a/ports/esp32/machine_wdt.c b/ports/esp32/machine_wdt.c
new file mode 100644
index 000000000..0389e8689
--- /dev/null
+++ b/ports/esp32/machine_wdt.c
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Paul Sokolovsky
+ * Copyright (c) 2017 Eric Poulsen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+
+#include "py/nlr.h"
+#include "py/obj.h"
+#include "py/runtime.h"
+
+#include "esp_task_wdt.h"
+
+const mp_obj_type_t machine_wdt_type;
+
+typedef struct _machine_wdt_obj_t {
+ mp_obj_base_t base;
+} machine_wdt_obj_t;
+
+STATIC machine_wdt_obj_t wdt_default = {{&machine_wdt_type}};
+
+STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
+ mp_arg_check_num(n_args, n_kw, 0, 1, false);
+
+ mp_int_t id = 0;
+ if (n_args > 0) {
+ id = mp_obj_get_int(args[0]);
+ }
+
+ switch (id) {
+ case 0:
+ esp_task_wdt_feed();
+ return &wdt_default;
+ default:
+ mp_raise_ValueError(NULL);
+ }
+}
+
+STATIC mp_obj_t machine_wdt_feed(mp_obj_t self_in) {
+ (void)self_in;
+ esp_task_wdt_feed();
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_feed_obj, machine_wdt_feed);
+
+STATIC const mp_map_elem_t machine_wdt_locals_dict_table[] = {
+ { MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&machine_wdt_feed_obj },
+};
+STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table);
+
+const mp_obj_type_t machine_wdt_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_WDT,
+ .make_new = machine_wdt_make_new,
+ .locals_dict = (mp_obj_t)&machine_wdt_locals_dict,
+};
diff --git a/esp32/main.c b/ports/esp32/main.c
similarity index 100%
rename from esp32/main.c
rename to ports/esp32/main.c
diff --git a/esp32/makeimg.py b/ports/esp32/makeimg.py
similarity index 100%
rename from esp32/makeimg.py
rename to ports/esp32/makeimg.py
diff --git a/esp32/memory.h b/ports/esp32/memory.h
similarity index 100%
rename from esp32/memory.h
rename to ports/esp32/memory.h
diff --git a/esp32/modesp.c b/ports/esp32/modesp.c
similarity index 68%
rename from esp32/modesp.c
rename to ports/esp32/modesp.c
index 805002655..e614f77a6 100644
--- a/esp32/modesp.c
+++ b/ports/esp32/modesp.c
@@ -29,6 +29,8 @@
#include
+#include "rom/gpio.h"
+#include "esp_log.h"
#include "esp_spi_flash.h"
#include "py/runtime.h"
@@ -37,6 +39,23 @@
#include "drivers/dht/dht.h"
#include "modesp.h"
+STATIC mp_obj_t esp_osdebug(size_t n_args, const mp_obj_t *args) {
+ esp_log_level_t level = LOG_LOCAL_LEVEL;
+ if (n_args == 2) {
+ level = mp_obj_get_int(args[1]);
+ }
+ if (args[0] == mp_const_none) {
+ // Disable logging
+ esp_log_level_set("*", ESP_LOG_ERROR);
+ } else {
+ // Enable logging at the given level
+ // TODO args[0] should set the UART to which debug is sent
+ esp_log_level_set("*", level);
+ }
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_osdebug_obj, 1, 2, esp_osdebug);
+
STATIC mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t buf_in) {
mp_int_t offset = mp_obj_get_int(offset_in);
mp_buffer_info_t bufinfo;
@@ -81,6 +100,19 @@ STATIC mp_obj_t esp_flash_user_start(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_user_start_obj, esp_flash_user_start);
+STATIC mp_obj_t esp_gpio_matrix_in(mp_obj_t pin, mp_obj_t sig, mp_obj_t inv) {
+ gpio_matrix_in(mp_obj_get_int(pin), mp_obj_get_int(sig), mp_obj_get_int(inv));
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_gpio_matrix_in_obj, esp_gpio_matrix_in);
+
+STATIC mp_obj_t esp_gpio_matrix_out(size_t n_args, const mp_obj_t *args) {
+ (void)n_args;
+ gpio_matrix_out(mp_obj_get_int(args[0]), mp_obj_get_int(args[1]), mp_obj_get_int(args[2]), mp_obj_get_int(args[3]));
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_gpio_matrix_out_obj, 4, 4, esp_gpio_matrix_out);
+
STATIC mp_obj_t esp_neopixel_write_(mp_obj_t pin, mp_obj_t buf, mp_obj_t timing) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
@@ -93,14 +125,27 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
STATIC const mp_rom_map_elem_t esp_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) },
+ { MP_ROM_QSTR(MP_QSTR_osdebug), MP_ROM_PTR(&esp_osdebug_obj) },
+
{ MP_ROM_QSTR(MP_QSTR_flash_read), MP_ROM_PTR(&esp_flash_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_flash_write), MP_ROM_PTR(&esp_flash_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_flash_erase), MP_ROM_PTR(&esp_flash_erase_obj) },
{ MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&esp_flash_size_obj) },
{ MP_ROM_QSTR(MP_QSTR_flash_user_start), MP_ROM_PTR(&esp_flash_user_start_obj) },
+ { MP_ROM_QSTR(MP_QSTR_gpio_matrix_in), MP_ROM_PTR(&esp_gpio_matrix_in_obj) },
+ { MP_ROM_QSTR(MP_QSTR_gpio_matrix_out), MP_ROM_PTR(&esp_gpio_matrix_out_obj) },
+
{ MP_ROM_QSTR(MP_QSTR_neopixel_write), MP_ROM_PTR(&esp_neopixel_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) },
+
+ // Constants for second arg of osdebug()
+ { MP_ROM_QSTR(MP_QSTR_LOG_NONE), MP_ROM_INT((mp_uint_t)ESP_LOG_NONE)},
+ { MP_ROM_QSTR(MP_QSTR_LOG_ERROR), MP_ROM_INT((mp_uint_t)ESP_LOG_ERROR)},
+ { MP_ROM_QSTR(MP_QSTR_LOG_WARNING), MP_ROM_INT((mp_uint_t)ESP_LOG_WARN)},
+ { MP_ROM_QSTR(MP_QSTR_LOG_INFO), MP_ROM_INT((mp_uint_t)ESP_LOG_INFO)},
+ { MP_ROM_QSTR(MP_QSTR_LOG_DEBUG), MP_ROM_INT((mp_uint_t)ESP_LOG_DEBUG)},
+ { MP_ROM_QSTR(MP_QSTR_LOG_VERBOSE), MP_ROM_INT((mp_uint_t)ESP_LOG_VERBOSE)},
};
STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table);
diff --git a/esp32/modesp.h b/ports/esp32/modesp.h
similarity index 100%
rename from esp32/modesp.h
rename to ports/esp32/modesp.h
diff --git a/esp32/modmachine.c b/ports/esp32/modmachine.c
similarity index 97%
rename from esp32/modmachine.c
rename to ports/esp32/modmachine.c
index 3a1a78b7e..32c9c5ad5 100644
--- a/esp32/modmachine.c
+++ b/ports/esp32/modmachine.c
@@ -54,8 +54,7 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
// set
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
if (freq != 80 && freq != 160 && freq != 240) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "frequency can only be either 80Mhz, 160MHz or 240MHz"));
+ mp_raise_ValueError("frequency can only be either 80Mhz, 160MHz or 240MHz");
}
/*
system_update_cpu_freq(freq);
@@ -115,6 +114,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) },
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) },
+ { MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) },
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
{ MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) },
{ MP_ROM_QSTR(MP_QSTR_TouchPad), MP_ROM_PTR(&machine_touchpad_type) },
diff --git a/esp32/modmachine.h b/ports/esp32/modmachine.h
similarity index 92%
rename from esp32/modmachine.h
rename to ports/esp32/modmachine.h
index 4909235b4..58229007d 100644
--- a/esp32/modmachine.h
+++ b/ports/esp32/modmachine.h
@@ -4,6 +4,7 @@
#include "py/obj.h"
extern const mp_obj_type_t machine_timer_type;
+extern const mp_obj_type_t machine_wdt_type;
extern const mp_obj_type_t machine_pin_type;
extern const mp_obj_type_t machine_touchpad_type;
extern const mp_obj_type_t machine_adc_type;
diff --git a/esp32/modnetwork.c b/ports/esp32/modnetwork.c
similarity index 91%
rename from esp32/modnetwork.c
rename to ports/esp32/modnetwork.c
index 6bcbb1c49..ad2891962 100644
--- a/esp32/modnetwork.c
+++ b/ports/esp32/modnetwork.c
@@ -7,6 +7,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2016, 2017 Nick Moore @mnemote
+ * Copyright (c) 2017 "Eric Poulsen"
*
* Based on esp8266/modnetwork.c which is Copyright (c) 2015 Paul Sokolovsky
* And the ESP IDF example code which is Public Domain / CC0
@@ -48,6 +49,8 @@
#include "lwip/dns.h"
#include "tcpip_adapter.h"
+#include "modnetwork.h"
+
#define MODNETWORK_INCLUDE_CONSTANTS (1)
NORETURN void _esp_exceptions(esp_err_t e) {
@@ -122,7 +125,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
ESP_LOGI("wifi", "STA_START");
break;
case SYSTEM_EVENT_STA_GOT_IP:
- ESP_LOGI("wifi", "GOT_IP");
+ ESP_LOGI("network", "GOT_IP");
break;
case SYSTEM_EVENT_STA_DISCONNECTED: {
// This is a workaround as ESP32 WiFi libs don't currently
@@ -130,8 +133,16 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
system_event_sta_disconnected_t *disconn = &event->event_info.disconnected;
ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d", disconn->reason);
switch (disconn->reason) {
+ case WIFI_REASON_BEACON_TIMEOUT:
+ mp_printf(MP_PYTHON_PRINTER, "beacon timeout\n");
+ // AP has dropped out; try to reconnect.
+ break;
+ case WIFI_REASON_NO_AP_FOUND:
+ mp_printf(MP_PYTHON_PRINTER, "no AP found\n");
+ // AP may not exist, or it may have momentarily dropped out; try to reconnect.
+ break;
case WIFI_REASON_AUTH_FAIL:
- mp_printf(MP_PYTHON_PRINTER, "authentication failed");
+ mp_printf(MP_PYTHON_PRINTER, "authentication failed\n");
wifi_sta_connected = false;
break;
default:
@@ -153,7 +164,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
break;
}
default:
- ESP_LOGI("wifi", "event %d", event->event_id);
+ ESP_LOGI("network", "event %d", event->event_id);
break;
}
return ESP_OK;
@@ -174,13 +185,26 @@ STATIC void require_if(mp_obj_t wlan_if, int if_no) {
}
STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) {
+ static int initialized = 0;
+ if (!initialized) {
+ wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
+ ESP_LOGD("modnetwork", "Initializing WiFi");
+ ESP_EXCEPTIONS( esp_wifi_init(&cfg) );
+ ESP_EXCEPTIONS( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
+ ESP_LOGD("modnetwork", "Initialized");
+ ESP_EXCEPTIONS( esp_wifi_set_mode(0) );
+ ESP_EXCEPTIONS( esp_wifi_start() );
+ ESP_LOGD("modnetwork", "Started");
+ initialized = 1;
+ }
+
int idx = (n_args > 0) ? mp_obj_get_int(args[0]) : WIFI_IF_STA;
if (idx == WIFI_IF_STA) {
return MP_OBJ_FROM_PTR(&wlan_sta_obj);
} else if (idx == WIFI_IF_AP) {
return MP_OBJ_FROM_PTR(&wlan_ap_obj);
} else {
- mp_raise_msg(&mp_type_ValueError, "invalid WLAN interface identifier");
+ mp_raise_ValueError("invalid WLAN interface identifier");
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(get_wlan_obj, 0, 1, get_wlan);
@@ -193,14 +217,6 @@ STATIC mp_obj_t esp_initialize() {
ESP_LOGD("modnetwork", "Initializing Event Loop");
ESP_EXCEPTIONS( esp_event_loop_init(event_handler, NULL) );
ESP_LOGD("modnetwork", "esp_event_loop_init done");
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
- ESP_LOGD("modnetwork", "Initializing WiFi");
- ESP_EXCEPTIONS( esp_wifi_init(&cfg) );
- ESP_EXCEPTIONS( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
- ESP_LOGD("modnetwork", "Initialized");
- ESP_EXCEPTIONS( esp_wifi_set_mode(0) );
- ESP_EXCEPTIONS( esp_wifi_start() );
- ESP_LOGD("modnetwork", "Started");
initialized = 1;
}
return mp_const_none;
@@ -320,16 +336,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_isconnected_obj, esp_isconnected);
STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
tcpip_adapter_ip_info_t info;
- ip_addr_t dns_addr;
+ tcpip_adapter_dns_info_t dns_info;
tcpip_adapter_get_ip_info(self->if_id, &info);
+ tcpip_adapter_get_dns_info(self->if_id, TCPIP_ADAPTER_DNS_MAIN, &dns_info);
if (n_args == 1) {
// get
- dns_addr = dns_getserver(0);
mp_obj_t tuple[4] = {
netutils_format_ipv4_addr((uint8_t*)&info.ip, NETUTILS_BIG),
netutils_format_ipv4_addr((uint8_t*)&info.netmask, NETUTILS_BIG),
netutils_format_ipv4_addr((uint8_t*)&info.gw, NETUTILS_BIG),
- netutils_format_ipv4_addr((uint8_t*)&dns_addr, NETUTILS_BIG),
+ netutils_format_ipv4_addr((uint8_t*)&dns_info.ip, NETUTILS_BIG),
};
return mp_obj_new_tuple(4, tuple);
} else {
@@ -348,28 +364,29 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
netutils_parse_ipv4_addr(items[1], (void*)&info.netmask, NETUTILS_BIG);
}
netutils_parse_ipv4_addr(items[2], (void*)&info.gw, NETUTILS_BIG);
- netutils_parse_ipv4_addr(items[3], (void*)&dns_addr, NETUTILS_BIG);
+ netutils_parse_ipv4_addr(items[3], (void*)&dns_info.ip, NETUTILS_BIG);
// To set a static IP we have to disable DHCP first
- if (self->if_id == WIFI_IF_STA) {
- esp_err_t e = tcpip_adapter_dhcpc_stop(WIFI_IF_STA);
+ if (self->if_id == WIFI_IF_STA || self->if_id == ESP_IF_ETH) {
+ esp_err_t e = tcpip_adapter_dhcpc_stop(self->if_id);
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) _esp_exceptions(e);
- ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(WIFI_IF_STA, &info));
+ ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(self->if_id, &info));
+ ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(self->if_id, TCPIP_ADAPTER_DNS_MAIN, &dns_info));
} else if (self->if_id == WIFI_IF_AP) {
esp_err_t e = tcpip_adapter_dhcps_stop(WIFI_IF_AP);
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) _esp_exceptions(e);
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(WIFI_IF_AP, &info));
+ ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(WIFI_IF_AP, TCPIP_ADAPTER_DNS_MAIN, &dns_info));
ESP_EXCEPTIONS(tcpip_adapter_dhcps_start(WIFI_IF_AP));
}
return mp_const_none;
}
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig);
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig);
STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
if (n_args != 1 && kwargs->used != 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
- "either pos or kw args are allowed"));
+ mp_raise_TypeError("either pos or kw args are allowed");
}
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
@@ -390,8 +407,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(kwargs->table[i].value, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len != 6) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "invalid buffer length"));
+ mp_raise_ValueError("invalid buffer length");
}
ESP_EXCEPTIONS(esp_wifi_set_mac(self->if_id, bufinfo.buf));
break;
@@ -449,8 +465,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
// Get config
if (n_args != 2) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
- "can query only one param"));
+ mp_raise_TypeError("can query only one param");
}
int req_if = -1;
@@ -492,8 +507,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
return val;
unknown:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "unknown config param"));
+ mp_raise_ValueError("unknown config param");
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);
@@ -527,6 +541,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) },
{ MP_OBJ_NEW_QSTR(MP_QSTR___init__), (mp_obj_t)&esp_initialize_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&get_wlan_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_LAN), (mp_obj_t)&get_lan_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_phy_mode), (mp_obj_t)&esp_phy_mode_obj },
#if MODNETWORK_INCLUDE_CONSTANTS
@@ -554,6 +569,11 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
MP_OBJ_NEW_SMALL_INT(WIFI_AUTH_WPA_WPA2_PSK) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_MAX),
MP_OBJ_NEW_SMALL_INT(WIFI_AUTH_MAX) },
+
+ { MP_OBJ_NEW_QSTR(MP_QSTR_PHY_LAN8720),
+ MP_OBJ_NEW_SMALL_INT(PHY_LAN8720) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_PHY_TLK110),
+ MP_OBJ_NEW_SMALL_INT(PHY_TLK110) },
#endif
};
diff --git a/ports/esp32/modnetwork.h b/ports/esp32/modnetwork.h
new file mode 100644
index 000000000..d9f56591e
--- /dev/null
+++ b/ports/esp32/modnetwork.h
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 "Eric Poulsen"
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef MICROPY_INCLUDED_ESP32_MODNETWORK_H
+#define MICROPY_INCLUDED_ESP32_MODNETWORK_H
+
+enum { PHY_LAN8720, PHY_TLK110 };
+
+MP_DECLARE_CONST_FUN_OBJ_KW(get_lan_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj);
+
+#endif
diff --git a/esp32/modsocket.c b/ports/esp32/modsocket.c
similarity index 94%
rename from esp32/modsocket.c
rename to ports/esp32/modsocket.c
index fad42e9d8..fa26a70c1 100644
--- a/esp32/modsocket.c
+++ b/ports/esp32/modsocket.c
@@ -51,6 +51,7 @@
#include "lwip/sockets.h"
#include "lwip/netdb.h"
#include "lwip/ip4.h"
+#include "lwip/igmp.h"
#include "esp_log.h"
#define SOCKET_POLL_US (100000)
@@ -208,18 +209,37 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
(void)n_args; // always 4
socket_obj_t *self = MP_OBJ_TO_PTR(args[0]);
- int level = mp_obj_get_int(args[1]);
- if (level != SOL_SOCKET) {
- mp_raise_ValueError("unsupported level");
- }
-
- // only "int" arguments are supported at the moment
int opt = mp_obj_get_int(args[2]);
- int val = mp_obj_get_int(args[3]);
- int ret = lwip_setsockopt_r(self->fd, SOL_SOCKET, opt, &val, sizeof(int));
- if (ret != 0) {
- exception_from_errno(errno);
+ switch (opt) {
+ // level: SOL_SOCKET
+ case SO_REUSEADDR: {
+ int val = mp_obj_get_int(args[3]);
+ int ret = lwip_setsockopt_r(self->fd, SOL_SOCKET, opt, &val, sizeof(int));
+ if (ret != 0) {
+ exception_from_errno(errno);
+ }
+ break;
+ }
+
+ // level: IPPROTO_IP
+ case IP_ADD_MEMBERSHIP: {
+ mp_buffer_info_t bufinfo;
+ mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
+ if (bufinfo.len != sizeof(ip4_addr_t) * 2) {
+ mp_raise_ValueError(NULL);
+ }
+
+ // POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
+ err_t err = igmp_joingroup((const ip4_addr_t*)bufinfo.buf + 1, bufinfo.buf);
+ if (err != ERR_OK) {
+ mp_raise_OSError(-err);
+ }
+ break;
+ }
+
+ default:
+ mp_printf(&mp_plat_print, "Warning: lwip.setsockopt() option not implemented\n");
}
return mp_const_none;
@@ -455,6 +475,7 @@ STATIC const mp_map_elem_t socket_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_fileno), (mp_obj_t)&socket_fileno_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
};
@@ -557,8 +578,10 @@ STATIC const mp_map_elem_t mp_module_socket_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_RAW), MP_OBJ_NEW_SMALL_INT(SOCK_RAW) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_TCP), MP_OBJ_NEW_SMALL_INT(IPPROTO_TCP) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_UDP), MP_OBJ_NEW_SMALL_INT(IPPROTO_UDP) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_IPPROTO_IP), MP_OBJ_NEW_SMALL_INT(IPPROTO_IP) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SOL_SOCKET), MP_OBJ_NEW_SMALL_INT(SOL_SOCKET) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SO_REUSEADDR), MP_OBJ_NEW_SMALL_INT(SO_REUSEADDR) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_IP_ADD_MEMBERSHIP), MP_OBJ_NEW_SMALL_INT(IP_ADD_MEMBERSHIP) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table);
diff --git a/esp32/moduhashlib.c b/ports/esp32/moduhashlib.c
similarity index 98%
rename from esp32/moduhashlib.c
rename to ports/esp32/moduhashlib.c
index 6f67aa7d9..e8bc5e83c 100644
--- a/esp32/moduhashlib.c
+++ b/ports/esp32/moduhashlib.c
@@ -46,6 +46,7 @@ STATIC mp_obj_t sha256_make_new(const mp_obj_type_t *type,
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(union sha_ctxs));
o->base.type = type;
mbedtls_sha256_init(&o->state.sha256);
+ mbedtls_sha256_starts(&o->state.sha256, 0);
if (n_args == 1) {
sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
}
@@ -58,6 +59,7 @@ STATIC mp_obj_t sha1_make_new(const mp_obj_type_t *type,
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(union sha_ctxs));
o->base.type = type;
mbedtls_sha1_init(&o->state.sha1);
+ mbedtls_sha1_starts(&o->state.sha1);
if (n_args == 1) {
sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
}
diff --git a/esp32/modules/_boot.py b/ports/esp32/modules/_boot.py
similarity index 100%
rename from esp32/modules/_boot.py
rename to ports/esp32/modules/_boot.py
diff --git a/esp32/modules/apa106.py b/ports/esp32/modules/apa106.py
similarity index 100%
rename from esp32/modules/apa106.py
rename to ports/esp32/modules/apa106.py
diff --git a/esp32/modules/dht.py b/ports/esp32/modules/dht.py
similarity index 100%
rename from esp32/modules/dht.py
rename to ports/esp32/modules/dht.py
diff --git a/esp32/modules/ds18x20.py b/ports/esp32/modules/ds18x20.py
similarity index 100%
rename from esp32/modules/ds18x20.py
rename to ports/esp32/modules/ds18x20.py
diff --git a/esp32/modules/flashbdev.py b/ports/esp32/modules/flashbdev.py
similarity index 100%
rename from esp32/modules/flashbdev.py
rename to ports/esp32/modules/flashbdev.py
diff --git a/esp32/modules/inisetup.py b/ports/esp32/modules/inisetup.py
similarity index 100%
rename from esp32/modules/inisetup.py
rename to ports/esp32/modules/inisetup.py
diff --git a/esp32/modules/neopixel.py b/ports/esp32/modules/neopixel.py
similarity index 100%
rename from esp32/modules/neopixel.py
rename to ports/esp32/modules/neopixel.py
diff --git a/ports/esp32/modules/ntptime.py b/ports/esp32/modules/ntptime.py
new file mode 120000
index 000000000..e90900d5a
--- /dev/null
+++ b/ports/esp32/modules/ntptime.py
@@ -0,0 +1 @@
+../../esp8266/modules/ntptime.py
\ No newline at end of file
diff --git a/esp32/modules/onewire.py b/ports/esp32/modules/onewire.py
similarity index 100%
rename from esp32/modules/onewire.py
rename to ports/esp32/modules/onewire.py
diff --git a/ports/esp32/modules/upip.py b/ports/esp32/modules/upip.py
new file mode 120000
index 000000000..130eb6901
--- /dev/null
+++ b/ports/esp32/modules/upip.py
@@ -0,0 +1 @@
+../../../tools/upip.py
\ No newline at end of file
diff --git a/ports/esp32/modules/upip_utarfile.py b/ports/esp32/modules/upip_utarfile.py
new file mode 120000
index 000000000..d9653d6a6
--- /dev/null
+++ b/ports/esp32/modules/upip_utarfile.py
@@ -0,0 +1 @@
+../../../tools/upip_utarfile.py
\ No newline at end of file
diff --git a/ports/esp32/modules/upysh.py b/ports/esp32/modules/upysh.py
new file mode 120000
index 000000000..12d100c29
--- /dev/null
+++ b/ports/esp32/modules/upysh.py
@@ -0,0 +1 @@
+../../../../micropython-lib/upysh/upysh.py
\ No newline at end of file
diff --git a/ports/esp32/modules/urequests.py b/ports/esp32/modules/urequests.py
new file mode 120000
index 000000000..76661112e
--- /dev/null
+++ b/ports/esp32/modules/urequests.py
@@ -0,0 +1 @@
+../../../../micropython-lib/urequests/urequests.py
\ No newline at end of file
diff --git a/esp32/moduos.c b/ports/esp32/moduos.c
similarity index 100%
rename from esp32/moduos.c
rename to ports/esp32/moduos.c
diff --git a/esp32/modutime.c b/ports/esp32/modutime.c
similarity index 59%
rename from esp32/modutime.c
rename to ports/esp32/modutime.c
index f037faad9..002854298 100644
--- a/esp32/modutime.c
+++ b/ports/esp32/modutime.c
@@ -30,8 +30,51 @@
#include
#include
+#include "py/runtime.h"
+#include "lib/timeutils/timeutils.h"
#include "extmod/utime_mphal.h"
+STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
+ timeutils_struct_time_t tm;
+ mp_int_t seconds;
+ if (n_args == 0 || args[0] == mp_const_none) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ seconds = tv.tv_sec;
+ } else {
+ seconds = mp_obj_get_int(args[0]);
+ }
+ timeutils_seconds_since_2000_to_struct_time(seconds, &tm);
+ mp_obj_t tuple[8] = {
+ tuple[0] = mp_obj_new_int(tm.tm_year),
+ tuple[1] = mp_obj_new_int(tm.tm_mon),
+ tuple[2] = mp_obj_new_int(tm.tm_mday),
+ tuple[3] = mp_obj_new_int(tm.tm_hour),
+ tuple[4] = mp_obj_new_int(tm.tm_min),
+ tuple[5] = mp_obj_new_int(tm.tm_sec),
+ tuple[6] = mp_obj_new_int(tm.tm_wday),
+ tuple[7] = mp_obj_new_int(tm.tm_yday),
+ };
+ return mp_obj_new_tuple(8, tuple);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime);
+
+STATIC mp_obj_t time_mktime(mp_obj_t tuple) {
+ size_t len;
+ mp_obj_t *elem;
+ mp_obj_get_array(tuple, &len, &elem);
+
+ // localtime generates a tuple of len 8. CPython uses 9, so we accept both.
+ if (len < 8 || len > 9) {
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "mktime needs a tuple of length 8 or 9 (%d given)", len));
+ }
+
+ return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]),
+ mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]),
+ mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5])));
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime);
+
STATIC mp_obj_t time_time(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -42,6 +85,8 @@ MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
+ { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) },
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
diff --git a/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h
similarity index 98%
rename from esp32/mpconfigport.h
rename to ports/esp32/mpconfigport.h
index 2c3259324..69d17fd81 100644
--- a/esp32/mpconfigport.h
+++ b/ports/esp32/mpconfigport.h
@@ -138,7 +138,8 @@
#define MICROPY_PY_MACHINE_SPI_MAX_BAUDRATE (ets_get_cpu_frequency() * 1000000 / 200) // roughly
#define MICROPY_PY_USSL (1)
#define MICROPY_SSL_MBEDTLS (1)
-#define MICROPY_PY_WEBSOCKET (0)
+#define MICROPY_PY_USSL_FINALISER (1)
+#define MICROPY_PY_WEBSOCKET (1)
#define MICROPY_PY_FRAMEBUF (1)
// fatfs configuration
@@ -176,6 +177,7 @@ extern const struct _mp_obj_module_t mp_module_onewire;
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mp_module_network }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&mp_module_onewire }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_uhashlib), (mp_obj_t)&mp_module_uhashlib }, \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
{ MP_OBJ_NEW_QSTR(MP_QSTR_binascii), (mp_obj_t)&mp_module_ubinascii }, \
diff --git a/esp32/mphalport.c b/ports/esp32/mphalport.c
similarity index 100%
rename from esp32/mphalport.c
rename to ports/esp32/mphalport.c
diff --git a/esp32/mphalport.h b/ports/esp32/mphalport.h
similarity index 97%
rename from esp32/mphalport.h
rename to ports/esp32/mphalport.h
index 8a0f1dc8b..3215bc062 100644
--- a/esp32/mphalport.h
+++ b/ports/esp32/mphalport.h
@@ -59,12 +59,15 @@ mp_hal_pin_obj_t machine_pin_get_id(mp_obj_t pin_in);
#define mp_obj_get_pin(o) machine_pin_get_id(o) // legacy name; only to support esp8266/modonewire
#define mp_hal_pin_name(p) (p)
static inline void mp_hal_pin_input(mp_hal_pin_obj_t pin) {
+ gpio_pad_select_gpio(pin);
gpio_set_direction(pin, GPIO_MODE_INPUT);
}
static inline void mp_hal_pin_output(mp_hal_pin_obj_t pin) {
+ gpio_pad_select_gpio(pin);
gpio_set_direction(pin, GPIO_MODE_INPUT_OUTPUT);
}
static inline void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin) {
+ gpio_pad_select_gpio(pin);
gpio_set_direction(pin, GPIO_MODE_INPUT_OUTPUT_OD);
}
static inline void mp_hal_pin_od_low(mp_hal_pin_obj_t pin) {
diff --git a/esp32/mpthreadport.c b/ports/esp32/mpthreadport.c
similarity index 100%
rename from esp32/mpthreadport.c
rename to ports/esp32/mpthreadport.c
diff --git a/esp32/mpthreadport.h b/ports/esp32/mpthreadport.h
similarity index 100%
rename from esp32/mpthreadport.h
rename to ports/esp32/mpthreadport.h
diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c
new file mode 100644
index 000000000..fba4de73a
--- /dev/null
+++ b/ports/esp32/network_lan.c
@@ -0,0 +1,203 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 "Eric Poulsen"
+ *
+ * Based on the ESP IDF example code which is Public Domain / CC0
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "py/runtime.h"
+#include "py/mphal.h"
+
+#include "eth_phy/phy.h"
+#include "eth_phy/phy_tlk110.h"
+#include "eth_phy/phy_lan8720.h"
+#include "tcpip_adapter.h"
+
+#include "modnetwork.h"
+
+typedef struct _lan_if_obj_t {
+ mp_obj_base_t base;
+ int if_id; // MUST BE FIRST to match wlan_if_obj_t
+ bool initialized;
+ bool active;
+ uint8_t mdc_pin;
+ uint8_t mdio_pin;
+ int8_t phy_power_pin;
+ uint8_t phy_addr;
+ uint8_t phy_type;
+ eth_phy_check_link_func link_func;
+ eth_phy_power_enable_func power_func;
+} lan_if_obj_t;
+
+const mp_obj_type_t lan_if_type;
+STATIC lan_if_obj_t lan_obj = {{&lan_if_type}, ESP_IF_ETH, false, false};
+
+STATIC void phy_power_enable(bool enable) {
+ lan_if_obj_t* self = &lan_obj;
+
+ if (self->phy_power_pin != -1) {
+
+ if (!enable) {
+ // Do the PHY-specific power_enable(false) function before powering down
+ self->power_func(false);
+ }
+
+ gpio_pad_select_gpio(self->phy_power_pin);
+ gpio_set_direction(self->phy_power_pin, GPIO_MODE_OUTPUT);
+ if (enable) {
+ gpio_set_level(self->phy_power_pin, 1);
+ } else {
+ gpio_set_level(self->phy_power_pin, 0);
+ }
+
+ // Allow the power up/down to take effect, min 300us
+ vTaskDelay(1);
+
+ if (enable) {
+ // Run the PHY-specific power on operations now the PHY has power
+ self->power_func(true);
+ }
+ }
+}
+
+STATIC void init_lan_rmii() {
+ lan_if_obj_t* self = &lan_obj;
+ phy_rmii_configure_data_interface_pins();
+ phy_rmii_smi_configure_pins(self->mdc_pin, self->mdio_pin);
+}
+
+STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ lan_if_obj_t* self = &lan_obj;
+
+ if (self->initialized) {
+ return MP_OBJ_FROM_PTR(&lan_obj);
+ }
+
+ enum { ARG_id, ARG_mdc, ARG_mdio, ARG_power, ARG_phy_addr, ARG_phy_type };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} },
+ { MP_QSTR_mdc, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ },
+ { MP_QSTR_mdio, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ },
+ { MP_QSTR_power, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ },
+ { MP_QSTR_phy_addr, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT },
+ { MP_QSTR_phy_type, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT },
+ };
+
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+
+ if (args[ARG_id].u_obj != mp_const_none) {
+ if (mp_obj_get_int(args[ARG_id].u_obj) != 0) {
+ mp_raise_ValueError("invalid LAN interface identifier");
+ }
+ }
+
+ self->mdc_pin = machine_pin_get_id(args[ARG_mdc].u_obj);
+ self->mdio_pin = machine_pin_get_id(args[ARG_mdio].u_obj);
+ self->phy_power_pin = args[ARG_power].u_obj == mp_const_none ? -1 : machine_pin_get_id(args[ARG_power].u_obj);
+
+ if (args[ARG_phy_addr].u_int < 0x00 || args[ARG_phy_addr].u_int > 0x1f) {
+ mp_raise_ValueError("invalid phy address");
+ }
+
+ if (args[ARG_phy_type].u_int != PHY_LAN8720 && args[ARG_phy_type].u_int != PHY_TLK110) {
+ mp_raise_ValueError("invalid phy type");
+ }
+
+ eth_config_t config;
+
+ switch (args[ARG_phy_type].u_int) {
+ case PHY_TLK110:
+ config = phy_tlk110_default_ethernet_config;
+ break;
+ case PHY_LAN8720:
+ config = phy_lan8720_default_ethernet_config;
+ break;
+ }
+
+ self->link_func = config.phy_check_link;
+
+ // Replace default power func with our own
+ self->power_func = config.phy_power_enable;
+ config.phy_power_enable = phy_power_enable;
+
+ config.phy_addr = args[ARG_phy_addr].u_int;
+ config.gpio_config = init_lan_rmii;
+ config.tcpip_input = tcpip_adapter_eth_input;
+
+ if (esp_eth_init(&config) == ESP_OK) {
+ self->active = false;
+ self->initialized = true;
+ } else {
+ mp_raise_msg(&mp_type_OSError, "esp_eth_init() failed");
+ }
+ return MP_OBJ_FROM_PTR(&lan_obj);
+}
+MP_DEFINE_CONST_FUN_OBJ_KW(get_lan_obj, 0, get_lan);
+
+STATIC mp_obj_t lan_active(size_t n_args, const mp_obj_t *args) {
+ lan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
+
+ if (n_args > 1) {
+ if (mp_obj_is_true(args[1])) {
+ self->active = (esp_eth_enable() == ESP_OK);
+ if (!self->active) {
+ mp_raise_msg(&mp_type_OSError, "ethernet enable failed");
+ }
+ } else {
+ self->active = !(esp_eth_disable() == ESP_OK);
+ if (self->active) {
+ mp_raise_msg(&mp_type_OSError, "ethernet disable failed");
+ }
+ }
+ }
+ return mp_obj_new_bool(self->active);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lan_active_obj, 1, 2, lan_active);
+
+STATIC mp_obj_t lan_status(mp_obj_t self_in) {
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(lan_status_obj, lan_status);
+
+STATIC mp_obj_t lan_isconnected(mp_obj_t self_in) {
+ lan_if_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ return self->active ? mp_obj_new_bool(self->link_func()) : mp_const_false;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(lan_isconnected_obj, lan_isconnected);
+
+STATIC const mp_rom_map_elem_t lan_if_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&lan_active_obj) },
+ { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&lan_isconnected_obj) },
+ { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lan_status_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(lan_if_locals_dict, lan_if_locals_dict_table);
+
+const mp_obj_type_t lan_if_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_LAN,
+ .locals_dict = (mp_obj_dict_t*)&lan_if_locals_dict,
+};
diff --git a/esp32/qstrdefsport.h b/ports/esp32/qstrdefsport.h
similarity index 100%
rename from esp32/qstrdefsport.h
rename to ports/esp32/qstrdefsport.h
diff --git a/esp32/sdkconfig.h b/ports/esp32/sdkconfig.h
similarity index 59%
rename from esp32/sdkconfig.h
rename to ports/esp32/sdkconfig.h
index de8630e4f..7fcbb7c01 100644
--- a/esp32/sdkconfig.h
+++ b/ports/esp32/sdkconfig.h
@@ -8,10 +8,14 @@
#define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS 1
#define CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS 4
+#define CONFIG_BROWNOUT_DET 1
+#define CONFIG_BROWNOUT_DET_LVL 0
+#define CONFIG_BROWNOUT_DET_LVL_SEL_0 1
+
#define CONFIG_TCPIP_TASK_STACK_SIZE 2560
+#define CONFIG_TCPIP_RECVMBOX_SIZE 32
#define CONFIG_ESP32_APPTRACE_DEST_NONE 1
-#define CONFIG_ESP32_PHY_AUTO_INIT 1
#define CONFIG_ESP32_PHY_MAX_TX_POWER 20
#define CONFIG_ESP32_PANIC_PRINT_REBOOT 1
#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1
@@ -29,17 +33,24 @@
#define CONFIG_ESP32_WIFI_TX_BUFFER_TYPE 1
#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER 1
#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32
+#define CONFIG_ESP32_WIFI_RX_BA_WIN 6
+#define CONFIG_ESP32_WIFI_TX_BA_WIN 6
#define CONFIG_ESP32_XTAL_FREQ_AUTO 1
#define CONFIG_ESP32_XTAL_FREQ 0
#define CONFIG_ESP32_RTC_CLK_CAL_CYCLES 1024
+#define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT 5
+#define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT 2048
#define CONFIG_FOUR_MAC_ADDRESS_FROM_EFUSE 1
-#define CONFIG_NUMBER_OF_MAC_ADDRESS_GENERATED_FROM_EFUSE 4
+#define CONFIG_DMA_RX_BUF_NUM 10
+#define CONFIG_DMA_TX_BUF_NUM 10
+#define CONFIG_EMAC_TASK_PRIORITY 20
#define CONFIG_INT_WDT 1
#define CONFIG_INT_WDT_TIMEOUT_MS 300
#define CONFIG_INT_WDT_CHECK_CPU1 0
#define CONFIG_TASK_WDT 1
+#define CONFIG_TASK_WDT_PANIC 1
#define CONFIG_TASK_WDT_TIMEOUT_S 5
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK 0
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 0
@@ -63,11 +74,13 @@
#define CONFIG_BTC_TASK_STACK_SIZE 3072
#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE 4096
#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE 32
+#define CONFIG_TIMER_TASK_STACK_SIZE 4096
#define CONFIG_TIMER_TASK_PRIORITY 1
#define CONFIG_TIMER_TASK_STACK_DEPTH 2048
#define CONFIG_TIMER_QUEUE_LENGTH 10
-#define CONFIG_NEWLIB_STDOUT_ADDCR 1
+#define CONFIG_NEWLIB_STDIN_LINE_ENDING_CR 1
+#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1
#define CONFIG_PHY_ENABLED 1
#define CONFIG_WIFI_ENABLED 1
#define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1
@@ -93,20 +106,64 @@
#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1
#define CONFIG_LWIP_MAX_SOCKETS 8
#define CONFIG_LWIP_SO_REUSE 1
+#define CONFIG_LWIP_ETHARP_TRUST_IP_MAC 1
+#define CONFIG_IP_LOST_TIMER_INTERVAL 120
+#define CONFIG_UDP_RECVMBOX_SIZE 6
#define CONFIG_TCP_MAXRTX 12
#define CONFIG_TCP_SYNMAXRTX 6
+#define CONFIG_TCP_MSL 60000
#define CONFIG_TCP_MSS 1436
#define CONFIG_TCP_SND_BUF_DEFAULT 5744
#define CONFIG_TCP_WND_DEFAULT 5744
#define CONFIG_TCP_QUEUE_OOSEQ 1
#define CONFIG_TCP_OVERSIZE_MSS 1
+#define CONFIG_TCP_RECVMBOX_SIZE 6
+#define CONFIG_MBEDTLS_AES_C 1
+#define CONFIG_MBEDTLS_CCM_C 1
+#define CONFIG_MBEDTLS_ECDH_C 1
+#define CONFIG_MBEDTLS_ECDSA_C 1
+#define CONFIG_MBEDTLS_ECP_C 1
+#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED 1
+#define CONFIG_MBEDTLS_ECP_NIST_OPTIM 1
+#define CONFIG_MBEDTLS_GCM_C 1
#define CONFIG_MBEDTLS_HARDWARE_AES 1
-#define CONFIG_MBEDTLS_HARDWARE_MPI 1
-#define CONFIG_MBEDTLS_HARDWARE_SHA 1
-#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384
-#define CONFIG_MBEDTLS_MPI_USE_INTERRUPT 1
#define CONFIG_MBEDTLS_HAVE_TIME 1
+#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1
+#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA 1
+#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA 1
+#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA 1
+#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA 1
+#define CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE 1
+#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA 1
+#define CONFIG_MBEDTLS_PEM_PARSE_C 1
+#define CONFIG_MBEDTLS_PEM_WRITE_C 1
+#define CONFIG_MBEDTLS_RC4_DISABLED 1
+#define CONFIG_MBEDTLS_SSL_ALPN 1
+#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384
+#define CONFIG_MBEDTLS_SSL_PROTO_TLS1 1
+#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1
+#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1
+#define CONFIG_MBEDTLS_SSL_RENEGOTIATION 1
+#define CONFIG_MBEDTLS_SSL_SESSION_TICKETS 1
+#define CONFIG_MBEDTLS_TLS_CLIENT 1
+#define CONFIG_MBEDTLS_TLS_ENABLED 1
+#define CONFIG_MBEDTLS_TLS_SERVER 1
+#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1
+#define CONFIG_MBEDTLS_X509_CRL_PARSE_C 1
+#define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1
+#define CONFIG_MAKE_WARN_UNDEFINED_VARIABLES 1
#define CONFIG_TOOLPREFIX "xtensa-esp32-elf-"
#define CONFIG_PYTHON "python2"
diff --git a/esp32/uart.c b/ports/esp32/uart.c
similarity index 100%
rename from esp32/uart.c
rename to ports/esp32/uart.c
diff --git a/esp32/uart.h b/ports/esp32/uart.h
similarity index 100%
rename from esp32/uart.h
rename to ports/esp32/uart.h
diff --git a/esp8266/Makefile b/ports/esp8266/Makefile
similarity index 92%
rename from esp8266/Makefile
rename to ports/esp8266/Makefile
index 1c169862e..95236a8d9 100644
--- a/esp8266/Makefile
+++ b/ports/esp8266/Makefile
@@ -1,4 +1,4 @@
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h #$(BUILD)/pins_qstr.h
@@ -7,12 +7,13 @@ MICROPY_PY_USSL = 1
MICROPY_SSL_AXTLS = 1
MICROPY_FATFS = 1
MICROPY_PY_BTREE = 1
+BTREE_DEFS_EXTRA = -DDEFPSIZE=1024 -DMINCACHE=3
FROZEN_DIR ?= scripts
FROZEN_MPY_DIR ?= modules
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
FWBIN = $(BUILD)/firmware-combined.bin
PORT ?= /dev/ttyACM0
@@ -23,8 +24,7 @@ CROSS_COMPILE = xtensa-lx106-elf-
ESP_SDK = $(shell $(CC) -print-sysroot)/usr
INC += -I.
-INC += -I..
-INC += -I../stmhal
+INC += -I$(TOP)
INC += -I$(BUILD)
INC += -I$(ESP_SDK)/include
@@ -86,7 +86,7 @@ SRC_C = \
moduos.c \
ets_alt_task.c \
fatfs_port.c \
- axtls_helpers.c \
+ posix_helpers.c \
hspi.c \
$(SRC_MOD)
@@ -221,16 +221,16 @@ ota:
#$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c
# $(call compile_c)
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
axtls: $(BUILD)/libaxtls.a
$(BUILD)/libaxtls.a:
- cd ../lib/axtls; cp config/upyconfig config/.config
- cd ../lib/axtls; $(MAKE) oldconfig -B
- cd ../lib/axtls; $(MAKE) clean
- cd ../lib/axtls; $(MAKE) all CC="$(CC)" LD="$(LD)" AR="$(AR)" CFLAGS_EXTRA="$(CFLAGS_XTENSA) -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096"
- cp ../lib/axtls/_stage/libaxtls.a $@
+ cd $(TOP)/lib/axtls; cp config/upyconfig config/.config
+ cd $(TOP)/lib/axtls; $(MAKE) oldconfig -B
+ cd $(TOP)/lib/axtls; $(MAKE) clean
+ cd $(TOP)/lib/axtls; $(MAKE) all CC="$(CC)" LD="$(LD)" AR="$(AR)" CFLAGS_EXTRA="$(CFLAGS_XTENSA) -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096"
+ cp $(TOP)/lib/axtls/_stage/libaxtls.a $@
clean-modules:
git clean -f -d modules
diff --git a/esp8266/README.md b/ports/esp8266/README.md
similarity index 100%
rename from esp8266/README.md
rename to ports/esp8266/README.md
diff --git a/esp8266/eagle.rom.addr.v6.ld b/ports/esp8266/eagle.rom.addr.v6.ld
similarity index 100%
rename from esp8266/eagle.rom.addr.v6.ld
rename to ports/esp8266/eagle.rom.addr.v6.ld
diff --git a/esp8266/esp8266.ld b/ports/esp8266/esp8266.ld
similarity index 100%
rename from esp8266/esp8266.ld
rename to ports/esp8266/esp8266.ld
diff --git a/esp8266/esp8266_512k.ld b/ports/esp8266/esp8266_512k.ld
similarity index 100%
rename from esp8266/esp8266_512k.ld
rename to ports/esp8266/esp8266_512k.ld
diff --git a/esp8266/esp8266_common.ld b/ports/esp8266/esp8266_common.ld
similarity index 100%
rename from esp8266/esp8266_common.ld
rename to ports/esp8266/esp8266_common.ld
diff --git a/esp8266/esp8266_ota.ld b/ports/esp8266/esp8266_ota.ld
similarity index 100%
rename from esp8266/esp8266_ota.ld
rename to ports/esp8266/esp8266_ota.ld
diff --git a/esp8266/esp_init_data.c b/ports/esp8266/esp_init_data.c
similarity index 100%
rename from esp8266/esp_init_data.c
rename to ports/esp8266/esp_init_data.c
diff --git a/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c
similarity index 76%
rename from esp8266/esp_mphal.c
rename to ports/esp8266/esp_mphal.c
index 55f9a5894..9f4f051fd 100644
--- a/esp8266/esp_mphal.c
+++ b/ports/esp8266/esp_mphal.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -31,8 +31,6 @@
#include "esp_mphal.h"
#include "user_interface.h"
#include "ets_alt_task.h"
-#include "py/obj.h"
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "extmod/misc.h"
#include "lib/utils/pyexec.h"
@@ -72,11 +70,6 @@ int mp_hal_stdin_rx_chr(void) {
}
}
-void mp_hal_stdout_tx_char(char c) {
- uart_tx_one_char(UART0, c);
- mp_uos_dupterm_tx_strn(&c, 1);
-}
-
#if 0
void mp_hal_debug_str(const char *str) {
while (*str) {
@@ -87,23 +80,39 @@ void mp_hal_debug_str(const char *str) {
#endif
void mp_hal_stdout_tx_str(const char *str) {
+ const char *last = str;
while (*str) {
- mp_hal_stdout_tx_char(*str++);
+ uart_tx_one_char(UART0, *str++);
}
+ mp_uos_dupterm_tx_strn(last, str - last);
}
void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
+ const char *last = str;
while (len--) {
- mp_hal_stdout_tx_char(*str++);
+ uart_tx_one_char(UART0, *str++);
}
+ mp_uos_dupterm_tx_strn(last, str - last);
}
void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) {
+ const char *last = str;
while (len--) {
if (*str == '\n') {
- mp_hal_stdout_tx_char('\r');
+ if (str > last) {
+ mp_uos_dupterm_tx_strn(last, str - last);
+ }
+ uart_tx_one_char(UART0, '\r');
+ uart_tx_one_char(UART0, '\n');
+ mp_uos_dupterm_tx_strn("\r\n", 2);
+ ++str;
+ last = str;
+ } else {
+ uart_tx_one_char(UART0, *str++);
}
- mp_hal_stdout_tx_char(*str++);
+ }
+ if (str > last) {
+ mp_uos_dupterm_tx_strn(last, str - last);
}
}
@@ -146,41 +155,6 @@ void mp_hal_signal_input(void) {
#endif
}
-static int call_dupterm_read(void) {
- if (MP_STATE_PORT(term_obj) == NULL) {
- return -1;
- }
-
- nlr_buf_t nlr;
- if (nlr_push(&nlr) == 0) {
- mp_obj_t readinto_m[3];
- mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_readinto, readinto_m);
- readinto_m[2] = MP_STATE_PORT(dupterm_arr_obj);
- mp_obj_t res = mp_call_method_n_kw(1, 0, readinto_m);
- if (res == mp_const_none) {
- nlr_pop();
- return -2;
- }
- if (res == MP_OBJ_NEW_SMALL_INT(0)) {
- mp_uos_deactivate("dupterm: EOF received, deactivating\n", MP_OBJ_NULL);
- nlr_pop();
- return -1;
- }
- mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(MP_STATE_PORT(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ);
- nlr_pop();
- if (*(byte*)bufinfo.buf == mp_interrupt_char) {
- mp_keyboard_interrupt();
- return -2;
- }
- return *(byte*)bufinfo.buf;
- } else {
- mp_uos_deactivate("dupterm: Exception in read() method, deactivating: ", nlr.ret_val);
- }
-
- return -1;
-}
-
STATIC void dupterm_task_handler(os_event_t *evt) {
static byte lock;
if (lock) {
@@ -188,7 +162,7 @@ STATIC void dupterm_task_handler(os_event_t *evt) {
}
lock = 1;
while (1) {
- int c = call_dupterm_read();
+ int c = mp_uos_dupterm_rx_chr();
if (c < 0) {
break;
}
diff --git a/esp8266/esp_mphal.h b/ports/esp8266/esp_mphal.h
similarity index 96%
rename from esp8266/esp_mphal.h
rename to ports/esp8266/esp_mphal.h
index 1d1d6de3f..194e56f64 100644
--- a/esp8266/esp_mphal.h
+++ b/ports/esp8266/esp_mphal.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -72,7 +72,7 @@ void ets_event_poll(void);
// C-level pin HAL
#include "etshal.h"
#include "gpio.h"
-#include "esp8266/modmachine.h"
+#include "modmachine.h"
#define MP_HAL_PIN_FMT "%u"
#define mp_hal_pin_obj_t uint32_t
#define mp_hal_get_pin_obj(o) mp_obj_get_pin(o)
diff --git a/esp8266/espapa102.c b/ports/esp8266/espapa102.c
similarity index 100%
rename from esp8266/espapa102.c
rename to ports/esp8266/espapa102.c
diff --git a/esp8266/espapa102.h b/ports/esp8266/espapa102.h
similarity index 100%
rename from esp8266/espapa102.h
rename to ports/esp8266/espapa102.h
diff --git a/esp8266/espneopixel.c b/ports/esp8266/espneopixel.c
similarity index 100%
rename from esp8266/espneopixel.c
rename to ports/esp8266/espneopixel.c
diff --git a/esp8266/espneopixel.h b/ports/esp8266/espneopixel.h
similarity index 100%
rename from esp8266/espneopixel.h
rename to ports/esp8266/espneopixel.h
diff --git a/esp8266/esppwm.c b/ports/esp8266/esppwm.c
similarity index 100%
rename from esp8266/esppwm.c
rename to ports/esp8266/esppwm.c
diff --git a/esp8266/esppwm.h b/ports/esp8266/esppwm.h
similarity index 100%
rename from esp8266/esppwm.h
rename to ports/esp8266/esppwm.h
diff --git a/esp8266/ets_alt_task.c b/ports/esp8266/ets_alt_task.c
similarity index 100%
rename from esp8266/ets_alt_task.c
rename to ports/esp8266/ets_alt_task.c
diff --git a/esp8266/ets_alt_task.h b/ports/esp8266/ets_alt_task.h
similarity index 100%
rename from esp8266/ets_alt_task.h
rename to ports/esp8266/ets_alt_task.h
diff --git a/esp8266/etshal.h b/ports/esp8266/etshal.h
similarity index 100%
rename from esp8266/etshal.h
rename to ports/esp8266/etshal.h
diff --git a/esp8266/fatfs_port.c b/ports/esp8266/fatfs_port.c
similarity index 95%
rename from esp8266/fatfs_port.c
rename to ports/esp8266/fatfs_port.c
index 02384f605..a8865c817 100644
--- a/esp8266/fatfs_port.c
+++ b/ports/esp8266/fatfs_port.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/gccollect.c b/ports/esp8266/gccollect.c
similarity index 96%
rename from esp8266/gccollect.c
rename to ports/esp8266/gccollect.c
index 1b9349f57..cd5d4932c 100644
--- a/esp8266/gccollect.c
+++ b/ports/esp8266/gccollect.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/gccollect.h b/ports/esp8266/gccollect.h
similarity index 95%
rename from esp8266/gccollect.h
rename to ports/esp8266/gccollect.h
index 0aee42771..5735d8a39 100644
--- a/esp8266/gccollect.h
+++ b/ports/esp8266/gccollect.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/gchelper.s b/ports/esp8266/gchelper.s
similarity index 100%
rename from esp8266/gchelper.s
rename to ports/esp8266/gchelper.s
diff --git a/esp8266/help.c b/ports/esp8266/help.c
similarity index 98%
rename from esp8266/help.c
rename to ports/esp8266/help.c
index 2035cdd6c..0a851f4c4 100644
--- a/esp8266/help.c
+++ b/ports/esp8266/help.c
@@ -26,7 +26,7 @@
#include "py/builtin.h"
-const char *esp_help_text =
+const char esp_help_text[] =
"Welcome to MicroPython!\n"
"\n"
"For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .\n"
diff --git a/esp8266/hspi.c b/ports/esp8266/hspi.c
similarity index 98%
rename from esp8266/hspi.c
rename to ports/esp8266/hspi.c
index 436fb4f6f..554a50460 100644
--- a/esp8266/hspi.c
+++ b/ports/esp8266/hspi.c
@@ -28,7 +28,7 @@
/*
Wrapper to setup HSPI/SPI GPIO pins and default SPI clock
spi_no - SPI (0) or HSPI (1)
-Not used in Micropython.
+Not used in MicroPython.
*/
void spi_init(uint8_t spi_no) {
spi_init_gpio(spi_no, SPI_CLK_USE_DIV);
@@ -48,7 +48,7 @@ Configures SPI mode parameters for clock edge and clock polarity.
(1) Data is valid on clock trailing edge
spi_cpol - (0) Clock is low when inactive
(1) Clock is high when inactive
-For Micropython this version is different from original.
+For MicroPython this version is different from original.
*/
void spi_mode(uint8_t spi_no, uint8_t spi_cpha, uint8_t spi_cpol) {
if (spi_cpol) {
@@ -99,7 +99,7 @@ void spi_init_gpio(uint8_t spi_no, uint8_t sysclk_as_spiclk) {
// GPIO14 is HSPI CLK pin (Clock)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);
// GPIO15 is HSPI CS pin (Chip Select / Slave Select)
- // In Micropython, we are handling CS ourself in drivers.
+ // In MicroPython, we are handling CS ourself in drivers.
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);
}
}
diff --git a/esp8266/hspi.h b/ports/esp8266/hspi.h
similarity index 100%
rename from esp8266/hspi.h
rename to ports/esp8266/hspi.h
diff --git a/esp8266/hspi_register.h b/ports/esp8266/hspi_register.h
similarity index 100%
rename from esp8266/hspi_register.h
rename to ports/esp8266/hspi_register.h
diff --git a/esp8266/intr.c b/ports/esp8266/intr.c
similarity index 100%
rename from esp8266/intr.c
rename to ports/esp8266/intr.c
diff --git a/esp8266/lexerstr32.c b/ports/esp8266/lexerstr32.c
similarity index 100%
rename from esp8266/lexerstr32.c
rename to ports/esp8266/lexerstr32.c
diff --git a/esp8266/machine_adc.c b/ports/esp8266/machine_adc.c
similarity index 89%
rename from esp8266/machine_adc.c
rename to ports/esp8266/machine_adc.c
index f1fb5be31..b422f0f9e 100644
--- a/esp8266/machine_adc.c
+++ b/ports/esp8266/machine_adc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,8 +27,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "user_interface.h"
@@ -70,8 +68,8 @@ STATIC mp_obj_t pyb_adc_read(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_adc_read_obj, pyb_adc_read);
-STATIC const mp_map_elem_t pyb_adc_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&pyb_adc_read_obj }
+STATIC const mp_rom_map_elem_t pyb_adc_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&pyb_adc_read_obj) }
};
STATIC MP_DEFINE_CONST_DICT(pyb_adc_locals_dict, pyb_adc_locals_dict_table);
@@ -79,5 +77,5 @@ const mp_obj_type_t pyb_adc_type = {
{ &mp_type_type },
.name = MP_QSTR_ADC,
.make_new = pyb_adc_make_new,
- .locals_dict = (mp_obj_t)&pyb_adc_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&pyb_adc_locals_dict,
};
diff --git a/esp8266/machine_hspi.c b/ports/esp8266/machine_hspi.c
similarity index 96%
rename from esp8266/machine_hspi.c
rename to ports/esp8266/machine_hspi.c
index 1be342b52..9fd0f4868 100644
--- a/esp8266/machine_hspi.c
+++ b/ports/esp8266/machine_hspi.c
@@ -122,15 +122,13 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
spi_init_gpio(HSPI, SPI_CLK_80MHZ_NODIV);
spi_clock(HSPI, 0, 0);
} else if (self->baudrate > 40000000L) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "impossible baudrate"));
+ mp_raise_ValueError("impossible baudrate");
} else {
uint32_t divider = 40000000L / self->baudrate;
uint16_t prediv = MIN(divider, SPI_CLKDIV_PRE + 1);
uint16_t cntdiv = (divider / prediv) * 2; // cntdiv has to be even
if (cntdiv > SPI_CLKCNT_N + 1 || cntdiv == 0 || prediv == 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "impossible baudrate"));
+ mp_raise_ValueError("impossible baudrate");
}
self->baudrate = 80000000L / (prediv * cntdiv);
spi_init_gpio(HSPI, SPI_CLK_USE_DIV);
@@ -151,7 +149,7 @@ mp_obj_t machine_hspi_make_new(const mp_obj_type_t *type, size_t n_args, size_t
// args[0] holds the id of the peripheral
if (args[0] != MP_OBJ_NEW_SMALL_INT(1)) {
// FlashROM is on SPI0, so far we don't support its usage
- mp_raise_ValueError("");
+ mp_raise_ValueError(NULL);
}
machine_hspi_obj_t *self = m_new_obj(machine_hspi_obj_t);
diff --git a/esp8266/machine_pin.c b/ports/esp8266/machine_pin.c
similarity index 90%
rename from esp8266/machine_pin.c
rename to ports/esp8266/machine_pin.c
index febbc1587..14505c8f0 100644
--- a/esp8266/machine_pin.c
+++ b/ports/esp8266/machine_pin.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -33,7 +33,6 @@
#include "user_interface.h"
#include "gpio.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
@@ -125,7 +124,7 @@ void pin_intr_handler(uint32_t status) {
pyb_pin_obj_t *mp_obj_get_pin_obj(mp_obj_t pin_in) {
if (mp_obj_get_type(pin_in) != &pyb_pin_type) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "expecting a pin"));
+ mp_raise_ValueError("expecting a pin");
}
pyb_pin_obj_t *self = pin_in;
return self;
@@ -243,7 +242,7 @@ STATIC void pyb_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
}
// pin.init(mode, pull=None, *, value)
-STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_mode, ARG_pull, ARG_value };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT },
@@ -280,7 +279,7 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, c
// only pull-down seems to be supported by the hardware, and
// we only expose pull-up behaviour in software
if (pull != GPIO_PULL_NONE) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin(16) doesn't support pull"));
+ mp_raise_ValueError("Pin(16) doesn't support pull");
}
} else {
PIN_FUNC_SELECT(self->periph, self->func);
@@ -319,7 +318,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
pin = (pyb_pin_obj_t*)&pyb_pin_obj[wanted_pin];
}
if (pin == NULL || pin->base.type == NULL) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid pin"));
+ mp_raise_ValueError("invalid pin");
}
if (n_args > 1 || n_kw > 0) {
@@ -347,13 +346,13 @@ STATIC mp_obj_t pyb_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
}
// pin.init(mode, pull)
-STATIC mp_obj_t pyb_pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
MP_DEFINE_CONST_FUN_OBJ_KW(pyb_pin_init_obj, 1, pyb_pin_obj_init);
// pin.value([value])
-STATIC mp_obj_t pyb_pin_value(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_pin_value(size_t n_args, const mp_obj_t *args) {
return pyb_pin_call(args[0], n_args - 1, 0, args + 1);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_pin_value_obj, 1, 2, pyb_pin_value);
@@ -426,24 +425,24 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i
return -1;
}
-STATIC const mp_map_elem_t pyb_pin_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_pin_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_pin_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pyb_pin_value_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&pyb_pin_off_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&pyb_pin_on_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_pin_irq_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_pin_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_pin_value_obj) },
+ { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&pyb_pin_off_obj) },
+ { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&pyb_pin_on_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_pin_irq_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_IN), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_INPUT) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OUT), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_OUTPUT) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OPEN_DRAIN), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_OPEN_DRAIN) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PULL_UP), MP_OBJ_NEW_SMALL_INT(GPIO_PULL_UP) },
- //{ MP_OBJ_NEW_QSTR(MP_QSTR_PULL_DOWN), MP_OBJ_NEW_SMALL_INT(GPIO_PULL_DOWN) },
-
- // IRG triggers, can be or'd together
- { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_RISING), MP_OBJ_NEW_SMALL_INT(GPIO_PIN_INTR_POSEDGE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_FALLING), MP_OBJ_NEW_SMALL_INT(GPIO_PIN_INTR_NEGEDGE) },
+ { MP_ROM_QSTR(MP_QSTR_IN), MP_ROM_INT(GPIO_MODE_INPUT) },
+ { MP_ROM_QSTR(MP_QSTR_OUT), MP_ROM_INT(GPIO_MODE_OUTPUT) },
+ { MP_ROM_QSTR(MP_QSTR_OPEN_DRAIN), MP_ROM_INT(GPIO_MODE_OPEN_DRAIN) },
+ { MP_ROM_QSTR(MP_QSTR_PULL_UP), MP_ROM_INT(GPIO_PULL_UP) },
+ //{ MP_ROM_QSTR(MP_QSTR_PULL_DOWN), MP_ROM_INT(GPIO_PULL_DOWN) },
+
+ // IRQ triggers, can be or'd together
+ { MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(GPIO_PIN_INTR_POSEDGE) },
+ { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_PIN_INTR_NEGEDGE) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_pin_locals_dict, pyb_pin_locals_dict_table);
@@ -459,7 +458,7 @@ const mp_obj_type_t pyb_pin_type = {
.make_new = mp_pin_make_new,
.call = pyb_pin_call,
.protocol = &pin_pin_p,
- .locals_dict = (mp_obj_t)&pyb_pin_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&pyb_pin_locals_dict,
};
/******************************************************************************/
diff --git a/esp8266/machine_pwm.c b/ports/esp8266/machine_pwm.c
similarity index 98%
rename from esp8266/machine_pwm.c
rename to ports/esp8266/machine_pwm.c
index 5d30f0965..4c5cb8727 100644
--- a/esp8266/machine_pwm.c
+++ b/ports/esp8266/machine_pwm.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,7 +29,6 @@
#include "esppwm.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "modmachine.h"
diff --git a/esp8266/machine_rtc.c b/ports/esp8266/machine_rtc.c
similarity index 88%
rename from esp8266/machine_rtc.c
rename to ports/esp8266/machine_rtc.c
index b92ce1d5a..bbfc172cd 100644
--- a/esp8266/machine_rtc.c
+++ b/ports/esp8266/machine_rtc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,8 +27,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "lib/timeutils/timeutils.h"
#include "user_interface.h"
@@ -126,7 +124,7 @@ void rtc_prepare_deepsleep(uint64_t sleep_us) {
system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta));
}
-STATIC mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_rtc_datetime(size_t n_args, const mp_obj_t *args) {
if (n_args == 1) {
// Get time
uint64_t msecs = pyb_rtc_get_us_since_2000() / 1000;
@@ -165,7 +163,7 @@ STATIC mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime);
-STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_rtc_memory(size_t n_args, const mp_obj_t *args) {
uint8_t rtcram[MEM_USER_MAXLEN];
uint32_t len;
@@ -183,8 +181,7 @@ STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
if (bufinfo.len > MEM_USER_MAXLEN) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "buffer too long"));
+ mp_raise_ValueError("buffer too long");
}
len = bufinfo.len;
@@ -208,7 +205,7 @@ STATIC mp_obj_t pyb_rtc_alarm(mp_obj_t self_in, mp_obj_t alarm_id, mp_obj_t time
// check we want alarm0
if (mp_obj_get_int(alarm_id) != 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid alarm"));
+ mp_raise_ValueError("invalid alarm");
}
// set expiry time (in microseconds)
@@ -245,7 +242,7 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
// check we want alarm0
if (args[ARG_trigger].u_int != 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid alarm"));
+ mp_raise_ValueError("invalid alarm");
}
// set the wake value
@@ -255,13 +252,13 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq);
-STATIC const mp_map_elem_t pyb_rtc_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_datetime), (mp_obj_t)&pyb_rtc_datetime_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_memory), (mp_obj_t)&pyb_rtc_memory_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_alarm), (mp_obj_t)&pyb_rtc_alarm_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_left), (mp_obj_t)&pyb_rtc_alarm_left_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_rtc_irq_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ALARM0), MP_OBJ_NEW_SMALL_INT(0) },
+STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&pyb_rtc_datetime_obj) },
+ { MP_ROM_QSTR(MP_QSTR_memory), MP_ROM_PTR(&pyb_rtc_memory_obj) },
+ { MP_ROM_QSTR(MP_QSTR_alarm), MP_ROM_PTR(&pyb_rtc_alarm_obj) },
+ { MP_ROM_QSTR(MP_QSTR_alarm_left), MP_ROM_PTR(&pyb_rtc_alarm_left_obj) },
+ { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_rtc_irq_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(0) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
@@ -269,5 +266,5 @@ const mp_obj_type_t pyb_rtc_type = {
{ &mp_type_type },
.name = MP_QSTR_RTC,
.make_new = pyb_rtc_make_new,
- .locals_dict = (mp_obj_t)&pyb_rtc_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&pyb_rtc_locals_dict,
};
diff --git a/esp8266/machine_uart.c b/ports/esp8266/machine_uart.c
similarity index 100%
rename from esp8266/machine_uart.c
rename to ports/esp8266/machine_uart.c
diff --git a/esp8266/machine_wdt.c b/ports/esp8266/machine_wdt.c
similarity index 87%
rename from esp8266/machine_wdt.c
rename to ports/esp8266/machine_wdt.c
index 83b5e8f32..4432297fa 100644
--- a/esp8266/machine_wdt.c
+++ b/ports/esp8266/machine_wdt.c
@@ -27,8 +27,6 @@
//#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "user_interface.h"
#include "etshal.h"
@@ -53,7 +51,7 @@ STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type_in, size_t n_args
case 0:
return &wdt_default;
default:
- mp_raise_ValueError("");
+ mp_raise_ValueError(NULL);
}
}
@@ -71,9 +69,9 @@ STATIC mp_obj_t machine_wdt_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_deinit_obj, machine_wdt_deinit);
-STATIC const mp_map_elem_t machine_wdt_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&machine_wdt_feed_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&machine_wdt_deinit_obj },
+STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_feed), MP_ROM_PTR(&machine_wdt_feed_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_wdt_deinit_obj) },
};
STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table);
@@ -81,5 +79,5 @@ const mp_obj_type_t esp_wdt_type = {
{ &mp_type_type },
.name = MP_QSTR_WDT,
.make_new = machine_wdt_make_new,
- .locals_dict = (mp_obj_t)&machine_wdt_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&machine_wdt_locals_dict,
};
diff --git a/esp8266/main.c b/ports/esp8266/main.c
similarity index 94%
rename from esp8266/main.c
rename to ports/esp8266/main.c
index 43b83759e..d1b88a8ce 100644
--- a/esp8266/main.c
+++ b/ports/esp8266/main.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,9 +27,7 @@
#include
#include
-#include "py/nlr.h"
#include "py/compile.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/mperrno.h"
@@ -53,8 +51,6 @@ STATIC void mp_reset(void) {
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));
mp_obj_list_init(mp_sys_argv, 0);
- MP_STATE_PORT(term_obj) = MP_OBJ_NULL;
- MP_STATE_PORT(dupterm_arr_obj) = MP_OBJ_NULL;
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
extern void esp_native_code_init(void);
esp_native_code_init();
diff --git a/esp8266/makeimg.py b/ports/esp8266/makeimg.py
similarity index 100%
rename from esp8266/makeimg.py
rename to ports/esp8266/makeimg.py
diff --git a/esp8266/modesp.c b/ports/esp8266/modesp.c
similarity index 83%
rename from esp8266/modesp.c
rename to ports/esp8266/modesp.c
index 5eaae27d6..8f9db4fba 100644
--- a/esp8266/modesp.c
+++ b/ports/esp8266/modesp.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -56,7 +56,7 @@ STATIC mp_obj_t esp_osdebug(mp_obj_t val) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_osdebug_obj, esp_osdebug);
-STATIC mp_obj_t esp_sleep_type(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t esp_sleep_type(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return mp_obj_new_int(wifi_get_sleep_type());
} else {
@@ -66,7 +66,7 @@ STATIC mp_obj_t esp_sleep_type(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_sleep_type_obj, 0, 1, esp_sleep_type);
-STATIC mp_obj_t esp_deepsleep(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t esp_deepsleep(size_t n_args, const mp_obj_t *args) {
uint32_t sleep_us = n_args > 0 ? mp_obj_get_int(args[0]) : 0;
// prepare for RTC reset at wake up
rtc_prepare_deepsleep(sleep_us);
@@ -118,7 +118,7 @@ STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len & 0x3) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "len must be multiple of 4"));
+ mp_raise_ValueError("len must be multiple of 4");
}
SpiFlashOpResult res = spi_flash_write(offset, bufinfo.buf, bufinfo.len);
if (res == SPI_FLASH_RESULT_OK) {
@@ -347,50 +347,40 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_set_native_code_location_obj, esp_set_nativ
#endif
-STATIC const mp_map_elem_t esp_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_esp) },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_osdebug), (mp_obj_t)&esp_osdebug_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_id), (mp_obj_t)&esp_flash_id_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_read), (mp_obj_t)&esp_flash_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_write), (mp_obj_t)&esp_flash_write_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_erase), (mp_obj_t)&esp_flash_erase_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_size), (mp_obj_t)&esp_flash_size_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flash_user_start), (mp_obj_t)&esp_flash_user_start_obj },
+STATIC const mp_rom_map_elem_t esp_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) },
+
+ { MP_ROM_QSTR(MP_QSTR_osdebug), MP_ROM_PTR(&esp_osdebug_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep_type), MP_ROM_PTR(&esp_sleep_type_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&esp_deepsleep_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_id), MP_ROM_PTR(&esp_flash_id_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_read), MP_ROM_PTR(&esp_flash_read_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_write), MP_ROM_PTR(&esp_flash_write_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_erase), MP_ROM_PTR(&esp_flash_erase_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&esp_flash_size_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flash_user_start), MP_ROM_PTR(&esp_flash_user_start_obj) },
#if MICROPY_ESP8266_NEOPIXEL
- { MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write), (mp_obj_t)&esp_neopixel_write_obj },
+ { MP_ROM_QSTR(MP_QSTR_neopixel_write), MP_ROM_PTR(&esp_neopixel_write_obj) },
#endif
#if MICROPY_ESP8266_APA102
- { MP_OBJ_NEW_QSTR(MP_QSTR_apa102_write), (mp_obj_t)&esp_apa102_write_obj },
+ { MP_ROM_QSTR(MP_QSTR_apa102_write), MP_ROM_PTR(&esp_apa102_write_obj) },
#endif
- { MP_OBJ_NEW_QSTR(MP_QSTR_dht_readinto), (mp_obj_t)&dht_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_freemem), (mp_obj_t)&esp_freemem_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_meminfo), (mp_obj_t)&esp_meminfo_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_check_fw), (mp_obj_t)&esp_check_fw_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj }, // TODO delete/rename/move elsewhere
- { MP_OBJ_NEW_QSTR(MP_QSTR_malloc), (mp_obj_t)&esp_malloc_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_free), (mp_obj_t)&esp_free_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_esf_free_bufs), (mp_obj_t)&esp_esf_free_bufs_obj },
+ { MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_freemem), MP_ROM_PTR(&esp_freemem_obj) },
+ { MP_ROM_QSTR(MP_QSTR_meminfo), MP_ROM_PTR(&esp_meminfo_obj) },
+ { MP_ROM_QSTR(MP_QSTR_check_fw), MP_ROM_PTR(&esp_check_fw_obj) },
+ { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&pyb_info_obj) }, // TODO delete/rename/move elsewhere
+ { MP_ROM_QSTR(MP_QSTR_malloc), MP_ROM_PTR(&esp_malloc_obj) },
+ { MP_ROM_QSTR(MP_QSTR_free), MP_ROM_PTR(&esp_free_obj) },
+ { MP_ROM_QSTR(MP_QSTR_esf_free_bufs), MP_ROM_PTR(&esp_esf_free_bufs_obj) },
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
- { MP_OBJ_NEW_QSTR(MP_QSTR_set_native_code_location), (mp_obj_t)&esp_set_native_code_location_obj },
+ { MP_ROM_QSTR(MP_QSTR_set_native_code_location), MP_ROM_PTR(&esp_set_native_code_location_obj) },
#endif
#if MODESP_INCLUDE_CONSTANTS
- { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_NONE),
- MP_OBJ_NEW_SMALL_INT(NONE_SLEEP_T) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_LIGHT),
- MP_OBJ_NEW_SMALL_INT(LIGHT_SLEEP_T) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_MODEM),
- MP_OBJ_NEW_SMALL_INT(MODEM_SLEEP_T) },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_STA_MODE),
- MP_OBJ_NEW_SMALL_INT(STATION_MODE)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_AP_MODE),
- MP_OBJ_NEW_SMALL_INT(SOFTAP_MODE)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STA_AP_MODE),
- MP_OBJ_NEW_SMALL_INT(STATIONAP_MODE)},
+ { MP_ROM_QSTR(MP_QSTR_SLEEP_NONE), MP_ROM_INT(NONE_SLEEP_T) },
+ { MP_ROM_QSTR(MP_QSTR_SLEEP_LIGHT), MP_ROM_INT(LIGHT_SLEEP_T) },
+ { MP_ROM_QSTR(MP_QSTR_SLEEP_MODEM), MP_ROM_INT(MODEM_SLEEP_T) },
#endif
};
diff --git a/esp8266/modmachine.c b/ports/esp8266/modmachine.c
similarity index 91%
rename from esp8266/modmachine.c
rename to ports/esp8266/modmachine.c
index c26c63396..99286848e 100644
--- a/esp8266/modmachine.c
+++ b/ports/esp8266/modmachine.c
@@ -51,7 +51,7 @@
extern const mp_obj_type_t esp_wdt_type;
-STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
// get
return mp_obj_new_int(system_get_cpu_freq() * 1000000);
@@ -59,8 +59,7 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
// set
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
if (freq != 80 && freq != 160) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "frequency can only be either 80Mhz or 160MHz"));
+ mp_raise_ValueError("frequency can only be either 80Mhz or 160MHz");
}
system_update_cpu_freq(freq);
return mp_const_none;
@@ -160,7 +159,7 @@ STATIC void esp_timer_cb(void *arg) {
mp_sched_schedule(self->callback, self);
}
-STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
// { MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
@@ -181,7 +180,7 @@ STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, mp_uint_t n_args, c
return mp_const_none;
}
-STATIC mp_obj_t esp_timer_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t esp_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return esp_timer_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_timer_init_obj, 1, esp_timer_init);
@@ -193,12 +192,12 @@ STATIC mp_obj_t esp_timer_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_timer_deinit_obj, esp_timer_deinit);
-STATIC const mp_map_elem_t esp_timer_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&esp_timer_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&esp_timer_init_obj },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&esp_timer_callback_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ONE_SHOT), MP_OBJ_NEW_SMALL_INT(false) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PERIODIC), MP_OBJ_NEW_SMALL_INT(true) },
+STATIC const mp_rom_map_elem_t esp_timer_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&esp_timer_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&esp_timer_init_obj) },
+// { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&esp_timer_callback_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(false) },
+ { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(true) },
};
STATIC MP_DEFINE_CONST_DICT(esp_timer_locals_dict, esp_timer_locals_dict_table);
@@ -207,7 +206,7 @@ const mp_obj_type_t esp_timer_type = {
.name = MP_QSTR_Timer,
.print = esp_timer_print,
.make_new = esp_timer_make_new,
- .locals_dict = (mp_obj_t)&esp_timer_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&esp_timer_locals_dict,
};
// this bit is unused in the Xtensa PS register
diff --git a/esp8266/modmachine.h b/ports/esp8266/modmachine.h
similarity index 100%
rename from esp8266/modmachine.h
rename to ports/esp8266/modmachine.h
diff --git a/esp8266/modnetwork.c b/ports/esp8266/modnetwork.c
similarity index 78%
rename from esp8266/modnetwork.c
rename to ports/esp8266/modnetwork.c
index eb9d75e28..b41a11f59 100644
--- a/esp8266/modnetwork.c
+++ b/ports/esp8266/modnetwork.c
@@ -1,9 +1,9 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
- * Copyright (c) 2015 Paul Sokolovsky
+ * Copyright (c) 2015-2016 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -28,7 +28,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/objlist.h"
#include "py/runtime.h"
#include "py/mphal.h"
@@ -62,7 +61,7 @@ STATIC void require_if(mp_obj_t wlan_if, int if_no) {
}
}
-STATIC mp_obj_t get_wlan(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) {
int idx = 0;
if (n_args > 0) {
idx = mp_obj_get_int(args[0]);
@@ -71,7 +70,7 @@ STATIC mp_obj_t get_wlan(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(get_wlan_obj, 0, 1, get_wlan);
-STATIC mp_obj_t esp_active(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t esp_active(size_t n_args, const mp_obj_t *args) {
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
uint32_t mode = wifi_get_opmode();
if (n_args > 1) {
@@ -94,29 +93,55 @@ STATIC mp_obj_t esp_active(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_active_obj, 1, 2, esp_active);
-STATIC mp_obj_t esp_connect(mp_uint_t n_args, const mp_obj_t *args) {
- require_if(args[0], STATION_IF);
+STATIC mp_obj_t esp_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ enum { ARG_ssid, ARG_password, ARG_bssid };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_, MP_ARG_OBJ, {.u_obj = mp_const_none} },
+ { MP_QSTR_, MP_ARG_OBJ, {.u_obj = mp_const_none} },
+ { MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
+ };
+
+ // parse args
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+
+ require_if(pos_args[0], STATION_IF);
struct station_config config = {{0}};
size_t len;
const char *p;
+ bool set_config = false;
- if (n_args > 1) {
- p = mp_obj_str_get_data(args[1], &len);
+ // set parameters based on given args
+ if (args[ARG_ssid].u_obj != mp_const_none) {
+ p = mp_obj_str_get_data(args[ARG_ssid].u_obj, &len);
len = MIN(len, sizeof(config.ssid));
memcpy(config.ssid, p, len);
- if (n_args > 2) {
- p = mp_obj_str_get_data(args[2], &len);
- len = MIN(len, sizeof(config.password));
- memcpy(config.password, p, len);
+ set_config = true;
+ }
+ if (args[ARG_password].u_obj != mp_const_none) {
+ p = mp_obj_str_get_data(args[ARG_password].u_obj, &len);
+ len = MIN(len, sizeof(config.password));
+ memcpy(config.password, p, len);
+ set_config = true;
+ }
+ if (args[ARG_bssid].u_obj != mp_const_none) {
+ p = mp_obj_str_get_data(args[ARG_bssid].u_obj, &len);
+ if (len != sizeof(config.bssid)) {
+ mp_raise_ValueError(NULL);
}
+ config.bssid_set = 1;
+ memcpy(config.bssid, p, sizeof(config.bssid));
+ set_config = true;
+ }
+ if (set_config) {
error_check(wifi_station_set_config(&config), "Cannot set STA config");
}
error_check(wifi_station_connect(), "Cannot connect to AP");
return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_connect_obj, 1, 7, esp_connect);
+STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_connect_obj, 1, esp_connect);
STATIC mp_obj_t esp_disconnect(mp_obj_t self_in) {
require_if(self_in, STATION_IF);
@@ -275,8 +300,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig)
STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
if (n_args != 1 && kwargs->used != 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
- "either pos or kw args are allowed"));
+ mp_raise_TypeError("either pos or kw args are allowed");
}
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
@@ -303,8 +327,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(kwargs->table[i].value, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len != 6) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "invalid buffer length"));
+ mp_raise_ValueError("invalid buffer length");
}
wifi_set_macaddr(self->if_id, bufinfo.buf);
break;
@@ -374,8 +397,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
// Get config
if (n_args != 2) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
- "can query only one param"));
+ mp_raise_TypeError("can query only one param");
}
mp_obj_t val;
@@ -422,20 +444,19 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
return val;
unknown:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "unknown config param"));
+ mp_raise_ValueError("unknown config param");
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);
-STATIC const mp_map_elem_t wlan_if_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_active), (mp_obj_t)&esp_active_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&esp_connect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)&esp_disconnect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&esp_status_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&esp_scan_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_isconnected), (mp_obj_t)&esp_isconnected_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_config), (mp_obj_t)&esp_config_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_ifconfig), (mp_obj_t)&esp_ifconfig_obj },
+STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&esp_active_obj) },
+ { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&esp_connect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&esp_disconnect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&esp_status_obj) },
+ { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&esp_scan_obj) },
+ { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&esp_isconnected_obj) },
+ { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
};
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
@@ -443,10 +464,10 @@ STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
const mp_obj_type_t wlan_if_type = {
{ &mp_type_type },
.name = MP_QSTR_WLAN,
- .locals_dict = (mp_obj_t)&wlan_if_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&wlan_if_locals_dict,
};
-STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return mp_obj_new_int(wifi_get_phy_mode());
} else {
@@ -456,47 +477,31 @@ STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_phy_mode_obj, 0, 1, esp_phy_mode);
-STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&get_wlan_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_phy_mode), (mp_obj_t)&esp_phy_mode_obj },
+STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
+ { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&get_wlan_obj) },
+ { MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_phy_mode_obj) },
#if MODNETWORK_INCLUDE_CONSTANTS
- { MP_OBJ_NEW_QSTR(MP_QSTR_STA_IF),
- MP_OBJ_NEW_SMALL_INT(STATION_IF)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_AP_IF),
- MP_OBJ_NEW_SMALL_INT(SOFTAP_IF)},
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_IDLE),
- MP_OBJ_NEW_SMALL_INT(STATION_IDLE)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_CONNECTING),
- MP_OBJ_NEW_SMALL_INT(STATION_CONNECTING)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_WRONG_PASSWORD),
- MP_OBJ_NEW_SMALL_INT(STATION_WRONG_PASSWORD)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_NO_AP_FOUND),
- MP_OBJ_NEW_SMALL_INT(STATION_NO_AP_FOUND)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_CONNECT_FAIL),
- MP_OBJ_NEW_SMALL_INT(STATION_CONNECT_FAIL)},
- { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_GOT_IP),
- MP_OBJ_NEW_SMALL_INT(STATION_GOT_IP)},
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11B),
- MP_OBJ_NEW_SMALL_INT(PHY_MODE_11B) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11G),
- MP_OBJ_NEW_SMALL_INT(PHY_MODE_11G) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11N),
- MP_OBJ_NEW_SMALL_INT(PHY_MODE_11N) },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_OPEN),
- MP_OBJ_NEW_SMALL_INT(AUTH_OPEN) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WEP),
- MP_OBJ_NEW_SMALL_INT(AUTH_WEP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA_PSK),
- MP_OBJ_NEW_SMALL_INT(AUTH_WPA_PSK) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA2_PSK),
- MP_OBJ_NEW_SMALL_INT(AUTH_WPA2_PSK) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK),
- MP_OBJ_NEW_SMALL_INT(AUTH_WPA_WPA2_PSK) },
+ { MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(STATION_IF)},
+ { MP_ROM_QSTR(MP_QSTR_AP_IF), MP_ROM_INT(SOFTAP_IF)},
+
+ { MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(STATION_IDLE)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(STATION_CONNECTING)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(STATION_WRONG_PASSWORD)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(STATION_NO_AP_FOUND)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_CONNECT_FAIL), MP_ROM_INT(STATION_CONNECT_FAIL)},
+ { MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STATION_GOT_IP)},
+
+ { MP_ROM_QSTR(MP_QSTR_MODE_11B), MP_ROM_INT(PHY_MODE_11B) },
+ { MP_ROM_QSTR(MP_QSTR_MODE_11G), MP_ROM_INT(PHY_MODE_11G) },
+ { MP_ROM_QSTR(MP_QSTR_MODE_11N), MP_ROM_INT(PHY_MODE_11N) },
+
+ { MP_ROM_QSTR(MP_QSTR_AUTH_OPEN), MP_ROM_INT(AUTH_OPEN) },
+ { MP_ROM_QSTR(MP_QSTR_AUTH_WEP), MP_ROM_INT(AUTH_WEP) },
+ { MP_ROM_QSTR(MP_QSTR_AUTH_WPA_PSK), MP_ROM_INT(AUTH_WPA_PSK) },
+ { MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_PSK), MP_ROM_INT(AUTH_WPA2_PSK) },
+ { MP_ROM_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK), MP_ROM_INT(AUTH_WPA_WPA2_PSK) },
#endif
};
diff --git a/esp8266/modpyb.c b/ports/esp8266/modpyb.c
similarity index 95%
rename from esp8266/modpyb.c
rename to ports/esp8266/modpyb.c
index 9fe8039bc..0a23f6f9d 100644
--- a/esp8266/modpyb.c
+++ b/ports/esp8266/modpyb.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -35,7 +35,7 @@
// only remaining function is pyb.info() which has been moved to the
// esp module, pending deletion/renaming/moving elsewhere.
-STATIC mp_obj_t pyb_info(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_info(size_t n_args, const mp_obj_t *args) {
// print info about memory
{
printf("_text_start=%p\n", &_text_start);
diff --git a/esp8266/modules/_boot.py b/ports/esp8266/modules/_boot.py
similarity index 100%
rename from esp8266/modules/_boot.py
rename to ports/esp8266/modules/_boot.py
diff --git a/esp8266/modules/apa102.py b/ports/esp8266/modules/apa102.py
similarity index 100%
rename from esp8266/modules/apa102.py
rename to ports/esp8266/modules/apa102.py
diff --git a/esp8266/modules/dht.py b/ports/esp8266/modules/dht.py
similarity index 100%
rename from esp8266/modules/dht.py
rename to ports/esp8266/modules/dht.py
diff --git a/ports/esp8266/modules/ds18x20.py b/ports/esp8266/modules/ds18x20.py
new file mode 120000
index 000000000..1ec92d1c9
--- /dev/null
+++ b/ports/esp8266/modules/ds18x20.py
@@ -0,0 +1 @@
+../../../drivers/onewire/ds18x20.py
\ No newline at end of file
diff --git a/esp8266/modules/flashbdev.py b/ports/esp8266/modules/flashbdev.py
similarity index 100%
rename from esp8266/modules/flashbdev.py
rename to ports/esp8266/modules/flashbdev.py
diff --git a/esp8266/modules/inisetup.py b/ports/esp8266/modules/inisetup.py
similarity index 100%
rename from esp8266/modules/inisetup.py
rename to ports/esp8266/modules/inisetup.py
diff --git a/esp8266/modules/neopixel.py b/ports/esp8266/modules/neopixel.py
similarity index 100%
rename from esp8266/modules/neopixel.py
rename to ports/esp8266/modules/neopixel.py
diff --git a/esp8266/modules/ntptime.py b/ports/esp8266/modules/ntptime.py
similarity index 100%
rename from esp8266/modules/ntptime.py
rename to ports/esp8266/modules/ntptime.py
diff --git a/ports/esp8266/modules/onewire.py b/ports/esp8266/modules/onewire.py
new file mode 120000
index 000000000..33f30e84f
--- /dev/null
+++ b/ports/esp8266/modules/onewire.py
@@ -0,0 +1 @@
+../../../drivers/onewire/onewire.py
\ No newline at end of file
diff --git a/esp8266/modules/port_diag.py b/ports/esp8266/modules/port_diag.py
similarity index 100%
rename from esp8266/modules/port_diag.py
rename to ports/esp8266/modules/port_diag.py
diff --git a/ports/esp8266/modules/upip.py b/ports/esp8266/modules/upip.py
new file mode 120000
index 000000000..130eb6901
--- /dev/null
+++ b/ports/esp8266/modules/upip.py
@@ -0,0 +1 @@
+../../../tools/upip.py
\ No newline at end of file
diff --git a/ports/esp8266/modules/upip_utarfile.py b/ports/esp8266/modules/upip_utarfile.py
new file mode 120000
index 000000000..d9653d6a6
--- /dev/null
+++ b/ports/esp8266/modules/upip_utarfile.py
@@ -0,0 +1 @@
+../../../tools/upip_utarfile.py
\ No newline at end of file
diff --git a/esp8266/modules/webrepl.py b/ports/esp8266/modules/webrepl.py
similarity index 96%
rename from esp8266/modules/webrepl.py
rename to ports/esp8266/modules/webrepl.py
index 5a76e9b26..aa156d148 100644
--- a/esp8266/modules/webrepl.py
+++ b/ports/esp8266/modules/webrepl.py
@@ -31,7 +31,9 @@ def setup_conn(port, accept_handler):
def accept_conn(listen_sock):
global client_s
cl, remote_addr = listen_sock.accept()
- if uos.dupterm():
+ prev = uos.dupterm(None)
+ uos.dupterm(prev)
+ if prev:
print("\nConcurrent WebREPL connection from", remote_addr, "rejected")
cl.close()
return
diff --git a/esp8266/modules/webrepl_setup.py b/ports/esp8266/modules/webrepl_setup.py
similarity index 93%
rename from esp8266/modules/webrepl_setup.py
rename to ports/esp8266/modules/webrepl_setup.py
index d91600e6e..5288c49c0 100644
--- a/esp8266/modules/webrepl_setup.py
+++ b/ports/esp8266/modules/webrepl_setup.py
@@ -17,12 +17,9 @@ def getpass(prompt):
def input_pass():
while 1:
- passwd1 = getpass("New password: ")
- if len(passwd1) < 4:
- print("Password too short")
- continue
- elif len(passwd1) > 9:
- print("Password too long")
+ passwd1 = getpass("New password (4-9 chars): ")
+ if len(passwd1) < 4 or len(passwd1) > 9:
+ print("Invalid password length")
continue
passwd2 = getpass("Confirm password: ")
if passwd1 == passwd2:
diff --git a/esp8266/modules/websocket_helper.py b/ports/esp8266/modules/websocket_helper.py
similarity index 100%
rename from esp8266/modules/websocket_helper.py
rename to ports/esp8266/modules/websocket_helper.py
diff --git a/esp8266/moduos.c b/ports/esp8266/moduos.c
similarity index 98%
rename from esp8266/moduos.c
rename to ports/esp8266/moduos.c
index 807d2e18a..d0554096e 100644
--- a/esp8266/moduos.c
+++ b/ports/esp8266/moduos.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/modutime.c b/ports/esp8266/modutime.c
similarity index 96%
rename from esp8266/modutime.c
rename to ports/esp8266/modutime.c
index bdeb3bb45..ab9cb7dc2 100644
--- a/esp8266/modutime.c
+++ b/ports/esp8266/modutime.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,8 +28,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/gc.h"
#include "py/runtime.h"
#include "py/mphal.h"
@@ -56,7 +54,7 @@
/// second is 0-59
/// weekday is 0-6 for Mon-Sun.
/// yearday is 1-366
-STATIC mp_obj_t time_localtime(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
timeutils_struct_time_t tm;
mp_int_t seconds;
if (n_args == 0 || args[0] == mp_const_none) {
diff --git a/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h
similarity index 87%
rename from esp8266/mpconfigport.h
rename to ports/esp8266/mpconfigport.h
index ab5591bb7..c45ed92c7 100644
--- a/esp8266/mpconfigport.h
+++ b/ports/esp8266/mpconfigport.h
@@ -1,6 +1,6 @@
#include
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
#define MICROPY_ALLOC_PATH_MAX (128)
@@ -149,7 +149,7 @@ void *esp_native_code_commit(void*, size_t);
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t esp_module;
@@ -161,21 +161,21 @@ extern const struct _mp_obj_module_t mp_module_machine;
extern const struct _mp_obj_module_t mp_module_onewire;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_lwip }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&network_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&mp_module_onewire }, \
+ { MP_ROM_QSTR(MP_QSTR_esp), MP_ROM_PTR(&esp_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_lwip) }, \
+ { MP_ROM_QSTR(MP_QSTR_network), MP_ROM_PTR(&network_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&utime_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&uos_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
+ { MP_ROM_QSTR(MP_QSTR__onewire), MP_ROM_PTR(&mp_module_onewire) }, \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&utime_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&uos_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_lwip }, \
+ { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&utime_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&uos_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) }, \
+ { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \
+ { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_module_uselect) }, \
+ { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_module_lwip) }, \
#define MP_STATE_PORT MP_STATE_VM
diff --git a/esp8266/mpconfigport_512k.h b/ports/esp8266/mpconfigport_512k.h
similarity index 100%
rename from esp8266/mpconfigport_512k.h
rename to ports/esp8266/mpconfigport_512k.h
diff --git a/esp8266/axtls_helpers.c b/ports/esp8266/posix_helpers.c
similarity index 81%
rename from esp8266/axtls_helpers.c
rename to ports/esp8266/posix_helpers.c
index 6d508fdeb..1fc677c5c 100644
--- a/esp8266/axtls_helpers.c
+++ b/ports/esp8266/posix_helpers.c
@@ -26,22 +26,33 @@
#include
#include
+#include
#include "py/mphal.h"
#include "py/gc.h"
-// Functions for axTLS
+// Functions for external libs like axTLS, BerkeleyDB, etc.
void *malloc(size_t size) {
- return gc_alloc(size, false);
+ void *p = gc_alloc(size, false);
+ if (p == NULL) {
+ // POSIX requires ENOMEM to be set in case of error
+ errno = ENOMEM;
+ }
+ return p;
}
void free(void *ptr) {
gc_free(ptr);
}
void *calloc(size_t nmemb, size_t size) {
- return m_malloc0(nmemb * size);
+ return malloc(nmemb * size);
}
void *realloc(void *ptr, size_t size) {
- return gc_realloc(ptr, size, true);
+ void *p = gc_realloc(ptr, size, true);
+ if (p == NULL) {
+ // POSIX requires ENOMEM to be set in case of error
+ errno = ENOMEM;
+ }
+ return p;
}
#define PLATFORM_HTONL(_n) ((uint32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) ))
diff --git a/esp8266/qstrdefsport.h b/ports/esp8266/qstrdefsport.h
similarity index 94%
rename from esp8266/qstrdefsport.h
rename to ports/esp8266/qstrdefsport.h
index 7610eb33d..8f301a69c 100644
--- a/esp8266/qstrdefsport.h
+++ b/ports/esp8266/qstrdefsport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/esp8266/strtoll.c b/ports/esp8266/strtoll.c
similarity index 100%
rename from esp8266/strtoll.c
rename to ports/esp8266/strtoll.c
diff --git a/esp8266/uart.c b/ports/esp8266/uart.c
similarity index 100%
rename from esp8266/uart.c
rename to ports/esp8266/uart.c
diff --git a/esp8266/uart.h b/ports/esp8266/uart.h
similarity index 95%
rename from esp8266/uart.h
rename to ports/esp8266/uart.h
index ebcd8b051..684689a0e 100644
--- a/esp8266/uart.h
+++ b/ports/esp8266/uart.h
@@ -14,9 +14,9 @@ typedef enum {
} UartBitsNum4Char;
typedef enum {
- UART_ONE_STOP_BIT = 0,
- UART_ONE_HALF_STOP_BIT = BIT2,
- UART_TWO_STOP_BIT = BIT2
+ UART_ONE_STOP_BIT = 0x1,
+ UART_ONE_HALF_STOP_BIT = 0x2,
+ UART_TWO_STOP_BIT = 0x3
} UartStopBitsNum;
typedef enum {
diff --git a/esp8266/uart_register.h b/ports/esp8266/uart_register.h
similarity index 100%
rename from esp8266/uart_register.h
rename to ports/esp8266/uart_register.h
diff --git a/esp8266/user_config.h b/ports/esp8266/user_config.h
similarity index 100%
rename from esp8266/user_config.h
rename to ports/esp8266/user_config.h
diff --git a/esp8266/xtirq.h b/ports/esp8266/xtirq.h
similarity index 100%
rename from esp8266/xtirq.h
rename to ports/esp8266/xtirq.h
diff --git a/minimal/Makefile b/ports/minimal/Makefile
similarity index 89%
rename from minimal/Makefile
rename to ports/minimal/Makefile
index 994d26880..ae295d655 100644
--- a/minimal/Makefile
+++ b/ports/minimal/Makefile
@@ -1,4 +1,4 @@
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
CROSS = 0
@@ -6,20 +6,19 @@ CROSS = 0
QSTR_DEFS = qstrdefsport.h
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
ifeq ($(CROSS), 1)
CROSS_COMPILE = arm-none-eabi-
endif
INC += -I.
-INC += -I..
-INC += -I../stmhal
+INC += -I$(TOP)
INC += -I$(BUILD)
ifeq ($(CROSS), 1)
-DFU = ../tools/dfu.py
-PYDFU = ../tools/pydfu.py
+DFU = $(TOP)/tools/dfu.py
+PYDFU = $(TOP)/tools/pydfu.py
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
CFLAGS = $(INC) -Wall -Werror -std=c99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT)
LDFLAGS = -nostdlib -T stm32f405.ld -Map=$@.map --cref --gc-sections
@@ -58,7 +57,7 @@ endif
$(BUILD)/_frozen_mpy.c: frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h
$(ECHO) "MISC freezing bytecode"
- $(Q)../tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@
+ $(Q)$(TOP)/tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@
$(BUILD)/firmware.elf: $(OBJ)
$(ECHO) "LINK $@"
@@ -88,4 +87,4 @@ run:
test: $(BUILD)/firmware.elf
$(Q)/bin/echo -e "print('hello world!', list(x+1 for x in range(10)), end='eol\\\\n')\\r\\n\\x04" | $(BUILD)/firmware.elf | tail -n2 | grep "^hello world! \\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\]eol"
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/minimal/README.md b/ports/minimal/README.md
similarity index 100%
rename from minimal/README.md
rename to ports/minimal/README.md
diff --git a/ports/minimal/frozentest.mpy b/ports/minimal/frozentest.mpy
new file mode 100644
index 000000000..7c6809bf6
Binary files /dev/null and b/ports/minimal/frozentest.mpy differ
diff --git a/minimal/frozentest.py b/ports/minimal/frozentest.py
similarity index 100%
rename from minimal/frozentest.py
rename to ports/minimal/frozentest.py
diff --git a/minimal/main.c b/ports/minimal/main.c
similarity index 99%
rename from minimal/main.c
rename to ports/minimal/main.c
index e28cfe45e..9d43a9cf9 100644
--- a/minimal/main.c
+++ b/ports/minimal/main.c
@@ -2,7 +2,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
diff --git a/minimal/mpconfigport.h b/ports/minimal/mpconfigport.h
similarity index 96%
rename from minimal/mpconfigport.h
rename to ports/minimal/mpconfigport.h
index 47fc98429..8744ca950 100644
--- a/minimal/mpconfigport.h
+++ b/ports/minimal/mpconfigport.h
@@ -1,6 +1,6 @@
#include
-// options to control how Micro Python is built
+// options to control how MicroPython is built
// You can disable the built-in MicroPython compiler by setting the following
// config option to 0. If you do this then you won't get a REPL prompt, but you
@@ -74,7 +74,7 @@ typedef long mp_off_t;
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
// We need to provide a declaration/definition of alloca()
#include
diff --git a/minimal/mphalport.h b/ports/minimal/mphalport.h
similarity index 100%
rename from minimal/mphalport.h
rename to ports/minimal/mphalport.h
diff --git a/minimal/qstrdefsport.h b/ports/minimal/qstrdefsport.h
similarity index 100%
rename from minimal/qstrdefsport.h
rename to ports/minimal/qstrdefsport.h
diff --git a/minimal/stm32f405.ld b/ports/minimal/stm32f405.ld
similarity index 100%
rename from minimal/stm32f405.ld
rename to ports/minimal/stm32f405.ld
diff --git a/minimal/uart_core.c b/ports/minimal/uart_core.c
similarity index 100%
rename from minimal/uart_core.c
rename to ports/minimal/uart_core.c
diff --git a/pic16bit/Makefile b/ports/pic16bit/Makefile
similarity index 93%
rename from pic16bit/Makefile
rename to ports/pic16bit/Makefile
index 1da444952..970e75d1f 100644
--- a/pic16bit/Makefile
+++ b/ports/pic16bit/Makefile
@@ -1,10 +1,10 @@
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
XC16 = /opt/microchip/xc16/v1.24
CROSS_COMPILE = $(XC16)/bin/xc16-
@@ -13,8 +13,7 @@ PARTFAMILY = dsPIC33F
PART = 33FJ256GP506
INC += -I.
-INC += -I..
-INC += -I../stmhal
+INC += -I$(TOP)
INC += -I$(BUILD)
INC += -I$(XC16)/include
INC += -I$(XC16)/support/$(PARTFAMILY)/h
@@ -68,4 +67,4 @@ $(BUILD)/firmware.elf: $(OBJ)
$(PY_BUILD)/gc.o: CFLAGS += -O1
$(PY_BUILD)/vm.o: CFLAGS += -O1
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/pic16bit/board.c b/ports/pic16bit/board.c
similarity index 98%
rename from pic16bit/board.c
rename to ports/pic16bit/board.c
index 77f059fc7..0321b0ee2 100644
--- a/pic16bit/board.c
+++ b/ports/pic16bit/board.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/pic16bit/board.h b/ports/pic16bit/board.h
similarity index 95%
rename from pic16bit/board.h
rename to ports/pic16bit/board.h
index f79dd3497..f45f87544 100644
--- a/pic16bit/board.h
+++ b/ports/pic16bit/board.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/pic16bit/main.c b/ports/pic16bit/main.c
similarity index 97%
rename from pic16bit/main.c
rename to ports/pic16bit/main.c
index 343fe86d0..4a61c5ff5 100644
--- a/pic16bit/main.c
+++ b/ports/pic16bit/main.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/pic16bit/modpyb.c b/ports/pic16bit/modpyb.c
similarity index 79%
rename from pic16bit/modpyb.c
rename to ports/pic16bit/modpyb.c
index 326d37f8a..629914633 100644
--- a/pic16bit/modpyb.c
+++ b/ports/pic16bit/modpyb.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -51,15 +51,15 @@ STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay);
-STATIC const mp_map_elem_t pyb_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) },
+STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_millis), (mp_obj_t)&pyb_millis_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_elapsed_millis), (mp_obj_t)&pyb_elapsed_millis_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_delay), (mp_obj_t)&pyb_delay_obj },
+ { MP_ROM_QSTR(MP_QSTR_millis), MP_ROM_PTR(&pyb_millis_obj) },
+ { MP_ROM_QSTR(MP_QSTR_elapsed_millis), MP_ROM_PTR(&pyb_elapsed_millis_obj) },
+ { MP_ROM_QSTR(MP_QSTR_delay), MP_ROM_PTR(&pyb_delay_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_LED), (mp_obj_t)&pyb_led_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Switch), (mp_obj_t)&pyb_switch_type },
+ { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pyb_led_type) },
+ { MP_ROM_QSTR(MP_QSTR_Switch), MP_ROM_PTR(&pyb_switch_type) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
diff --git a/pic16bit/modpyb.h b/ports/pic16bit/modpyb.h
similarity index 95%
rename from pic16bit/modpyb.h
rename to ports/pic16bit/modpyb.h
index 910ec1b6e..ac19fd2f3 100644
--- a/pic16bit/modpyb.h
+++ b/ports/pic16bit/modpyb.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/pic16bit/modpybled.c b/ports/pic16bit/modpybled.c
similarity index 89%
rename from pic16bit/modpybled.c
rename to ports/pic16bit/modpybled.c
index 797246d13..0d200c603 100644
--- a/pic16bit/modpybled.c
+++ b/ports/pic16bit/modpybled.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -76,10 +76,10 @@ mp_obj_t pyb_led_toggle(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_toggle_obj, pyb_led_toggle);
-STATIC const mp_map_elem_t pyb_led_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&pyb_led_on_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&pyb_led_off_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&pyb_led_toggle_obj },
+STATIC const mp_rom_map_elem_t pyb_led_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&pyb_led_on_obj) },
+ { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&pyb_led_off_obj) },
+ { MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&pyb_led_toggle_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_led_locals_dict, pyb_led_locals_dict_table);
diff --git a/pic16bit/modpybswitch.c b/ports/pic16bit/modpybswitch.c
similarity index 93%
rename from pic16bit/modpybswitch.c
rename to ports/pic16bit/modpybswitch.c
index aa102e821..0799ad9e8 100644
--- a/pic16bit/modpybswitch.c
+++ b/ports/pic16bit/modpybswitch.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -65,8 +65,8 @@ mp_obj_t pyb_switch_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_
return pyb_switch_value(self_in);
}
-STATIC const mp_map_elem_t pyb_switch_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pyb_switch_value_obj },
+STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_switch_value_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table);
diff --git a/pic16bit/mpconfigport.h b/ports/pic16bit/mpconfigport.h
similarity index 95%
rename from pic16bit/mpconfigport.h
rename to ports/pic16bit/mpconfigport.h
index e4113956b..59880dc59 100644
--- a/pic16bit/mpconfigport.h
+++ b/ports/pic16bit/mpconfigport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -88,12 +88,12 @@ typedef int mp_off_t;
// extra builtin names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
// extra builtin modules to add to the list of known ones
extern const struct _mp_obj_module_t pyb_module;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
+ { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
#define MP_STATE_PORT MP_STATE_VM
diff --git a/pic16bit/pic16bit_mphal.c b/ports/pic16bit/pic16bit_mphal.c
similarity index 96%
rename from pic16bit/pic16bit_mphal.c
rename to ports/pic16bit/pic16bit_mphal.c
index 557b1e0da..35955f2d3 100644
--- a/pic16bit/pic16bit_mphal.c
+++ b/ports/pic16bit/pic16bit_mphal.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/pic16bit/pic16bit_mphal.h b/ports/pic16bit/pic16bit_mphal.h
similarity index 94%
rename from pic16bit/pic16bit_mphal.h
rename to ports/pic16bit/pic16bit_mphal.h
index ffcca41bf..f5da6cdc8 100644
--- a/pic16bit/pic16bit_mphal.h
+++ b/ports/pic16bit/pic16bit_mphal.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/pic16bit/qstrdefsport.h b/ports/pic16bit/qstrdefsport.h
similarity index 100%
rename from pic16bit/qstrdefsport.h
rename to ports/pic16bit/qstrdefsport.h
diff --git a/pic16bit/unistd.h b/ports/pic16bit/unistd.h
similarity index 92%
rename from pic16bit/unistd.h
rename to ports/pic16bit/unistd.h
index 5b60c8a62..23c5e54c7 100644
--- a/pic16bit/unistd.h
+++ b/ports/pic16bit/unistd.h
@@ -3,6 +3,7 @@
// XC16 compiler doesn't seem to have unistd.h file
+#define SEEK_SET 0
#define SEEK_CUR 1
typedef int ssize_t;
diff --git a/qemu-arm/Makefile b/ports/qemu-arm/Makefile
similarity index 91%
rename from qemu-arm/Makefile
rename to ports/qemu-arm/Makefile
index 743b6683a..39e13853f 100644
--- a/qemu-arm/Makefile
+++ b/ports/qemu-arm/Makefile
@@ -1,18 +1,18 @@
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
-include mpconfigport.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
CROSS_COMPILE = arm-none-eabi-
INC += -I.
-INC += -I..
+INC += -I$(TOP)
INC += -I$(BUILD)
-INC += -I../tools/tinytest/
+INC += -I$(TOP)/tools/tinytest/
CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3 -mfloat-abi=soft
CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \
@@ -98,10 +98,10 @@ test: $(BUILD)/firmware-test.elf
$(BUILD)/test_main.o: $(BUILD)/genhdr/tests.h
$(BUILD)/genhdr/tests.h:
- $(Q)echo "Generating $@";(cd ../tests; ../tools/tinytest-codegen.py) > $@
+ $(Q)echo "Generating $@";(cd $(TOP)/tests; ../tools/tinytest-codegen.py) > $@
$(BUILD)/tinytest.o:
- $(Q)$(CC) $(CFLAGS) -DNO_FORKING -o $@ -c ../tools/tinytest/tinytest.c
+ $(Q)$(CC) $(CFLAGS) -DNO_FORKING -o $@ -c $(TOP)/tools/tinytest/tinytest.c
## `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here.
$(BUILD)/firmware.elf: $(OBJ_COMMON) $(OBJ_RUN)
@@ -112,4 +112,4 @@ $(BUILD)/firmware-test.elf: $(OBJ_COMMON) $(OBJ_TEST)
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(Q)$(SIZE) $@
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/qemu-arm/README.md b/ports/qemu-arm/README.md
similarity index 100%
rename from qemu-arm/README.md
rename to ports/qemu-arm/README.md
diff --git a/qemu-arm/main.c b/ports/qemu-arm/main.c
similarity index 97%
rename from qemu-arm/main.c
rename to ports/qemu-arm/main.c
index d5fbcd84b..d23ef576f 100644
--- a/qemu-arm/main.c
+++ b/ports/qemu-arm/main.c
@@ -4,10 +4,8 @@
#include
#include
-#include "py/nlr.h"
#include "py/obj.h"
#include "py/compile.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/gc.h"
diff --git a/qemu-arm/modmachine.c b/ports/qemu-arm/modmachine.c
similarity index 100%
rename from qemu-arm/modmachine.c
rename to ports/qemu-arm/modmachine.c
diff --git a/qemu-arm/moduos.c b/ports/qemu-arm/moduos.c
similarity index 100%
rename from qemu-arm/moduos.c
rename to ports/qemu-arm/moduos.c
diff --git a/qemu-arm/mpconfigport.h b/ports/qemu-arm/mpconfigport.h
similarity index 93%
rename from qemu-arm/mpconfigport.h
rename to ports/qemu-arm/mpconfigport.h
index ebec027e8..51706b927 100644
--- a/qemu-arm/mpconfigport.h
+++ b/ports/qemu-arm/mpconfigport.h
@@ -1,6 +1,6 @@
#include
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_ALLOC_PATH_MAX (512)
#define MICROPY_EMIT_X64 (0)
@@ -18,6 +18,7 @@
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
+#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
#define MICROPY_PY_BUILTINS_FROZENSET (1)
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
@@ -57,7 +58,7 @@ typedef long mp_off_t;
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
// extra built-in modules to add to the list of known ones
extern const struct _mp_obj_module_t mp_module_uos;
diff --git a/qemu-arm/mphalport.h b/ports/qemu-arm/mphalport.h
similarity index 100%
rename from qemu-arm/mphalport.h
rename to ports/qemu-arm/mphalport.h
diff --git a/qemu-arm/qstrdefsport.h b/ports/qemu-arm/qstrdefsport.h
similarity index 100%
rename from qemu-arm/qstrdefsport.h
rename to ports/qemu-arm/qstrdefsport.h
diff --git a/qemu-arm/test_main.c b/ports/qemu-arm/test_main.c
similarity index 98%
rename from qemu-arm/test_main.c
rename to ports/qemu-arm/test_main.c
index 5c07d1607..c018ae428 100644
--- a/qemu-arm/test_main.c
+++ b/ports/qemu-arm/test_main.c
@@ -4,10 +4,8 @@
#include
#include
-#include "py/nlr.h"
#include "py/obj.h"
#include "py/compile.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/gc.h"
diff --git a/stmhal/.gitignore b/ports/stm32/.gitignore
similarity index 100%
rename from stmhal/.gitignore
rename to ports/stm32/.gitignore
diff --git a/stmhal/Makefile b/ports/stm32/Makefile
similarity index 88%
rename from stmhal/Makefile
rename to ports/stm32/Makefile
index ae1db2ae9..68b007471 100644
--- a/stmhal/Makefile
+++ b/ports/stm32/Makefile
@@ -8,7 +8,7 @@ endif
# If the build directory is not given, make it reflect the board name.
BUILD ?= build-$(BOARD)
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
-include mpconfigport.mk
include boards/$(BOARD)/mpconfigboard.mk
@@ -19,18 +19,19 @@ QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h $(BUILD)/modstm_qstr.h
FROZEN_MPY_DIR ?= modules
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
LD_DIR=boards
-CMSIS_DIR=cmsis
-HAL_DIR=hal/$(MCU_SERIES)
+CMSIS_DIR=$(TOP)/lib/stm32lib/CMSIS/STM32$(MCU_SERIES_UPPER)xx/Include
+MCU_SERIES_UPPER = $(shell echo $(MCU_SERIES) | tr '[:lower:]' '[:upper:]')
+HAL_DIR=lib/stm32lib/STM32$(MCU_SERIES_UPPER)xx_HAL_Driver
USBDEV_DIR=usbdev
#USBHOST_DIR=usbhost
FATFS_DIR=lib/oofatfs
-DFU=../tools/dfu.py
+DFU=$(TOP)/tools/dfu.py
# may need to prefix dfu-util with sudo
USE_PYDFU ?= 1
-PYDFU ?= ../tools/pydfu.py
+PYDFU ?= $(TOP)/tools/pydfu.py
DFU_UTIL ?= dfu-util
DEVICE=0483:df11
STFLASH ?= st-flash
@@ -40,11 +41,11 @@ OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg
CROSS_COMPILE = arm-none-eabi-
INC += -I.
-INC += -I..
+INC += -I$(TOP)
INC += -I$(BUILD)
-INC += -I../lib/cmsis/inc
+INC += -I$(TOP)/lib/cmsis/inc
INC += -I$(CMSIS_DIR)/
-INC += -I$(HAL_DIR)/inc
+INC += -I$(TOP)/$(HAL_DIR)/Inc
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/inc
#INC += -I$(USBHOST_DIR)
@@ -205,7 +206,7 @@ SRC_C = \
timer.c \
led.c \
pin.c \
- pin_defs_stmhal.c \
+ pin_defs_stm32.c \
pin_named_pins.c \
bufhelper.c \
dma.c \
@@ -244,7 +245,7 @@ SRC_O = \
startup_stm32.o \
gchelper.o \
-SRC_HAL = $(addprefix $(HAL_DIR)/src/stm32$(MCU_SERIES)xx_,\
+SRC_HAL = $(addprefix $(HAL_DIR)/Src/stm32$(MCU_SERIES)xx_,\
hal.c \
hal_adc.c \
hal_adc_ex.c \
@@ -285,13 +286,13 @@ SRC_USBDEV = $(addprefix $(USBDEV_DIR)/,\
class/src/usbd_msc_data.c \
)
-ifeq ($(MICROPY_PY_WIZNET5K),1)
+ifneq ($(MICROPY_PY_WIZNET5K),0)
WIZNET5K_DIR=drivers/wiznet5k
INC += -I$(TOP)/$(WIZNET5K_DIR)
-CFLAGS_MOD += -DMICROPY_PY_WIZNET5K=1
+CFLAGS_MOD += -DMICROPY_PY_WIZNET5K=$(MICROPY_PY_WIZNET5K) -D_WIZCHIP_=$(MICROPY_PY_WIZNET5K)
SRC_MOD += modnwwiznet5k.c
SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\
- ethernet/w5200/w5200.c \
+ ethernet/w$(MICROPY_PY_WIZNET5K)/w$(MICROPY_PY_WIZNET5K).c \
ethernet/wizchip_conf.c \
ethernet/socket.c \
internet/dns/dns.c \
@@ -344,7 +345,12 @@ $(PY_BUILD)/formatfloat.o: COPT += -Os
$(PY_BUILD)/parsenum.o: COPT += -Os
$(PY_BUILD)/mpprint.o: COPT += -Os
-all: $(BUILD)/firmware.dfu $(BUILD)/firmware.hex
+all: $(TOP)/lib/stm32lib/README.md $(BUILD)/firmware.dfu $(BUILD)/firmware.hex
+
+# For convenience, automatically fetch required submodules if they don't exist
+$(TOP)/lib/stm32lib/README.md:
+ $(ECHO) "stm32lib submodule not found, fetching it now..."
+ (cd $(TOP) && git submodule update --init lib/stm32lib)
ifneq ($(FROZEN_DIR),)
# To use frozen source modules, put your .py files in a subdirectory (eg scripts/)
@@ -397,6 +403,7 @@ $(BUILD)/firmware.elf: $(OBJ)
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
$(Q)$(SIZE) $@
+PLLVALUES = boards/pllvalues.py
MAKE_PINS = boards/make-pins.py
BOARD_PINS = boards/$(BOARD)/pins.csv
PREFIX_FILE = boards/stm32f4xx_prefix.c
@@ -406,8 +413,8 @@ GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
-INSERT_USB_IDS = ../tools/insert-usb-ids.py
-FILE2H = ../tools/file2h.py
+INSERT_USB_IDS = $(TOP)/tools/insert-usb-ids.py
+FILE2H = $(TOP)/tools/file2h.py
USB_IDS_FILE = usb.h
CDCINF_TEMPLATE = pybcdc.inf_template
@@ -425,7 +432,7 @@ SRC_QSTR_AUTO_DEPS += $(GEN_CDCINF_HEADER)
# any of the objects. The normal dependency generation will deal with the
# case when pins.h is modified. But when it doesn't exist, we don't know
# which source files might need it.
-$(OBJ): | $(HEADER_BUILD)/pins.h
+$(OBJ): | $(GEN_PINS_HDR)
# With conditional pins, we may need to regenerate qstrdefs.h when config
# options change.
@@ -443,11 +450,17 @@ $(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/
$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c
$(call compile_c)
+GEN_PLLFREQTABLE_HDR = $(HEADER_BUILD)/pllfreqtable.h
GEN_STMCONST_HDR = $(HEADER_BUILD)/modstm_const.h
GEN_STMCONST_QSTR = $(BUILD)/modstm_qstr.h
GEN_STMCONST_MPZ = $(HEADER_BUILD)/modstm_mpz.h
CMSIS_MCU_LOWER = $(shell echo $(CMSIS_MCU) | tr '[:upper:]' '[:lower:]')
-CMSIS_MCU_HDR = cmsis/$(CMSIS_MCU_LOWER).h
+CMSIS_MCU_HDR = $(CMSIS_DIR)/$(CMSIS_MCU_LOWER).h
+
+modmachine.c: $(GEN_PLLFREQTABLE_HDR)
+$(GEN_PLLFREQTABLE_HDR): $(PLLVALUES) | $(HEADER_BUILD)
+ $(ECHO) "Create $@"
+ $(Q)$(PYTHON) $(PLLVALUES) -c file:boards/$(BOARD)/stm32$(MCU_SERIES)xx_hal_conf.h > $@
$(BUILD)/modstm.o: $(GEN_STMCONST_HDR)
# Use a pattern rule here so that make will only call make-stmconst.py once to
@@ -464,4 +477,4 @@ $(GEN_CDCINF_FILE): $(CDCINF_TEMPLATE) $(INSERT_USB_IDS) $(USB_IDS_FILE) | $(HEA
$(ECHO) "Create $@"
$(Q)$(PYTHON) $(INSERT_USB_IDS) $(USB_IDS_FILE) $< > $@
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/stmhal/README.md b/ports/stm32/README.md
similarity index 95%
rename from stmhal/README.md
rename to ports/stm32/README.md
index 32b6d4176..bb184e8db 100644
--- a/stmhal/README.md
+++ b/ports/stm32/README.md
@@ -24,7 +24,7 @@ bytecode. The cross-compiler is built and run on the host machine, using:
$ make -C mpy-cross
```
This command should be executed from the root directory of this repository.
-All other commands below should be executed from the stmhal/ directory.
+All other commands below should be executed from the ports/stm32/ directory.
An ARM compiler is required for the build, along with the associated binary
utilities. The default compiler is `arm-none-eabi-gcc`, which is available for
@@ -71,7 +71,7 @@ Or using `dfu-util` directly:
ST Discovery or Nucleo boards have a builtin programmer called ST-LINK. With
these boards and using Linux or OS X, you have the option to upload the
-`stmhal` firmware using the `st-flash` utility from the
+`stm32` firmware using the `st-flash` utility from the
[stlink](https://github.com/texane/stlink) project. To do so, connect the board
with a mini USB cable to its ST-LINK USB port and then use the make target
`deploy-stlink`. For example, if you have the STM32F4DISCOVERY board, you can
@@ -101,7 +101,7 @@ a mini USB cable to its ST-LINK USB port and then use the make target
$ make BOARD=STM32F4DISC deploy-openocd
The `openocd` program, which writes the firmware to the target board's flash,
-is configured via the file `stmhal/boards/openocd_stm32f4.cfg`. This
+is configured via the file `ports/stm32/boards/openocd_stm32f4.cfg`. This
configuration should work for all boards based on a STM32F4xx MCU with a
ST-LINKv2 interface. You can override the path to this configuration by setting
`OPENOCD_CONFIG` in your Makefile or on the command line.
diff --git a/stmhal/accel.c b/ports/stm32/accel.c
similarity index 97%
rename from stmhal/accel.c
rename to ports/stm32/accel.c
index 0e6eaf03d..7b36e2082 100644
--- a/stmhal/accel.c
+++ b/ports/stm32/accel.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include "py/mphal.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "pin.h"
#include "genhdr/pins.h"
@@ -102,7 +101,7 @@ STATIC void accel_start(void) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
#define NUM_AXIS (3)
#define FILT_DEPTH (4)
diff --git a/stmhal/accel.h b/ports/stm32/accel.h
similarity index 94%
rename from stmhal/accel.h
rename to ports/stm32/accel.h
index 42b156329..fc35f7775 100644
--- a/stmhal/accel.h
+++ b/ports/stm32/accel.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/adc.c b/ports/stm32/adc.c
similarity index 98%
rename from stmhal/adc.c
rename to ports/stm32/adc.c
index 6485e2ab7..9a0dc56a3 100644
--- a/stmhal/adc.c
+++ b/ports/stm32/adc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mphal.h"
@@ -95,7 +94,7 @@
defined(STM32F746xx) || defined(STM32F767xx) || \
defined(STM32F769xx) || defined(STM32F446xx)
#define VBAT_DIV (4)
-#elif defined(STM32L476xx)
+#elif defined(STM32L475xx) || defined(STM32L476xx)
#define VBAT_DIV (3)
#else
#error Unsupported processor
@@ -263,7 +262,7 @@ STATIC uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) {
}
/******************************************************************************/
-/* Micro Python bindings : adc object (single channel) */
+/* MicroPython bindings : adc object (single channel) */
STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_obj_adc_t *self = self_in;
@@ -596,7 +595,7 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) {
#endif
/******************************************************************************/
-/* Micro Python bindings : adc_all object */
+/* MicroPython bindings : adc_all object */
STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
// check number of arguments
diff --git a/stmhal/adc.h b/ports/stm32/adc.h
similarity index 94%
rename from stmhal/adc.h
rename to ports/stm32/adc.h
index 6ec558464..c90e6b343 100644
--- a/stmhal/adc.h
+++ b/ports/stm32/adc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/autoflash b/ports/stm32/autoflash
similarity index 100%
rename from stmhal/autoflash
rename to ports/stm32/autoflash
diff --git a/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.h b/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.h
new file mode 100644
index 000000000..77f029c00
--- /dev/null
+++ b/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.h
@@ -0,0 +1,76 @@
+#define MICROPY_HW_BOARD_NAME "B-L475E-IOT01A"
+#define MICROPY_HW_MCU_NAME "STM32L475"
+
+#define MICROPY_HW_HAS_SWITCH (1)
+#define MICROPY_HW_HAS_FLASH (0)
+#define MICROPY_HW_HAS_SDCARD (0)
+#define MICROPY_HW_HAS_MMA7660 (0)
+#define MICROPY_HW_HAS_LIS3DSH (0)
+#define MICROPY_HW_HAS_LCD (0)
+#define MICROPY_HW_ENABLE_RNG (1)
+#define MICROPY_HW_ENABLE_RTC (1)
+#define MICROPY_HW_ENABLE_TIMER (1)
+#define MICROPY_HW_ENABLE_SERVO (0)
+#define MICROPY_HW_ENABLE_DAC (0)
+#define MICROPY_HW_ENABLE_CAN (0)
+
+// MSI is used and is 4MHz
+#define MICROPY_HW_CLK_PLLM (1)
+#define MICROPY_HW_CLK_PLLN (40)
+#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV7)
+#define MICROPY_HW_CLK_PLLR (RCC_PLLR_DIV2)
+#define MICROPY_HW_CLK_PLLQ (RCC_PLLQ_DIV4)
+
+#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_4
+
+// USART1 config connected to ST-Link
+#define MICROPY_HW_UART1_TX (pin_B6)
+#define MICROPY_HW_UART1_RX (pin_B7)
+// USART2 config connected to PMOD: Flow control is defined and therfore used
+#define MICROPY_HW_UART2_CTS (pin_D3)
+#define MICROPY_HW_UART2_RTS (pin_D4)
+#define MICROPY_HW_UART2_TX (pin_D5)
+#define MICROPY_HW_UART2_RX (pin_D6)
+// USART3 config for internal use
+#define MICROPY_HW_UART3_TX (pin_D8)
+#define MICROPY_HW_UART3_RX (pin_D9)
+// USART4 config
+#define MICROPY_HW_UART4_TX (pin_A0)
+#define MICROPY_HW_UART4_RX (pin_A1)
+// USART 1 is connected to the virtual com port on the ST-LINK
+#define MICROPY_HW_UART_REPL PYB_UART_1
+#define MICROPY_HW_UART_REPL_BAUD 115200
+
+// I2C busses
+#define MICROPY_HW_I2C1_SCL (pin_B8)
+#define MICROPY_HW_I2C1_SDA (pin_B9)
+#define MICROPY_HW_I2C2_SCL (pin_B10)
+#define MICROPY_HW_I2C2_SDA (pin_B11)
+
+// SPI busses
+#define MICROPY_HW_SPI1_NSS (pin_A4)
+#define MICROPY_HW_SPI1_SCK (pin_A5)
+#define MICROPY_HW_SPI1_MISO (pin_A6)
+#define MICROPY_HW_SPI1_MOSI (pin_A7)
+
+#define MICROPY_HW_SPI2_NSS (pin_D0)
+#define MICROPY_HW_SPI2_SCK (pin_D1)
+#define MICROPY_HW_SPI2_MISO (pin_D3)
+#define MICROPY_HW_SPI2_MOSI (pin_D4)
+
+#define MICROPY_HW_SPI3_NSS (pin_A15)
+#define MICROPY_HW_SPI3_SCK (pin_C10)
+#define MICROPY_HW_SPI3_MISO (pin_C11)
+#define MICROPY_HW_SPI3_MOSI (pin_C12)
+
+// User and wake-up switch. Pressing the button makes the input go low.
+#define MICROPY_HW_USRSW_PIN (pin_C13)
+#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
+#define MICROPY_HW_USRSW_EXTI_MODE (GPIO_MODE_IT_FALLING)
+#define MICROPY_HW_USRSW_PRESSED (0)
+
+// LEDs
+#define MICROPY_HW_LED1 (pin_A5) // green
+#define MICROPY_HW_LED2 (pin_B14) // green
+#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
+#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
diff --git a/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.mk b/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.mk
new file mode 100644
index 000000000..1ba61a327
--- /dev/null
+++ b/ports/stm32/boards/B_L475E_IOT01A/mpconfigboard.mk
@@ -0,0 +1,8 @@
+MCU_SERIES = l4
+CMSIS_MCU = STM32L475xx
+# The stm32l475 does not have a LDC controller which is
+# the only diffrence to the stm32l476 - so reuse some files.
+AF_FILE = boards/stm32l476_af.csv
+LD_FILE = boards/stm32l476xg.ld
+TEXT_ADDR = 0x08004000
+OPENOCD_CONFIG = boards/openocd_stm32l4.cfg
diff --git a/ports/stm32/boards/B_L475E_IOT01A/pins.csv b/ports/stm32/boards/B_L475E_IOT01A/pins.csv
new file mode 100644
index 000000000..afe87b71c
--- /dev/null
+++ b/ports/stm32/boards/B_L475E_IOT01A/pins.csv
@@ -0,0 +1,82 @@
+PA0,PA0
+PA1,PA1
+PA2,PA2
+PA3,PA3
+PA4,PA4
+PA5,PA5
+PA6,PA6
+PA7,PA7
+PA8,PA8
+PA9,PA9
+PA10,PA10
+PA11,PA11
+PA12,PA12
+PA13,PA13
+PA14,PA14
+PA15,PA15
+PB0,PB0
+PB1,PB1
+PB2,PB2
+PB3,PB3
+PB4,PB4
+PB5,PB5
+PB6,PB6
+PB7,PB7
+PB8,PB8
+PB9,PB9
+PB10,PB10
+PB11,PB11
+PB12,PB12
+PB13,PB13
+PB14,PB14
+PB15,PB15
+PC0,PC0
+PC1,PC1
+PC2,PC2
+PC3,PC3
+PC4,PC4
+PC5,PC5
+PC6,PC6
+PC7,PC7
+PC8,PC8
+PC9,PC9
+PC10,PC10
+PC11,PC11
+PC12,PC12
+PC13,PC13
+PC14,PC14
+PC15,PC15
+PD0,PD0
+PD1,PD1
+PD2,PD2
+PD3,PD3
+PD4,PD4
+PD5,PD5
+PD6,PD6
+PD7,PD7
+PD8,PD8
+PD9,PD9
+PD10,PD10
+PD11,PD11
+PD12,PD12
+PD13,PD13
+PD14,PD14
+PD15,PD15
+PE0,PE0
+PE1,PE1
+PE2,PE2
+PE3,PE3
+PE4,PE4
+PE5,PE5
+PE6,PE6
+PE7,PE7
+PE8,PE8
+PE9,PE9
+PE10,PE10
+PE11,PE11
+PE12,PE12
+PE13,PE13
+PE14,PE14
+PE15,PE15
+PH0,PH0
+PH1,PH1
diff --git a/stmhal/boards/LIMIFROG/stm32l4xx_hal_conf.h b/ports/stm32/boards/B_L475E_IOT01A/stm32l4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/LIMIFROG/stm32l4xx_hal_conf.h
rename to ports/stm32/boards/B_L475E_IOT01A/stm32l4xx_hal_conf.h
diff --git a/stmhal/boards/CERB40/mpconfigboard.h b/ports/stm32/boards/CERB40/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/CERB40/mpconfigboard.h
rename to ports/stm32/boards/CERB40/mpconfigboard.h
diff --git a/stmhal/boards/CERB40/mpconfigboard.mk b/ports/stm32/boards/CERB40/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/CERB40/mpconfigboard.mk
rename to ports/stm32/boards/CERB40/mpconfigboard.mk
diff --git a/stmhal/boards/CERB40/pins.csv b/ports/stm32/boards/CERB40/pins.csv
similarity index 100%
rename from stmhal/boards/CERB40/pins.csv
rename to ports/stm32/boards/CERB40/pins.csv
diff --git a/stmhal/boards/CERB40/stm32f4xx_hal_conf.h b/ports/stm32/boards/CERB40/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/CERB40/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/CERB40/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h b/ports/stm32/boards/ESPRUINO_PICO/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/ESPRUINO_PICO/mpconfigboard.h
rename to ports/stm32/boards/ESPRUINO_PICO/mpconfigboard.h
diff --git a/stmhal/boards/ESPRUINO_PICO/mpconfigboard.mk b/ports/stm32/boards/ESPRUINO_PICO/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/ESPRUINO_PICO/mpconfigboard.mk
rename to ports/stm32/boards/ESPRUINO_PICO/mpconfigboard.mk
diff --git a/stmhal/boards/ESPRUINO_PICO/pins.csv b/ports/stm32/boards/ESPRUINO_PICO/pins.csv
similarity index 100%
rename from stmhal/boards/ESPRUINO_PICO/pins.csv
rename to ports/stm32/boards/ESPRUINO_PICO/pins.csv
diff --git a/stmhal/boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h b/ports/stm32/boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/HYDRABUS/mpconfigboard.h b/ports/stm32/boards/HYDRABUS/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/HYDRABUS/mpconfigboard.h
rename to ports/stm32/boards/HYDRABUS/mpconfigboard.h
diff --git a/stmhal/boards/HYDRABUS/mpconfigboard.mk b/ports/stm32/boards/HYDRABUS/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/HYDRABUS/mpconfigboard.mk
rename to ports/stm32/boards/HYDRABUS/mpconfigboard.mk
diff --git a/stmhal/boards/HYDRABUS/pins.csv b/ports/stm32/boards/HYDRABUS/pins.csv
similarity index 100%
rename from stmhal/boards/HYDRABUS/pins.csv
rename to ports/stm32/boards/HYDRABUS/pins.csv
diff --git a/stmhal/boards/HYDRABUS/stm32f4xx_hal_conf.h b/ports/stm32/boards/HYDRABUS/stm32f4xx_hal_conf.h
similarity index 94%
rename from stmhal/boards/HYDRABUS/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/HYDRABUS/stm32f4xx_hal_conf.h
index 8941e8290..d3df51c10 100644
--- a/stmhal/boards/HYDRABUS/stm32f4xx_hal_conf.h
+++ b/ports/stm32/boards/HYDRABUS/stm32f4xx_hal_conf.h
@@ -1,411 +1,411 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_hal_conf.h
- * @author MCD Application Team
- * @version V1.1.0
- * @date 19-June-2014
- * @brief HAL configuration file.
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2014 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __STM32F4xx_HAL_CONF_H
-#define __STM32F4xx_HAL_CONF_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-
-#define USE_USB_FS
-
-/* ########################## Module Selection ############################## */
-/**
- * @brief This is the list of modules to be used in the HAL driver
- */
-#define HAL_MODULE_ENABLED
-#define HAL_ADC_MODULE_ENABLED
-#define HAL_CAN_MODULE_ENABLED
-/* #define HAL_CRC_MODULE_ENABLED */
-/* #define HAL_CRYP_MODULE_ENABLED */
-#define HAL_DAC_MODULE_ENABLED
-/* #define HAL_DCMI_MODULE_ENABLED */
-#define HAL_DMA_MODULE_ENABLED
-/* #define HAL_DMA2D_MODULE_ENABLED */
-/* #define HAL_ETH_MODULE_ENABLED */
-#define HAL_FLASH_MODULE_ENABLED
-/* #define HAL_NAND_MODULE_ENABLED */
-/* #define HAL_NOR_MODULE_ENABLED */
-/* #define HAL_PCCARD_MODULE_ENABLED */
-/* #define HAL_SRAM_MODULE_ENABLED */
-/* #define HAL_SDRAM_MODULE_ENABLED */
-/* #define HAL_HASH_MODULE_ENABLED */
-#define HAL_GPIO_MODULE_ENABLED
-#define HAL_I2C_MODULE_ENABLED
-/* #define HAL_I2S_MODULE_ENABLED */
-/* #define HAL_IWDG_MODULE_ENABLED */
-/* #define HAL_LTDC_MODULE_ENABLED */
-#define HAL_PWR_MODULE_ENABLED
-#define HAL_RCC_MODULE_ENABLED
-#define HAL_RNG_MODULE_ENABLED
-#define HAL_RTC_MODULE_ENABLED
-/* #define HAL_SAI_MODULE_ENABLED */
-#define HAL_SD_MODULE_ENABLED
-#define HAL_SPI_MODULE_ENABLED
-#define HAL_TIM_MODULE_ENABLED
-#define HAL_UART_MODULE_ENABLED
-/* #define HAL_USART_MODULE_ENABLED */
-/* #define HAL_IRDA_MODULE_ENABLED */
-/* #define HAL_SMARTCARD_MODULE_ENABLED */
-/* #define HAL_WWDG_MODULE_ENABLED */
-#define HAL_CORTEX_MODULE_ENABLED
-#define HAL_PCD_MODULE_ENABLED
-/* #define HAL_HCD_MODULE_ENABLED */
-
-
-/* ########################## HSE/HSI Values adaptation ##################### */
-/**
- * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
- * This value is used by the RCC HAL module to compute the system frequency
- * (when HSE is used as system clock source, directly or through the PLL).
- */
-#if !defined (HSE_VALUE)
- #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
-#endif /* HSE_VALUE */
-
-#if !defined (HSE_STARTUP_TIMEOUT)
- #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
-#endif /* HSE_STARTUP_TIMEOUT */
-
-/**
- * @brief Internal High Speed oscillator (HSI) value.
- * This value is used by the RCC HAL module to compute the system frequency
- * (when HSI is used as system clock source, directly or through the PLL).
- */
-#if !defined (HSI_VALUE)
- #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
-#endif /* HSI_VALUE */
-
-/**
- * @brief Internal Low Speed oscillator (LSI) value.
- */
-#if !defined (LSI_VALUE)
- #define LSI_VALUE ((uint32_t)40000)
-#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
- The real value may vary depending on the variations
- in voltage and temperature. */
-/**
- * @brief External Low Speed oscillator (LSE) value.
- */
-#if !defined (LSE_VALUE)
- #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
-#endif /* LSE_VALUE */
-
-#if !defined (LSE_STARTUP_TIMEOUT)
- #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
-#endif /* LSE_STARTUP_TIMEOUT */
-
-/**
- * @brief External clock source for I2S peripheral
- * This value is used by the I2S HAL module to compute the I2S clock source
- * frequency, this source is inserted directly through I2S_CKIN pad.
- */
-#if !defined (EXTERNAL_CLOCK_VALUE)
- #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
-#endif /* EXTERNAL_CLOCK_VALUE */
-
-/* Tip: To avoid modifying this file each time you need to use different HSE,
- === you can define the HSE value in your toolchain compiler preprocessor. */
-
-/* ########################### System Configuration ######################### */
-/**
- * @brief This is the HAL system configuration section
- */
-#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
-#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
-#define USE_RTOS 0
-#define PREFETCH_ENABLE 1
-#define INSTRUCTION_CACHE_ENABLE 1
-#define DATA_CACHE_ENABLE 1
-
-/* ########################## Assert Selection ############################## */
-/**
- * @brief Uncomment the line below to expanse the "assert_param" macro in the
- * HAL drivers code
- */
-/* #define USE_FULL_ASSERT 1 */
-
-/* ################## Ethernet peripheral configuration ##################### */
-
-/* Section 1 : Ethernet peripheral configuration */
-
-/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
-#define MAC_ADDR0 2
-#define MAC_ADDR1 0
-#define MAC_ADDR2 0
-#define MAC_ADDR3 0
-#define MAC_ADDR4 0
-#define MAC_ADDR5 0
-
-/* Definition of the Ethernet driver buffers size and count */
-#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
-#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
-#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
-#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
-
-/* Section 2: PHY configuration section */
-
-/* DP83848 PHY Address*/
-#define DP83848_PHY_ADDRESS 0x01
-/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
-#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
-/* PHY Configuration delay */
-#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
-
-#define PHY_READ_TO ((uint32_t)0x0000FFFF)
-#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
-
-/* Section 3: Common PHY Registers */
-
-#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
-#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
-
-#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
-#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
-#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
-#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
-#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
-#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
-#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
-#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
-#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
-#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
-
-#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
-#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
-#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
-
-/* Section 4: Extended PHY Registers */
-
-#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
-#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
-#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
-
-#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
-#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
-#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
-
-#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
-#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
-
-#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
-#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
-
-/* Includes ------------------------------------------------------------------*/
-/**
- * @brief Include module's header file
- */
-
-#ifdef HAL_RCC_MODULE_ENABLED
- #include "stm32f4xx_hal_rcc.h"
-#endif /* HAL_RCC_MODULE_ENABLED */
-
-#ifdef HAL_GPIO_MODULE_ENABLED
- #include "stm32f4xx_hal_gpio.h"
-#endif /* HAL_GPIO_MODULE_ENABLED */
-
-#ifdef HAL_DMA_MODULE_ENABLED
- #include "stm32f4xx_hal_dma.h"
-#endif /* HAL_DMA_MODULE_ENABLED */
-
-#ifdef HAL_CORTEX_MODULE_ENABLED
- #include "stm32f4xx_hal_cortex.h"
-#endif /* HAL_CORTEX_MODULE_ENABLED */
-
-#ifdef HAL_ADC_MODULE_ENABLED
- #include "stm32f4xx_hal_adc.h"
-#endif /* HAL_ADC_MODULE_ENABLED */
-
-#ifdef HAL_CAN_MODULE_ENABLED
- #include "stm32f4xx_hal_can.h"
-#endif /* HAL_CAN_MODULE_ENABLED */
-
-#ifdef HAL_CRC_MODULE_ENABLED
- #include "stm32f4xx_hal_crc.h"
-#endif /* HAL_CRC_MODULE_ENABLED */
-
-#ifdef HAL_CRYP_MODULE_ENABLED
- #include "stm32f4xx_hal_cryp.h"
-#endif /* HAL_CRYP_MODULE_ENABLED */
-
-#ifdef HAL_DMA2D_MODULE_ENABLED
- #include "stm32f4xx_hal_dma2d.h"
-#endif /* HAL_DMA2D_MODULE_ENABLED */
-
-#ifdef HAL_DAC_MODULE_ENABLED
- #include "stm32f4xx_hal_dac.h"
-#endif /* HAL_DAC_MODULE_ENABLED */
-
-#ifdef HAL_DCMI_MODULE_ENABLED
- #include "stm32f4xx_hal_dcmi.h"
-#endif /* HAL_DCMI_MODULE_ENABLED */
-
-#ifdef HAL_ETH_MODULE_ENABLED
- #include "stm32f4xx_hal_eth.h"
-#endif /* HAL_ETH_MODULE_ENABLED */
-
-#ifdef HAL_FLASH_MODULE_ENABLED
- #include "stm32f4xx_hal_flash.h"
-#endif /* HAL_FLASH_MODULE_ENABLED */
-
-#ifdef HAL_SRAM_MODULE_ENABLED
- #include "stm32f4xx_hal_sram.h"
-#endif /* HAL_SRAM_MODULE_ENABLED */
-
-#ifdef HAL_NOR_MODULE_ENABLED
- #include "stm32f4xx_hal_nor.h"
-#endif /* HAL_NOR_MODULE_ENABLED */
-
-#ifdef HAL_NAND_MODULE_ENABLED
- #include "stm32f4xx_hal_nand.h"
-#endif /* HAL_NAND_MODULE_ENABLED */
-
-#ifdef HAL_PCCARD_MODULE_ENABLED
- #include "stm32f4xx_hal_pccard.h"
-#endif /* HAL_PCCARD_MODULE_ENABLED */
-
-#ifdef HAL_SDRAM_MODULE_ENABLED
- #include "stm32f4xx_hal_sdram.h"
-#endif /* HAL_SDRAM_MODULE_ENABLED */
-
-#ifdef HAL_HASH_MODULE_ENABLED
- #include "stm32f4xx_hal_hash.h"
-#endif /* HAL_HASH_MODULE_ENABLED */
-
-#ifdef HAL_I2C_MODULE_ENABLED
- #include "stm32f4xx_hal_i2c.h"
-#endif /* HAL_I2C_MODULE_ENABLED */
-
-#ifdef HAL_I2S_MODULE_ENABLED
- #include "stm32f4xx_hal_i2s.h"
-#endif /* HAL_I2S_MODULE_ENABLED */
-
-#ifdef HAL_IWDG_MODULE_ENABLED
- #include "stm32f4xx_hal_iwdg.h"
-#endif /* HAL_IWDG_MODULE_ENABLED */
-
-#ifdef HAL_LTDC_MODULE_ENABLED
- #include "stm32f4xx_hal_ltdc.h"
-#endif /* HAL_LTDC_MODULE_ENABLED */
-
-#ifdef HAL_PWR_MODULE_ENABLED
- #include "stm32f4xx_hal_pwr.h"
-#endif /* HAL_PWR_MODULE_ENABLED */
-
-#ifdef HAL_RNG_MODULE_ENABLED
- #include "stm32f4xx_hal_rng.h"
-#endif /* HAL_RNG_MODULE_ENABLED */
-
-#ifdef HAL_RTC_MODULE_ENABLED
- #include "stm32f4xx_hal_rtc.h"
-#endif /* HAL_RTC_MODULE_ENABLED */
-
-#ifdef HAL_SAI_MODULE_ENABLED
- #include "stm32f4xx_hal_sai.h"
-#endif /* HAL_SAI_MODULE_ENABLED */
-
-#ifdef HAL_SD_MODULE_ENABLED
- #include "stm32f4xx_hal_sd.h"
-#endif /* HAL_SD_MODULE_ENABLED */
-
-#ifdef HAL_SPI_MODULE_ENABLED
- #include "stm32f4xx_hal_spi.h"
-#endif /* HAL_SPI_MODULE_ENABLED */
-
-#ifdef HAL_TIM_MODULE_ENABLED
- #include "stm32f4xx_hal_tim.h"
-#endif /* HAL_TIM_MODULE_ENABLED */
-
-#ifdef HAL_UART_MODULE_ENABLED
- #include "stm32f4xx_hal_uart.h"
-#endif /* HAL_UART_MODULE_ENABLED */
-
-#ifdef HAL_USART_MODULE_ENABLED
- #include "stm32f4xx_hal_usart.h"
-#endif /* HAL_USART_MODULE_ENABLED */
-
-#ifdef HAL_IRDA_MODULE_ENABLED
- #include "stm32f4xx_hal_irda.h"
-#endif /* HAL_IRDA_MODULE_ENABLED */
-
-#ifdef HAL_SMARTCARD_MODULE_ENABLED
- #include "stm32f4xx_hal_smartcard.h"
-#endif /* HAL_SMARTCARD_MODULE_ENABLED */
-
-#ifdef HAL_WWDG_MODULE_ENABLED
- #include "stm32f4xx_hal_wwdg.h"
-#endif /* HAL_WWDG_MODULE_ENABLED */
-
-#ifdef HAL_PCD_MODULE_ENABLED
- #include "stm32f4xx_hal_pcd.h"
-#endif /* HAL_PCD_MODULE_ENABLED */
-
-#ifdef HAL_HCD_MODULE_ENABLED
- #include "stm32f4xx_hal_hcd.h"
-#endif /* HAL_HCD_MODULE_ENABLED */
-
-/* Exported macro ------------------------------------------------------------*/
-#ifdef USE_FULL_ASSERT
-/**
- * @brief The assert_param macro is used for function's parameters check.
- * @param expr: If expr is false, it calls assert_failed function
- * which reports the name of the source file and the source
- * line number of the call that failed.
- * If expr is true, it returns no value.
- * @retval None
- */
- #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
-/* Exported functions ------------------------------------------------------- */
- void assert_failed(uint8_t* file, uint32_t line);
-#else
- #define assert_param(expr) ((void)0)
-#endif /* USE_FULL_ASSERT */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __STM32F4xx_HAL_CONF_H */
-
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+ ******************************************************************************
+ * @file stm32f4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 19-June-2014
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+#define USE_USB_FS
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+/* #define HAL_CRC_MODULE_ENABLED */
+/* #define HAL_CRYP_MODULE_ENABLED */
+#define HAL_DAC_MODULE_ENABLED
+/* #define HAL_DCMI_MODULE_ENABLED */
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_DMA2D_MODULE_ENABLED */
+/* #define HAL_ETH_MODULE_ENABLED */
+#define HAL_FLASH_MODULE_ENABLED
+/* #define HAL_NAND_MODULE_ENABLED */
+/* #define HAL_NOR_MODULE_ENABLED */
+/* #define HAL_PCCARD_MODULE_ENABLED */
+/* #define HAL_SRAM_MODULE_ENABLED */
+/* #define HAL_SDRAM_MODULE_ENABLED */
+/* #define HAL_HASH_MODULE_ENABLED */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+/* #define HAL_I2S_MODULE_ENABLED */
+/* #define HAL_IWDG_MODULE_ENABLED */
+/* #define HAL_LTDC_MODULE_ENABLED */
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+#define HAL_SPI_MODULE_ENABLED
+#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED */
+/* #define HAL_IRDA_MODULE_ENABLED */
+/* #define HAL_SMARTCARD_MODULE_ENABLED */
+/* #define HAL_WWDG_MODULE_ENABLED */
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_PCD_MODULE_ENABLED
+/* #define HAL_HCD_MODULE_ENABLED */
+
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief Internal Low Speed oscillator (LSI) value.
+ */
+#if !defined (LSI_VALUE)
+ #define LSI_VALUE ((uint32_t)40000)
+#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
+ The real value may vary depending on the variations
+ in voltage and temperature. */
+/**
+ * @brief External Low Speed oscillator (LSE) value.
+ */
+#if !defined (LSE_VALUE)
+ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+#if !defined (LSE_STARTUP_TIMEOUT)
+ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
+#endif /* LSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief External clock source for I2S peripheral
+ * This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad.
+ */
+#if !defined (EXTERNAL_CLOCK_VALUE)
+ #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0 2
+#define MAC_ADDR1 0
+#define MAC_ADDR2 0
+#define MAC_ADDR3 0
+#define MAC_ADDR4 0
+#define MAC_ADDR5 0
+
+/* Definition of the Ethernet driver buffers size and count */
+#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
+#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
+#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
+#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/
+#define DP83848_PHY_ADDRESS 0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
+#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
+#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
+
+#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
+
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
+#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
+#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
+
+#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
+
+#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
+#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
+
+#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
+#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32f4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+ #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+ #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/boards/LIMIFROG/board_init.c b/ports/stm32/boards/LIMIFROG/board_init.c
similarity index 100%
rename from stmhal/boards/LIMIFROG/board_init.c
rename to ports/stm32/boards/LIMIFROG/board_init.c
diff --git a/stmhal/boards/LIMIFROG/mpconfigboard.h b/ports/stm32/boards/LIMIFROG/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/LIMIFROG/mpconfigboard.h
rename to ports/stm32/boards/LIMIFROG/mpconfigboard.h
diff --git a/stmhal/boards/LIMIFROG/mpconfigboard.mk b/ports/stm32/boards/LIMIFROG/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/LIMIFROG/mpconfigboard.mk
rename to ports/stm32/boards/LIMIFROG/mpconfigboard.mk
diff --git a/stmhal/boards/LIMIFROG/pins.csv b/ports/stm32/boards/LIMIFROG/pins.csv
similarity index 100%
rename from stmhal/boards/LIMIFROG/pins.csv
rename to ports/stm32/boards/LIMIFROG/pins.csv
diff --git a/stmhal/boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h b/ports/stm32/boards/LIMIFROG/stm32l4xx_hal_conf.h
old mode 100755
new mode 100644
similarity index 100%
rename from stmhal/boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h
rename to ports/stm32/boards/LIMIFROG/stm32l4xx_hal_conf.h
diff --git a/stmhal/boards/NETDUINO_PLUS_2/board_init.c b/ports/stm32/boards/NETDUINO_PLUS_2/board_init.c
similarity index 100%
rename from stmhal/boards/NETDUINO_PLUS_2/board_init.c
rename to ports/stm32/boards/NETDUINO_PLUS_2/board_init.c
diff --git a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h b/ports/stm32/boards/NETDUINO_PLUS_2/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h
rename to ports/stm32/boards/NETDUINO_PLUS_2/mpconfigboard.h
diff --git a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.mk b/ports/stm32/boards/NETDUINO_PLUS_2/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.mk
rename to ports/stm32/boards/NETDUINO_PLUS_2/mpconfigboard.mk
diff --git a/stmhal/boards/NETDUINO_PLUS_2/pins.csv b/ports/stm32/boards/NETDUINO_PLUS_2/pins.csv
similarity index 100%
rename from stmhal/boards/NETDUINO_PLUS_2/pins.csv
rename to ports/stm32/boards/NETDUINO_PLUS_2/pins.csv
diff --git a/stmhal/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h b/ports/stm32/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h
similarity index 94%
rename from stmhal/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h
index 8b04c2845..42c2c4e9b 100644
--- a/stmhal/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h
+++ b/ports/stm32/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h
@@ -1,411 +1,411 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_hal_conf.h
- * @author MCD Application Team
- * @version V1.1.0
- * @date 19-June-2014
- * @brief HAL configuration file.
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2014 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __STM32F4xx_HAL_CONF_H
-#define __STM32F4xx_HAL_CONF_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-
-#define USE_USB_FS
-
-/* ########################## Module Selection ############################## */
-/**
- * @brief This is the list of modules to be used in the HAL driver
- */
-#define HAL_MODULE_ENABLED
-#define HAL_ADC_MODULE_ENABLED
-#define HAL_CAN_MODULE_ENABLED
-/* #define HAL_CRC_MODULE_ENABLED */
-/* #define HAL_CRYP_MODULE_ENABLED */
-#define HAL_DAC_MODULE_ENABLED
-/* #define HAL_DCMI_MODULE_ENABLED */
-#define HAL_DMA_MODULE_ENABLED
-/* #define HAL_DMA2D_MODULE_ENABLED */
-/* #define HAL_ETH_MODULE_ENABLED */
-#define HAL_FLASH_MODULE_ENABLED
-/* #define HAL_NAND_MODULE_ENABLED */
-/* #define HAL_NOR_MODULE_ENABLED */
-/* #define HAL_PCCARD_MODULE_ENABLED */
-/* #define HAL_SRAM_MODULE_ENABLED */
-/* #define HAL_SDRAM_MODULE_ENABLED */
-/* #define HAL_HASH_MODULE_ENABLED */
-#define HAL_GPIO_MODULE_ENABLED
-#define HAL_I2C_MODULE_ENABLED
-/* #define HAL_I2S_MODULE_ENABLED */
-/* #define HAL_IWDG_MODULE_ENABLED */
-/* #define HAL_LTDC_MODULE_ENABLED */
-#define HAL_PWR_MODULE_ENABLED
-#define HAL_RCC_MODULE_ENABLED
-#define HAL_RNG_MODULE_ENABLED
-#define HAL_RTC_MODULE_ENABLED
-/* #define HAL_SAI_MODULE_ENABLED */
-#define HAL_SD_MODULE_ENABLED
-#define HAL_SPI_MODULE_ENABLED
-#define HAL_TIM_MODULE_ENABLED
-#define HAL_UART_MODULE_ENABLED
-/* #define HAL_USART_MODULE_ENABLED */
-/* #define HAL_IRDA_MODULE_ENABLED */
-/* #define HAL_SMARTCARD_MODULE_ENABLED */
-/* #define HAL_WWDG_MODULE_ENABLED */
-#define HAL_CORTEX_MODULE_ENABLED
-#define HAL_PCD_MODULE_ENABLED
-/* #define HAL_HCD_MODULE_ENABLED */
-
-
-/* ########################## HSE/HSI Values adaptation ##################### */
-/**
- * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
- * This value is used by the RCC HAL module to compute the system frequency
- * (when HSE is used as system clock source, directly or through the PLL).
- */
-#if !defined (HSE_VALUE)
- #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
-#endif /* HSE_VALUE */
-
-#if !defined (HSE_STARTUP_TIMEOUT)
- #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
-#endif /* HSE_STARTUP_TIMEOUT */
-
-/**
- * @brief Internal High Speed oscillator (HSI) value.
- * This value is used by the RCC HAL module to compute the system frequency
- * (when HSI is used as system clock source, directly or through the PLL).
- */
-#if !defined (HSI_VALUE)
- #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
-#endif /* HSI_VALUE */
-
-/**
- * @brief Internal Low Speed oscillator (LSI) value.
- */
-#if !defined (LSI_VALUE)
- #define LSI_VALUE ((uint32_t)40000)
-#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
- The real value may vary depending on the variations
- in voltage and temperature. */
-/**
- * @brief External Low Speed oscillator (LSE) value.
- */
-#if !defined (LSE_VALUE)
- #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
-#endif /* LSE_VALUE */
-
-#if !defined (LSE_STARTUP_TIMEOUT)
- #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
-#endif /* LSE_STARTUP_TIMEOUT */
-
-/**
- * @brief External clock source for I2S peripheral
- * This value is used by the I2S HAL module to compute the I2S clock source
- * frequency, this source is inserted directly through I2S_CKIN pad.
- */
-#if !defined (EXTERNAL_CLOCK_VALUE)
- #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
-#endif /* EXTERNAL_CLOCK_VALUE */
-
-/* Tip: To avoid modifying this file each time you need to use different HSE,
- === you can define the HSE value in your toolchain compiler preprocessor. */
-
-/* ########################### System Configuration ######################### */
-/**
- * @brief This is the HAL system configuration section
- */
-#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
-#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
-#define USE_RTOS 0
-#define PREFETCH_ENABLE 1
-#define INSTRUCTION_CACHE_ENABLE 1
-#define DATA_CACHE_ENABLE 1
-
-/* ########################## Assert Selection ############################## */
-/**
- * @brief Uncomment the line below to expanse the "assert_param" macro in the
- * HAL drivers code
- */
-/* #define USE_FULL_ASSERT 1 */
-
-/* ################## Ethernet peripheral configuration ##################### */
-
-/* Section 1 : Ethernet peripheral configuration */
-
-/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
-#define MAC_ADDR0 2
-#define MAC_ADDR1 0
-#define MAC_ADDR2 0
-#define MAC_ADDR3 0
-#define MAC_ADDR4 0
-#define MAC_ADDR5 0
-
-/* Definition of the Ethernet driver buffers size and count */
-#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
-#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
-#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
-#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
-
-/* Section 2: PHY configuration section */
-
-/* DP83848 PHY Address*/
-#define DP83848_PHY_ADDRESS 0x01
-/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
-#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
-/* PHY Configuration delay */
-#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
-
-#define PHY_READ_TO ((uint32_t)0x0000FFFF)
-#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
-
-/* Section 3: Common PHY Registers */
-
-#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
-#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
-
-#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
-#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
-#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
-#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
-#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
-#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
-#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
-#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
-#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
-#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
-
-#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
-#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
-#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
-
-/* Section 4: Extended PHY Registers */
-
-#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
-#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
-#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
-
-#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
-#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
-#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
-
-#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
-#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
-
-#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
-#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
-
-/* Includes ------------------------------------------------------------------*/
-/**
- * @brief Include module's header file
- */
-
-#ifdef HAL_RCC_MODULE_ENABLED
- #include "stm32f4xx_hal_rcc.h"
-#endif /* HAL_RCC_MODULE_ENABLED */
-
-#ifdef HAL_GPIO_MODULE_ENABLED
- #include "stm32f4xx_hal_gpio.h"
-#endif /* HAL_GPIO_MODULE_ENABLED */
-
-#ifdef HAL_DMA_MODULE_ENABLED
- #include "stm32f4xx_hal_dma.h"
-#endif /* HAL_DMA_MODULE_ENABLED */
-
-#ifdef HAL_CORTEX_MODULE_ENABLED
- #include "stm32f4xx_hal_cortex.h"
-#endif /* HAL_CORTEX_MODULE_ENABLED */
-
-#ifdef HAL_ADC_MODULE_ENABLED
- #include "stm32f4xx_hal_adc.h"
-#endif /* HAL_ADC_MODULE_ENABLED */
-
-#ifdef HAL_CAN_MODULE_ENABLED
- #include "stm32f4xx_hal_can.h"
-#endif /* HAL_CAN_MODULE_ENABLED */
-
-#ifdef HAL_CRC_MODULE_ENABLED
- #include "stm32f4xx_hal_crc.h"
-#endif /* HAL_CRC_MODULE_ENABLED */
-
-#ifdef HAL_CRYP_MODULE_ENABLED
- #include "stm32f4xx_hal_cryp.h"
-#endif /* HAL_CRYP_MODULE_ENABLED */
-
-#ifdef HAL_DMA2D_MODULE_ENABLED
- #include "stm32f4xx_hal_dma2d.h"
-#endif /* HAL_DMA2D_MODULE_ENABLED */
-
-#ifdef HAL_DAC_MODULE_ENABLED
- #include "stm32f4xx_hal_dac.h"
-#endif /* HAL_DAC_MODULE_ENABLED */
-
-#ifdef HAL_DCMI_MODULE_ENABLED
- #include "stm32f4xx_hal_dcmi.h"
-#endif /* HAL_DCMI_MODULE_ENABLED */
-
-#ifdef HAL_ETH_MODULE_ENABLED
- #include "stm32f4xx_hal_eth.h"
-#endif /* HAL_ETH_MODULE_ENABLED */
-
-#ifdef HAL_FLASH_MODULE_ENABLED
- #include "stm32f4xx_hal_flash.h"
-#endif /* HAL_FLASH_MODULE_ENABLED */
-
-#ifdef HAL_SRAM_MODULE_ENABLED
- #include "stm32f4xx_hal_sram.h"
-#endif /* HAL_SRAM_MODULE_ENABLED */
-
-#ifdef HAL_NOR_MODULE_ENABLED
- #include "stm32f4xx_hal_nor.h"
-#endif /* HAL_NOR_MODULE_ENABLED */
-
-#ifdef HAL_NAND_MODULE_ENABLED
- #include "stm32f4xx_hal_nand.h"
-#endif /* HAL_NAND_MODULE_ENABLED */
-
-#ifdef HAL_PCCARD_MODULE_ENABLED
- #include "stm32f4xx_hal_pccard.h"
-#endif /* HAL_PCCARD_MODULE_ENABLED */
-
-#ifdef HAL_SDRAM_MODULE_ENABLED
- #include "stm32f4xx_hal_sdram.h"
-#endif /* HAL_SDRAM_MODULE_ENABLED */
-
-#ifdef HAL_HASH_MODULE_ENABLED
- #include "stm32f4xx_hal_hash.h"
-#endif /* HAL_HASH_MODULE_ENABLED */
-
-#ifdef HAL_I2C_MODULE_ENABLED
- #include "stm32f4xx_hal_i2c.h"
-#endif /* HAL_I2C_MODULE_ENABLED */
-
-#ifdef HAL_I2S_MODULE_ENABLED
- #include "stm32f4xx_hal_i2s.h"
-#endif /* HAL_I2S_MODULE_ENABLED */
-
-#ifdef HAL_IWDG_MODULE_ENABLED
- #include "stm32f4xx_hal_iwdg.h"
-#endif /* HAL_IWDG_MODULE_ENABLED */
-
-#ifdef HAL_LTDC_MODULE_ENABLED
- #include "stm32f4xx_hal_ltdc.h"
-#endif /* HAL_LTDC_MODULE_ENABLED */
-
-#ifdef HAL_PWR_MODULE_ENABLED
- #include "stm32f4xx_hal_pwr.h"
-#endif /* HAL_PWR_MODULE_ENABLED */
-
-#ifdef HAL_RNG_MODULE_ENABLED
- #include "stm32f4xx_hal_rng.h"
-#endif /* HAL_RNG_MODULE_ENABLED */
-
-#ifdef HAL_RTC_MODULE_ENABLED
- #include "stm32f4xx_hal_rtc.h"
-#endif /* HAL_RTC_MODULE_ENABLED */
-
-#ifdef HAL_SAI_MODULE_ENABLED
- #include "stm32f4xx_hal_sai.h"
-#endif /* HAL_SAI_MODULE_ENABLED */
-
-#ifdef HAL_SD_MODULE_ENABLED
- #include "stm32f4xx_hal_sd.h"
-#endif /* HAL_SD_MODULE_ENABLED */
-
-#ifdef HAL_SPI_MODULE_ENABLED
- #include "stm32f4xx_hal_spi.h"
-#endif /* HAL_SPI_MODULE_ENABLED */
-
-#ifdef HAL_TIM_MODULE_ENABLED
- #include "stm32f4xx_hal_tim.h"
-#endif /* HAL_TIM_MODULE_ENABLED */
-
-#ifdef HAL_UART_MODULE_ENABLED
- #include "stm32f4xx_hal_uart.h"
-#endif /* HAL_UART_MODULE_ENABLED */
-
-#ifdef HAL_USART_MODULE_ENABLED
- #include "stm32f4xx_hal_usart.h"
-#endif /* HAL_USART_MODULE_ENABLED */
-
-#ifdef HAL_IRDA_MODULE_ENABLED
- #include "stm32f4xx_hal_irda.h"
-#endif /* HAL_IRDA_MODULE_ENABLED */
-
-#ifdef HAL_SMARTCARD_MODULE_ENABLED
- #include "stm32f4xx_hal_smartcard.h"
-#endif /* HAL_SMARTCARD_MODULE_ENABLED */
-
-#ifdef HAL_WWDG_MODULE_ENABLED
- #include "stm32f4xx_hal_wwdg.h"
-#endif /* HAL_WWDG_MODULE_ENABLED */
-
-#ifdef HAL_PCD_MODULE_ENABLED
- #include "stm32f4xx_hal_pcd.h"
-#endif /* HAL_PCD_MODULE_ENABLED */
-
-#ifdef HAL_HCD_MODULE_ENABLED
- #include "stm32f4xx_hal_hcd.h"
-#endif /* HAL_HCD_MODULE_ENABLED */
-
-/* Exported macro ------------------------------------------------------------*/
-#ifdef USE_FULL_ASSERT
-/**
- * @brief The assert_param macro is used for function's parameters check.
- * @param expr: If expr is false, it calls assert_failed function
- * which reports the name of the source file and the source
- * line number of the call that failed.
- * If expr is true, it returns no value.
- * @retval None
- */
- #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
-/* Exported functions ------------------------------------------------------- */
- void assert_failed(uint8_t* file, uint32_t line);
-#else
- #define assert_param(expr) ((void)0)
-#endif /* USE_FULL_ASSERT */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __STM32F4xx_HAL_CONF_H */
-
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+ ******************************************************************************
+ * @file stm32f4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 19-June-2014
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+#define USE_USB_FS
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+/* #define HAL_CRC_MODULE_ENABLED */
+/* #define HAL_CRYP_MODULE_ENABLED */
+#define HAL_DAC_MODULE_ENABLED
+/* #define HAL_DCMI_MODULE_ENABLED */
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_DMA2D_MODULE_ENABLED */
+/* #define HAL_ETH_MODULE_ENABLED */
+#define HAL_FLASH_MODULE_ENABLED
+/* #define HAL_NAND_MODULE_ENABLED */
+/* #define HAL_NOR_MODULE_ENABLED */
+/* #define HAL_PCCARD_MODULE_ENABLED */
+/* #define HAL_SRAM_MODULE_ENABLED */
+/* #define HAL_SDRAM_MODULE_ENABLED */
+/* #define HAL_HASH_MODULE_ENABLED */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+/* #define HAL_I2S_MODULE_ENABLED */
+/* #define HAL_IWDG_MODULE_ENABLED */
+/* #define HAL_LTDC_MODULE_ENABLED */
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+#define HAL_SPI_MODULE_ENABLED
+#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED */
+/* #define HAL_IRDA_MODULE_ENABLED */
+/* #define HAL_SMARTCARD_MODULE_ENABLED */
+/* #define HAL_WWDG_MODULE_ENABLED */
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_PCD_MODULE_ENABLED
+/* #define HAL_HCD_MODULE_ENABLED */
+
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief Internal Low Speed oscillator (LSI) value.
+ */
+#if !defined (LSI_VALUE)
+ #define LSI_VALUE ((uint32_t)40000)
+#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
+ The real value may vary depending on the variations
+ in voltage and temperature. */
+/**
+ * @brief External Low Speed oscillator (LSE) value.
+ */
+#if !defined (LSE_VALUE)
+ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+#if !defined (LSE_STARTUP_TIMEOUT)
+ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
+#endif /* LSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief External clock source for I2S peripheral
+ * This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad.
+ */
+#if !defined (EXTERNAL_CLOCK_VALUE)
+ #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0 2
+#define MAC_ADDR1 0
+#define MAC_ADDR2 0
+#define MAC_ADDR3 0
+#define MAC_ADDR4 0
+#define MAC_ADDR5 0
+
+/* Definition of the Ethernet driver buffers size and count */
+#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
+#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
+#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
+#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/
+#define DP83848_PHY_ADDRESS 0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
+#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
+#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
+
+#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
+
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
+#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
+#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
+
+#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
+
+#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
+#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
+
+#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
+#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32f4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+ #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+ #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/boards/NUCLEO_F401RE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_F401RE/mpconfigboard.h
similarity index 94%
rename from stmhal/boards/NUCLEO_F401RE/mpconfigboard.h
rename to ports/stm32/boards/NUCLEO_F401RE/mpconfigboard.h
index c12d52756..a843d3c35 100644
--- a/stmhal/boards/NUCLEO_F401RE/mpconfigboard.h
+++ b/ports/stm32/boards/NUCLEO_F401RE/mpconfigboard.h
@@ -22,8 +22,8 @@
#define MICROPY_HW_UART_REPL_BAUD 115200
// I2C busses
-#define MICROPY_HW_I2C1_SCL (pin_B6) // Arduino D10, pin 17 on CN10
-#define MICROPY_HW_I2C1_SDA (pin_B7) // pin 21 on CN7
+#define MICROPY_HW_I2C1_SCL (pin_B8) // Arduino D15, pin 3 on CN10
+#define MICROPY_HW_I2C1_SDA (pin_B9) // D14, pin 5 on CN10
#define MICROPY_HW_I2C2_SCL (pin_B10) // Arduino D6, pin 25 on CN10
#define MICROPY_HW_I2C2_SDA (pin_B3) // Arduino D3, pin 31 on CN10
#define MICROPY_HW_I2C3_SCL (pin_A8) // Arduino D7, pin 23 on CN10
diff --git a/stmhal/boards/NUCLEO_F401RE/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F401RE/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/NUCLEO_F401RE/mpconfigboard.mk
rename to ports/stm32/boards/NUCLEO_F401RE/mpconfigboard.mk
diff --git a/stmhal/boards/NUCLEO_F401RE/pins.csv b/ports/stm32/boards/NUCLEO_F401RE/pins.csv
similarity index 100%
rename from stmhal/boards/NUCLEO_F401RE/pins.csv
rename to ports/stm32/boards/NUCLEO_F401RE/pins.csv
diff --git a/stmhal/boards/PYBV3/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F401RE/stm32f4xx_hal_conf.h
similarity index 94%
rename from stmhal/boards/PYBV3/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/NUCLEO_F401RE/stm32f4xx_hal_conf.h
index 8941e8290..f4db4cb63 100644
--- a/stmhal/boards/PYBV3/stm32f4xx_hal_conf.h
+++ b/ports/stm32/boards/NUCLEO_F401RE/stm32f4xx_hal_conf.h
@@ -1,411 +1,413 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_hal_conf.h
- * @author MCD Application Team
- * @version V1.1.0
- * @date 19-June-2014
- * @brief HAL configuration file.
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2014 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __STM32F4xx_HAL_CONF_H
-#define __STM32F4xx_HAL_CONF_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-
-#define USE_USB_FS
-
-/* ########################## Module Selection ############################## */
-/**
- * @brief This is the list of modules to be used in the HAL driver
- */
-#define HAL_MODULE_ENABLED
-#define HAL_ADC_MODULE_ENABLED
-#define HAL_CAN_MODULE_ENABLED
-/* #define HAL_CRC_MODULE_ENABLED */
-/* #define HAL_CRYP_MODULE_ENABLED */
-#define HAL_DAC_MODULE_ENABLED
-/* #define HAL_DCMI_MODULE_ENABLED */
-#define HAL_DMA_MODULE_ENABLED
-/* #define HAL_DMA2D_MODULE_ENABLED */
-/* #define HAL_ETH_MODULE_ENABLED */
-#define HAL_FLASH_MODULE_ENABLED
-/* #define HAL_NAND_MODULE_ENABLED */
-/* #define HAL_NOR_MODULE_ENABLED */
-/* #define HAL_PCCARD_MODULE_ENABLED */
-/* #define HAL_SRAM_MODULE_ENABLED */
-/* #define HAL_SDRAM_MODULE_ENABLED */
-/* #define HAL_HASH_MODULE_ENABLED */
-#define HAL_GPIO_MODULE_ENABLED
-#define HAL_I2C_MODULE_ENABLED
-/* #define HAL_I2S_MODULE_ENABLED */
-/* #define HAL_IWDG_MODULE_ENABLED */
-/* #define HAL_LTDC_MODULE_ENABLED */
-#define HAL_PWR_MODULE_ENABLED
-#define HAL_RCC_MODULE_ENABLED
-#define HAL_RNG_MODULE_ENABLED
-#define HAL_RTC_MODULE_ENABLED
-/* #define HAL_SAI_MODULE_ENABLED */
-#define HAL_SD_MODULE_ENABLED
-#define HAL_SPI_MODULE_ENABLED
-#define HAL_TIM_MODULE_ENABLED
-#define HAL_UART_MODULE_ENABLED
-/* #define HAL_USART_MODULE_ENABLED */
-/* #define HAL_IRDA_MODULE_ENABLED */
-/* #define HAL_SMARTCARD_MODULE_ENABLED */
-/* #define HAL_WWDG_MODULE_ENABLED */
-#define HAL_CORTEX_MODULE_ENABLED
-#define HAL_PCD_MODULE_ENABLED
-/* #define HAL_HCD_MODULE_ENABLED */
-
-
-/* ########################## HSE/HSI Values adaptation ##################### */
-/**
- * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
- * This value is used by the RCC HAL module to compute the system frequency
- * (when HSE is used as system clock source, directly or through the PLL).
- */
-#if !defined (HSE_VALUE)
- #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
-#endif /* HSE_VALUE */
-
-#if !defined (HSE_STARTUP_TIMEOUT)
- #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
-#endif /* HSE_STARTUP_TIMEOUT */
-
-/**
- * @brief Internal High Speed oscillator (HSI) value.
- * This value is used by the RCC HAL module to compute the system frequency
- * (when HSI is used as system clock source, directly or through the PLL).
- */
-#if !defined (HSI_VALUE)
- #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
-#endif /* HSI_VALUE */
-
-/**
- * @brief Internal Low Speed oscillator (LSI) value.
- */
-#if !defined (LSI_VALUE)
- #define LSI_VALUE ((uint32_t)40000)
-#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
- The real value may vary depending on the variations
- in voltage and temperature. */
-/**
- * @brief External Low Speed oscillator (LSE) value.
- */
-#if !defined (LSE_VALUE)
- #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
-#endif /* LSE_VALUE */
-
-#if !defined (LSE_STARTUP_TIMEOUT)
- #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
-#endif /* LSE_STARTUP_TIMEOUT */
-
-/**
- * @brief External clock source for I2S peripheral
- * This value is used by the I2S HAL module to compute the I2S clock source
- * frequency, this source is inserted directly through I2S_CKIN pad.
- */
-#if !defined (EXTERNAL_CLOCK_VALUE)
- #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
-#endif /* EXTERNAL_CLOCK_VALUE */
-
-/* Tip: To avoid modifying this file each time you need to use different HSE,
- === you can define the HSE value in your toolchain compiler preprocessor. */
-
-/* ########################### System Configuration ######################### */
-/**
- * @brief This is the HAL system configuration section
- */
-#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
-#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
-#define USE_RTOS 0
-#define PREFETCH_ENABLE 1
-#define INSTRUCTION_CACHE_ENABLE 1
-#define DATA_CACHE_ENABLE 1
-
-/* ########################## Assert Selection ############################## */
-/**
- * @brief Uncomment the line below to expanse the "assert_param" macro in the
- * HAL drivers code
- */
-/* #define USE_FULL_ASSERT 1 */
-
-/* ################## Ethernet peripheral configuration ##################### */
-
-/* Section 1 : Ethernet peripheral configuration */
-
-/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
-#define MAC_ADDR0 2
-#define MAC_ADDR1 0
-#define MAC_ADDR2 0
-#define MAC_ADDR3 0
-#define MAC_ADDR4 0
-#define MAC_ADDR5 0
-
-/* Definition of the Ethernet driver buffers size and count */
-#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
-#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
-#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
-#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
-
-/* Section 2: PHY configuration section */
-
-/* DP83848 PHY Address*/
-#define DP83848_PHY_ADDRESS 0x01
-/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
-#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
-/* PHY Configuration delay */
-#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
-
-#define PHY_READ_TO ((uint32_t)0x0000FFFF)
-#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
-
-/* Section 3: Common PHY Registers */
-
-#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
-#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
-
-#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
-#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
-#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
-#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
-#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
-#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
-#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
-#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
-#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
-#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
-
-#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
-#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
-#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
-
-/* Section 4: Extended PHY Registers */
-
-#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
-#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
-#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
-
-#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
-#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
-#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
-
-#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
-#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
-
-#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
-#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
-
-/* Includes ------------------------------------------------------------------*/
-/**
- * @brief Include module's header file
- */
-
-#ifdef HAL_RCC_MODULE_ENABLED
- #include "stm32f4xx_hal_rcc.h"
-#endif /* HAL_RCC_MODULE_ENABLED */
-
-#ifdef HAL_GPIO_MODULE_ENABLED
- #include "stm32f4xx_hal_gpio.h"
-#endif /* HAL_GPIO_MODULE_ENABLED */
-
-#ifdef HAL_DMA_MODULE_ENABLED
- #include "stm32f4xx_hal_dma.h"
-#endif /* HAL_DMA_MODULE_ENABLED */
-
-#ifdef HAL_CORTEX_MODULE_ENABLED
- #include "stm32f4xx_hal_cortex.h"
-#endif /* HAL_CORTEX_MODULE_ENABLED */
-
-#ifdef HAL_ADC_MODULE_ENABLED
- #include "stm32f4xx_hal_adc.h"
-#endif /* HAL_ADC_MODULE_ENABLED */
-
-#ifdef HAL_CAN_MODULE_ENABLED
- #include "stm32f4xx_hal_can.h"
-#endif /* HAL_CAN_MODULE_ENABLED */
-
-#ifdef HAL_CRC_MODULE_ENABLED
- #include "stm32f4xx_hal_crc.h"
-#endif /* HAL_CRC_MODULE_ENABLED */
-
-#ifdef HAL_CRYP_MODULE_ENABLED
- #include "stm32f4xx_hal_cryp.h"
-#endif /* HAL_CRYP_MODULE_ENABLED */
-
-#ifdef HAL_DMA2D_MODULE_ENABLED
- #include "stm32f4xx_hal_dma2d.h"
-#endif /* HAL_DMA2D_MODULE_ENABLED */
-
-#ifdef HAL_DAC_MODULE_ENABLED
- #include "stm32f4xx_hal_dac.h"
-#endif /* HAL_DAC_MODULE_ENABLED */
-
-#ifdef HAL_DCMI_MODULE_ENABLED
- #include "stm32f4xx_hal_dcmi.h"
-#endif /* HAL_DCMI_MODULE_ENABLED */
-
-#ifdef HAL_ETH_MODULE_ENABLED
- #include "stm32f4xx_hal_eth.h"
-#endif /* HAL_ETH_MODULE_ENABLED */
-
-#ifdef HAL_FLASH_MODULE_ENABLED
- #include "stm32f4xx_hal_flash.h"
-#endif /* HAL_FLASH_MODULE_ENABLED */
-
-#ifdef HAL_SRAM_MODULE_ENABLED
- #include "stm32f4xx_hal_sram.h"
-#endif /* HAL_SRAM_MODULE_ENABLED */
-
-#ifdef HAL_NOR_MODULE_ENABLED
- #include "stm32f4xx_hal_nor.h"
-#endif /* HAL_NOR_MODULE_ENABLED */
-
-#ifdef HAL_NAND_MODULE_ENABLED
- #include "stm32f4xx_hal_nand.h"
-#endif /* HAL_NAND_MODULE_ENABLED */
-
-#ifdef HAL_PCCARD_MODULE_ENABLED
- #include "stm32f4xx_hal_pccard.h"
-#endif /* HAL_PCCARD_MODULE_ENABLED */
-
-#ifdef HAL_SDRAM_MODULE_ENABLED
- #include "stm32f4xx_hal_sdram.h"
-#endif /* HAL_SDRAM_MODULE_ENABLED */
-
-#ifdef HAL_HASH_MODULE_ENABLED
- #include "stm32f4xx_hal_hash.h"
-#endif /* HAL_HASH_MODULE_ENABLED */
-
-#ifdef HAL_I2C_MODULE_ENABLED
- #include "stm32f4xx_hal_i2c.h"
-#endif /* HAL_I2C_MODULE_ENABLED */
-
-#ifdef HAL_I2S_MODULE_ENABLED
- #include "stm32f4xx_hal_i2s.h"
-#endif /* HAL_I2S_MODULE_ENABLED */
-
-#ifdef HAL_IWDG_MODULE_ENABLED
- #include "stm32f4xx_hal_iwdg.h"
-#endif /* HAL_IWDG_MODULE_ENABLED */
-
-#ifdef HAL_LTDC_MODULE_ENABLED
- #include "stm32f4xx_hal_ltdc.h"
-#endif /* HAL_LTDC_MODULE_ENABLED */
-
-#ifdef HAL_PWR_MODULE_ENABLED
- #include "stm32f4xx_hal_pwr.h"
-#endif /* HAL_PWR_MODULE_ENABLED */
-
-#ifdef HAL_RNG_MODULE_ENABLED
- #include "stm32f4xx_hal_rng.h"
-#endif /* HAL_RNG_MODULE_ENABLED */
-
-#ifdef HAL_RTC_MODULE_ENABLED
- #include "stm32f4xx_hal_rtc.h"
-#endif /* HAL_RTC_MODULE_ENABLED */
-
-#ifdef HAL_SAI_MODULE_ENABLED
- #include "stm32f4xx_hal_sai.h"
-#endif /* HAL_SAI_MODULE_ENABLED */
-
-#ifdef HAL_SD_MODULE_ENABLED
- #include "stm32f4xx_hal_sd.h"
-#endif /* HAL_SD_MODULE_ENABLED */
-
-#ifdef HAL_SPI_MODULE_ENABLED
- #include "stm32f4xx_hal_spi.h"
-#endif /* HAL_SPI_MODULE_ENABLED */
-
-#ifdef HAL_TIM_MODULE_ENABLED
- #include "stm32f4xx_hal_tim.h"
-#endif /* HAL_TIM_MODULE_ENABLED */
-
-#ifdef HAL_UART_MODULE_ENABLED
- #include "stm32f4xx_hal_uart.h"
-#endif /* HAL_UART_MODULE_ENABLED */
-
-#ifdef HAL_USART_MODULE_ENABLED
- #include "stm32f4xx_hal_usart.h"
-#endif /* HAL_USART_MODULE_ENABLED */
-
-#ifdef HAL_IRDA_MODULE_ENABLED
- #include "stm32f4xx_hal_irda.h"
-#endif /* HAL_IRDA_MODULE_ENABLED */
-
-#ifdef HAL_SMARTCARD_MODULE_ENABLED
- #include "stm32f4xx_hal_smartcard.h"
-#endif /* HAL_SMARTCARD_MODULE_ENABLED */
-
-#ifdef HAL_WWDG_MODULE_ENABLED
- #include "stm32f4xx_hal_wwdg.h"
-#endif /* HAL_WWDG_MODULE_ENABLED */
-
-#ifdef HAL_PCD_MODULE_ENABLED
- #include "stm32f4xx_hal_pcd.h"
-#endif /* HAL_PCD_MODULE_ENABLED */
-
-#ifdef HAL_HCD_MODULE_ENABLED
- #include "stm32f4xx_hal_hcd.h"
-#endif /* HAL_HCD_MODULE_ENABLED */
-
-/* Exported macro ------------------------------------------------------------*/
-#ifdef USE_FULL_ASSERT
-/**
- * @brief The assert_param macro is used for function's parameters check.
- * @param expr: If expr is false, it calls assert_failed function
- * which reports the name of the source file and the source
- * line number of the call that failed.
- * If expr is true, it returns no value.
- * @retval None
- */
- #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
-/* Exported functions ------------------------------------------------------- */
- void assert_failed(uint8_t* file, uint32_t line);
-#else
- #define assert_param(expr) ((void)0)
-#endif /* USE_FULL_ASSERT */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __STM32F4xx_HAL_CONF_H */
-
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+ ******************************************************************************
+ * @file stm32f4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 19-June-2014
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+// This board doesn't really have USB, but the stm32 codebase doesn't build
+// without some USB defined, so we leave this on for now.
+#define USE_USB_FS
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+/* #define HAL_CRC_MODULE_ENABLED */
+/* #define HAL_CRYP_MODULE_ENABLED */
+#define HAL_DAC_MODULE_ENABLED
+/* #define HAL_DCMI_MODULE_ENABLED */
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_DMA2D_MODULE_ENABLED */
+/* #define HAL_ETH_MODULE_ENABLED */
+#define HAL_FLASH_MODULE_ENABLED
+/* #define HAL_NAND_MODULE_ENABLED */
+/* #define HAL_NOR_MODULE_ENABLED */
+/* #define HAL_PCCARD_MODULE_ENABLED */
+/* #define HAL_SRAM_MODULE_ENABLED */
+/* #define HAL_SDRAM_MODULE_ENABLED */
+/* #define HAL_HASH_MODULE_ENABLED */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+/* #define HAL_I2S_MODULE_ENABLED */
+/* #define HAL_IWDG_MODULE_ENABLED */
+/* #define HAL_LTDC_MODULE_ENABLED */
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+#define HAL_SPI_MODULE_ENABLED
+#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED */
+/* #define HAL_IRDA_MODULE_ENABLED */
+/* #define HAL_SMARTCARD_MODULE_ENABLED */
+/* #define HAL_WWDG_MODULE_ENABLED */
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_PCD_MODULE_ENABLED
+/* #define HAL_HCD_MODULE_ENABLED */
+
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief Internal Low Speed oscillator (LSI) value.
+ */
+#if !defined (LSI_VALUE)
+ #define LSI_VALUE ((uint32_t)40000)
+#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
+ The real value may vary depending on the variations
+ in voltage and temperature. */
+/**
+ * @brief External Low Speed oscillator (LSE) value.
+ */
+#if !defined (LSE_VALUE)
+ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+#if !defined (LSE_STARTUP_TIMEOUT)
+ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
+#endif /* LSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief External clock source for I2S peripheral
+ * This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad.
+ */
+#if !defined (EXTERNAL_CLOCK_VALUE)
+ #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0 2
+#define MAC_ADDR1 0
+#define MAC_ADDR2 0
+#define MAC_ADDR3 0
+#define MAC_ADDR4 0
+#define MAC_ADDR5 0
+
+/* Definition of the Ethernet driver buffers size and count */
+#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
+#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
+#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
+#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/
+#define DP83848_PHY_ADDRESS 0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
+#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
+#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
+
+#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
+
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
+#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
+#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
+
+#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
+
+#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
+#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
+
+#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
+#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32f4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+ #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+ #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/boards/NUCLEO_F411RE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_F411RE/mpconfigboard.h
similarity index 95%
rename from stmhal/boards/NUCLEO_F411RE/mpconfigboard.h
rename to ports/stm32/boards/NUCLEO_F411RE/mpconfigboard.h
index 1f7f0a23b..26b1e0b61 100644
--- a/stmhal/boards/NUCLEO_F411RE/mpconfigboard.h
+++ b/ports/stm32/boards/NUCLEO_F411RE/mpconfigboard.h
@@ -22,8 +22,8 @@
#define MICROPY_HW_UART_REPL_BAUD 115200
// I2C busses
-#define MICROPY_HW_I2C1_SCL (pin_B6) // Arduino D10, pin 17 on CN10
-#define MICROPY_HW_I2C1_SDA (pin_B7) // pin 21 on CN7
+#define MICROPY_HW_I2C1_SCL (pin_B8) // Arduino D15, pin 3 on CN10
+#define MICROPY_HW_I2C1_SDA (pin_B9) // D14, pin 5 on CN10
#define MICROPY_HW_I2C2_SCL (pin_B10) // Arduino D6, pin 25 on CN10
#define MICROPY_HW_I2C2_SDA (pin_B3) // Arduino D3, pin 31 on CN10
#define MICROPY_HW_I2C3_SCL (pin_A8) // Arduino D7, pin 23 on CN10
diff --git a/stmhal/boards/NUCLEO_F411RE/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F411RE/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/NUCLEO_F411RE/mpconfigboard.mk
rename to ports/stm32/boards/NUCLEO_F411RE/mpconfigboard.mk
diff --git a/stmhal/boards/NUCLEO_F411RE/pins.csv b/ports/stm32/boards/NUCLEO_F411RE/pins.csv
similarity index 100%
rename from stmhal/boards/NUCLEO_F411RE/pins.csv
rename to ports/stm32/boards/NUCLEO_F411RE/pins.csv
diff --git a/stmhal/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h
similarity index 99%
rename from stmhal/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h
index e16fba155..0c424888f 100644
--- a/stmhal/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h
+++ b/ports/stm32/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h
@@ -46,7 +46,7 @@
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
-// This board doesn't really have USB, but the stmhal codebase doesn't build
+// This board doesn't really have USB, but the stm32 codebase doesn't build
// without some USB defined, so we leave this on for now.
#define USE_USB_FS
diff --git a/stmhal/boards/NUCLEO_F429ZI/mpconfigboard.h b/ports/stm32/boards/NUCLEO_F429ZI/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/NUCLEO_F429ZI/mpconfigboard.h
rename to ports/stm32/boards/NUCLEO_F429ZI/mpconfigboard.h
diff --git a/stmhal/boards/NUCLEO_F429ZI/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F429ZI/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/NUCLEO_F429ZI/mpconfigboard.mk
rename to ports/stm32/boards/NUCLEO_F429ZI/mpconfigboard.mk
diff --git a/stmhal/boards/NUCLEO_F429ZI/pins.csv b/ports/stm32/boards/NUCLEO_F429ZI/pins.csv
similarity index 100%
rename from stmhal/boards/NUCLEO_F429ZI/pins.csv
rename to ports/stm32/boards/NUCLEO_F429ZI/pins.csv
diff --git a/stmhal/boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/NUCLEO_F446RE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_F446RE/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/NUCLEO_F446RE/mpconfigboard.h
rename to ports/stm32/boards/NUCLEO_F446RE/mpconfigboard.h
diff --git a/stmhal/boards/NUCLEO_F446RE/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F446RE/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/NUCLEO_F446RE/mpconfigboard.mk
rename to ports/stm32/boards/NUCLEO_F446RE/mpconfigboard.mk
diff --git a/stmhal/boards/NUCLEO_F446RE/pins.csv b/ports/stm32/boards/NUCLEO_F446RE/pins.csv
similarity index 100%
rename from stmhal/boards/NUCLEO_F446RE/pins.csv
rename to ports/stm32/boards/NUCLEO_F446RE/pins.csv
diff --git a/stmhal/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h
similarity index 99%
rename from stmhal/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h
index 3d0ce926b..487ca009f 100644
--- a/stmhal/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h
+++ b/ports/stm32/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h
@@ -46,7 +46,7 @@
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
-// This board doesn't really have USB, but the stmhal codebase doesn't build
+// This board doesn't really have USB, but the stm32 codebase doesn't build
// without some USB defined, so we leave this on for now.
#define USE_USB_FS
diff --git a/stmhal/boards/NUCLEO_F767ZI/mpconfigboard.h b/ports/stm32/boards/NUCLEO_F767ZI/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/NUCLEO_F767ZI/mpconfigboard.h
rename to ports/stm32/boards/NUCLEO_F767ZI/mpconfigboard.h
diff --git a/stmhal/boards/NUCLEO_F767ZI/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F767ZI/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/NUCLEO_F767ZI/mpconfigboard.mk
rename to ports/stm32/boards/NUCLEO_F767ZI/mpconfigboard.mk
diff --git a/stmhal/boards/NUCLEO_F767ZI/pins.csv b/ports/stm32/boards/NUCLEO_F767ZI/pins.csv
similarity index 100%
rename from stmhal/boards/NUCLEO_F767ZI/pins.csv
rename to ports/stm32/boards/NUCLEO_F767ZI/pins.csv
diff --git a/stmhal/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h
rename to ports/stm32/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h
diff --git a/stmhal/boards/NUCLEO_L476RG/mpconfigboard.h b/ports/stm32/boards/NUCLEO_L476RG/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/NUCLEO_L476RG/mpconfigboard.h
rename to ports/stm32/boards/NUCLEO_L476RG/mpconfigboard.h
diff --git a/stmhal/boards/NUCLEO_L476RG/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_L476RG/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/NUCLEO_L476RG/mpconfigboard.mk
rename to ports/stm32/boards/NUCLEO_L476RG/mpconfigboard.mk
diff --git a/stmhal/boards/NUCLEO_L476RG/pins.csv b/ports/stm32/boards/NUCLEO_L476RG/pins.csv
similarity index 100%
rename from stmhal/boards/NUCLEO_L476RG/pins.csv
rename to ports/stm32/boards/NUCLEO_L476RG/pins.csv
diff --git a/stmhal/boards/STM32L476DISC/stm32l4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h
old mode 100644
new mode 100755
similarity index 100%
rename from stmhal/boards/STM32L476DISC/stm32l4xx_hal_conf.h
rename to ports/stm32/boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h
diff --git a/stmhal/boards/OLIMEX_E407/mpconfigboard.h b/ports/stm32/boards/OLIMEX_E407/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/OLIMEX_E407/mpconfigboard.h
rename to ports/stm32/boards/OLIMEX_E407/mpconfigboard.h
diff --git a/stmhal/boards/OLIMEX_E407/mpconfigboard.mk b/ports/stm32/boards/OLIMEX_E407/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/OLIMEX_E407/mpconfigboard.mk
rename to ports/stm32/boards/OLIMEX_E407/mpconfigboard.mk
diff --git a/stmhal/boards/OLIMEX_E407/pins.csv b/ports/stm32/boards/OLIMEX_E407/pins.csv
similarity index 100%
rename from stmhal/boards/OLIMEX_E407/pins.csv
rename to ports/stm32/boards/OLIMEX_E407/pins.csv
diff --git a/stmhal/boards/OLIMEX_E407/stm32f4xx_hal_conf.h b/ports/stm32/boards/OLIMEX_E407/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/OLIMEX_E407/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/OLIMEX_E407/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/PYBLITEV10/mpconfigboard.h b/ports/stm32/boards/PYBLITEV10/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/PYBLITEV10/mpconfigboard.h
rename to ports/stm32/boards/PYBLITEV10/mpconfigboard.h
diff --git a/stmhal/boards/PYBLITEV10/mpconfigboard.mk b/ports/stm32/boards/PYBLITEV10/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/PYBLITEV10/mpconfigboard.mk
rename to ports/stm32/boards/PYBLITEV10/mpconfigboard.mk
diff --git a/stmhal/boards/PYBLITEV10/pins.csv b/ports/stm32/boards/PYBLITEV10/pins.csv
similarity index 100%
rename from stmhal/boards/PYBLITEV10/pins.csv
rename to ports/stm32/boards/PYBLITEV10/pins.csv
diff --git a/stmhal/boards/PYBLITEV10/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBLITEV10/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/PYBLITEV10/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/PYBLITEV10/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/PYBV10/mpconfigboard.h b/ports/stm32/boards/PYBV10/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/PYBV10/mpconfigboard.h
rename to ports/stm32/boards/PYBV10/mpconfigboard.h
diff --git a/stmhal/boards/PYBV10/mpconfigboard.mk b/ports/stm32/boards/PYBV10/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/PYBV10/mpconfigboard.mk
rename to ports/stm32/boards/PYBV10/mpconfigboard.mk
diff --git a/stmhal/boards/PYBV10/pins.csv b/ports/stm32/boards/PYBV10/pins.csv
similarity index 100%
rename from stmhal/boards/PYBV10/pins.csv
rename to ports/stm32/boards/PYBV10/pins.csv
diff --git a/stmhal/boards/PYBV10/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBV10/stm32f4xx_hal_conf.h
similarity index 94%
rename from stmhal/boards/PYBV10/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/PYBV10/stm32f4xx_hal_conf.h
index 52518e196..3d9252264 100644
--- a/stmhal/boards/PYBV10/stm32f4xx_hal_conf.h
+++ b/ports/stm32/boards/PYBV10/stm32f4xx_hal_conf.h
@@ -1,411 +1,411 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_hal_conf.h
- * @author MCD Application Team
- * @version V1.1.0
- * @date 19-June-2014
- * @brief HAL configuration file.
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2014 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __STM32F4xx_HAL_CONF_H
-#define __STM32F4xx_HAL_CONF_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-
-#define USE_USB_FS
-
-/* ########################## Module Selection ############################## */
-/**
- * @brief This is the list of modules to be used in the HAL driver
- */
-#define HAL_MODULE_ENABLED
-#define HAL_ADC_MODULE_ENABLED
-#define HAL_CAN_MODULE_ENABLED
-/* #define HAL_CRC_MODULE_ENABLED */
-/* #define HAL_CRYP_MODULE_ENABLED */
-#define HAL_DAC_MODULE_ENABLED
-/* #define HAL_DCMI_MODULE_ENABLED */
-#define HAL_DMA_MODULE_ENABLED
-/* #define HAL_DMA2D_MODULE_ENABLED */
-/* #define HAL_ETH_MODULE_ENABLED */
-#define HAL_FLASH_MODULE_ENABLED
-/* #define HAL_NAND_MODULE_ENABLED */
-/* #define HAL_NOR_MODULE_ENABLED */
-/* #define HAL_PCCARD_MODULE_ENABLED */
-/* #define HAL_SRAM_MODULE_ENABLED */
-/* #define HAL_SDRAM_MODULE_ENABLED */
-/* #define HAL_HASH_MODULE_ENABLED */
-#define HAL_GPIO_MODULE_ENABLED
-#define HAL_I2C_MODULE_ENABLED
-#define HAL_I2S_MODULE_ENABLED
-/* #define HAL_IWDG_MODULE_ENABLED */
-/* #define HAL_LTDC_MODULE_ENABLED */
-#define HAL_PWR_MODULE_ENABLED
-#define HAL_RCC_MODULE_ENABLED
-#define HAL_RNG_MODULE_ENABLED
-#define HAL_RTC_MODULE_ENABLED
-/* #define HAL_SAI_MODULE_ENABLED */
-#define HAL_SD_MODULE_ENABLED
-#define HAL_SPI_MODULE_ENABLED
-#define HAL_TIM_MODULE_ENABLED
-#define HAL_UART_MODULE_ENABLED
-/* #define HAL_USART_MODULE_ENABLED */
-/* #define HAL_IRDA_MODULE_ENABLED */
-/* #define HAL_SMARTCARD_MODULE_ENABLED */
-/* #define HAL_WWDG_MODULE_ENABLED */
-#define HAL_CORTEX_MODULE_ENABLED
-#define HAL_PCD_MODULE_ENABLED
-/* #define HAL_HCD_MODULE_ENABLED */
-
-
-/* ########################## HSE/HSI Values adaptation ##################### */
-/**
- * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
- * This value is used by the RCC HAL module to compute the system frequency
- * (when HSE is used as system clock source, directly or through the PLL).
- */
-#if !defined (HSE_VALUE)
- #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
-#endif /* HSE_VALUE */
-
-#if !defined (HSE_STARTUP_TIMEOUT)
- #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
-#endif /* HSE_STARTUP_TIMEOUT */
-
-/**
- * @brief Internal High Speed oscillator (HSI) value.
- * This value is used by the RCC HAL module to compute the system frequency
- * (when HSI is used as system clock source, directly or through the PLL).
- */
-#if !defined (HSI_VALUE)
- #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
-#endif /* HSI_VALUE */
-
-/**
- * @brief Internal Low Speed oscillator (LSI) value.
- */
-#if !defined (LSI_VALUE)
- #define LSI_VALUE ((uint32_t)40000)
-#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
- The real value may vary depending on the variations
- in voltage and temperature. */
-/**
- * @brief External Low Speed oscillator (LSE) value.
- */
-#if !defined (LSE_VALUE)
- #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
-#endif /* LSE_VALUE */
-
-#if !defined (LSE_STARTUP_TIMEOUT)
- #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
-#endif /* LSE_STARTUP_TIMEOUT */
-
-/**
- * @brief External clock source for I2S peripheral
- * This value is used by the I2S HAL module to compute the I2S clock source
- * frequency, this source is inserted directly through I2S_CKIN pad.
- */
-#if !defined (EXTERNAL_CLOCK_VALUE)
- #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
-#endif /* EXTERNAL_CLOCK_VALUE */
-
-/* Tip: To avoid modifying this file each time you need to use different HSE,
- === you can define the HSE value in your toolchain compiler preprocessor. */
-
-/* ########################### System Configuration ######################### */
-/**
- * @brief This is the HAL system configuration section
- */
-#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
-#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
-#define USE_RTOS 0
-#define PREFETCH_ENABLE 1
-#define INSTRUCTION_CACHE_ENABLE 1
-#define DATA_CACHE_ENABLE 1
-
-/* ########################## Assert Selection ############################## */
-/**
- * @brief Uncomment the line below to expanse the "assert_param" macro in the
- * HAL drivers code
- */
-/* #define USE_FULL_ASSERT 1 */
-
-/* ################## Ethernet peripheral configuration ##################### */
-
-/* Section 1 : Ethernet peripheral configuration */
-
-/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
-#define MAC_ADDR0 2
-#define MAC_ADDR1 0
-#define MAC_ADDR2 0
-#define MAC_ADDR3 0
-#define MAC_ADDR4 0
-#define MAC_ADDR5 0
-
-/* Definition of the Ethernet driver buffers size and count */
-#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
-#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
-#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
-#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
-
-/* Section 2: PHY configuration section */
-
-/* DP83848 PHY Address*/
-#define DP83848_PHY_ADDRESS 0x01
-/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
-#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
-/* PHY Configuration delay */
-#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
-
-#define PHY_READ_TO ((uint32_t)0x0000FFFF)
-#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
-
-/* Section 3: Common PHY Registers */
-
-#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
-#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
-
-#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
-#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
-#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
-#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
-#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
-#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
-#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
-#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
-#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
-#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
-
-#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
-#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
-#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
-
-/* Section 4: Extended PHY Registers */
-
-#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
-#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
-#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
-
-#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
-#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
-#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
-
-#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
-#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
-
-#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
-#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
-
-/* Includes ------------------------------------------------------------------*/
-/**
- * @brief Include module's header file
- */
-
-#ifdef HAL_RCC_MODULE_ENABLED
- #include "stm32f4xx_hal_rcc.h"
-#endif /* HAL_RCC_MODULE_ENABLED */
-
-#ifdef HAL_GPIO_MODULE_ENABLED
- #include "stm32f4xx_hal_gpio.h"
-#endif /* HAL_GPIO_MODULE_ENABLED */
-
-#ifdef HAL_DMA_MODULE_ENABLED
- #include "stm32f4xx_hal_dma.h"
-#endif /* HAL_DMA_MODULE_ENABLED */
-
-#ifdef HAL_CORTEX_MODULE_ENABLED
- #include "stm32f4xx_hal_cortex.h"
-#endif /* HAL_CORTEX_MODULE_ENABLED */
-
-#ifdef HAL_ADC_MODULE_ENABLED
- #include "stm32f4xx_hal_adc.h"
-#endif /* HAL_ADC_MODULE_ENABLED */
-
-#ifdef HAL_CAN_MODULE_ENABLED
- #include "stm32f4xx_hal_can.h"
-#endif /* HAL_CAN_MODULE_ENABLED */
-
-#ifdef HAL_CRC_MODULE_ENABLED
- #include "stm32f4xx_hal_crc.h"
-#endif /* HAL_CRC_MODULE_ENABLED */
-
-#ifdef HAL_CRYP_MODULE_ENABLED
- #include "stm32f4xx_hal_cryp.h"
-#endif /* HAL_CRYP_MODULE_ENABLED */
-
-#ifdef HAL_DMA2D_MODULE_ENABLED
- #include "stm32f4xx_hal_dma2d.h"
-#endif /* HAL_DMA2D_MODULE_ENABLED */
-
-#ifdef HAL_DAC_MODULE_ENABLED
- #include "stm32f4xx_hal_dac.h"
-#endif /* HAL_DAC_MODULE_ENABLED */
-
-#ifdef HAL_DCMI_MODULE_ENABLED
- #include "stm32f4xx_hal_dcmi.h"
-#endif /* HAL_DCMI_MODULE_ENABLED */
-
-#ifdef HAL_ETH_MODULE_ENABLED
- #include "stm32f4xx_hal_eth.h"
-#endif /* HAL_ETH_MODULE_ENABLED */
-
-#ifdef HAL_FLASH_MODULE_ENABLED
- #include "stm32f4xx_hal_flash.h"
-#endif /* HAL_FLASH_MODULE_ENABLED */
-
-#ifdef HAL_SRAM_MODULE_ENABLED
- #include "stm32f4xx_hal_sram.h"
-#endif /* HAL_SRAM_MODULE_ENABLED */
-
-#ifdef HAL_NOR_MODULE_ENABLED
- #include "stm32f4xx_hal_nor.h"
-#endif /* HAL_NOR_MODULE_ENABLED */
-
-#ifdef HAL_NAND_MODULE_ENABLED
- #include "stm32f4xx_hal_nand.h"
-#endif /* HAL_NAND_MODULE_ENABLED */
-
-#ifdef HAL_PCCARD_MODULE_ENABLED
- #include "stm32f4xx_hal_pccard.h"
-#endif /* HAL_PCCARD_MODULE_ENABLED */
-
-#ifdef HAL_SDRAM_MODULE_ENABLED
- #include "stm32f4xx_hal_sdram.h"
-#endif /* HAL_SDRAM_MODULE_ENABLED */
-
-#ifdef HAL_HASH_MODULE_ENABLED
- #include "stm32f4xx_hal_hash.h"
-#endif /* HAL_HASH_MODULE_ENABLED */
-
-#ifdef HAL_I2C_MODULE_ENABLED
- #include "stm32f4xx_hal_i2c.h"
-#endif /* HAL_I2C_MODULE_ENABLED */
-
-#ifdef HAL_I2S_MODULE_ENABLED
- #include "stm32f4xx_hal_i2s.h"
-#endif /* HAL_I2S_MODULE_ENABLED */
-
-#ifdef HAL_IWDG_MODULE_ENABLED
- #include "stm32f4xx_hal_iwdg.h"
-#endif /* HAL_IWDG_MODULE_ENABLED */
-
-#ifdef HAL_LTDC_MODULE_ENABLED
- #include "stm32f4xx_hal_ltdc.h"
-#endif /* HAL_LTDC_MODULE_ENABLED */
-
-#ifdef HAL_PWR_MODULE_ENABLED
- #include "stm32f4xx_hal_pwr.h"
-#endif /* HAL_PWR_MODULE_ENABLED */
-
-#ifdef HAL_RNG_MODULE_ENABLED
- #include "stm32f4xx_hal_rng.h"
-#endif /* HAL_RNG_MODULE_ENABLED */
-
-#ifdef HAL_RTC_MODULE_ENABLED
- #include "stm32f4xx_hal_rtc.h"
-#endif /* HAL_RTC_MODULE_ENABLED */
-
-#ifdef HAL_SAI_MODULE_ENABLED
- #include "stm32f4xx_hal_sai.h"
-#endif /* HAL_SAI_MODULE_ENABLED */
-
-#ifdef HAL_SD_MODULE_ENABLED
- #include "stm32f4xx_hal_sd.h"
-#endif /* HAL_SD_MODULE_ENABLED */
-
-#ifdef HAL_SPI_MODULE_ENABLED
- #include "stm32f4xx_hal_spi.h"
-#endif /* HAL_SPI_MODULE_ENABLED */
-
-#ifdef HAL_TIM_MODULE_ENABLED
- #include "stm32f4xx_hal_tim.h"
-#endif /* HAL_TIM_MODULE_ENABLED */
-
-#ifdef HAL_UART_MODULE_ENABLED
- #include "stm32f4xx_hal_uart.h"
-#endif /* HAL_UART_MODULE_ENABLED */
-
-#ifdef HAL_USART_MODULE_ENABLED
- #include "stm32f4xx_hal_usart.h"
-#endif /* HAL_USART_MODULE_ENABLED */
-
-#ifdef HAL_IRDA_MODULE_ENABLED
- #include "stm32f4xx_hal_irda.h"
-#endif /* HAL_IRDA_MODULE_ENABLED */
-
-#ifdef HAL_SMARTCARD_MODULE_ENABLED
- #include "stm32f4xx_hal_smartcard.h"
-#endif /* HAL_SMARTCARD_MODULE_ENABLED */
-
-#ifdef HAL_WWDG_MODULE_ENABLED
- #include "stm32f4xx_hal_wwdg.h"
-#endif /* HAL_WWDG_MODULE_ENABLED */
-
-#ifdef HAL_PCD_MODULE_ENABLED
- #include "stm32f4xx_hal_pcd.h"
-#endif /* HAL_PCD_MODULE_ENABLED */
-
-#ifdef HAL_HCD_MODULE_ENABLED
- #include "stm32f4xx_hal_hcd.h"
-#endif /* HAL_HCD_MODULE_ENABLED */
-
-/* Exported macro ------------------------------------------------------------*/
-#ifdef USE_FULL_ASSERT
-/**
- * @brief The assert_param macro is used for function's parameters check.
- * @param expr: If expr is false, it calls assert_failed function
- * which reports the name of the source file and the source
- * line number of the call that failed.
- * If expr is true, it returns no value.
- * @retval None
- */
- #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
-/* Exported functions ------------------------------------------------------- */
- void assert_failed(uint8_t* file, uint32_t line);
-#else
- #define assert_param(expr) ((void)0)
-#endif /* USE_FULL_ASSERT */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __STM32F4xx_HAL_CONF_H */
-
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+ ******************************************************************************
+ * @file stm32f4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 19-June-2014
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+#define USE_USB_FS
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+/* #define HAL_CRC_MODULE_ENABLED */
+/* #define HAL_CRYP_MODULE_ENABLED */
+#define HAL_DAC_MODULE_ENABLED
+/* #define HAL_DCMI_MODULE_ENABLED */
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_DMA2D_MODULE_ENABLED */
+/* #define HAL_ETH_MODULE_ENABLED */
+#define HAL_FLASH_MODULE_ENABLED
+/* #define HAL_NAND_MODULE_ENABLED */
+/* #define HAL_NOR_MODULE_ENABLED */
+/* #define HAL_PCCARD_MODULE_ENABLED */
+/* #define HAL_SRAM_MODULE_ENABLED */
+/* #define HAL_SDRAM_MODULE_ENABLED */
+/* #define HAL_HASH_MODULE_ENABLED */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+#define HAL_I2S_MODULE_ENABLED
+/* #define HAL_IWDG_MODULE_ENABLED */
+/* #define HAL_LTDC_MODULE_ENABLED */
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+#define HAL_SPI_MODULE_ENABLED
+#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED */
+/* #define HAL_IRDA_MODULE_ENABLED */
+/* #define HAL_SMARTCARD_MODULE_ENABLED */
+/* #define HAL_WWDG_MODULE_ENABLED */
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_PCD_MODULE_ENABLED
+/* #define HAL_HCD_MODULE_ENABLED */
+
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief Internal Low Speed oscillator (LSI) value.
+ */
+#if !defined (LSI_VALUE)
+ #define LSI_VALUE ((uint32_t)40000)
+#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
+ The real value may vary depending on the variations
+ in voltage and temperature. */
+/**
+ * @brief External Low Speed oscillator (LSE) value.
+ */
+#if !defined (LSE_VALUE)
+ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+#if !defined (LSE_STARTUP_TIMEOUT)
+ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
+#endif /* LSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief External clock source for I2S peripheral
+ * This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad.
+ */
+#if !defined (EXTERNAL_CLOCK_VALUE)
+ #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0 2
+#define MAC_ADDR1 0
+#define MAC_ADDR2 0
+#define MAC_ADDR3 0
+#define MAC_ADDR4 0
+#define MAC_ADDR5 0
+
+/* Definition of the Ethernet driver buffers size and count */
+#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
+#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
+#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
+#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/
+#define DP83848_PHY_ADDRESS 0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
+#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
+#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
+
+#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
+
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
+#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
+#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
+
+#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
+
+#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
+#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
+
+#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
+#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32f4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+ #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+ #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/boards/PYBV11/mpconfigboard.h b/ports/stm32/boards/PYBV11/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/PYBV11/mpconfigboard.h
rename to ports/stm32/boards/PYBV11/mpconfigboard.h
diff --git a/stmhal/boards/PYBV11/mpconfigboard.mk b/ports/stm32/boards/PYBV11/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/PYBV11/mpconfigboard.mk
rename to ports/stm32/boards/PYBV11/mpconfigboard.mk
diff --git a/stmhal/boards/PYBV11/pins.csv b/ports/stm32/boards/PYBV11/pins.csv
similarity index 100%
rename from stmhal/boards/PYBV11/pins.csv
rename to ports/stm32/boards/PYBV11/pins.csv
diff --git a/stmhal/boards/PYBV11/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBV11/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/PYBV11/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/PYBV11/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/PYBV3/mpconfigboard.h b/ports/stm32/boards/PYBV3/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/PYBV3/mpconfigboard.h
rename to ports/stm32/boards/PYBV3/mpconfigboard.h
diff --git a/stmhal/boards/PYBV3/mpconfigboard.mk b/ports/stm32/boards/PYBV3/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/PYBV3/mpconfigboard.mk
rename to ports/stm32/boards/PYBV3/mpconfigboard.mk
diff --git a/stmhal/boards/PYBV3/pins.csv b/ports/stm32/boards/PYBV3/pins.csv
similarity index 100%
rename from stmhal/boards/PYBV3/pins.csv
rename to ports/stm32/boards/PYBV3/pins.csv
diff --git a/ports/stm32/boards/PYBV3/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBV3/stm32f4xx_hal_conf.h
new file mode 100644
index 000000000..d3df51c10
--- /dev/null
+++ b/ports/stm32/boards/PYBV3/stm32f4xx_hal_conf.h
@@ -0,0 +1,411 @@
+/**
+ ******************************************************************************
+ * @file stm32f4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 19-June-2014
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+#define USE_USB_FS
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+/* #define HAL_CRC_MODULE_ENABLED */
+/* #define HAL_CRYP_MODULE_ENABLED */
+#define HAL_DAC_MODULE_ENABLED
+/* #define HAL_DCMI_MODULE_ENABLED */
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_DMA2D_MODULE_ENABLED */
+/* #define HAL_ETH_MODULE_ENABLED */
+#define HAL_FLASH_MODULE_ENABLED
+/* #define HAL_NAND_MODULE_ENABLED */
+/* #define HAL_NOR_MODULE_ENABLED */
+/* #define HAL_PCCARD_MODULE_ENABLED */
+/* #define HAL_SRAM_MODULE_ENABLED */
+/* #define HAL_SDRAM_MODULE_ENABLED */
+/* #define HAL_HASH_MODULE_ENABLED */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+/* #define HAL_I2S_MODULE_ENABLED */
+/* #define HAL_IWDG_MODULE_ENABLED */
+/* #define HAL_LTDC_MODULE_ENABLED */
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+#define HAL_SPI_MODULE_ENABLED
+#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED */
+/* #define HAL_IRDA_MODULE_ENABLED */
+/* #define HAL_SMARTCARD_MODULE_ENABLED */
+/* #define HAL_WWDG_MODULE_ENABLED */
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_PCD_MODULE_ENABLED
+/* #define HAL_HCD_MODULE_ENABLED */
+
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief Internal Low Speed oscillator (LSI) value.
+ */
+#if !defined (LSI_VALUE)
+ #define LSI_VALUE ((uint32_t)40000)
+#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
+ The real value may vary depending on the variations
+ in voltage and temperature. */
+/**
+ * @brief External Low Speed oscillator (LSE) value.
+ */
+#if !defined (LSE_VALUE)
+ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+#if !defined (LSE_STARTUP_TIMEOUT)
+ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
+#endif /* LSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief External clock source for I2S peripheral
+ * This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad.
+ */
+#if !defined (EXTERNAL_CLOCK_VALUE)
+ #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0 2
+#define MAC_ADDR1 0
+#define MAC_ADDR2 0
+#define MAC_ADDR3 0
+#define MAC_ADDR4 0
+#define MAC_ADDR5 0
+
+/* Definition of the Ethernet driver buffers size and count */
+#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
+#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
+#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
+#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/
+#define DP83848_PHY_ADDRESS 0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
+#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
+#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
+
+#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
+
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
+#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
+#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
+
+#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
+
+#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
+#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
+
+#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
+#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32f4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+ #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+ #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/boards/PYBV4/mpconfigboard.h b/ports/stm32/boards/PYBV4/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/PYBV4/mpconfigboard.h
rename to ports/stm32/boards/PYBV4/mpconfigboard.h
diff --git a/stmhal/boards/PYBV4/mpconfigboard.mk b/ports/stm32/boards/PYBV4/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/PYBV4/mpconfigboard.mk
rename to ports/stm32/boards/PYBV4/mpconfigboard.mk
diff --git a/stmhal/boards/PYBV4/pins.csv b/ports/stm32/boards/PYBV4/pins.csv
similarity index 100%
rename from stmhal/boards/PYBV4/pins.csv
rename to ports/stm32/boards/PYBV4/pins.csv
diff --git a/ports/stm32/boards/PYBV4/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBV4/stm32f4xx_hal_conf.h
new file mode 100644
index 000000000..d3df51c10
--- /dev/null
+++ b/ports/stm32/boards/PYBV4/stm32f4xx_hal_conf.h
@@ -0,0 +1,411 @@
+/**
+ ******************************************************************************
+ * @file stm32f4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 19-June-2014
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+#define USE_USB_FS
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+/* #define HAL_CRC_MODULE_ENABLED */
+/* #define HAL_CRYP_MODULE_ENABLED */
+#define HAL_DAC_MODULE_ENABLED
+/* #define HAL_DCMI_MODULE_ENABLED */
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_DMA2D_MODULE_ENABLED */
+/* #define HAL_ETH_MODULE_ENABLED */
+#define HAL_FLASH_MODULE_ENABLED
+/* #define HAL_NAND_MODULE_ENABLED */
+/* #define HAL_NOR_MODULE_ENABLED */
+/* #define HAL_PCCARD_MODULE_ENABLED */
+/* #define HAL_SRAM_MODULE_ENABLED */
+/* #define HAL_SDRAM_MODULE_ENABLED */
+/* #define HAL_HASH_MODULE_ENABLED */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+/* #define HAL_I2S_MODULE_ENABLED */
+/* #define HAL_IWDG_MODULE_ENABLED */
+/* #define HAL_LTDC_MODULE_ENABLED */
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+#define HAL_SPI_MODULE_ENABLED
+#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED */
+/* #define HAL_IRDA_MODULE_ENABLED */
+/* #define HAL_SMARTCARD_MODULE_ENABLED */
+/* #define HAL_WWDG_MODULE_ENABLED */
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_PCD_MODULE_ENABLED
+/* #define HAL_HCD_MODULE_ENABLED */
+
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief Internal Low Speed oscillator (LSI) value.
+ */
+#if !defined (LSI_VALUE)
+ #define LSI_VALUE ((uint32_t)40000)
+#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
+ The real value may vary depending on the variations
+ in voltage and temperature. */
+/**
+ * @brief External Low Speed oscillator (LSE) value.
+ */
+#if !defined (LSE_VALUE)
+ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+#if !defined (LSE_STARTUP_TIMEOUT)
+ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
+#endif /* LSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief External clock source for I2S peripheral
+ * This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad.
+ */
+#if !defined (EXTERNAL_CLOCK_VALUE)
+ #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0 2
+#define MAC_ADDR1 0
+#define MAC_ADDR2 0
+#define MAC_ADDR3 0
+#define MAC_ADDR4 0
+#define MAC_ADDR5 0
+
+/* Definition of the Ethernet driver buffers size and count */
+#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
+#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
+#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
+#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/
+#define DP83848_PHY_ADDRESS 0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
+#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
+#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
+
+#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
+
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
+#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
+#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
+
+#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
+
+#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
+#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
+
+#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
+#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32f4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+ #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+ #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/boards/STM32F411DISC/mpconfigboard.h b/ports/stm32/boards/STM32F411DISC/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/STM32F411DISC/mpconfigboard.h
rename to ports/stm32/boards/STM32F411DISC/mpconfigboard.h
diff --git a/stmhal/boards/STM32F411DISC/mpconfigboard.mk b/ports/stm32/boards/STM32F411DISC/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/STM32F411DISC/mpconfigboard.mk
rename to ports/stm32/boards/STM32F411DISC/mpconfigboard.mk
diff --git a/stmhal/boards/STM32F411DISC/pins.csv b/ports/stm32/boards/STM32F411DISC/pins.csv
similarity index 100%
rename from stmhal/boards/STM32F411DISC/pins.csv
rename to ports/stm32/boards/STM32F411DISC/pins.csv
diff --git a/stmhal/boards/STM32F411DISC/stm32f4xx_hal_conf.h b/ports/stm32/boards/STM32F411DISC/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/STM32F411DISC/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/STM32F411DISC/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/STM32F429DISC/mpconfigboard.h b/ports/stm32/boards/STM32F429DISC/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/STM32F429DISC/mpconfigboard.h
rename to ports/stm32/boards/STM32F429DISC/mpconfigboard.h
diff --git a/stmhal/boards/STM32F429DISC/mpconfigboard.mk b/ports/stm32/boards/STM32F429DISC/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/STM32F429DISC/mpconfigboard.mk
rename to ports/stm32/boards/STM32F429DISC/mpconfigboard.mk
diff --git a/stmhal/boards/STM32F429DISC/pins.csv b/ports/stm32/boards/STM32F429DISC/pins.csv
similarity index 100%
rename from stmhal/boards/STM32F429DISC/pins.csv
rename to ports/stm32/boards/STM32F429DISC/pins.csv
diff --git a/stmhal/boards/STM32F429DISC/stm32f4xx_hal_conf.h b/ports/stm32/boards/STM32F429DISC/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/STM32F429DISC/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/STM32F429DISC/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/STM32F439/mpconfigboard.h b/ports/stm32/boards/STM32F439/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/STM32F439/mpconfigboard.h
rename to ports/stm32/boards/STM32F439/mpconfigboard.h
diff --git a/stmhal/boards/STM32F439/mpconfigboard.mk b/ports/stm32/boards/STM32F439/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/STM32F439/mpconfigboard.mk
rename to ports/stm32/boards/STM32F439/mpconfigboard.mk
diff --git a/stmhal/boards/STM32F439/pins.csv b/ports/stm32/boards/STM32F439/pins.csv
similarity index 100%
rename from stmhal/boards/STM32F439/pins.csv
rename to ports/stm32/boards/STM32F439/pins.csv
diff --git a/stmhal/boards/STM32F439/stm32f4xx_hal_conf.h b/ports/stm32/boards/STM32F439/stm32f4xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/STM32F439/stm32f4xx_hal_conf.h
rename to ports/stm32/boards/STM32F439/stm32f4xx_hal_conf.h
diff --git a/stmhal/boards/STM32F4DISC/mpconfigboard.h b/ports/stm32/boards/STM32F4DISC/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/STM32F4DISC/mpconfigboard.h
rename to ports/stm32/boards/STM32F4DISC/mpconfigboard.h
diff --git a/stmhal/boards/STM32F4DISC/mpconfigboard.mk b/ports/stm32/boards/STM32F4DISC/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/STM32F4DISC/mpconfigboard.mk
rename to ports/stm32/boards/STM32F4DISC/mpconfigboard.mk
diff --git a/stmhal/boards/STM32F4DISC/pins.csv b/ports/stm32/boards/STM32F4DISC/pins.csv
similarity index 100%
rename from stmhal/boards/STM32F4DISC/pins.csv
rename to ports/stm32/boards/STM32F4DISC/pins.csv
diff --git a/stmhal/boards/STM32F4DISC/staccel.py b/ports/stm32/boards/STM32F4DISC/staccel.py
similarity index 100%
rename from stmhal/boards/STM32F4DISC/staccel.py
rename to ports/stm32/boards/STM32F4DISC/staccel.py
diff --git a/ports/stm32/boards/STM32F4DISC/stm32f4xx_hal_conf.h b/ports/stm32/boards/STM32F4DISC/stm32f4xx_hal_conf.h
new file mode 100644
index 000000000..d3df51c10
--- /dev/null
+++ b/ports/stm32/boards/STM32F4DISC/stm32f4xx_hal_conf.h
@@ -0,0 +1,411 @@
+/**
+ ******************************************************************************
+ * @file stm32f4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 19-June-2014
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+#define USE_USB_FS
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+/* #define HAL_CRC_MODULE_ENABLED */
+/* #define HAL_CRYP_MODULE_ENABLED */
+#define HAL_DAC_MODULE_ENABLED
+/* #define HAL_DCMI_MODULE_ENABLED */
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_DMA2D_MODULE_ENABLED */
+/* #define HAL_ETH_MODULE_ENABLED */
+#define HAL_FLASH_MODULE_ENABLED
+/* #define HAL_NAND_MODULE_ENABLED */
+/* #define HAL_NOR_MODULE_ENABLED */
+/* #define HAL_PCCARD_MODULE_ENABLED */
+/* #define HAL_SRAM_MODULE_ENABLED */
+/* #define HAL_SDRAM_MODULE_ENABLED */
+/* #define HAL_HASH_MODULE_ENABLED */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+/* #define HAL_I2S_MODULE_ENABLED */
+/* #define HAL_IWDG_MODULE_ENABLED */
+/* #define HAL_LTDC_MODULE_ENABLED */
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+#define HAL_SPI_MODULE_ENABLED
+#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED */
+/* #define HAL_IRDA_MODULE_ENABLED */
+/* #define HAL_SMARTCARD_MODULE_ENABLED */
+/* #define HAL_WWDG_MODULE_ENABLED */
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_PCD_MODULE_ENABLED
+/* #define HAL_HCD_MODULE_ENABLED */
+
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief Internal Low Speed oscillator (LSI) value.
+ */
+#if !defined (LSI_VALUE)
+ #define LSI_VALUE ((uint32_t)40000)
+#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
+ The real value may vary depending on the variations
+ in voltage and temperature. */
+/**
+ * @brief External Low Speed oscillator (LSE) value.
+ */
+#if !defined (LSE_VALUE)
+ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+#if !defined (LSE_STARTUP_TIMEOUT)
+ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
+#endif /* LSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief External clock source for I2S peripheral
+ * This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad.
+ */
+#if !defined (EXTERNAL_CLOCK_VALUE)
+ #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0 2
+#define MAC_ADDR1 0
+#define MAC_ADDR2 0
+#define MAC_ADDR3 0
+#define MAC_ADDR4 0
+#define MAC_ADDR5 0
+
+/* Definition of the Ethernet driver buffers size and count */
+#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
+#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
+#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
+#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/
+#define DP83848_PHY_ADDRESS 0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
+#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
+#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
+
+#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
+
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
+#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
+#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
+
+#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
+
+#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
+#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
+
+#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
+#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32f4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+ #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+ #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/boards/STM32F769DISC/mpconfigboard.h b/ports/stm32/boards/STM32F769DISC/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/STM32F769DISC/mpconfigboard.h
rename to ports/stm32/boards/STM32F769DISC/mpconfigboard.h
diff --git a/stmhal/boards/STM32F769DISC/mpconfigboard.mk b/ports/stm32/boards/STM32F769DISC/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/STM32F769DISC/mpconfigboard.mk
rename to ports/stm32/boards/STM32F769DISC/mpconfigboard.mk
diff --git a/stmhal/boards/STM32F769DISC/pins.csv b/ports/stm32/boards/STM32F769DISC/pins.csv
similarity index 100%
rename from stmhal/boards/STM32F769DISC/pins.csv
rename to ports/stm32/boards/STM32F769DISC/pins.csv
diff --git a/stmhal/boards/STM32F769DISC/stm32f7xx_hal_conf.h b/ports/stm32/boards/STM32F769DISC/stm32f7xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/STM32F769DISC/stm32f7xx_hal_conf.h
rename to ports/stm32/boards/STM32F769DISC/stm32f7xx_hal_conf.h
diff --git a/stmhal/boards/STM32F7DISC/board_init.c b/ports/stm32/boards/STM32F7DISC/board_init.c
similarity index 100%
rename from stmhal/boards/STM32F7DISC/board_init.c
rename to ports/stm32/boards/STM32F7DISC/board_init.c
diff --git a/stmhal/boards/STM32F7DISC/mpconfigboard.h b/ports/stm32/boards/STM32F7DISC/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/STM32F7DISC/mpconfigboard.h
rename to ports/stm32/boards/STM32F7DISC/mpconfigboard.h
diff --git a/stmhal/boards/STM32F7DISC/mpconfigboard.mk b/ports/stm32/boards/STM32F7DISC/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/STM32F7DISC/mpconfigboard.mk
rename to ports/stm32/boards/STM32F7DISC/mpconfigboard.mk
diff --git a/stmhal/boards/STM32F7DISC/pins.csv b/ports/stm32/boards/STM32F7DISC/pins.csv
similarity index 100%
rename from stmhal/boards/STM32F7DISC/pins.csv
rename to ports/stm32/boards/STM32F7DISC/pins.csv
diff --git a/stmhal/boards/STM32F7DISC/stm32f7xx_hal_conf.h b/ports/stm32/boards/STM32F7DISC/stm32f7xx_hal_conf.h
similarity index 100%
rename from stmhal/boards/STM32F7DISC/stm32f7xx_hal_conf.h
rename to ports/stm32/boards/STM32F7DISC/stm32f7xx_hal_conf.h
diff --git a/stmhal/boards/STM32L476DISC/board_init.c b/ports/stm32/boards/STM32L476DISC/board_init.c
similarity index 100%
rename from stmhal/boards/STM32L476DISC/board_init.c
rename to ports/stm32/boards/STM32L476DISC/board_init.c
diff --git a/stmhal/boards/STM32L476DISC/mpconfigboard.h b/ports/stm32/boards/STM32L476DISC/mpconfigboard.h
similarity index 100%
rename from stmhal/boards/STM32L476DISC/mpconfigboard.h
rename to ports/stm32/boards/STM32L476DISC/mpconfigboard.h
diff --git a/stmhal/boards/STM32L476DISC/mpconfigboard.mk b/ports/stm32/boards/STM32L476DISC/mpconfigboard.mk
similarity index 100%
rename from stmhal/boards/STM32L476DISC/mpconfigboard.mk
rename to ports/stm32/boards/STM32L476DISC/mpconfigboard.mk
diff --git a/stmhal/boards/STM32L476DISC/pins.csv b/ports/stm32/boards/STM32L476DISC/pins.csv
similarity index 100%
rename from stmhal/boards/STM32L476DISC/pins.csv
rename to ports/stm32/boards/STM32L476DISC/pins.csv
diff --git a/ports/stm32/boards/STM32L476DISC/stm32l4xx_hal_conf.h b/ports/stm32/boards/STM32L476DISC/stm32l4xx_hal_conf.h
new file mode 100644
index 000000000..9348e0679
--- /dev/null
+++ b/ports/stm32/boards/STM32L476DISC/stm32l4xx_hal_conf.h
@@ -0,0 +1,373 @@
+/**
+ ******************************************************************************
+ * @file stm32l4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.2.0
+ * @date 25-November-2015
+ * @brief HAL configuration template file.
+ * This file should be copied to the application folder and renamed
+ * to stm32l4xx_hal_conf.h.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2015 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L4xx_HAL_CONF_H
+#define __STM32L4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#define USE_USB_FS
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+/* #define HAL_COMP_MODULE_ENABLED */
+#define HAL_CORTEX_MODULE_ENABLED
+/* #define HAL_CRC_MODULE_ENABLED */
+/* #define HAL_CRYP_MODULE_ENABLED */
+#define HAL_DAC_MODULE_ENABLED
+/* #define HAL_DFSDM_MODULE_ENABLED */
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_FIREWALL_MODULE_ENABLED */
+#define HAL_FLASH_MODULE_ENABLED
+/* #define HAL_HCD_MODULE_ENABLED */
+/* #define HAL_NAND_MODULE_ENABLED */
+/* #define HAL_NOR_MODULE_ENABLED */
+/* #define HAL_SRAM_MODULE_ENABLED */
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+/* #define HAL_IRDA_MODULE_ENABLED */
+/* #define HAL_IWDG_MODULE_ENABLED */
+/* #define HAL_LCD_MODULE_ENABLED */
+/* #define HAL_LPTIM_MODULE_ENABLED */
+/* #define HAL_OPAMP_MODULE_ENABLED */
+#define HAL_PCD_MODULE_ENABLED
+#define HAL_PWR_MODULE_ENABLED
+/* #define HAL_QSPI_MODULE_ENABLED */
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+/* #define HAL_SMARTCARD_MODULE_ENABLED */
+/* #define HAL_SMBUS_MODULE_ENABLED */
+#define HAL_SPI_MODULE_ENABLED
+/* #define HAL_SWPMI_MODULE_ENABLED */
+#define HAL_TIM_MODULE_ENABLED
+/* #define HAL_TSC_MODULE_ENABLED */
+#define HAL_UART_MODULE_ENABLED
+/* #define HAL_USART_MODULE_ENABLED */
+/* #define HAL_WWDG_MODULE_ENABLED */
+
+
+/* ########################## Oscillator Values adaptation ####################*/
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal Multiple Speed oscillator (MSI) default value.
+ * This value is the default MSI range value after Reset.
+ */
+#if !defined (MSI_VALUE)
+ #define MSI_VALUE ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* MSI_VALUE */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief Internal Low Speed oscillator (LSI) value.
+ */
+#if !defined (LSI_VALUE)
+ #define LSI_VALUE ((uint32_t)32000) /*!< LSI Typical Value in Hz*/
+#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
+ The real value may vary depending on the variations
+ in voltage and temperature. */
+/**
+ * @brief External Low Speed oscillator (LSE) value.
+ * This value is used by the UART, RTC HAL module to compute the system frequency
+ */
+#if !defined (LSE_VALUE)
+ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/
+#endif /* LSE_VALUE */
+
+#if !defined (LSE_STARTUP_TIMEOUT)
+ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief External clock source for SAI1 peripheral
+ * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
+ * frequency.
+ */
+#if !defined (EXTERNAL_SAI1_CLOCK_VALUE)
+ #define EXTERNAL_SAI1_CLOCK_VALUE ((uint32_t)48000) /*!< Value of the SAI1 External clock source in Hz*/
+#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
+
+/**
+ * @brief External clock source for SAI2 peripheral
+ * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
+ * frequency.
+ */
+#if !defined (EXTERNAL_SAI2_CLOCK_VALUE)
+ #define EXTERNAL_SAI2_CLOCK_VALUE ((uint32_t)48000) /*!< Value of the SAI2 External clock source in Hz*/
+#endif /* EXTERNAL_SAI2_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32l4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32l4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32l4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_DFSDM_MODULE_ENABLED
+ #include "stm32l4xx_hal_dfsdm.h"
+#endif /* HAL_DFSDM_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32l4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32l4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32l4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_COMP_MODULE_ENABLED
+ #include "stm32l4xx_hal_comp.h"
+#endif /* HAL_COMP_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32l4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32l4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32l4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_FIREWALL_MODULE_ENABLED
+ #include "stm32l4xx_hal_firewall.h"
+#endif /* HAL_FIREWALL_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32l4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32l4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32l4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32l4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32l4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32l4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LCD_MODULE_ENABLED
+ #include "stm32l4xx_hal_lcd.h"
+#endif /* HAL_LCD_MODULE_ENABLED */
+
+#ifdef HAL_LPTIM_MODULE_ENABLED
+#include "stm32l4xx_hal_lptim.h"
+#endif /* HAL_LPTIM_MODULE_ENABLED */
+
+#ifdef HAL_OPAMP_MODULE_ENABLED
+#include "stm32l4xx_hal_opamp.h"
+#endif /* HAL_OPAMP_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32l4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_QSPI_MODULE_ENABLED
+ #include "stm32l4xx_hal_qspi.h"
+#endif /* HAL_QSPI_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32l4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32l4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32l4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32l4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SMBUS_MODULE_ENABLED
+ #include "stm32l4xx_hal_smbus.h"
+#endif /* HAL_SMBUS_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32l4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_SWPMI_MODULE_ENABLED
+ #include "stm32l4xx_hal_swpmi.h"
+#endif /* HAL_SWPMI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32l4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_TSC_MODULE_ENABLED
+ #include "stm32l4xx_hal_tsc.h"
+#endif /* HAL_TSC_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32l4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32l4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32l4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32l4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32l4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32l4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32l4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/boards/common.ld b/ports/stm32/boards/common.ld
similarity index 100%
rename from stmhal/boards/common.ld
rename to ports/stm32/boards/common.ld
diff --git a/stmhal/boards/make-pins.py b/ports/stm32/boards/make-pins.py
similarity index 99%
rename from stmhal/boards/make-pins.py
rename to ports/stm32/boards/make-pins.py
index 51619ffa2..210c7b63c 100755
--- a/stmhal/boards/make-pins.py
+++ b/ports/stm32/boards/make-pins.py
@@ -370,8 +370,8 @@ def print_af_hdr(self, af_const_filename):
af_words = mux_name.split('_') # ex mux_name: AF9_I2C2
cond_var = conditional_var(af_words[1])
print_conditional_if(cond_var, file=af_const_file)
- key = 'MP_OBJ_NEW_QSTR(MP_QSTR_{}),'.format(mux_name)
- val = 'MP_OBJ_NEW_SMALL_INT(GPIO_{})'.format(mux_name)
+ key = 'MP_ROM_QSTR(MP_QSTR_{}),'.format(mux_name)
+ val = 'MP_ROM_INT(GPIO_{})'.format(mux_name)
print(' { %-*s %s },' % (mux_name_width + 26, key, val),
file=af_const_file)
print_conditional_endif(cond_var, file=af_const_file)
diff --git a/stmhal/boards/openocd_stm32f4.cfg b/ports/stm32/boards/openocd_stm32f4.cfg
similarity index 100%
rename from stmhal/boards/openocd_stm32f4.cfg
rename to ports/stm32/boards/openocd_stm32f4.cfg
diff --git a/stmhal/boards/openocd_stm32f7.cfg b/ports/stm32/boards/openocd_stm32f7.cfg
similarity index 100%
rename from stmhal/boards/openocd_stm32f7.cfg
rename to ports/stm32/boards/openocd_stm32f7.cfg
diff --git a/stmhal/boards/openocd_stm32l4.cfg b/ports/stm32/boards/openocd_stm32l4.cfg
similarity index 100%
rename from stmhal/boards/openocd_stm32l4.cfg
rename to ports/stm32/boards/openocd_stm32l4.cfg
diff --git a/stmhal/boards/pllvalues.py b/ports/stm32/boards/pllvalues.py
similarity index 56%
rename from stmhal/boards/pllvalues.py
rename to ports/stm32/boards/pllvalues.py
index 183313f30..befd6cfa0 100644
--- a/stmhal/boards/pllvalues.py
+++ b/ports/stm32/boards/pllvalues.py
@@ -4,6 +4,8 @@
for the machine.freq() function.
"""
+from __future__ import print_function
+
def close_int(x):
return abs(x - round(x)) < 0.01
@@ -38,7 +40,10 @@ def compute_pll(hse, sys):
# improved version that doesn't require N/M to be an integer
def compute_pll2(hse, sys):
- for P in (2, 4, 6, 8): # allowed values of P
+ # Loop over the allowed values of P, looking for a valid PLL configuration
+ # that gives the desired "sys" frequency. We use floats for P to force
+ # floating point arithmetic on Python 2.
+ for P in (2.0, 4.0, 6.0, 8.0):
Q = sys * P / 48
# Q must be an integer in a set range
if not (close_int(Q) and 2 <= Q <= 15):
@@ -67,14 +72,17 @@ def compute_pll2(hse, sys):
# no valid values found
return None
-def verify_and_print_pll(hse, sys, pll):
+def compute_derived(hse, pll):
M, N, P, Q = pll
-
- # compute derived quantities
vco_in = hse / M
vco_out = hse * N / M
pllck = hse / M * N / P
pll48ck = hse / M * N / Q
+ return (vco_in, vco_out, pllck, pll48ck)
+
+def verify_pll(hse, pll):
+ M, N, P, Q = pll
+ vco_in, vco_out, pllck, pll48ck = compute_derived(hse, pll)
# verify ints
assert close_int(M)
@@ -90,26 +98,68 @@ def verify_and_print_pll(hse, sys, pll):
assert 1 <= vco_in <= 2
assert 192 <= vco_out <= 432
- # print out values
- print(out_format % (sys, M, N, P, Q, vco_in, vco_out, pllck, pll48ck))
+def generate_c_table(hse, valid_plls):
+ valid_plls = valid_plls + [(16, (0, 0, 2, 0))]
+ if hse < 16:
+ valid_plls.append((hse, (1, 0, 2, 0)))
+ valid_plls.sort()
+ print("// (M, P/2-1, SYS) values for %u MHz HSE" % hse)
+ print("static const uint16_t pll_freq_table[%u] = {" % len(valid_plls))
+ for sys, (M, N, P, Q) in valid_plls:
+ print(" (%u << 10) | (%u << 8) | %u," % (M, P // 2 - 1, sys))
+ print("};")
+
+def print_table(hse, valid_plls):
+ print("HSE =", hse, "MHz")
+ print("sys : M N P Q : VCO_IN VCO_OUT PLLCK PLL48CK")
+ out_format = "%3u : %2u %.1f %.2f %.2f : %5.2f %6.2f %6.2f %6.2f"
+ for sys, pll in valid_plls:
+ print(out_format % ((sys,) + pll + compute_derived(hse, pll)))
+ print("found %u valid configurations" % len(valid_plls))
def main():
global out_format
+
+ # parse input args
import sys
- if len(sys.argv) != 2:
- print("usage: pllvalues.py ")
+ argv = sys.argv[1:]
+
+ c_table = False
+ if argv[0] == '-c':
+ c_table = True
+ argv.pop(0)
+
+ if len(argv) != 1:
+ print("usage: pllvalues.py [-c] ")
sys.exit(1)
- hse_value = int(sys.argv[1])
- print("HSE =", hse_value, "MHz")
- print("sys : M N P Q : VCO_IN VCO_OUT PLLCK PLL48CK")
- out_format = "%3u : %2u %.1f %.2f %.2f : %5.2f %6.2f %6.2f %6.2f"
- n_valid = 0
+
+ if argv[0].startswith("file:"):
+ # extract HSE_VALUE from header file
+ with open(argv[0][5:]) as f:
+ for line in f:
+ line = line.strip()
+ if line.startswith("#define") and line.find("HSE_VALUE") != -1:
+ idx_start = line.find("((uint32_t)") + 11
+ idx_end = line.find(")", idx_start)
+ hse = int(line[idx_start:idx_end]) // 1000000
+ break
+ else:
+ raise ValueError("%s does not contain a definition of HSE_VALUE" % argv[0])
+ else:
+ # HSE given directly as an integer
+ hse = int(argv[0])
+
+ valid_plls = []
for sysclk in range(1, 217):
- pll = compute_pll2(hse_value, sysclk)
+ pll = compute_pll2(hse, sysclk)
if pll is not None:
- n_valid += 1
- verify_and_print_pll(hse_value, sysclk, pll)
- print("found %u valid configurations" % n_valid)
+ verify_pll(hse, pll)
+ valid_plls.append((sysclk, pll))
+
+ if c_table:
+ generate_c_table(hse, valid_plls)
+ else:
+ print_table(hse, valid_plls)
if __name__ == "__main__":
main()
diff --git a/stmhal/boards/stm32f401_af.csv b/ports/stm32/boards/stm32f401_af.csv
similarity index 100%
rename from stmhal/boards/stm32f401_af.csv
rename to ports/stm32/boards/stm32f401_af.csv
diff --git a/stmhal/boards/stm32f401xd.ld b/ports/stm32/boards/stm32f401xd.ld
similarity index 62%
rename from stmhal/boards/stm32f401xd.ld
rename to ports/stm32/boards/stm32f401xd.ld
index 415c25849..89f605609 100644
--- a/stmhal/boards/stm32f401xd.ld
+++ b/ports/stm32/boards/stm32f401xd.ld
@@ -5,11 +5,11 @@
/* Specify the memory areas */
MEMORY
{
- FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x060000 /* entire flash, 384 KiB */
- FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x004000 /* sector 0, 16 KiB */
- FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 0x01C000 /* sectors 1,2,3 are 16K, 4 is 64K */
- FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x040000 /* sectors 5,6 2*128KiB = 256 KiB */
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x018000 /* 96 KiB */
+ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 384K /* entire flash */
+ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
+ FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1,2,3 are 16K, 4 is 64K */
+ FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 256K /* sectors 5,6 are 128K */
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
}
/* produce a link error if there is not this amount of RAM for these sections */
diff --git a/stmhal/boards/stm32f401xe.ld b/ports/stm32/boards/stm32f401xe.ld
similarity index 61%
rename from stmhal/boards/stm32f401xe.ld
rename to ports/stm32/boards/stm32f401xe.ld
index a2e693b49..ae2f89904 100644
--- a/stmhal/boards/stm32f401xe.ld
+++ b/ports/stm32/boards/stm32f401xe.ld
@@ -5,11 +5,11 @@
/* Specify the memory areas */
MEMORY
{
- FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x080000 /* entire flash, 512 KiB */
- FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x004000 /* sector 0, 16 KiB */
- FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 0x01C000 /* sectors 1,2,3 are 16K, 4 is 64K */
- FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x060000 /* sectors 5,6,7 3*128KiB = 384 KiB */
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x018000 /* 96 KiB */
+ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* entire flash */
+ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
+ FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1,2,3 are 16K, 4 is 64K */
+ FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sectors 5,6,7 are 128K */
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
}
/* produce a link error if there is not this amount of RAM for these sections */
diff --git a/stmhal/boards/stm32f405.ld b/ports/stm32/boards/stm32f405.ld
similarity index 100%
rename from stmhal/boards/stm32f405.ld
rename to ports/stm32/boards/stm32f405.ld
diff --git a/stmhal/boards/stm32f405_af.csv b/ports/stm32/boards/stm32f405_af.csv
similarity index 100%
rename from stmhal/boards/stm32f405_af.csv
rename to ports/stm32/boards/stm32f405_af.csv
diff --git a/stmhal/boards/stm32f411.ld b/ports/stm32/boards/stm32f411.ld
similarity index 60%
rename from stmhal/boards/stm32f411.ld
rename to ports/stm32/boards/stm32f411.ld
index d156e852a..7adfa35c9 100644
--- a/stmhal/boards/stm32f411.ld
+++ b/ports/stm32/boards/stm32f411.ld
@@ -5,11 +5,11 @@
/* Specify the memory areas */
MEMORY
{
- FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x080000 /* entire flash, 512 KiB */
- FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x004000 /* sector 0, 16 KiB */
- /* sectors 1,2,3 are 16K, 4 is 64K (for filesystem) */
- FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x060000 /* sectors 5,6,7 3*128KiB = 384 KiB */
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x020000 /* 128 KiB */
+ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* entire flash */
+ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
+ FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1,2,3 are 16K, 4 is 64K */
+ FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sectors 5,6,7 are 128K */
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
}
/* produce a link error if there is not this amount of RAM for these sections */
diff --git a/stmhal/boards/stm32f411_af.csv b/ports/stm32/boards/stm32f411_af.csv
similarity index 100%
rename from stmhal/boards/stm32f411_af.csv
rename to ports/stm32/boards/stm32f411_af.csv
diff --git a/stmhal/boards/stm32f429.ld b/ports/stm32/boards/stm32f429.ld
similarity index 62%
rename from stmhal/boards/stm32f429.ld
rename to ports/stm32/boards/stm32f429.ld
index f358233a6..a0931684d 100644
--- a/stmhal/boards/stm32f429.ld
+++ b/ports/stm32/boards/stm32f429.ld
@@ -5,11 +5,12 @@
/* Specify the memory areas */
MEMORY
{
- FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x0200000 /* entire flash, 2048 KiB */
- FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sector 0, 16 KiB */
- FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x0088000 /* sectors 5,6,7,8, 4*128KiB = 512 KiB (could increase it more) */
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x0030000 /* 192 KiB */
- SDRAM(xrw) : ORIGIN = 0xC0000000, LENGTH = 0x0800000 /* 8 MByte */
+ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K /* entire flash */
+ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0, 16 KiB */
+ FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1-4: 3*16K+64K */
+ FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 896K /* sectors 5-11 are 128K */
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
+ SDRAM(xrw) : ORIGIN = 0xC0000000, LENGTH = 8192K
}
/* produce a link error if there is not this amount of RAM for these sections */
diff --git a/stmhal/boards/stm32f429_af.csv b/ports/stm32/boards/stm32f429_af.csv
similarity index 100%
rename from stmhal/boards/stm32f429_af.csv
rename to ports/stm32/boards/stm32f429_af.csv
diff --git a/stmhal/boards/stm32f439.ld b/ports/stm32/boards/stm32f439.ld
similarity index 52%
rename from stmhal/boards/stm32f439.ld
rename to ports/stm32/boards/stm32f439.ld
index 0da185e89..a76a0ebc7 100644
--- a/stmhal/boards/stm32f439.ld
+++ b/ports/stm32/boards/stm32f439.ld
@@ -5,11 +5,13 @@
/* Specify the memory areas */
MEMORY
{
- FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x200000 /* entire flash, 2048 KiB */
- FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x004000 /* sector 0, 16 KiB */
- FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x080000 /* sectors 5,6,7,8, 4*128KiB = 512 KiB (could increase it more) */
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x030000 /* 192 KiB */
- CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 0x010000 /* 64 KiB */
+ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K /* entire flash */
+ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
+ FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 896K /* sectors 5-11 are 128K */
+ FLASH_FS (rx) : ORIGIN = 0x08100000, LENGTH = 256K /* sectors 12-17 are 4*16K+64K+128K */
+ FLASH_FS2 (rx) : ORIGIN = 0x08140000, LENGTH = 128K /* sector 18 */
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
+ CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
}
/* produce a link error if there is not this amount of RAM for these sections */
diff --git a/stmhal/boards/stm32f439_af.csv b/ports/stm32/boards/stm32f439_af.csv
similarity index 100%
rename from stmhal/boards/stm32f439_af.csv
rename to ports/stm32/boards/stm32f439_af.csv
diff --git a/stmhal/boards/stm32f4xx_prefix.c b/ports/stm32/boards/stm32f4xx_prefix.c
similarity index 100%
rename from stmhal/boards/stm32f4xx_prefix.c
rename to ports/stm32/boards/stm32f4xx_prefix.c
diff --git a/stmhal/boards/stm32f746.ld b/ports/stm32/boards/stm32f746.ld
similarity index 100%
rename from stmhal/boards/stm32f746.ld
rename to ports/stm32/boards/stm32f746.ld
diff --git a/stmhal/boards/stm32f746_af.csv b/ports/stm32/boards/stm32f746_af.csv
similarity index 100%
rename from stmhal/boards/stm32f746_af.csv
rename to ports/stm32/boards/stm32f746_af.csv
diff --git a/stmhal/boards/stm32f767.ld b/ports/stm32/boards/stm32f767.ld
similarity index 100%
rename from stmhal/boards/stm32f767.ld
rename to ports/stm32/boards/stm32f767.ld
diff --git a/stmhal/boards/stm32f767_af.csv b/ports/stm32/boards/stm32f767_af.csv
similarity index 96%
rename from stmhal/boards/stm32f767_af.csv
rename to ports/stm32/boards/stm32f767_af.csv
index db27818c6..1708dfcca 100644
--- a/stmhal/boards/stm32f767_af.csv
+++ b/ports/stm32/boards/stm32f767_af.csv
@@ -15,9 +15,9 @@ PortA,PA11,,TIM1_CH4,,,,,,USART1_CTS,,CAN1_RX,OTG_FS_DM,,,,LCD_R4,EVENTOUT
PortA,PA12,,TIM1_ETR,,,,,,USART1_RTS,SAI2_FS_B,CAN1_TX,OTG_FS_DP,,,,LCD_R5,EVENTOUT
PortA,PA13,JTMS,SWDIO,,,,,,,,,,,,,,EVENTOUT
PortA,PA14,JTCK,SWCLK,,,,,,,,,,,,,,EVENTOUT
-PortA,PA15,JTDI,TIM2_CH1/TIM2_ETR,,,HDMICE,CSPI1_NSS/I2S1_WS,SPI3_NSS/I2S3_WS,,UART4_RTS,,,,,,,EVENTOUT
-PortB,PB0,,TIM1_CH2N,TIM3_CH3T,IM8_CH2N,,,,,UART4_CTS,LCD_R3,OTG_HS_ULPI_D1,ETH_MII_RXD2,,,,EVENTOUT
-PortB,PB1,,TIM1_CH3N,TIM3_CH4T,IM8_CH3N,,,,,,LCD_R6,OTG_HS_ULPI_D2,ETH_MII_RXD3,,,,EVENTOUT
+PortA,PA15,JTDI,TIM2_CH1/TIM2_ETR,,,HDMICEC,SPI1_NSS/I2S1_WS,SPI3_NSS/I2S3_WS,,UART4_RTS,,,,,,,EVENTOUT
+PortB,PB0,,TIM1_CH2N,TIM3_CH3T,TIM8_CH2N,,,,,UART4_CTS,LCD_R3,OTG_HS_ULPI_D1,ETH_MII_RXD2,,,,EVENTOUT
+PortB,PB1,,TIM1_CH3N,TIM3_CH4T,TIM8_CH3N,,,,,,LCD_R6,OTG_HS_ULPI_D2,ETH_MII_RXD3,,,,EVENTOUT
PortB,PB2,,,,,,,SAI1_SD_A,SPI3_MOSI/I2S3_SD,,QUADSPI_CLK,,,,,,EVENTOUT
PortB,PB3,JTDO/TRACESWO,TIM2_CH2,,,,SPI1_SCK/I2S1_CK,SPI3_SCK/I2S3_CK,,,,SDMMC2_D2,,,,,EVENTOUT
PortB,PB4,NJTRST,,TIM3_CH1,,,SPI1_MISO,SPI3_MISO,SPI2_NSS/I2S2_WS,,,SDMMC2_D3,,,,,EVENTOUT
@@ -41,7 +41,7 @@ PortC,PC5,,,,,,,,,SPDIFRX_IN3,,,ETH_MII_RXD1/ETH_RMII_RXD1,FMC_SDCKE0,,,EVENTOUT
PortC,PC6,,,TIM3_CH1,TIM8_CH1,,I2S2_MCK,,,USART6_TX,,SDMMC2_D6,,SDMMC1_D6,DCMI_D0,LCD_HSYNC,EVENTOUT
PortC,PC7,,,TIM3_CH2,TIM8_CH2,,,I2S3_MCK,,USART6_RX,,SDMMC2_D7,,SDMMC1_D7,DCMI_D1,LCD_G6,EVENTOUT
PortC,PC8,TRACED1,,TIM3_CH3,TIM8_CH3,,,,UART5_RTS,USART6_CK,,,,SDMMC1_D0,DCMI_D2,,EVENTOUT
-PortC,PC9,MCO2,,TIM3_CH4,TIM8_CH4,I2C3_SDA,I2S_CKIN,,UART5_CTS,,QUADSPI_BK1_IO0,,,SDMMC1_D1,DCMI_D3,,EVENTOUT
+PortC,PC9,MCO2,,TIM3_CH4,TIM8_CH4,I2C3_SDA,I2S2_CKIN,,UART5_CTS,,QUADSPI_BK1_IO0,,,SDMMC1_D1,DCMI_D3,,EVENTOUT
PortC,PC10,,,,,,,SPI3_SCK/I2S3_CK,USART3_TX,UART4_TX,QUADSPI_BK1_IO1,,,SDMMC1_D2,DCMI_D8,LCD_R2,EVENTOUT
PortC,PC11,,,,,,,SPI3_MISO,USART3_RX,UART4_RX,QUADSPI_BK2_NCS,,,SDMMC1_D3,DCMI_D4,,EVENTOUT
PortC,PC12,TRACED3,,,,,,SPI3_MOSI/I2S3_SD,USART3_CK,UART5_TX,,,,SDMMC1_CK,DCMI_D9,,EVENTOUT
diff --git a/stmhal/boards/stm32f769.ld b/ports/stm32/boards/stm32f769.ld
similarity index 100%
rename from stmhal/boards/stm32f769.ld
rename to ports/stm32/boards/stm32f769.ld
diff --git a/stmhal/boards/stm32l476_af.csv b/ports/stm32/boards/stm32l476_af.csv
similarity index 100%
rename from stmhal/boards/stm32l476_af.csv
rename to ports/stm32/boards/stm32l476_af.csv
diff --git a/stmhal/boards/stm32l476xe.ld b/ports/stm32/boards/stm32l476xe.ld
similarity index 78%
rename from stmhal/boards/stm32l476xe.ld
rename to ports/stm32/boards/stm32l476xe.ld
index bb9895d2a..11b2972ad 100644
--- a/stmhal/boards/stm32l476xe.ld
+++ b/ports/stm32/boards/stm32l476xe.ld
@@ -6,9 +6,9 @@
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
- FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sectors 0-7, 16 KiB */
- FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 0x005C000 /* sectors 8-191, 368 KiB */
- FLASH_FS (r) : ORIGIN = 0x08060000, LENGTH = 0x0020000 /* sectors 192-255, 128 KiB */
+ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sectors 0-7 */
+ FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 368K /* sectors 8-191 */
+ FLASH_FS (r) : ORIGIN = 0x08060000, LENGTH = 128K /* sectors 192-255 */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
SRAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
}
diff --git a/stmhal/boards/stm32l476xg.ld b/ports/stm32/boards/stm32l476xg.ld
similarity index 78%
rename from stmhal/boards/stm32l476xg.ld
rename to ports/stm32/boards/stm32l476xg.ld
index 684078c43..a94fa2750 100644
--- a/stmhal/boards/stm32l476xg.ld
+++ b/ports/stm32/boards/stm32l476xg.ld
@@ -6,9 +6,9 @@
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
- FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sectors 0-7, 16 KiB */
- FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 0x007C000 /* sectors 8-255, 496 KiB */
- FLASH_FS (r) : ORIGIN = 0x08080000, LENGTH = 0x0080000 /* sectors 256-511 512 KiB */
+ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sectors 0-7 */
+ FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 496K /* sectors 8-255 */
+ FLASH_FS (r) : ORIGIN = 0x08080000, LENGTH = 512K /* sectors 256-511 */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
SRAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
}
diff --git a/stmhal/bufhelper.c b/ports/stm32/bufhelper.c
similarity index 96%
rename from stmhal/bufhelper.c
rename to ports/stm32/bufhelper.c
index ca76e9496..79511969b 100644
--- a/stmhal/bufhelper.c
+++ b/ports/stm32/bufhelper.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/bufhelper.h b/ports/stm32/bufhelper.h
similarity index 95%
rename from stmhal/bufhelper.h
rename to ports/stm32/bufhelper.h
index 55f57be8e..c1967bf43 100644
--- a/stmhal/bufhelper.h
+++ b/ports/stm32/bufhelper.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/can.c b/ports/stm32/can.c
similarity index 98%
rename from stmhal/can.c
rename to ports/stm32/can.c
index 6152022b7..25a608ce9 100644
--- a/stmhal/can.c
+++ b/ports/stm32/can.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/objtuple.h"
#include "py/runtime.h"
#include "py/gc.h"
@@ -262,7 +261,7 @@ STATIC HAL_StatusTypeDef CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout)
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_can_obj_t *self = self_in;
@@ -288,7 +287,7 @@ STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
}
// init(mode, extframe=False, prescaler=100, *, sjw=1, bs1=6, bs2=8)
-STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = CAN_MODE_NORMAL} },
{ MP_QSTR_extframe, MP_ARG_BOOL, {.u_bool = false} },
@@ -400,7 +399,7 @@ STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_
return self;
}
-STATIC mp_obj_t pyb_can_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_can_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_can_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_init_obj, 1, pyb_can_init);
@@ -454,7 +453,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_can_any_obj, pyb_can_any);
/// - `timeout` is the timeout in milliseconds to wait for the send.
///
/// Return value: `None`.
-STATIC mp_obj_t pyb_can_send(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
@@ -514,7 +513,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_send_obj, 1, pyb_can_send);
/// - `timeout` is the timeout in milliseconds to wait for the receive.
///
/// Return value: buffer of data bytes.
-STATIC mp_obj_t pyb_can_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_can_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_fifo, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
@@ -527,7 +526,7 @@ STATIC mp_obj_t pyb_can_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
// receive the data
CanRxMsgTypeDef rx_msg;
- self->can.pRxMsg = &rx_msg;
+ self->can.pRxMsg = self->can.pRx1Msg = &rx_msg;
HAL_StatusTypeDef status = HAL_CAN_Receive(&self->can, args[0].u_int, args[1].u_int);
if (status != HAL_OK) {
@@ -617,7 +616,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_can_clearfilter_obj, pyb_can_clearfilter);
/// Configures a filterbank
/// Return value: `None`.
#define EXTENDED_ID_TO_16BIT_FILTER(id) (((id & 0xC00000) >> 13) | ((id & 0x38000) >> 15)) | 8
-STATIC mp_obj_t pyb_can_setfilter(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_bank, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
diff --git a/stmhal/can.h b/ports/stm32/can.h
similarity index 95%
rename from stmhal/can.h
rename to ports/stm32/can.h
index 7c40e9bf9..860012813 100644
--- a/stmhal/can.h
+++ b/ports/stm32/can.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/dac.c b/ports/stm32/dac.c
similarity index 97%
rename from stmhal/dac.c
rename to ports/stm32/dac.c
index 243aa08c3..268b1bcfb 100644
--- a/stmhal/dac.c
+++ b/ports/stm32/dac.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -119,12 +119,12 @@ STATIC uint32_t TIMx_Config(mp_obj_t timer) {
return DAC_TRIGGER_T8_TRGO;
#endif
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Timer does not support DAC triggering"));
+ mp_raise_ValueError("Timer does not support DAC triggering");
}
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
typedef enum {
DAC_STATE_RESET,
@@ -142,7 +142,7 @@ typedef struct _pyb_dac_obj_t {
uint8_t state;
} pyb_dac_obj_t;
-STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
};
@@ -246,7 +246,7 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
return dac;
}
-STATIC mp_obj_t pyb_dac_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_dac_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_dac_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_init_obj, 1, pyb_dac_init);
@@ -369,7 +369,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_write_obj, pyb_dac_write);
// and we can reuse the same timer for both DACs (and maybe also ADC) without
// setting the freq twice.
// Can still do 1-liner: dac.write_trig(buf, trig=Timer(6, freq=100), loop=True)
-mp_obj_t pyb_dac_write_timed(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+mp_obj_t pyb_dac_write_timed(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_freq, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
diff --git a/stmhal/dac.h b/ports/stm32/dac.h
similarity index 94%
rename from stmhal/dac.h
rename to ports/stm32/dac.h
index 93192c0fe..f487f52a9 100644
--- a/stmhal/dac.h
+++ b/ports/stm32/dac.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/dma.c b/ports/stm32/dma.c
similarity index 99%
rename from stmhal/dma.c
rename to ports/stm32/dma.c
index e43b67e73..df6275d65 100644
--- a/stmhal/dma.c
+++ b/ports/stm32/dma.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/dma.h b/ports/stm32/dma.h
similarity index 98%
rename from stmhal/dma.h
rename to ports/stm32/dma.h
index d8b11ca3a..55fb62175 100644
--- a/stmhal/dma.h
+++ b/ports/stm32/dma.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/extint.c b/ports/stm32/extint.c
similarity index 99%
rename from stmhal/extint.c
rename to ports/stm32/extint.c
index 70023557f..41943f1cd 100644
--- a/stmhal/extint.c
+++ b/ports/stm32/extint.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -83,7 +83,7 @@
// TODO Add python method to change callback object.
-#define EXTI_OFFSET (EXTI_BASE - PERIPH_BASE)
+#define EXTI_OFFSET (EXTI_BASE - PERIPH_BASE)
// Macro used to set/clear the bit corresponding to the line in the IMR/EMR
// register in an atomic fashion by using bitband addressing.
diff --git a/stmhal/extint.h b/ports/stm32/extint.h
similarity index 97%
rename from stmhal/extint.h
rename to ports/stm32/extint.h
index 0eae8942c..846790b9b 100644
--- a/stmhal/extint.h
+++ b/ports/stm32/extint.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/fatfs_port.c b/ports/stm32/fatfs_port.c
similarity index 100%
rename from stmhal/fatfs_port.c
rename to ports/stm32/fatfs_port.c
diff --git a/stmhal/flash.c b/ports/stm32/flash.c
similarity index 99%
rename from stmhal/flash.c
rename to ports/stm32/flash.c
index e374be0e5..bebb3a161 100644
--- a/stmhal/flash.c
+++ b/ports/stm32/flash.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/flash.h b/ports/stm32/flash.h
similarity index 95%
rename from stmhal/flash.h
rename to ports/stm32/flash.h
index c5b5bf352..688e70a3c 100644
--- a/stmhal/flash.h
+++ b/ports/stm32/flash.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/font_petme128_8x8.h b/ports/stm32/font_petme128_8x8.h
similarity index 98%
rename from stmhal/font_petme128_8x8.h
rename to ports/stm32/font_petme128_8x8.h
index f27277760..8b0cc9cb0 100644
--- a/stmhal/font_petme128_8x8.h
+++ b/ports/stm32/font_petme128_8x8.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/gccollect.c b/ports/stm32/gccollect.c
similarity index 96%
rename from stmhal/gccollect.c
rename to ports/stm32/gccollect.c
index d7223dedc..cdec2a136 100644
--- a/stmhal/gccollect.c
+++ b/ports/stm32/gccollect.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/obj.h"
#include "py/gc.h"
#include "py/mpthread.h"
diff --git a/stmhal/gccollect.h b/ports/stm32/gccollect.h
similarity index 95%
rename from stmhal/gccollect.h
rename to ports/stm32/gccollect.h
index 2cb32a8d4..1b64a51a6 100644
--- a/stmhal/gccollect.h
+++ b/ports/stm32/gccollect.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/gchelper.s b/ports/stm32/gchelper.s
similarity index 100%
rename from stmhal/gchelper.s
rename to ports/stm32/gchelper.s
diff --git a/stmhal/help.c b/ports/stm32/help.c
similarity index 97%
rename from stmhal/help.c
rename to ports/stm32/help.c
index 83ef7e596..f9d97b70d 100644
--- a/stmhal/help.c
+++ b/ports/stm32/help.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,7 +26,7 @@
#include "py/builtin.h"
-const char *stmhal_help_text =
+const char stm32_help_text[] =
"Welcome to MicroPython!\n"
"\n"
"For online help please visit http://micropython.org/help/.\n"
diff --git a/stmhal/i2c.c b/ports/stm32/i2c.c
similarity index 95%
rename from stmhal/i2c.c
rename to ports/stm32/i2c.c
index f77222715..b22787cab 100644
--- a/stmhal/i2c.c
+++ b/ports/stm32/i2c.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "irq.h"
@@ -511,9 +510,9 @@ STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
-STATIC inline bool in_master_mode(pyb_i2c_obj_t *self) { return self->i2c->Init.OwnAddress1 == PYB_I2C_MASTER_ADDRESS; }
+static inline bool in_master_mode(pyb_i2c_obj_t *self) { return self->i2c->Init.OwnAddress1 == PYB_I2C_MASTER_ADDRESS; }
STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_i2c_obj_t *self = self_in;
@@ -552,7 +551,7 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
/// - `addr` is the 7-bit address (only sensible for a slave)
/// - `baudrate` is the SCL clock rate (only sensible for a master)
/// - `gencall` is whether to support general call mode
-STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_INT, {.u_int = PYB_I2C_MASTER} },
{ MP_QSTR_addr, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0x12} },
@@ -650,7 +649,7 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
return (mp_obj_t)i2c_obj;
}
-STATIC mp_obj_t pyb_i2c_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_i2c_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init);
@@ -670,7 +669,7 @@ STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) {
pyb_i2c_obj_t *self = self_in;
if (!in_master_mode(self)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master"));
+ mp_raise_TypeError("I2C must be a master");
}
mp_uint_t i2c_addr = mp_obj_get_int(i2c_addr_o) << 1;
@@ -693,18 +692,15 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
pyb_i2c_obj_t *self = self_in;
if (!in_master_mode(self)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master"));
+ mp_raise_TypeError("I2C must be a master");
}
mp_obj_t list = mp_obj_new_list(0, NULL);
for (uint addr = 0x08; addr <= 0x77; addr++) {
- for (int i = 0; i < 10; i++) {
- HAL_StatusTypeDef status = HAL_I2C_IsDeviceReady(self->i2c, addr << 1, 10, 200);
- if (status == HAL_OK) {
- mp_obj_list_append(list, mp_obj_new_int(addr));
- break;
- }
+ HAL_StatusTypeDef status = HAL_I2C_IsDeviceReady(self->i2c, addr << 1, 1, 200);
+ if (status == HAL_OK) {
+ mp_obj_list_append(list, MP_OBJ_NEW_SMALL_INT(addr));
}
}
@@ -720,7 +716,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan);
/// - `timeout` is the timeout in milliseconds to wait for the send
///
/// Return value: `None`.
-STATIC mp_obj_t pyb_i2c_send(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_addr, MP_ARG_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} },
@@ -754,7 +750,7 @@ STATIC mp_obj_t pyb_i2c_send(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
if (use_dma) {
dma_deinit(self->tx_dma_descr);
}
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "addr argument required"));
+ mp_raise_TypeError("addr argument required");
}
mp_uint_t i2c_addr = args[1].u_int << 1;
if (!use_dma) {
@@ -800,7 +796,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_send_obj, 1, pyb_i2c_send);
///
/// Return value: if `recv` is an integer then a new buffer of the bytes received,
/// otherwise the same buffer that was passed in to `recv`.
-STATIC mp_obj_t pyb_i2c_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_recv, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_addr, MP_ARG_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} },
@@ -830,7 +826,7 @@ STATIC mp_obj_t pyb_i2c_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
HAL_StatusTypeDef status;
if (in_master_mode(self)) {
if (args[1].u_int == PYB_I2C_MASTER_ADDRESS) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "addr argument required"));
+ mp_raise_TypeError("addr argument required");
}
mp_uint_t i2c_addr = args[1].u_int << 1;
if (!use_dma) {
@@ -890,14 +886,14 @@ STATIC const mp_arg_t pyb_i2c_mem_read_allowed_args[] = {
{ MP_QSTR_addr_size, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
};
-STATIC mp_obj_t pyb_i2c_mem_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_mem_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
pyb_i2c_obj_t *self = pos_args[0];
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args), pyb_i2c_mem_read_allowed_args, args);
if (!in_master_mode(self)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master"));
+ mp_raise_TypeError("I2C must be a master");
}
// get the buffer to read into
@@ -958,14 +954,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read);
///
/// Returns `None`.
/// This is only valid in master mode.
-STATIC mp_obj_t pyb_i2c_mem_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_i2c_mem_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args (same as mem_read)
pyb_i2c_obj_t *self = pos_args[0];
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args), pyb_i2c_mem_read_allowed_args, args);
if (!in_master_mode(self)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master"));
+ mp_raise_TypeError("I2C must be a master");
}
// get the buffer to write from
diff --git a/stmhal/i2c.h b/ports/stm32/i2c.h
similarity index 96%
rename from stmhal/i2c.h
rename to ports/stm32/i2c.h
index eda076e82..6affe3973 100644
--- a/stmhal/i2c.h
+++ b/ports/stm32/i2c.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/irq.c b/ports/stm32/irq.c
similarity index 96%
rename from stmhal/irq.c
rename to ports/stm32/irq.c
index 44758e11b..7298a4b50 100644
--- a/stmhal/irq.c
+++ b/ports/stm32/irq.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,7 +24,6 @@
* THE SOFTWARE.
*/
-#include "py/nlr.h"
#include "py/obj.h"
#include "py/mphal.h"
#include "irq.h"
diff --git a/stmhal/irq.h b/ports/stm32/irq.h
similarity index 98%
rename from stmhal/irq.h
rename to ports/stm32/irq.h
index 8d44b50ed..2cf58639e 100644
--- a/stmhal/irq.h
+++ b/ports/stm32/irq.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/lcd.c b/ports/stm32/lcd.c
similarity index 98%
rename from stmhal/lcd.c
rename to ports/stm32/lcd.c
index cdf9fa0d1..488df1699 100644
--- a/stmhal/lcd.c
+++ b/ports/stm32/lcd.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include "py/mphal.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#if MICROPY_HW_HAS_LCD
@@ -421,7 +420,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_get_obj, pyb_lcd_get);
/// Set the pixel at `(x, y)` to the given colour (0 or 1).
///
/// This method writes to the hidden buffer. Use `show()` to show the buffer.
-STATIC mp_obj_t pyb_lcd_pixel(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_lcd_pixel(size_t n_args, const mp_obj_t *args) {
pyb_lcd_obj_t *self = args[0];
int x = mp_obj_get_int(args[1]);
int y = mp_obj_get_int(args[2]);
@@ -442,7 +441,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_pixel_obj, 4, 4, pyb_lcd_pixe
/// Draw the given text to the position `(x, y)` using the given colour (0 or 1).
///
/// This method writes to the hidden buffer. Use `show()` to show the buffer.
-STATIC mp_obj_t pyb_lcd_text(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_lcd_text(size_t n_args, const mp_obj_t *args) {
// extract arguments
pyb_lcd_obj_t *self = args[0];
size_t len;
diff --git a/stmhal/lcd.h b/ports/stm32/lcd.h
similarity index 94%
rename from stmhal/lcd.h
rename to ports/stm32/lcd.h
index be4f6ed25..c0d9bd97d 100644
--- a/stmhal/lcd.h
+++ b/ports/stm32/lcd.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/led.c b/ports/stm32/led.c
similarity index 98%
rename from stmhal/led.c
rename to ports/stm32/led.c
index 4b9895fc5..9bbcaa6b3 100644
--- a/stmhal/led.c
+++ b/ports/stm32/led.c
@@ -26,7 +26,6 @@
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "timer.h"
@@ -279,7 +278,7 @@ void led_debug(int n, int delay) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_led_obj_t *self = self_in;
@@ -334,7 +333,7 @@ mp_obj_t led_obj_toggle(mp_obj_t self_in) {
/// Get or set the LED intensity. Intensity ranges between 0 (off) and 255 (full on).
/// If no argument is given, return the LED intensity.
/// If an argument is given, set the LED intensity and return `None`.
-mp_obj_t led_obj_intensity(mp_uint_t n_args, const mp_obj_t *args) {
+mp_obj_t led_obj_intensity(size_t n_args, const mp_obj_t *args) {
pyb_led_obj_t *self = args[0];
if (n_args == 1) {
return mp_obj_new_int(led_get_intensity(self->led_id));
diff --git a/stmhal/led.h b/ports/stm32/led.h
similarity index 95%
rename from stmhal/led.h
rename to ports/stm32/led.h
index fc9348181..f1b05d1e2 100644
--- a/stmhal/led.h
+++ b/ports/stm32/led.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/machine_i2c.c b/ports/stm32/machine_i2c.c
similarity index 100%
rename from stmhal/machine_i2c.c
rename to ports/stm32/machine_i2c.c
diff --git a/stmhal/main.c b/ports/stm32/main.c
similarity index 99%
rename from stmhal/main.c
rename to ports/stm32/main.c
index 566c2db07..16279d073 100644
--- a/stmhal/main.c
+++ b/ports/stm32/main.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -112,7 +112,7 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
}
#endif
-STATIC mp_obj_t pyb_main(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_opt, MP_ARG_INT, {.u_int = 0} }
};
@@ -511,7 +511,7 @@ int main(void) {
// GC init
gc_init(&_heap_start, &_heap_end);
- // Micro Python init
+ // MicroPython init
mp_init();
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
diff --git a/stmhal/make-stmconst.py b/ports/stm32/make-stmconst.py
similarity index 92%
rename from stmhal/make-stmconst.py
rename to ports/stm32/make-stmconst.py
index 9bb7a0569..3a8e22b38 100644
--- a/stmhal/make-stmconst.py
+++ b/ports/stm32/make-stmconst.py
@@ -1,10 +1,7 @@
"""
-Read in the cmsis/devinc/stm32f405xx.h header, extract relevant constants,
-and create modstmconst.c.
-
-This is not part of the automatic build process because stm32f405xx.h isn't
-expected to change. After generating the file, some manual intervention is
-needed to copy the new qstr definitions to qstrdefsport.h.
+This script reads in the given CMSIS device include file (eg stm32f405xx.h),
+extracts relevant peripheral constants, and creates qstrs, mpz's and constants
+for the stm module.
"""
from __future__ import print_function
@@ -128,14 +125,14 @@ def parse_file(filename):
def print_int_obj(val, needed_mpzs):
if -0x40000000 <= val < 0x40000000:
- print('MP_OBJ_NEW_SMALL_INT(%#x)' % val, end='')
+ print('MP_ROM_INT(%#x)' % val, end='')
else:
- print('(mp_obj_t)&mpz_%08x' % val, end='')
+ print('MP_ROM_PTR(&mpz_%08x)' % val, end='')
needed_mpzs.add(val)
def print_periph(periph_name, periph_val, needed_qstrs, needed_mpzs):
qstr = periph_name.upper()
- print('{ MP_OBJ_NEW_QSTR(MP_QSTR_%s), ' % qstr, end='')
+ print('{ MP_ROM_QSTR(MP_QSTR_%s), ' % qstr, end='')
print_int_obj(periph_val, needed_mpzs)
print(' },')
needed_qstrs.add(qstr)
@@ -144,7 +141,7 @@ def print_regs(reg_name, reg_defs, needed_qstrs, needed_mpzs):
reg_name = reg_name.upper()
for r in reg_defs:
qstr = reg_name + '_' + r[0]
- print('{ MP_OBJ_NEW_QSTR(MP_QSTR_%s), ' % qstr, end='')
+ print('{ MP_ROM_QSTR(MP_QSTR_%s), ' % qstr, end='')
print_int_obj(r[1], needed_mpzs)
print(' }, // %s-bits, %s' % (r[2], r[3]))
needed_qstrs.add(qstr)
@@ -242,7 +239,7 @@ def main():
#print("#define MOD_STM_CONST_MODULES \\")
#for mod_lower, mod_upper in modules:
- # print(" { MP_OBJ_NEW_QSTR(MP_QSTR_%s), (mp_obj_t)&stm_%s_obj }, \\" % (mod_upper, mod_lower))
+ # print(" { MP_ROM_QSTR(MP_QSTR_%s), MP_ROM_PTR(&stm_%s_obj) }, \\" % (mod_upper, mod_lower))
print("")
@@ -254,7 +251,7 @@ def main():
for mpz in sorted(needed_mpzs):
assert 0 <= mpz <= 0xffffffff
print('STATIC const mp_obj_int_t mpz_%08x = {{&mp_type_int}, '
- '{.neg=0, .fixed_dig=1, .alloc=2, .len=2, ' '.dig=(uint16_t[]){%#x, %#x}}};'
+ '{.neg=0, .fixed_dig=1, .alloc=2, .len=2, ' '.dig=(uint16_t*)(const uint16_t[]){%#x, %#x}}};'
% (mpz, mpz & 0xffff, (mpz >> 16) & 0xffff), file=mpz_file)
if __name__ == "__main__":
diff --git a/stmhal/modmachine.c b/ports/stm32/modmachine.c
similarity index 88%
rename from stmhal/modmachine.c
rename to ports/stm32/modmachine.c
index c5444ec98..8c59758fa 100644
--- a/stmhal/modmachine.c
+++ b/ports/stm32/modmachine.c
@@ -52,12 +52,9 @@
#include "spi.h"
#include "uart.h"
#include "wdt.h"
+#include "genhdr/pllfreqtable.h"
-#if defined(MCU_SERIES_F4)
-// the HAL does not define these constants
-#define RCC_CSR_IWDGRSTF (0x20000000)
-#define RCC_CSR_PINRSTF (0x04000000)
-#elif defined(MCU_SERIES_L4)
+#if defined(MCU_SERIES_L4)
// L4 does not have a POR, so use BOR instead
#define RCC_CSR_PORRSTF RCC_CSR_BORRSTF
#endif
@@ -77,6 +74,12 @@ void machine_init(void) {
reset_cause = PYB_RESET_DEEPSLEEP;
PWR->CR |= PWR_CR_CSBF;
} else
+ #elif defined(MCU_SERIES_F7)
+ if (PWR->CSR1 & PWR_CSR1_SBF) {
+ // came out of standby
+ reset_cause = PYB_RESET_DEEPSLEEP;
+ PWR->CR1 |= PWR_CR1_CSBF;
+ } else
#endif
{
// get reset cause from RCC flags
@@ -98,7 +101,7 @@ void machine_init(void) {
// machine.info([dump_alloc_table])
// Print out lots of information about the board.
-STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
// get and print unique id; 96 bits
{
byte *id = (byte*)MP_HAL_UNIQUE_ID_ADDRESS;
@@ -202,6 +205,11 @@ STATIC NORETURN mp_obj_t machine_bootloader(void) {
HAL_RCC_DeInit();
HAL_DeInit();
+ #if (__MPU_PRESENT == 1)
+ // MPU must be disabled for bootloader to function correctly
+ HAL_MPU_Disable();
+ #endif
+
#if defined(MCU_SERIES_F7)
// arm-none-eabi-gcc 4.9.0 does not correctly inline this
// MSP function, so we write it out explicitly here.
@@ -243,7 +251,7 @@ STATIC mp_uint_t machine_freq_calc_apb_div(mp_uint_t wanted_div) {
else if (wanted_div <= 8) { return RCC_HCLK_DIV8; }
else { return RCC_SYSCLK_DIV16; }
}
-STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
// get
mp_obj_t tuple[4] = {
@@ -258,68 +266,38 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
mp_int_t wanted_sysclk = mp_obj_get_int(args[0]) / 1000000;
#if defined(MCU_SERIES_L4)
- nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError, "machine.freq set not supported yet"));
+ mp_raise_NotImplementedError("machine.freq set not supported yet");
#endif
// default PLL parameters that give 48MHz on PLL48CK
uint32_t m = HSE_VALUE / 1000000, n = 336, p = 2, q = 7;
uint32_t sysclk_source;
- // the following logic assumes HSE < HSI
- if (HSE_VALUE / 1000000 <= wanted_sysclk && wanted_sysclk < HSI_VALUE / 1000000) {
- // use HSE as SYSCLK
- sysclk_source = RCC_SYSCLKSOURCE_HSE;
- } else if (HSI_VALUE / 1000000 <= wanted_sysclk && wanted_sysclk < 24) {
- // use HSI as SYSCLK
- sysclk_source = RCC_SYSCLKSOURCE_HSI;
- } else {
- // search for a valid PLL configuration that keeps USB at 48MHz
- for (; wanted_sysclk > 0; wanted_sysclk--) {
- for (p = 2; p <= 8; p += 2) {
- // compute VCO_OUT
- mp_uint_t vco_out = wanted_sysclk * p;
- // make sure VCO_OUT is between 192MHz and 432MHz
- if (vco_out < 192 || vco_out > 432) {
- continue;
- }
- // make sure Q is an integer
- if (vco_out % 48 != 0) {
- continue;
- }
- // solve for Q to get PLL48CK at 48MHz
- q = vco_out / 48;
- // make sure Q is in range
- if (q < 2 || q > 15) {
- continue;
- }
- // make sure N/M is an integer
- if (vco_out % (HSE_VALUE / 1000000) != 0) {
- continue;
- }
- // solve for N/M
- mp_uint_t n_by_m = vco_out / (HSE_VALUE / 1000000);
- // solve for M, making sure VCO_IN (=HSE/M) is between 1MHz and 2MHz
- m = 192 / n_by_m;
- while (m < (HSE_VALUE / 2000000) || n_by_m * m < 192) {
- m += 1;
- }
- if (m > (HSE_VALUE / 1000000)) {
- continue;
- }
- // solve for N
- n = n_by_m * m;
- // make sure N is in range
- if (n < 192 || n > 432) {
- continue;
- }
-
- // found values!
+ // search for a valid PLL configuration that keeps USB at 48MHz
+ for (const uint16_t *pll = &pll_freq_table[MP_ARRAY_SIZE(pll_freq_table) - 1]; pll >= &pll_freq_table[0]; --pll) {
+ uint32_t sys = *pll & 0xff;
+ if (sys <= wanted_sysclk) {
+ m = (*pll >> 10) & 0x3f;
+ p = ((*pll >> 7) & 0x6) + 2;
+ if (m == 0) {
+ // special entry for using HSI directly
+ sysclk_source = RCC_SYSCLKSOURCE_HSI;
+ goto set_clk;
+ } else if (m == 1) {
+ // special entry for using HSE directly
+ sysclk_source = RCC_SYSCLKSOURCE_HSE;
+ goto set_clk;
+ } else {
+ // use PLL
sysclk_source = RCC_SYSCLKSOURCE_PLLCLK;
+ uint32_t vco_out = sys * p;
+ n = vco_out * m / (HSE_VALUE / 1000000);
+ q = vco_out / 48;
goto set_clk;
}
}
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "can't make valid freq"));
}
+ mp_raise_ValueError("can't make valid freq");
set_clk:
//printf("%lu %lu %lu %lu %lu\n", sysclk_source, m, n, p, q);
@@ -381,6 +359,21 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
// set PLL as system clock source if wanted
if (sysclk_source == RCC_SYSCLKSOURCE_PLLCLK) {
+ #if defined(MCU_SERIES_F7)
+ // if possible, scale down the internal voltage regulator to save power
+ uint32_t volt_scale;
+ if (wanted_sysclk <= 151000000) {
+ volt_scale = PWR_REGULATOR_VOLTAGE_SCALE3;
+ } else if (wanted_sysclk <= 180000000) {
+ volt_scale = PWR_REGULATOR_VOLTAGE_SCALE2;
+ } else {
+ volt_scale = PWR_REGULATOR_VOLTAGE_SCALE1;
+ }
+ if (HAL_PWREx_ControlVoltageScaling(volt_scale) != HAL_OK) {
+ goto fail;
+ }
+ #endif
+
#if !defined(MICROPY_HW_FLASH_LATENCY)
#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_5
#endif
@@ -450,7 +443,11 @@ STATIC mp_obj_t machine_sleep(void) {
// takes longer to wake but reduces stop current
HAL_PWREx_EnableFlashPowerDown();
+ # if defined(MCU_SERIES_F7)
+ HAL_PWR_EnterSTOPMode((PWR_CR1_LPDS | PWR_CR1_LPUDS | PWR_CR1_FPDS | PWR_CR1_UDEN), PWR_STOPENTRY_WFI);
+ # else
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
+ #endif
// reconfigure the system clock after waking up
@@ -478,7 +475,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep);
STATIC mp_obj_t machine_deepsleep(void) {
rtc_init_finalise();
-#if defined(MCU_SERIES_F7) || defined(MCU_SERIES_L4)
+#if defined(MCU_SERIES_L4)
printf("machine.deepsleep not supported yet\n");
#else
// We need to clear the PWR wake-up-flag before entering standby, since
@@ -500,8 +497,15 @@ STATIC mp_obj_t machine_deepsleep(void) {
// clear RTC wake-up flags
RTC->ISR &= ~(RTC_ISR_ALRAF | RTC_ISR_ALRBF | RTC_ISR_WUTF | RTC_ISR_TSF);
+ #if defined(MCU_SERIES_F7)
+ // disable wake-up flags
+ PWR->CSR2 &= ~(PWR_CSR2_EWUP6 | PWR_CSR2_EWUP5 | PWR_CSR2_EWUP4 | PWR_CSR2_EWUP3 | PWR_CSR2_EWUP2 | PWR_CSR2_EWUP1);
+ // clear global wake-up flag
+ PWR->CR2 |= PWR_CR2_CWUPF6 | PWR_CR2_CWUPF5 | PWR_CR2_CWUPF4 | PWR_CR2_CWUPF3 | PWR_CR2_CWUPF2 | PWR_CR2_CWUPF1;
+ #else
// clear global wake-up flag
PWR->CR |= PWR_CR_CWUF;
+ #endif
// enable previously-enabled RTC interrupts
RTC->CR |= save_irq_bits;
diff --git a/stmhal/modmachine.h b/ports/stm32/modmachine.h
similarity index 97%
rename from stmhal/modmachine.h
rename to ports/stm32/modmachine.h
index ac39f854e..77668695f 100644
--- a/stmhal/modmachine.h
+++ b/ports/stm32/modmachine.h
@@ -26,8 +26,6 @@
#ifndef MICROPY_INCLUDED_STMHAL_MODMACHINE_H
#define MICROPY_INCLUDED_STMHAL_MODMACHINE_H
-#include "py/mpstate.h"
-#include "py/nlr.h"
#include "py/obj.h"
void machine_init(void);
diff --git a/stmhal/modnetwork.c b/ports/stm32/modnetwork.c
similarity index 97%
rename from stmhal/modnetwork.c
rename to ports/stm32/modnetwork.c
index 09a80ef3c..642174532 100644
--- a/stmhal/modnetwork.c
+++ b/ports/stm32/modnetwork.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/objlist.h"
#include "py/runtime.h"
#include "modnetwork.h"
diff --git a/stmhal/modnetwork.h b/ports/stm32/modnetwork.h
similarity index 98%
rename from stmhal/modnetwork.h
rename to ports/stm32/modnetwork.h
index 83e4255d5..ecda94da4 100644
--- a/stmhal/modnetwork.h
+++ b/ports/stm32/modnetwork.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/modnwcc3k.c b/ports/stm32/modnwcc3k.c
similarity index 98%
rename from stmhal/modnwcc3k.c
rename to ports/stm32/modnwcc3k.c
index 957d74e6e..8cc0a613d 100644
--- a/stmhal/modnwcc3k.c
+++ b/ports/stm32/modnwcc3k.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -30,7 +30,6 @@
// CC3000 defines its own ENOBUFS (different to standard one!)
#undef ENOBUFS
-#include "py/nlr.h"
#include "py/objtuple.h"
#include "py/objlist.h"
#include "py/stream.h"
@@ -126,7 +125,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin
if (ip == 0) {
// unknown host
- return MP_ENOENT;
+ return -2;
}
out_ip[0] = ip >> 24;
@@ -412,7 +411,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request
}
/******************************************************************************/
-// Micro Python bindings; CC3K class
+// MicroPython bindings; CC3K class
typedef struct _cc3k_obj_t {
mp_obj_base_t base;
@@ -464,7 +463,7 @@ STATIC mp_obj_t cc3k_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
}
// method connect(ssid, key=None, *, security=WPA2, bssid=None)
-STATIC mp_obj_t cc3k_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t cc3k_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_key, MP_ARG_OBJ, {.u_obj = mp_const_none} },
diff --git a/stmhal/modnwwiznet5k.c b/ports/stm32/modnwwiznet5k.c
similarity index 89%
rename from stmhal/modnwwiznet5k.c
rename to ports/stm32/modnwwiznet5k.c
index 4752cdc0b..763137c70 100644
--- a/stmhal/modnwwiznet5k.c
+++ b/ports/stm32/modnwwiznet5k.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,9 +28,9 @@
#include
#include
-#include "py/nlr.h"
#include "py/objlist.h"
#include "py/runtime.h"
+#include "py/stream.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "lib/netutils/netutils.h"
@@ -93,7 +93,7 @@ STATIC int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len,
return 0;
} else {
// failure
- return MP_ENOENT;
+ return -2;
}
}
@@ -174,11 +174,7 @@ STATIC int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_
int sr = getSn_SR((uint8_t)socket->u_param.fileno);
if (sr == SOCK_ESTABLISHED) {
socket2->u_param = socket->u_param;
- // TODO need to populate this with the correct values
- ip[0] = 0;
- ip[1] = 0;
- ip[2] = 0;
- ip[3] = 0;
+ getSn_DIPR((uint8_t)socket2->u_param.fileno, ip);
*port = getSn_PORT(socket2->u_param.fileno);
// WIZnet turns the listening socket into the client socket, so we
@@ -213,7 +209,10 @@ STATIC int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, m
}
// now connect
+ MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(connect)(socket->u_param.fileno, ip, port);
+ MP_THREAD_GIL_ENTER();
+
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
@@ -225,7 +224,10 @@ STATIC int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, m
}
STATIC mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) {
+ MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(send)(socket->u_param.fileno, (byte*)buf, len);
+ MP_THREAD_GIL_ENTER();
+
// TODO convert Wiz errno's to POSIX ones
if (ret < 0) {
wiznet5k_socket_close(socket);
@@ -236,7 +238,10 @@ STATIC mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const by
}
STATIC mp_uint_t wiznet5k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) {
+ MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(recv)(socket->u_param.fileno, buf, len);
+ MP_THREAD_GIL_ENTER();
+
// TODO convert Wiz errno's to POSIX ones
if (ret < 0) {
wiznet5k_socket_close(socket);
@@ -254,7 +259,10 @@ STATIC mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const
}
}
+ MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(sendto)(socket->u_param.fileno, (byte*)buf, len, ip, port);
+ MP_THREAD_GIL_ENTER();
+
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
@@ -265,7 +273,9 @@ STATIC mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const
STATIC mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
uint16_t port2;
+ MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(recvfrom)(socket->u_param.fileno, buf, len, ip, &port2);
+ MP_THREAD_GIL_ENTER();
*port = port2;
if (ret < 0) {
wiznet5k_socket_close(socket);
@@ -296,9 +306,19 @@ STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_
}
STATIC int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) {
- // TODO
- *_errno = MP_EINVAL;
- return -1;
+ if (request == MP_STREAM_POLL) {
+ int ret = 0;
+ if (arg & MP_STREAM_POLL_RD && getSn_RX_RSR(socket->u_param.fileno) != 0) {
+ ret |= MP_STREAM_POLL_RD;
+ }
+ if (arg & MP_STREAM_POLL_WR && getSn_TX_FSR(socket->u_param.fileno) != 0) {
+ ret |= MP_STREAM_POLL_WR;
+ }
+ return ret;
+ } else {
+ *_errno = MP_EINVAL;
+ return MP_STREAM_ERROR;
+ }
}
#if 0
@@ -314,7 +334,7 @@ STATIC mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in) {
#endif
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
/// \classmethod \constructor(spi, pin_cs, pin_rst)
/// Create and return a WIZNET5K object.
@@ -337,7 +357,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size
wiznet5k_obj.spi->Init.CLKPolarity = SPI_POLARITY_LOW; // clock is low when idle
wiznet5k_obj.spi->Init.CLKPhase = SPI_PHASE_1EDGE; // data latched on first edge, which is rising edge for low-idle
wiznet5k_obj.spi->Init.NSS = SPI_NSS_SOFT;
- wiznet5k_obj.spi->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; // clock freq = f_PCLK / this_prescale_value; Wiz820i can do up to 80MHz
+ wiznet5k_obj.spi->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; // clock freq = f_PCLK / this_prescale_value; Wiz820i can do up to 80MHz
wiznet5k_obj.spi->Init.FirstBit = SPI_FIRSTBIT_MSB;
wiznet5k_obj.spi->Init.TIMode = SPI_TIMODE_DISABLED;
wiznet5k_obj.spi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
@@ -389,7 +409,12 @@ STATIC mp_obj_t wiznet5k_regs(mp_obj_t self_in) {
if (i % 16 == 0) {
printf("\n %04x:", i);
}
- printf(" %02x", WIZCHIP_READ(i));
+ #if MICROPY_PY_WIZNET5K == 5200
+ uint32_t reg = i;
+ #else
+ uint32_t reg = _W5500_IO_BASE_ | i << 8;
+ #endif
+ printf(" %02x", WIZCHIP_READ(reg));
}
for (int sn = 0; sn < 4; ++sn) {
printf("\nWiz SREG[%d]:", sn);
@@ -397,7 +422,12 @@ STATIC mp_obj_t wiznet5k_regs(mp_obj_t self_in) {
if (i % 16 == 0) {
printf("\n %04x:", i);
}
- printf(" %02x", WIZCHIP_READ(WIZCHIP_SREG_ADDR(sn, i)));
+ #if MICROPY_PY_WIZNET5K == 5200
+ uint32_t reg = WIZCHIP_SREG_ADDR(sn, i);
+ #else
+ uint32_t reg = _W5500_IO_BASE_ | i << 8 | WIZCHIP_SREG_BLOCK(sn) << 3;
+ #endif
+ printf(" %02x", WIZCHIP_READ(reg));
}
}
printf("\n");
@@ -405,9 +435,15 @@ STATIC mp_obj_t wiznet5k_regs(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_regs_obj, wiznet5k_regs);
+STATIC mp_obj_t wiznet5k_isconnected(mp_obj_t self_in) {
+ (void)self_in;
+ return mp_obj_new_bool(wizphy_getphylink() == PHY_LINK_ON);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_isconnected_obj, wiznet5k_isconnected);
+
/// \method ifconfig([(ip, subnet, gateway, dns)])
/// Get/set IP address, subnet mask, gateway and DNS.
-STATIC mp_obj_t wiznet5k_ifconfig(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) {
wiz_NetInfo netinfo;
ctlnetwork(CN_GET_NETINFO, &netinfo);
if (n_args == 1) {
@@ -436,6 +472,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ifconfig_obj, 1, 2, wiznet5k
STATIC const mp_rom_map_elem_t wiznet5k_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_regs), MP_ROM_PTR(&wiznet5k_regs_obj) },
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&wiznet5k_ifconfig_obj) },
+ { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&wiznet5k_isconnected_obj) },
};
STATIC MP_DEFINE_CONST_DICT(wiznet5k_locals_dict, wiznet5k_locals_dict_table);
diff --git a/stmhal/modpyb.c b/ports/stm32/modpyb.c
similarity index 89%
rename from stmhal/modpyb.c
rename to ports/stm32/modpyb.c
index 7322c6a5b..81cbdcc19 100644
--- a/stmhal/modpyb.c
+++ b/ports/stm32/modpyb.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,9 +27,7 @@
#include
#include
-#include "py/mpstate.h"
-#include "py/nlr.h"
-#include "py/obj.h"
+#include "py/runtime.h"
#include "py/gc.h"
#include "py/builtin.h"
#include "py/mphal.h"
@@ -106,6 +104,28 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros);
MP_DECLARE_CONST_FUN_OBJ_KW(pyb_main_obj); // defined in main.c
+// Get or set the UART object that the REPL is repeated on.
+// This is a legacy function, use of uos.dupterm is preferred.
+STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) {
+ if (n_args == 0) {
+ if (MP_STATE_PORT(pyb_stdio_uart) == NULL) {
+ return mp_const_none;
+ } else {
+ return MP_STATE_PORT(pyb_stdio_uart);
+ }
+ } else {
+ if (args[0] == mp_const_none) {
+ MP_STATE_PORT(pyb_stdio_uart) = NULL;
+ } else if (mp_obj_get_type(args[0]) == &pyb_uart_type) {
+ MP_STATE_PORT(pyb_stdio_uart) = args[0];
+ } else {
+ mp_raise_ValueError("need a UART object");
+ }
+ return mp_const_none;
+ }
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uart);
+
STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) },
@@ -128,7 +148,7 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&machine_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_standby), MP_ROM_PTR(&machine_deepsleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&pyb_main_obj) },
- { MP_ROM_QSTR(MP_QSTR_repl_uart), MP_ROM_PTR(&mod_os_dupterm_obj) },
+ { MP_ROM_QSTR(MP_QSTR_repl_uart), MP_ROM_PTR(&pyb_repl_uart_obj) },
{ MP_ROM_QSTR(MP_QSTR_usb_mode), MP_ROM_PTR(&pyb_usb_mode_obj) },
{ MP_ROM_QSTR(MP_QSTR_hid_mouse), MP_ROM_PTR(&pyb_usb_hid_mouse_obj) },
diff --git a/stmhal/modstm.c b/ports/stm32/modstm.c
similarity index 96%
rename from stmhal/modstm.c
rename to ports/stm32/modstm.c
index eabbf08e4..2084c0aa0 100644
--- a/stmhal/modstm.c
+++ b/ports/stm32/modstm.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/ports/stm32/modules/lcd160cr.py b/ports/stm32/modules/lcd160cr.py
new file mode 120000
index 000000000..9e63f1d23
--- /dev/null
+++ b/ports/stm32/modules/lcd160cr.py
@@ -0,0 +1 @@
+../../../drivers/display/lcd160cr.py
\ No newline at end of file
diff --git a/ports/stm32/modules/lcd160cr_test.py b/ports/stm32/modules/lcd160cr_test.py
new file mode 120000
index 000000000..5f5bcc128
--- /dev/null
+++ b/ports/stm32/modules/lcd160cr_test.py
@@ -0,0 +1 @@
+../../../drivers/display/lcd160cr_test.py
\ No newline at end of file
diff --git a/ports/stm32/modules/onewire.py b/ports/stm32/modules/onewire.py
new file mode 120000
index 000000000..33f30e84f
--- /dev/null
+++ b/ports/stm32/modules/onewire.py
@@ -0,0 +1 @@
+../../../drivers/onewire/onewire.py
\ No newline at end of file
diff --git a/stmhal/moduos.c b/ports/stm32/moduos.c
similarity index 85%
rename from stmhal/moduos.c
rename to ports/stm32/moduos.c
index ece6019fb..f6e1483d3 100644
--- a/stmhal/moduos.c
+++ b/ports/stm32/moduos.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,13 +27,13 @@
#include
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/objtuple.h"
#include "py/objstr.h"
#include "lib/timeutils/timeutils.h"
#include "lib/oofatfs/ff.h"
#include "lib/oofatfs/diskio.h"
+#include "extmod/misc.h"
#include "extmod/vfs.h"
#include "extmod/vfs_fat.h"
#include "genhdr/mpversion.h"
@@ -106,28 +106,6 @@ STATIC mp_obj_t os_urandom(mp_obj_t num) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);
#endif
-// Get or set the UART object that the REPL is repeated on.
-// TODO should accept any object with read/write methods.
-STATIC mp_obj_t os_dupterm(mp_uint_t n_args, const mp_obj_t *args) {
- if (n_args == 0) {
- if (MP_STATE_PORT(pyb_stdio_uart) == NULL) {
- return mp_const_none;
- } else {
- return MP_STATE_PORT(pyb_stdio_uart);
- }
- } else {
- if (args[0] == mp_const_none) {
- MP_STATE_PORT(pyb_stdio_uart) = NULL;
- } else if (mp_obj_get_type(args[0]) == &pyb_uart_type) {
- MP_STATE_PORT(pyb_stdio_uart) = args[0];
- } else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "need a UART object"));
- }
- return mp_const_none;
- }
-}
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_os_dupterm_obj, 0, 1, os_dupterm);
-
STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) },
@@ -155,7 +133,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
#endif
// these are MicroPython extensions
- { MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mod_os_dupterm_obj) },
+ { MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_uos_dupterm_obj) },
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
diff --git a/stmhal/modusocket.c b/ports/stm32/modusocket.c
similarity index 89%
rename from stmhal/modusocket.c
rename to ports/stm32/modusocket.c
index 081a322ae..71a237b0d 100644
--- a/stmhal/modusocket.c
+++ b/ports/stm32/modusocket.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/objtuple.h"
#include "py/objlist.h"
#include "py/runtime.h"
@@ -280,7 +279,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
// method socket.setsockopt(level, optname, value)
-STATIC mp_obj_t socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
mod_network_socket_obj_t *self = args[0];
mp_int_t level = mp_obj_get_int(args[1]);
@@ -391,29 +390,48 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
size_t hlen;
const char *host = mp_obj_str_get_data(host_in, &hlen);
mp_int_t port = mp_obj_get_int(port_in);
+ uint8_t out_ip[MOD_NETWORK_IPADDR_BUF_SIZE];
+ bool have_ip = false;
+
+ if (hlen > 0) {
+ // check if host is already in IP form
+ nlr_buf_t nlr;
+ if (nlr_push(&nlr) == 0) {
+ netutils_parse_ipv4_addr(host_in, out_ip, NETUTILS_BIG);
+ have_ip = true;
+ nlr_pop();
+ } else {
+ // swallow exception: host was not in IP form so need to do DNS lookup
+ }
+ }
- // find a NIC that can do a name lookup
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
- mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
- mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
- if (nic_type->gethostbyname != NULL) {
- uint8_t out_ip[MOD_NETWORK_IPADDR_BUF_SIZE];
- int ret = nic_type->gethostbyname(nic, host, hlen, out_ip);
- if (ret != 0) {
- // TODO CPython raises: socket.gaierror: [Errno -2] Name or service not known
- mp_raise_OSError(ret);
+ if (!have_ip) {
+ // find a NIC that can do a name lookup
+ for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
+ mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
+ mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
+ if (nic_type->gethostbyname != NULL) {
+ int ret = nic_type->gethostbyname(nic, host, hlen, out_ip);
+ if (ret != 0) {
+ mp_raise_OSError(ret);
+ }
+ have_ip = true;
+ break;
}
- mp_obj_tuple_t *tuple = mp_obj_new_tuple(5, NULL);
- tuple->items[0] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET);
- tuple->items[1] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM);
- tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);
- tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_);
- tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_BIG);
- return mp_obj_new_list(1, (mp_obj_t*)&tuple);
}
}
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "no available NIC"));
+ if (!have_ip) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "no available NIC"));
+ }
+
+ mp_obj_tuple_t *tuple = mp_obj_new_tuple(5, NULL);
+ tuple->items[0] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET);
+ tuple->items[1] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM);
+ tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);
+ tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_);
+ tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_BIG);
+ return mp_obj_new_list(1, (mp_obj_t*)&tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_usocket_getaddrinfo_obj, mod_usocket_getaddrinfo);
diff --git a/stmhal/modutime.c b/ports/stm32/modutime.c
similarity index 97%
rename from stmhal/modutime.c
rename to ports/stm32/modutime.c
index 58c43a55e..54045f4c5 100644
--- a/stmhal/modutime.c
+++ b/ports/stm32/modutime.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -53,7 +53,7 @@
/// second is 0-59
/// weekday is 0-6 for Mon-Sun.
/// yearday is 1-366
-STATIC mp_obj_t time_localtime(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
if (n_args == 0 || args[0] == mp_const_none) {
// get current date and time
// note: need to call get time then get date to correctly access the registers
diff --git a/stmhal/mpconfigport.h b/ports/stm32/mpconfigport.h
similarity index 79%
rename from stmhal/mpconfigport.h
rename to ports/stm32/mpconfigport.h
index a8ea2f02a..51d442561 100644
--- a/stmhal/mpconfigport.h
+++ b/ports/stm32/mpconfigport.h
@@ -92,7 +92,7 @@
#define MICROPY_PY_BUILTINS_INPUT (1)
#define MICROPY_PY_BUILTINS_POW3 (1)
#define MICROPY_PY_BUILTINS_HELP (1)
-#define MICROPY_PY_BUILTINS_HELP_TEXT stmhal_help_text
+#define MICROPY_PY_BUILTINS_HELP_TEXT stm32_help_text
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
@@ -126,6 +126,7 @@
#define MICROPY_PY_USELECT (1)
#define MICROPY_PY_UTIMEQ (1)
#define MICROPY_PY_UTIME_MP_HAL (1)
+#define MICROPY_PY_OS_DUPTERM (1)
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
@@ -163,7 +164,7 @@
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t machine_module;
@@ -182,59 +183,65 @@ extern const struct _mp_obj_module_t mp_module_network;
extern const struct _mp_obj_module_t mp_module_onewire;
#if MICROPY_PY_USOCKET
-#define SOCKET_BUILTIN_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket },
-#define SOCKET_BUILTIN_MODULE_WEAK_LINKS { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket },
+#define SOCKET_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_usocket) },
+#define SOCKET_BUILTIN_MODULE_WEAK_LINKS { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_module_usocket) },
#else
#define SOCKET_BUILTIN_MODULE
#define SOCKET_BUILTIN_MODULE_WEAK_LINKS
#endif
#if MICROPY_PY_NETWORK
-#define NETWORK_BUILTIN_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mp_module_network },
+#define NETWORK_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_network), MP_ROM_PTR(&mp_module_network) },
#else
#define NETWORK_BUILTIN_MODULE
#endif
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_umachine), (mp_obj_t)&machine_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_stm), (mp_obj_t)&stm_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
+ { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&machine_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_stm), MP_ROM_PTR(&stm_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
+ { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
SOCKET_BUILTIN_MODULE \
NETWORK_BUILTIN_MODULE \
- { MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&mp_module_onewire }, \
+ { MP_ROM_QSTR(MP_QSTR__onewire), MP_ROM_PTR(&mp_module_onewire) }, \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_binascii), (mp_obj_t)&mp_module_ubinascii }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_collections), (mp_obj_t)&mp_module_collections }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_re), (mp_obj_t)&mp_module_ure }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_zlib), (mp_obj_t)&mp_module_uzlib }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_heapq), (mp_obj_t)&mp_module_uheapq }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_hashlib), (mp_obj_t)&mp_module_uhashlib }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_io), (mp_obj_t)&mp_module_io }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&mp_module_uos }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&mp_module_urandom }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_utime }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
+ { MP_ROM_QSTR(MP_QSTR_binascii), MP_ROM_PTR(&mp_module_ubinascii) }, \
+ { MP_ROM_QSTR(MP_QSTR_collections), MP_ROM_PTR(&mp_module_collections) }, \
+ { MP_ROM_QSTR(MP_QSTR_re), MP_ROM_PTR(&mp_module_ure) }, \
+ { MP_ROM_QSTR(MP_QSTR_zlib), MP_ROM_PTR(&mp_module_uzlib) }, \
+ { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) }, \
+ { MP_ROM_QSTR(MP_QSTR_heapq), MP_ROM_PTR(&mp_module_uheapq) }, \
+ { MP_ROM_QSTR(MP_QSTR_hashlib), MP_ROM_PTR(&mp_module_uhashlib) }, \
+ { MP_ROM_QSTR(MP_QSTR_io), MP_ROM_PTR(&mp_module_io) }, \
+ { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&mp_module_uos) }, \
+ { MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&mp_module_urandom) }, \
+ { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_utime) }, \
+ { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_module_uselect) }, \
SOCKET_BUILTIN_MODULE_WEAK_LINKS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \
+ { MP_ROM_QSTR(MP_QSTR_struct), MP_ROM_PTR(&mp_module_ustruct) }, \
+ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \
// extra constants
#define MICROPY_PORT_CONSTANTS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_umachine), (mp_obj_t)&machine_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_stm), (mp_obj_t)&stm_module }, \
+ { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&machine_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
+ { MP_ROM_QSTR(MP_QSTR_stm), MP_ROM_PTR(&stm_module) }, \
#if defined(MCU_SERIES_F7)
#define PYB_EXTI_NUM_VECTORS (24)
+#define MICROPY_HW_MAX_TIMER (17)
#define MICROPY_HW_MAX_UART (8)
+#elif defined(MCU_SERIES_L4)
+#define PYB_EXTI_NUM_VECTORS (23)
+#define MICROPY_HW_MAX_TIMER (17)
+#define MICROPY_HW_MAX_UART (6)
#else
#define PYB_EXTI_NUM_VECTORS (23)
+#define MICROPY_HW_MAX_TIMER (14)
#define MICROPY_HW_MAX_UART (6)
#endif
@@ -254,8 +261,8 @@ extern const struct _mp_obj_module_t mp_module_onewire;
\
mp_obj_t pyb_extint_callback[PYB_EXTI_NUM_VECTORS]; \
\
- /* Used to do callbacks to Python code on interrupt */ \
- struct _pyb_timer_obj_t *pyb_timer_obj_all[14]; \
+ /* pointers to all Timer objects (if they have been created) */ \
+ struct _pyb_timer_obj_t *pyb_timer_obj_all[MICROPY_HW_MAX_TIMER]; \
\
/* stdio is repeated on this UART object if it's not null */ \
struct _pyb_uart_obj_t *pyb_stdio_uart; \
@@ -320,6 +327,8 @@ static inline mp_uint_t disable_irq(void) {
__WFI(); \
} \
} while (0);
+
+#define MICROPY_THREAD_YIELD() pyb_thread_yield()
#else
#define MICROPY_EVENT_POLL_HOOK \
do { \
@@ -327,8 +336,13 @@ static inline mp_uint_t disable_irq(void) {
mp_handle_pending(); \
__WFI(); \
} while (0);
+
+#define MICROPY_THREAD_YIELD()
#endif
+// We need an implementation of the log2 function which is not a macro
+#define MP_NEED_LOG2 (1)
+
// There is no classical C heap in bare-metal ports, only Python
// garbage-collected heap. For completeness, emulate C heap via
// GC heap. Note that MicroPython core never uses malloc() and friends,
@@ -345,4 +359,4 @@ static inline mp_uint_t disable_irq(void) {
// We need to provide a declaration/definition of alloca()
#include
-#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stmhal.h"
+#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stm32.h"
diff --git a/ports/stm32/mpconfigport.mk b/ports/stm32/mpconfigport.mk
new file mode 100644
index 000000000..e708de6c1
--- /dev/null
+++ b/ports/stm32/mpconfigport.mk
@@ -0,0 +1,10 @@
+# Enable/disable extra modules
+
+# wiznet5k module for ethernet support; valid values are:
+# 0 : no Wiznet support
+# 5200 : support for W5200 module
+# 5500 : support for W5500 module
+MICROPY_PY_WIZNET5K ?= 0
+
+# cc3k module for wifi support
+MICROPY_PY_CC3K ?= 0
diff --git a/stmhal/mphalport.c b/ports/stm32/mphalport.c
similarity index 87%
rename from stmhal/mphalport.c
rename to ports/stm32/mphalport.c
index dff781ff2..e9c4f28f7 100644
--- a/stmhal/mphalport.c
+++ b/ports/stm32/mphalport.c
@@ -1,9 +1,9 @@
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "py/mphal.h"
+#include "extmod/misc.h"
#include "usb.h"
#include "uart.h"
@@ -39,6 +39,10 @@ int mp_hal_stdin_rx_chr(void) {
} else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
}
+ int dupterm_c = mp_uos_dupterm_rx_chr();
+ if (dupterm_c >= 0) {
+ return dupterm_c;
+ }
MICROPY_EVENT_POLL_HOOK
}
}
@@ -57,15 +61,26 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
if (usb_vcp_is_enabled()) {
usb_vcp_send_strn(str, len);
}
+ mp_uos_dupterm_tx_strn(str, len);
}
+// Efficiently convert "\n" to "\r\n"
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
- // send stdout to UART and USB CDC VCP
- if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
- uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
+ const char *last = str;
+ while (len--) {
+ if (*str == '\n') {
+ if (str > last) {
+ mp_hal_stdout_tx_strn(last, str - last);
+ }
+ mp_hal_stdout_tx_strn("\r\n", 2);
+ ++str;
+ last = str;
+ } else {
+ ++str;
+ }
}
- if (usb_vcp_is_enabled()) {
- usb_vcp_send_strn_cooked(str, len);
+ if (str > last) {
+ mp_hal_stdout_tx_strn(last, str - last);
}
}
diff --git a/stmhal/mphalport.h b/ports/stm32/mphalport.h
similarity index 98%
rename from stmhal/mphalport.h
rename to ports/stm32/mphalport.h
index 8dd95c470..939df0b3d 100644
--- a/stmhal/mphalport.h
+++ b/ports/stm32/mphalport.h
@@ -27,7 +27,7 @@ void mp_hal_set_interrupt_char(int c); // -1 to disable
// timing functions
-#include "stmhal/irq.h"
+#include "irq.h"
#define mp_hal_quiet_timing_enter() raise_irq_pri(1)
#define mp_hal_quiet_timing_exit(irq_state) restore_irq_pri(irq_state)
@@ -44,7 +44,7 @@ static inline mp_uint_t mp_hal_ticks_cpu(void) {
// C-level pin HAL
-#include "stmhal/pin.h"
+#include "pin.h"
#define MP_HAL_PIN_FMT "%q"
#define MP_HAL_PIN_MODE_INPUT (0)
diff --git a/stmhal/mpthreadport.c b/ports/stm32/mpthreadport.c
similarity index 98%
rename from stmhal/mpthreadport.c
rename to ports/stm32/mpthreadport.c
index d7c5b569b..11653b24c 100644
--- a/stmhal/mpthreadport.c
+++ b/ports/stm32/mpthreadport.c
@@ -26,8 +26,6 @@
#include
-#include "py/mpconfig.h"
-#include "py/mpstate.h"
#include "py/gc.h"
#include "py/mpthread.h"
#include "gccollect.h"
diff --git a/stmhal/mpthreadport.h b/ports/stm32/mpthreadport.h
similarity index 100%
rename from stmhal/mpthreadport.h
rename to ports/stm32/mpthreadport.h
diff --git a/stmhal/pendsv.c b/ports/stm32/pendsv.c
similarity index 98%
rename from stmhal/pendsv.c
rename to ports/stm32/pendsv.c
index 7b3906f25..0aeb1a6dc 100644
--- a/stmhal/pendsv.c
+++ b/ports/stm32/pendsv.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,7 +26,6 @@
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "lib/utils/interrupt_char.h"
#include "pendsv.h"
diff --git a/stmhal/pendsv.h b/ports/stm32/pendsv.h
similarity index 95%
rename from stmhal/pendsv.h
rename to ports/stm32/pendsv.h
index b64e61386..6a9eb0d79 100644
--- a/stmhal/pendsv.h
+++ b/ports/stm32/pendsv.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/pin.c b/ports/stm32/pin.c
similarity index 96%
rename from stmhal/pin.c
rename to ports/stm32/pin.c
index f30474e1f..ee2d84646 100644
--- a/stmhal/pin.c
+++ b/ports/stm32/pin.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "extmod/virtpin.h"
@@ -120,7 +119,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
pin_obj = mp_call_function_1(MP_STATE_PORT(pin_class_mapper), user_obj);
if (pin_obj != mp_const_none) {
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object"));
+ mp_raise_ValueError("Pin.mapper didn't return a Pin object");
}
if (pin_class_debug) {
printf("Pin.mapper maps ");
@@ -241,7 +240,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
}
}
-STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
+STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
/// \classmethod \constructor(id, ...)
/// Create a new Pin object associated with the id. If additional arguments are given,
@@ -278,7 +277,7 @@ STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_
/// \classmethod mapper([fun])
/// Get or set the pin mapper function.
-STATIC mp_obj_t pin_mapper(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pin_mapper(size_t n_args, const mp_obj_t *args) {
if (n_args > 1) {
MP_STATE_PORT(pin_class_mapper) = args[1];
return mp_const_none;
@@ -290,7 +289,7 @@ STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, (mp_obj_t)&pin_mapper_fun
/// \classmethod dict([dict])
/// Get or set the pin mapper dictionary.
-STATIC mp_obj_t pin_map_dict(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pin_map_dict(size_t n_args, const mp_obj_t *args) {
if (n_args > 1) {
MP_STATE_PORT(pin_class_map_dict) = args[1];
return mp_const_none;
@@ -316,7 +315,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
/// \classmethod debug([state])
/// Get or set the debugging state (`True` or `False` for on or off).
-STATIC mp_obj_t pin_debug(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) {
if (n_args > 1) {
pin_class_debug = mp_obj_is_true(args[1]);
return mp_const_none;
@@ -327,7 +326,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_obj);
// init(mode, pull=None, af=-1, *, value, alt)
-STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT },
{ MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none}},
@@ -384,7 +383,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con
return mp_const_none;
}
-STATIC mp_obj_t pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
@@ -396,7 +395,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
/// - With `value` given, set the logic level of the pin. `value` can be
/// anything that converts to a boolean. If it converts to `True`, the pin
/// is set high, otherwise it is set low.
-STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
return pin_call(args[0], n_args - 1, 0, args + 1);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
diff --git a/stmhal/pin.h b/ports/stm32/pin.h
similarity index 97%
rename from stmhal/pin.h
rename to ports/stm32/pin.h
index 1ec4bd6b8..90de79e5c 100644
--- a/stmhal/pin.h
+++ b/ports/stm32/pin.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/pin_defs_stmhal.c b/ports/stm32/pin_defs_stm32.c
similarity index 100%
rename from stmhal/pin_defs_stmhal.c
rename to ports/stm32/pin_defs_stm32.c
diff --git a/stmhal/pin_defs_stmhal.h b/ports/stm32/pin_defs_stm32.h
similarity index 97%
rename from stmhal/pin_defs_stmhal.h
rename to ports/stm32/pin_defs_stm32.h
index d6a2ef424..c5b286283 100644
--- a/stmhal/pin_defs_stmhal.h
+++ b/ports/stm32/pin_defs_stm32.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
-// This file contains pin definitions that are specific to the stmhal port.
+// This file contains pin definitions that are specific to the stm32 port.
// This file should only ever be #included by pin.h and not directly.
enum {
diff --git a/stmhal/pin_named_pins.c b/ports/stm32/pin_named_pins.c
similarity index 97%
rename from stmhal/pin_named_pins.c
rename to ports/stm32/pin_named_pins.c
index fac19ee97..726da54dd 100644
--- a/stmhal/pin_named_pins.c
+++ b/ports/stm32/pin_named_pins.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/portmodules.h b/ports/stm32/portmodules.h
similarity index 95%
rename from stmhal/portmodules.h
rename to ports/stm32/portmodules.h
index 4e892da96..b575109b8 100644
--- a/stmhal/portmodules.h
+++ b/ports/stm32/portmodules.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/pybcdc.inf_template b/ports/stm32/pybcdc.inf_template
similarity index 100%
rename from stmhal/pybcdc.inf_template
rename to ports/stm32/pybcdc.inf_template
diff --git a/stmhal/pybthread.c b/ports/stm32/pybthread.c
similarity index 100%
rename from stmhal/pybthread.c
rename to ports/stm32/pybthread.c
diff --git a/stmhal/pybthread.h b/ports/stm32/pybthread.h
similarity index 100%
rename from stmhal/pybthread.h
rename to ports/stm32/pybthread.h
diff --git a/stmhal/qstrdefsport.h b/ports/stm32/qstrdefsport.h
similarity index 95%
rename from stmhal/qstrdefsport.h
rename to ports/stm32/qstrdefsport.h
index 1d83f43bd..31220c5a4 100644
--- a/stmhal/qstrdefsport.h
+++ b/ports/stm32/qstrdefsport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/rng.c b/ports/stm32/rng.c
similarity index 96%
rename from stmhal/rng.c
rename to ports/stm32/rng.c
index a5a9874d1..c0c5e9aeb 100644
--- a/stmhal/rng.c
+++ b/ports/stm32/rng.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/rng.h b/ports/stm32/rng.h
similarity index 94%
rename from stmhal/rng.h
rename to ports/stm32/rng.h
index f022f3a67..43e49fe72 100644
--- a/stmhal/rng.h
+++ b/ports/stm32/rng.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/rtc.c b/ports/stm32/rtc.c
similarity index 97%
rename from stmhal/rtc.c
rename to ports/stm32/rtc.c
index 755684570..73272d363 100644
--- a/stmhal/rtc.c
+++ b/ports/stm32/rtc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -412,7 +412,7 @@ STATIC void RTC_CalendarConfig(void) {
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
typedef struct _pyb_rtc_obj_t {
mp_obj_base_t base;
@@ -481,7 +481,7 @@ uint32_t rtc_us_to_subsec(uint32_t us) {
#define rtc_subsec_to_us
#endif
-mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
+mp_obj_t pyb_rtc_datetime(size_t n_args, const mp_obj_t *args) {
rtc_init_finalise();
if (n_args == 1) {
// get date and time
@@ -531,7 +531,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime
// wakeup(None)
// wakeup(ms, callback=None)
// wakeup(wucksel, wut, callback)
-mp_obj_t pyb_rtc_wakeup(mp_uint_t n_args, const mp_obj_t *args) {
+mp_obj_t pyb_rtc_wakeup(size_t n_args, const mp_obj_t *args) {
// wut is wakeup counter start value, wucksel is clock source
// counter is decremented at wucksel rate, and wakes the MCU when it gets to 0
// wucksel=0b000 is RTC/16 (RTC runs at 32768Hz)
@@ -575,7 +575,7 @@ mp_obj_t pyb_rtc_wakeup(mp_uint_t n_args, const mp_obj_t *args) {
wut -= 0x10000;
if (wut > 0x10000) {
// wut still too large
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "wakeup value too large"));
+ mp_raise_ValueError("wakeup value too large");
}
}
}
@@ -666,7 +666,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_wakeup_obj, 2, 4, pyb_rtc_wakeup);
// calibration(cal)
// When an integer argument is provided, check that it falls in the range [-511 to 512]
// and set the calibration value; otherwise return calibration value
-mp_obj_t pyb_rtc_calibration(mp_uint_t n_args, const mp_obj_t *args) {
+mp_obj_t pyb_rtc_calibration(size_t n_args, const mp_obj_t *args) {
rtc_init_finalise();
mp_int_t cal;
if (n_args == 2) {
@@ -685,12 +685,10 @@ mp_obj_t pyb_rtc_calibration(mp_uint_t n_args, const mp_obj_t *args) {
}
return mp_obj_new_int(cal & 1);
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "calibration value out of range"));
+ mp_raise_ValueError("calibration value out of range");
}
#else
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
- "calibration value out of range"));
+ mp_raise_ValueError("calibration value out of range");
#endif
}
if (cal > 0) {
diff --git a/stmhal/rtc.h b/ports/stm32/rtc.h
similarity index 95%
rename from stmhal/rtc.h
rename to ports/stm32/rtc.h
index f382fa6b6..09ab2aedf 100644
--- a/stmhal/rtc.h
+++ b/ports/stm32/rtc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/sdcard.c b/ports/stm32/sdcard.c
similarity index 88%
rename from stmhal/sdcard.c
rename to ports/stm32/sdcard.c
index 5260e0a50..484426b84 100644
--- a/stmhal/sdcard.c
+++ b/ports/stm32/sdcard.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,7 +26,6 @@
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "lib/oofatfs/ff.h"
@@ -191,8 +190,7 @@ bool sdcard_power_on(void) {
sd_handle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
// init the SD interface, with retry if it's not ready yet
- HAL_SD_CardInfoTypedef cardinfo;
- for (int retry = 10; HAL_SD_Init(&sd_handle, &cardinfo) != SD_OK; retry--) {
+ for (int retry = 10; HAL_SD_Init(&sd_handle) != HAL_OK; retry--) {
if (retry == 0) {
goto error;
}
@@ -200,7 +198,7 @@ bool sdcard_power_on(void) {
}
// configure the SD bus width for wide operation
- if (HAL_SD_WideBusOperation_Config(&sd_handle, SDIO_BUS_WIDE_4B) != SD_OK) {
+ if (HAL_SD_ConfigWideBusOperation(&sd_handle, SDIO_BUS_WIDE_4B) != HAL_OK) {
HAL_SD_DeInit(&sd_handle);
goto error;
}
@@ -224,9 +222,9 @@ uint64_t sdcard_get_capacity_in_bytes(void) {
if (sd_handle.Instance == NULL) {
return 0;
}
- HAL_SD_CardInfoTypedef cardinfo;
- HAL_SD_Get_CardInfo(&sd_handle, &cardinfo);
- return cardinfo.CardCapacity;
+ HAL_SD_CardInfoTypeDef cardinfo;
+ HAL_SD_GetCardInfo(&sd_handle, &cardinfo);
+ return (uint64_t)cardinfo.LogBlockNbr * (uint64_t)cardinfo.LogBlockSize;
}
void SDIO_IRQHandler(void) {
@@ -243,13 +241,37 @@ void SDMMC2_IRQHandler(void) {
}
#endif
+STATIC HAL_StatusTypeDef sdcard_wait_finished(SD_HandleTypeDef *sd, uint32_t timeout) {
+ // Wait for HAL driver to be ready (eg for DMA to finish)
+ uint32_t start = HAL_GetTick();
+ while (sd->State == HAL_SD_STATE_BUSY) {
+ if (HAL_GetTick() - start >= timeout) {
+ return HAL_TIMEOUT;
+ }
+ }
+ // Wait for SD card to complete the operation
+ for (;;) {
+ HAL_SD_CardStateTypeDef state = HAL_SD_GetCardState(sd);
+ if (state == HAL_SD_CARD_TRANSFER) {
+ return HAL_OK;
+ }
+ if (!(state == HAL_SD_CARD_SENDING || state == HAL_SD_CARD_RECEIVING || state == HAL_SD_CARD_PROGRAMMING)) {
+ return HAL_ERROR;
+ }
+ if (HAL_GetTick() - start >= timeout) {
+ return HAL_TIMEOUT;
+ }
+ }
+ return HAL_OK;
+}
+
mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
// check that SD card is initialised
if (sd_handle.Instance == NULL) {
- return SD_ERROR;
+ return HAL_ERROR;
}
- HAL_SD_ErrorTypedef err = SD_OK;
+ HAL_StatusTypeDef err = HAL_OK;
// check that dest pointer is aligned on a 4-byte boundary
uint8_t *orig_dest = NULL;
@@ -280,10 +302,9 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
// from reading the peripheral the CPU then reads the new data
MP_HAL_CLEANINVALIDATE_DCACHE(dest, num_blocks * SDCARD_BLOCK_SIZE);
- err = HAL_SD_ReadBlocks_BlockNumber_DMA(&sd_handle, (uint32_t*)dest, block_num, SDCARD_BLOCK_SIZE, num_blocks);
- if (err == SD_OK) {
- // wait for DMA transfer to finish, with a large timeout
- err = HAL_SD_CheckReadOperation(&sd_handle, 100000000);
+ err = HAL_SD_ReadBlocks_DMA(&sd_handle, dest, block_num, num_blocks);
+ if (err == HAL_OK) {
+ err = sdcard_wait_finished(&sd_handle, 60000);
}
dma_deinit(&SDMMC_RX_DMA);
@@ -291,7 +312,10 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
restore_irq_pri(basepri);
} else {
- err = HAL_SD_ReadBlocks_BlockNumber(&sd_handle, (uint32_t*)dest, block_num, SDCARD_BLOCK_SIZE, num_blocks);
+ err = HAL_SD_ReadBlocks(&sd_handle, dest, block_num, num_blocks, 60000);
+ if (err == HAL_OK) {
+ err = sdcard_wait_finished(&sd_handle, 60000);
+ }
}
if (orig_dest != NULL) {
@@ -306,22 +330,22 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
mp_uint_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
// check that SD card is initialised
if (sd_handle.Instance == NULL) {
- return SD_ERROR;
+ return HAL_ERROR;
}
- HAL_SD_ErrorTypedef err = SD_OK;
+ HAL_StatusTypeDef err = HAL_OK;
// check that src pointer is aligned on a 4-byte boundary
if (((uint32_t)src & 3) != 0) {
// pointer is not aligned, so allocate a temporary block to do the write
uint8_t *src_aligned = m_new_maybe(uint8_t, SDCARD_BLOCK_SIZE);
if (src_aligned == NULL) {
- return SD_ERROR;
+ return HAL_ERROR;
}
for (size_t i = 0; i < num_blocks; ++i) {
memcpy(src_aligned, src + i * SDCARD_BLOCK_SIZE, SDCARD_BLOCK_SIZE);
err = sdcard_write_blocks(src_aligned, block_num + i, 1);
- if (err != SD_OK) {
+ if (err != HAL_OK) {
break;
}
}
@@ -339,24 +363,26 @@ mp_uint_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t n
// make sure cache is flushed to RAM so the DMA can read the correct data
MP_HAL_CLEAN_DCACHE(src, num_blocks * SDCARD_BLOCK_SIZE);
- err = HAL_SD_WriteBlocks_BlockNumber_DMA(&sd_handle, (uint32_t*)src, block_num, SDCARD_BLOCK_SIZE, num_blocks);
- if (err == SD_OK) {
- // wait for DMA transfer to finish, with a large timeout
- err = HAL_SD_CheckWriteOperation(&sd_handle, 100000000);
+ err = HAL_SD_WriteBlocks_DMA(&sd_handle, (uint8_t*)src, block_num, num_blocks);
+ if (err == HAL_OK) {
+ err = sdcard_wait_finished(&sd_handle, 60000);
}
dma_deinit(&SDMMC_TX_DMA);
sd_handle.hdmatx = NULL;
restore_irq_pri(basepri);
} else {
- err = HAL_SD_WriteBlocks_BlockNumber(&sd_handle, (uint32_t*)src, block_num, SDCARD_BLOCK_SIZE, num_blocks);
+ err = HAL_SD_WriteBlocks(&sd_handle, (uint8_t*)src, block_num, num_blocks, 60000);
+ if (err == HAL_OK) {
+ err = sdcard_wait_finished(&sd_handle, 60000);
+ }
}
return err;
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
//
// Expose the SD card as an object with the block protocol.
@@ -392,12 +418,12 @@ STATIC mp_obj_t sd_info(mp_obj_t self) {
if (sd_handle.Instance == NULL) {
return mp_const_none;
}
- HAL_SD_CardInfoTypedef cardinfo;
- HAL_SD_Get_CardInfo(&sd_handle, &cardinfo);
+ HAL_SD_CardInfoTypeDef cardinfo;
+ HAL_SD_GetCardInfo(&sd_handle, &cardinfo);
// cardinfo.SD_csd and cardinfo.SD_cid have lots of info but we don't use them
mp_obj_t tuple[3] = {
- mp_obj_new_int_from_ull(cardinfo.CardCapacity),
- mp_obj_new_int_from_uint(cardinfo.CardBlockSize),
+ mp_obj_new_int_from_ull((uint64_t)cardinfo.LogBlockNbr * (uint64_t)cardinfo.LogBlockSize),
+ mp_obj_new_int_from_uint(cardinfo.LogBlockSize),
mp_obj_new_int(cardinfo.CardType),
};
return mp_obj_new_tuple(3, tuple);
diff --git a/stmhal/sdcard.h b/ports/stm32/sdcard.h
similarity index 96%
rename from stmhal/sdcard.h
rename to ports/stm32/sdcard.h
index d595f0f1a..8c698fc2f 100644
--- a/stmhal/sdcard.h
+++ b/ports/stm32/sdcard.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/servo.c b/ports/stm32/servo.c
similarity index 96%
rename from stmhal/servo.c
rename to ports/stm32/servo.c
index e4bcbc30e..0e54b4d0a 100644
--- a/stmhal/servo.c
+++ b/ports/stm32/servo.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -147,7 +147,7 @@ STATIC void servo_init_channel(pyb_servo_obj_t *s) {
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
STATIC mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) {
int p = mp_obj_get_int(port);
@@ -205,7 +205,7 @@ STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, siz
/// \method pulse_width([value])
/// Get or set the pulse width in milliseconds.
-STATIC mp_obj_t pyb_servo_pulse_width(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_servo_pulse_width(size_t n_args, const mp_obj_t *args) {
pyb_servo_obj_t *self = args[0];
if (n_args == 1) {
// get pulse width, in us
@@ -223,7 +223,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_pulse_width_obj, 1, 2, pyb_
/// \method calibration([pulse_min, pulse_max, pulse_centre, [pulse_angle_90, pulse_speed_100]])
/// Get or set the calibration of the servo timing.
// TODO should accept 1 arg, a 5-tuple of values to set
-STATIC mp_obj_t pyb_servo_calibration(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_servo_calibration(size_t n_args, const mp_obj_t *args) {
pyb_servo_obj_t *self = args[0];
if (n_args == 1) {
// get calibration values
@@ -258,7 +258,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_calibration_obj, 1, 6, pyb_
///
/// - `angle` is the angle to move to in degrees.
/// - `time` is the number of milliseconds to take to get to the specified angle.
-STATIC mp_obj_t pyb_servo_angle(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_servo_angle(size_t n_args, const mp_obj_t *args) {
pyb_servo_obj_t *self = args[0];
if (n_args == 1) {
// get angle
@@ -288,7 +288,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_
///
/// - `speed` is the speed to move to change to, between -100 and 100.
/// - `time` is the number of milliseconds to take to get to the specified speed.
-STATIC mp_obj_t pyb_servo_speed(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_servo_speed(size_t n_args, const mp_obj_t *args) {
pyb_servo_obj_t *self = args[0];
if (n_args == 1) {
// get speed
diff --git a/stmhal/servo.h b/ports/stm32/servo.h
similarity index 95%
rename from stmhal/servo.h
rename to ports/stm32/servo.h
index 18fd493d5..c602a07da 100644
--- a/stmhal/servo.h
+++ b/ports/stm32/servo.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/spi.c b/ports/stm32/spi.c
similarity index 98%
rename from stmhal/spi.c
rename to ports/stm32/spi.c
index b710fc3a7..cfd9c2667 100644
--- a/stmhal/spi.c
+++ b/ports/stm32/spi.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "extmod/machine_spi.h"
@@ -550,7 +549,7 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
///
/// - `mode` must be either `SPI.MASTER` or `SPI.SLAVE`.
/// - `baudrate` is the SCK clock rate (only sensible for a master).
-STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 328125} },
@@ -628,7 +627,7 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
return (mp_obj_t)spi_obj;
}
-STATIC mp_obj_t pyb_spi_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_spi_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init);
@@ -649,7 +648,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit);
/// - `timeout` is the timeout in milliseconds to wait for the send.
///
/// Return value: `None`.
-STATIC mp_obj_t pyb_spi_send(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_spi_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// TODO assumes transmission size is 8-bits wide
static const mp_arg_t allowed_args[] = {
@@ -684,7 +683,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_obj, 1, pyb_spi_send);
///
/// Return value: if `recv` is an integer then a new buffer of the bytes received,
/// otherwise the same buffer that was passed in to `recv`.
-STATIC mp_obj_t pyb_spi_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_spi_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// TODO assumes transmission size is 8-bits wide
static const mp_arg_t allowed_args[] = {
@@ -724,7 +723,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_recv_obj, 1, pyb_spi_recv);
/// - `timeout` is the timeout in milliseconds to wait for the receive.
///
/// Return value: the buffer with the received bytes.
-STATIC mp_obj_t pyb_spi_send_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_spi_send_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// TODO assumes transmission size is 8-bits wide
static const mp_arg_t allowed_args[] = {
@@ -765,7 +764,7 @@ STATIC mp_obj_t pyb_spi_send_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp
// recv argument given
mp_get_buffer_raise(args[1].u_obj, &bufinfo_recv, MP_BUFFER_WRITE);
if (bufinfo_recv.len != bufinfo_send.len) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "recv must be same length as send"));
+ mp_raise_ValueError("recv must be same length as send");
}
o_ret = args[1].u_obj;
}
diff --git a/stmhal/spi.h b/ports/stm32/spi.h
similarity index 95%
rename from stmhal/spi.h
rename to ports/stm32/spi.h
index e6752fdd1..eda109a7e 100644
--- a/stmhal/spi.h
+++ b/ports/stm32/spi.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/startup_stm32.S b/ports/stm32/startup_stm32.S
similarity index 100%
rename from stmhal/startup_stm32.S
rename to ports/stm32/startup_stm32.S
diff --git a/stmhal/stm32_it.c b/ports/stm32/stm32_it.c
similarity index 99%
rename from stmhal/stm32_it.c
rename to ports/stm32/stm32_it.c
index 357b6d79d..f1ac9b6b8 100644
--- a/stmhal/stm32_it.c
+++ b/ports/stm32/stm32_it.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* Original template from ST Cube library. See below for header.
*
@@ -67,7 +67,6 @@
#include
-#include "py/mpstate.h"
#include "py/obj.h"
#include "py/mphal.h"
#include "stm32_it.h"
diff --git a/stmhal/stm32_it.h b/ports/stm32/stm32_it.h
similarity index 98%
rename from stmhal/stm32_it.h
rename to ports/stm32/stm32_it.h
index d6ed1b2b9..b498dee8d 100644
--- a/stmhal/stm32_it.h
+++ b/ports/stm32/stm32_it.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* Original template from ST Cube library. See below for header.
*
diff --git a/stmhal/storage.c b/ports/stm32/storage.c
similarity index 96%
rename from stmhal/storage.c
rename to ports/stm32/storage.c
index 1931cd607..4b329c2db 100644
--- a/stmhal/storage.c
+++ b/ports/stm32/storage.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -92,12 +92,12 @@ STATIC byte flash_cache_mem[0x4000] __attribute__((aligned(4))); // 16k
#define FLASH_MEM_SEG1_START_ADDR (0x08008000) // sector 1
#define FLASH_MEM_SEG1_NUM_BLOCKS (192) // sectors 1,2,3: 32k+32k+32=96k
-#elif defined(STM32L476xx)
+#elif defined(STM32L475xx) || defined(STM32L476xx)
extern uint8_t _flash_fs_start;
extern uint8_t _flash_fs_end;
-// The STM32L476 doesn't have CCRAM, so we use the 32K SRAM2 for this.
+// The STM32L475/6 doesn't have CCRAM, so we use the 32K SRAM2 for this.
#define CACHE_MEM_START_ADDR (0x10000000) // SRAM2 data RAM, 32k
#define FLASH_SECTOR_SIZE_MAX (0x00800) // 2k max
#define FLASH_MEM_SEG1_START_ADDR ((long)&_flash_fs_start)
@@ -176,17 +176,19 @@ static uint8_t *flash_cache_get_addr_for_read(uint32_t flash_addr) {
static bool flash_is_initialised = false;
+STATIC const mp_machine_soft_spi_obj_t spiflash_spi_bus = {
+ .base = {&mp_machine_soft_spi_type},
+ .delay_half = MICROPY_PY_MACHINE_SPI_MIN_DELAY,
+ .polarity = 0,
+ .phase = 0,
+ .sck = &MICROPY_HW_SPIFLASH_SCK,
+ .mosi = &MICROPY_HW_SPIFLASH_MOSI,
+ .miso = &MICROPY_HW_SPIFLASH_MISO,
+};
+
STATIC const mp_spiflash_t spiflash = {
.cs = &MICROPY_HW_SPIFLASH_CS,
- .spi = {
- .base = {&mp_machine_soft_spi_type},
- .delay_half = MICROPY_PY_MACHINE_SPI_MIN_DELAY,
- .polarity = 0,
- .phase = 0,
- .sck = &MICROPY_HW_SPIFLASH_SCK,
- .mosi = &MICROPY_HW_SPIFLASH_MOSI,
- .miso = &MICROPY_HW_SPIFLASH_MISO,
- },
+ .spi = (mp_obj_base_t*)&spiflash_spi_bus.base,
};
#endif
diff --git a/stmhal/storage.h b/ports/stm32/storage.h
similarity index 96%
rename from stmhal/storage.h
rename to ports/stm32/storage.h
index 0ecb5715a..291e09a9a 100644
--- a/stmhal/storage.h
+++ b/ports/stm32/storage.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/system_stm32.c b/ports/stm32/system_stm32.c
similarity index 97%
rename from stmhal/system_stm32.c
rename to ports/stm32/system_stm32.c
index a63bd3c57..b71a03181 100644
--- a/stmhal/system_stm32.c
+++ b/ports/stm32/system_stm32.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* Taken from ST Cube library and modified. See below for original header.
*
@@ -113,7 +113,10 @@ void __fatal_error(const char *msg);
#define CONFIG_RCC_CR_2ND (RCC_CR_HSEON || RCC_CR_CSSON || RCC_CR_PLLON)
#define CONFIG_RCC_PLLCFGR (0x24003010)
-#if defined(MCU_SERIES_F7)
+#if defined(MCU_SERIES_F4)
+const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
+const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
+#elif defined(MCU_SERIES_F7)
const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
#endif
@@ -328,12 +331,8 @@ void SystemClock_Config(void)
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
#elif defined(MCU_SERIES_L4)
- /* Enable the LSE Oscillator */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
- RCC_OscInitStruct.LSEState = RCC_LSE_ON;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
- __fatal_error("HAL_RCC_OscConfig");
- }
+ // Configure LSE Drive Capability
+ __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
#endif
/* Enable HSE Oscillator and activate PLL with HSE as source */
@@ -461,6 +460,8 @@ void SystemClock_Config(void)
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_PLLSAI1;
+ PeriphClkInitStruct.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI;
+ PeriphClkInitStruct.PLLSAI1.PLLSAI1M = 1;
PeriphClkInitStruct.PLLSAI1.PLLSAI1N = 24;
PeriphClkInitStruct.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
PeriphClkInitStruct.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
diff --git a/stmhal/systick.c b/ports/stm32/systick.c
similarity index 98%
rename from stmhal/systick.c
rename to ports/stm32/systick.c
index 4eac583e2..c07d0fabc 100644
--- a/stmhal/systick.c
+++ b/ports/stm32/systick.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/systick.h b/ports/stm32/systick.h
similarity index 95%
rename from stmhal/systick.h
rename to ports/stm32/systick.h
index 524afae40..c1def50c2 100644
--- a/stmhal/systick.h
+++ b/ports/stm32/systick.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/timer.c b/ports/stm32/timer.c
similarity index 91%
rename from stmhal/timer.c
rename to ports/stm32/timer.c
index 6513f95d3..96a6baa02 100644
--- a/stmhal/timer.c
+++ b/ports/stm32/timer.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,9 +28,6 @@
#include
#include
-#include "usbd_cdc_msc_hid.h"
-#include "usbd_cdc_interface.h"
-
#include "py/runtime.h"
#include "py/gc.h"
#include "timer.h"
@@ -247,7 +244,7 @@ uint32_t timer_get_source_freq(uint32_t tim_id) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
STATIC const mp_obj_type_t pyb_timer_channel_type;
@@ -278,7 +275,7 @@ STATIC uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj
if (freq <= 0) {
goto bad_freq;
bad_freq:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "must have positive freq"));
+ mp_raise_ValueError("must have positive freq");
}
period = source_freq / freq;
}
@@ -429,7 +426,7 @@ STATIC void config_deadtime(pyb_timer_obj_t *self, mp_int_t ticks) {
TIM_HandleTypeDef *pyb_timer_get_handle(mp_obj_t timer) {
if (mp_obj_get_type(timer) != &pyb_timer_type) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "need a Timer object"));
+ mp_raise_ValueError("need a Timer object");
}
pyb_timer_obj_t *self = timer;
return &self->tim;
@@ -515,7 +512,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
/// `deadtime` is only available on timers 1 and 8.
///
/// You must either specify freq or both of period and prescaler.
-STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_prescaler, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
@@ -541,7 +538,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c
init->Prescaler = args[1].u_int;
init->Period = args[2].u_int;
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "must specify either freq, or prescaler and period"));
+ mp_raise_TypeError("must specify either freq, or prescaler and period");
}
init->CounterMode = args[3].u_int;
@@ -623,6 +620,12 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c
#endif
config_deadtime(self, args[6].u_int);
}
+
+ // Enable ARPE so that the auto-reload register is buffered.
+ // This allows to smoothly change the frequency of the timer.
+ self->tim.Instance->CR1 |= TIM_CR1_ARPE;
+
+ // Start the timer running
if (args[5].u_obj == mp_const_none) {
HAL_TIM_Base_Start(&self->tim);
} else {
@@ -632,6 +635,62 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c
return mp_const_none;
}
+// This table encodes the timer instance and irq number.
+// It assumes that timer instance pointer has the lower 8 bits cleared.
+#define TIM_ENTRY(id, irq) [id - 1] = (uint32_t)TIM##id | irq
+STATIC const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER] = {
+ #if defined(MCU_SERIES_F4) || defined(MCU_SERIES_F7)
+ TIM_ENTRY(1, TIM1_UP_TIM10_IRQn),
+ #elif defined(MCU_SERIES_L4)
+ TIM_ENTRY(1, TIM1_UP_TIM16_IRQn),
+ #endif
+ TIM_ENTRY(2, TIM2_IRQn),
+ TIM_ENTRY(3, TIM3_IRQn),
+ TIM_ENTRY(4, TIM4_IRQn),
+ TIM_ENTRY(5, TIM5_IRQn),
+ #if defined(TIM6)
+ TIM_ENTRY(6, TIM6_DAC_IRQn),
+ #endif
+ #if defined(TIM7)
+ TIM_ENTRY(7, TIM7_IRQn),
+ #endif
+ #if defined(TIM8)
+ #if defined(MCU_SERIES_F4) || defined(MCU_SERIES_F7)
+ TIM_ENTRY(8, TIM8_UP_TIM13_IRQn),
+ #elif defined(MCU_SERIES_L4)
+ TIM_ENTRY(8, TIM8_UP_IRQn),
+ #endif
+ #endif
+ #if defined(TIM9)
+ TIM_ENTRY(9, TIM1_BRK_TIM9_IRQn),
+ #endif
+ #if defined(TIM10)
+ TIM_ENTRY(10, TIM1_UP_TIM10_IRQn),
+ #endif
+ #if defined(TIM11)
+ TIM_ENTRY(11, TIM1_TRG_COM_TIM11_IRQn),
+ #endif
+ #if defined(TIM12)
+ TIM_ENTRY(12, TIM8_BRK_TIM12_IRQn),
+ #endif
+ #if defined(TIM13)
+ TIM_ENTRY(13, TIM8_UP_TIM13_IRQn),
+ #endif
+ #if defined(TIM14)
+ TIM_ENTRY(14, TIM8_TRG_COM_TIM14_IRQn),
+ #endif
+ #if defined(TIM15)
+ TIM_ENTRY(15, TIM1_BRK_TIM15_IRQn),
+ #endif
+ #if defined(TIM16)
+ TIM_ENTRY(16, TIM1_UP_TIM16_IRQn),
+ #endif
+ #if defined(TIM17)
+ TIM_ENTRY(17, TIM1_TRG_COM_TIM17_IRQn),
+ #endif
+};
+#undef TIM_ENTRY
+
/// \classmethod \constructor(id, ...)
/// Construct a new timer object of the given id. If additional
/// arguments are given, then the timer is initialised by `init(...)`.
@@ -640,74 +699,30 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
// check arguments
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
- // create new Timer object
- pyb_timer_obj_t *tim = m_new_obj(pyb_timer_obj_t);
- memset(tim, 0, sizeof(*tim));
-
- tim->base.type = &pyb_timer_type;
- tim->callback = mp_const_none;
- tim->channel = NULL;
-
- // get TIM number
- tim->tim_id = mp_obj_get_int(args[0]);
- tim->is_32bit = false;
+ // get the timer id
+ mp_int_t tim_id = mp_obj_get_int(args[0]);
- switch (tim->tim_id) {
- #if defined(MCU_SERIES_F4) || defined(MCU_SERIES_F7)
- case 1: tim->tim.Instance = TIM1; tim->irqn = TIM1_UP_TIM10_IRQn; break;
- #elif defined(MCU_SERIES_L4)
- case 1: tim->tim.Instance = TIM1; tim->irqn = TIM1_UP_TIM16_IRQn; break;
- #endif
- case 2: tim->tim.Instance = TIM2; tim->irqn = TIM2_IRQn; tim->is_32bit = true; break;
- case 3: tim->tim.Instance = TIM3; tim->irqn = TIM3_IRQn; break;
- case 4: tim->tim.Instance = TIM4; tim->irqn = TIM4_IRQn; break;
- case 5: tim->tim.Instance = TIM5; tim->irqn = TIM5_IRQn; tim->is_32bit = true; break;
- #if defined(TIM6)
- case 6: tim->tim.Instance = TIM6; tim->irqn = TIM6_DAC_IRQn; break;
- #endif
- #if defined(TIM7)
- case 7: tim->tim.Instance = TIM7; tim->irqn = TIM7_IRQn; break;
- #endif
- #if defined(TIM8)
- #if defined(MCU_SERIES_F4) || defined(MCU_SERIES_F7)
- case 8: tim->tim.Instance = TIM8; tim->irqn = TIM8_UP_TIM13_IRQn; break;
- #elif defined(MCU_SERIES_L4)
- case 8: tim->tim.Instance = TIM8; tim->irqn = TIM8_UP_IRQn; break;
- #endif
- #endif
- #if defined(TIM9)
- case 9: tim->tim.Instance = TIM9; tim->irqn = TIM1_BRK_TIM9_IRQn; break;
- #endif
- #if defined(TIM10)
- case 10: tim->tim.Instance = TIM10; tim->irqn = TIM1_UP_TIM10_IRQn; break;
- #endif
- #if defined(TIM11)
- case 11: tim->tim.Instance = TIM11; tim->irqn = TIM1_TRG_COM_TIM11_IRQn; break;
- #endif
- #if defined(TIM12)
- case 12: tim->tim.Instance = TIM12; tim->irqn = TIM8_BRK_TIM12_IRQn; break;
- #endif
- #if defined(TIM13)
- case 13: tim->tim.Instance = TIM13; tim->irqn = TIM8_UP_TIM13_IRQn; break;
- #endif
- #if defined(TIM14)
- case 14: tim->tim.Instance = TIM14; tim->irqn = TIM8_TRG_COM_TIM14_IRQn; break;
- #endif
- #if defined(TIM15)
- case 15: tim->tim.Instance = TIM15; tim->irqn = TIM1_BRK_TIM15_IRQn; break;
- #endif
- #if defined(TIM16)
- case 16: tim->tim.Instance = TIM16; tim->irqn = TIM1_UP_TIM16_IRQn; break;
- #endif
- #if defined(TIM17)
- case 17: tim->tim.Instance = TIM17; tim->irqn = TIM1_TRG_COM_TIM17_IRQn; break;
- #endif
- default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer(%d) doesn't exist", tim->tim_id));
+ // check if the timer exists
+ if (tim_id <= 0 || tim_id > MICROPY_HW_MAX_TIMER || tim_instance_table[tim_id - 1] == 0) {
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer(%d) doesn't exist", tim_id));
}
- // set the global variable for interrupt callbacks
- if (tim->tim_id - 1 < PYB_TIMER_OBJ_ALL_NUM) {
- MP_STATE_PORT(pyb_timer_obj_all)[tim->tim_id - 1] = tim;
+ pyb_timer_obj_t *tim;
+ if (MP_STATE_PORT(pyb_timer_obj_all)[tim_id - 1] == NULL) {
+ // create new Timer object
+ tim = m_new_obj(pyb_timer_obj_t);
+ memset(tim, 0, sizeof(*tim));
+ tim->base.type = &pyb_timer_type;
+ tim->tim_id = tim_id;
+ tim->is_32bit = tim_id == 2 || tim_id == 5;
+ tim->callback = mp_const_none;
+ uint32_t ti = tim_instance_table[tim_id - 1];
+ tim->tim.Instance = (TIM_TypeDef*)(ti & 0xffffff00);
+ tim->irqn = ti & 0xff;
+ MP_STATE_PORT(pyb_timer_obj_all)[tim_id - 1] = tim;
+ } else {
+ // reference existing Timer object
+ tim = MP_STATE_PORT(pyb_timer_obj_all)[tim_id - 1];
}
if (n_args > 1 || n_kw > 0) {
@@ -720,7 +735,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
return (mp_obj_t)tim;
}
-STATIC mp_obj_t pyb_timer_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_timer_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init);
@@ -823,7 +838,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);
/// timer = pyb.Timer(2, freq=1000)
/// ch2 = timer.channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.X2, pulse_width=210000)
/// ch3 = timer.channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.X3, pulse_width=420000)
-STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -891,7 +906,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
mp_obj_t pin_obj = args[2].u_obj;
if (pin_obj != mp_const_none) {
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "pin argument needs to be be a Pin type"));
+ mp_raise_ValueError("pin argument needs to be be a Pin type");
}
const pin_obj_t *pin = pin_obj;
const pin_af_obj_t *af = pin_find_af(pin, AF_FN_TIM, self->tim_id);
@@ -1066,7 +1081,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel);
/// \method counter([value])
/// Get or set the timer counter.
-STATIC mp_obj_t pyb_timer_counter(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
if (n_args == 1) {
// get
@@ -1090,7 +1105,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_source_freq_obj, pyb_timer_source_fre
/// \method freq([value])
/// Get or set the frequency for the timer (changes prescaler and period if set).
-STATIC mp_obj_t pyb_timer_freq(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
if (n_args == 1) {
// get
@@ -1112,10 +1127,6 @@ STATIC mp_obj_t pyb_timer_freq(mp_uint_t n_args, const mp_obj_t *args) {
uint32_t prescaler = compute_prescaler_period_from_freq(self, args[1], &period);
self->tim.Instance->PSC = prescaler;
__HAL_TIM_SetAutoreload(&self->tim, period);
- // Reset the counter to zero. Otherwise, if counter >= period it will
- // continue counting until it wraps (at either 16 or 32 bits depending
- // on the timer).
- __HAL_TIM_SetCounter(&self->tim, 0);
return mp_const_none;
}
}
@@ -1123,7 +1134,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_freq_obj, 1, 2, pyb_timer_f
/// \method prescaler([value])
/// Get or set the prescaler for the timer.
-STATIC mp_obj_t pyb_timer_prescaler(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_prescaler(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
if (n_args == 1) {
// get
@@ -1138,7 +1149,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_prescaler_obj, 1, 2, pyb_ti
/// \method period([value])
/// Get or set the period of the timer.
-STATIC mp_obj_t pyb_timer_period(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
if (n_args == 1) {
// get
@@ -1146,10 +1157,6 @@ STATIC mp_obj_t pyb_timer_period(mp_uint_t n_args, const mp_obj_t *args) {
} else {
// set
__HAL_TIM_SetAutoreload(&self->tim, mp_obj_get_int(args[1]) & TIMER_CNT_MASK(self));
- // Reset the counter to zero. Otherwise, if counter >= period it will
- // continue counting until it wraps (at either 16 or 32 bits depending
- // on the timer).
- __HAL_TIM_SetCounter(&self->tim, 0);
return mp_const_none;
}
}
@@ -1174,7 +1181,7 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) {
HAL_TIM_Base_Start_IT(&self->tim); // This will re-enable the IRQ
HAL_NVIC_EnableIRQ(self->irqn);
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object"));
+ mp_raise_ValueError("callback must be None or a callable object");
}
return mp_const_none;
}
@@ -1254,7 +1261,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m
///
/// In edge aligned mode, a pulse_width of `period + 1` corresponds to a duty cycle of 100%
/// In center aligned mode, a pulse width of `period` corresponds to a duty cycle of 100%
-STATIC mp_obj_t pyb_timer_channel_capture_compare(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *self = args[0];
if (n_args == 1) {
// get
@@ -1273,7 +1280,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj
/// for which the pulse is active. The value can be an integer or
/// floating-point number for more accuracy. For example, a value of 25 gives
/// a duty cycle of 25%.
-STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *self = args[0];
uint32_t period = compute_period(self->timer);
if (n_args == 1) {
@@ -1331,7 +1338,7 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
break;
}
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object"));
+ mp_raise_ValueError("callback must be None or a callable object");
}
return mp_const_none;
}
diff --git a/stmhal/timer.h b/ports/stm32/timer.h
similarity index 95%
rename from stmhal/timer.h
rename to ports/stm32/timer.h
index 72e461f2f..775accc3d 100644
--- a/stmhal/timer.h
+++ b/ports/stm32/timer.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/uart.c b/ports/stm32/uart.c
similarity index 97%
rename from stmhal/uart.c
rename to ports/stm32/uart.c
index b4ff40e79..0b46d4f04 100644
--- a/stmhal/uart.c
+++ b/ports/stm32/uart.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "py/mperrno.h"
@@ -453,26 +452,11 @@ STATIC size_t uart_tx_data(pyb_uart_obj_t *self, const void *src_in, size_t num_
return num_tx;
}
-STATIC void uart_tx_char(pyb_uart_obj_t *uart_obj, int c) {
- uint16_t ch = c;
- int errcode;
- uart_tx_data(uart_obj, &ch, 1, &errcode);
-}
-
void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len) {
int errcode;
uart_tx_data(uart_obj, str, len, &errcode);
}
-void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len) {
- for (const char *top = str + len; str < top; str++) {
- if (*str == '\n') {
- uart_tx_char(uart_obj, '\r');
- }
- uart_tx_char(uart_obj, *str);
- }
-}
-
// this IRQ handler is set up to handle RXNE interrupts only
void uart_irq_handler(mp_uint_t uart_id) {
// get the uart object
@@ -509,7 +493,7 @@ void uart_irq_handler(mp_uint_t uart_id) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_uart_obj_t *self = self_in;
@@ -555,7 +539,7 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
/// - `timeout_char` is the timeout in milliseconds to wait between characters.
/// - `flow` is RTS | CTS where RTS == 256, CTS == 512
/// - `read_buf_len` is the character length of the read buffer (0 to disable).
-STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_baudrate, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 9600} },
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
@@ -782,7 +766,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
return self;
}
-STATIC mp_obj_t pyb_uart_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_uart_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init);
diff --git a/stmhal/uart.h b/ports/stm32/uart.h
similarity index 92%
rename from stmhal/uart.h
rename to ports/stm32/uart.h
index 749530954..d176520a1 100644
--- a/stmhal/uart.h
+++ b/ports/stm32/uart.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -48,6 +48,5 @@ void uart_irq_handler(mp_uint_t uart_id);
mp_uint_t uart_rx_any(pyb_uart_obj_t *uart_obj);
int uart_rx_char(pyb_uart_obj_t *uart_obj);
void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);
-void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
#endif // MICROPY_INCLUDED_STMHAL_UART_H
diff --git a/stmhal/usb.c b/ports/stm32/usb.c
similarity index 82%
rename from stmhal/usb.c
rename to ports/stm32/usb.c
index f70dea142..69f381d9b 100644
--- a/stmhal/usb.c
+++ b/ports/stm32/usb.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -53,8 +53,16 @@
// this will be persistent across a soft-reset
mp_uint_t pyb_usb_flags = 0;
+typedef struct _usb_device_t {
+ uint32_t enabled;
+ USBD_HandleTypeDef hUSBDDevice;
+ usbd_cdc_msc_hid_state_t usbd_cdc_msc_hid_state;
+ usbd_cdc_itf_t usbd_cdc_itf;
+ usbd_hid_itf_t usbd_hid_itf;
+} usb_device_t;
+
#ifdef USE_DEVICE_MODE
-STATIC USBD_HandleTypeDef hUSBDDevice;
+usb_device_t usb_device;
pyb_usb_storage_medium_t pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_NONE;
#endif
@@ -103,73 +111,74 @@ void pyb_usb_init0(void) {
bool pyb_usb_dev_init(uint16_t vid, uint16_t pid, usb_device_mode_t mode, USBD_HID_ModeInfoTypeDef *hid_info) {
#ifdef USE_DEVICE_MODE
- if (!(pyb_usb_flags & PYB_USB_FLAG_DEV_ENABLED)) {
+ usb_device_t *usb_dev = &usb_device;
+ if (!usb_dev->enabled) {
// only init USB once in the device's power-lifetime
- USBD_SetVIDPIDRelease(vid, pid, 0x0200, mode == USBD_MODE_CDC);
- if (USBD_SelectMode(mode, hid_info) != 0) {
+
+ // configure the VID, PID and the USBD mode (interfaces it will expose)
+ USBD_SetVIDPIDRelease(&usb_dev->usbd_cdc_msc_hid_state, vid, pid, 0x0200, mode == USBD_MODE_CDC);
+ if (USBD_SelectMode(&usb_dev->usbd_cdc_msc_hid_state, mode, hid_info) != 0) {
return false;
}
- USBD_Init(&hUSBDDevice, (USBD_DescriptorsTypeDef*)&USBD_Descriptors, USB_PHY_ID);
- USBD_RegisterClass(&hUSBDDevice, &USBD_CDC_MSC_HID);
- USBD_CDC_RegisterInterface(&hUSBDDevice, (USBD_CDC_ItfTypeDef*)&USBD_CDC_fops);
+
+ // set up the USBD state
+ USBD_HandleTypeDef *usbd = &usb_dev->hUSBDDevice;
+ usbd->id = USB_PHY_ID;
+ usbd->dev_state = USBD_STATE_DEFAULT;
+ usbd->pDesc = (USBD_DescriptorsTypeDef*)&USBD_Descriptors;
+ usbd->pClass = &USBD_CDC_MSC_HID;
+ usb_dev->usbd_cdc_msc_hid_state.pdev = usbd;
+ usb_dev->usbd_cdc_msc_hid_state.cdc = &usb_dev->usbd_cdc_itf;
+ usb_dev->usbd_cdc_msc_hid_state.hid = &usb_dev->usbd_hid_itf;
+ usbd->pClassData = &usb_dev->usbd_cdc_msc_hid_state;
+
switch (pyb_usb_storage_medium) {
#if MICROPY_HW_HAS_SDCARD
case PYB_USB_STORAGE_MEDIUM_SDCARD:
- USBD_MSC_RegisterStorage(&hUSBDDevice, (USBD_StorageTypeDef*)&USBD_SDCARD_STORAGE_fops);
+ USBD_MSC_RegisterStorage(&usb_dev->usbd_cdc_msc_hid_state, (USBD_StorageTypeDef*)&USBD_SDCARD_STORAGE_fops);
break;
#endif
default:
- USBD_MSC_RegisterStorage(&hUSBDDevice, (USBD_StorageTypeDef*)&USBD_FLASH_STORAGE_fops);
+ USBD_MSC_RegisterStorage(&usb_dev->usbd_cdc_msc_hid_state, (USBD_StorageTypeDef*)&USBD_FLASH_STORAGE_fops);
break;
}
- USBD_HID_RegisterInterface(&hUSBDDevice, (USBD_HID_ItfTypeDef*)&USBD_HID_fops);
- USBD_Start(&hUSBDDevice);
+
+ // start the USB device
+ USBD_LL_Init(usbd);
+ USBD_LL_Start(usbd);
+ usb_dev->enabled = true;
}
- pyb_usb_flags |= PYB_USB_FLAG_DEV_ENABLED;
#endif
return true;
}
void pyb_usb_dev_deinit(void) {
- if (pyb_usb_flags & PYB_USB_FLAG_DEV_ENABLED) {
- USBD_Stop(&hUSBDDevice);
- pyb_usb_flags &= ~PYB_USB_FLAG_DEV_ENABLED;
+ usb_device_t *usb_dev = &usb_device;
+ if (usb_dev->enabled) {
+ USBD_Stop(&usb_dev->hUSBDDevice);
+ usb_dev->enabled = false;
}
}
bool usb_vcp_is_enabled(void) {
- return (pyb_usb_flags & PYB_USB_FLAG_DEV_ENABLED) != 0;
+ return usb_device.enabled;
}
int usb_vcp_recv_byte(uint8_t *c) {
- return USBD_CDC_Rx(c, 1, 0);
+ return usbd_cdc_rx(&usb_device.usbd_cdc_itf, c, 1, 0);
}
void usb_vcp_send_strn(const char *str, int len) {
#ifdef USE_DEVICE_MODE
- if (pyb_usb_flags & PYB_USB_FLAG_DEV_ENABLED) {
- USBD_CDC_TxAlways((const uint8_t*)str, len);
- }
-#endif
-}
-
-void usb_vcp_send_strn_cooked(const char *str, int len) {
-#ifdef USE_DEVICE_MODE
- if (pyb_usb_flags & PYB_USB_FLAG_DEV_ENABLED) {
- for (const char *top = str + len; str < top; str++) {
- if (*str == '\n') {
- USBD_CDC_TxAlways((const uint8_t*)"\r\n", 2);
- } else {
- USBD_CDC_TxAlways((const uint8_t*)str, 1);
- }
- }
+ if (usb_device.enabled) {
+ usbd_cdc_tx_always(&usb_device.usbd_cdc_itf, (const uint8_t*)str, len);
}
#endif
}
/******************************************************************************/
-// Micro Python bindings for USB
+// MicroPython bindings for USB
/*
Philosophy of USB driver and Python API: pyb.usb_mode(...) configures the USB
@@ -197,7 +206,7 @@ void usb_vcp_send_strn_cooked(const char *str, int len) {
pyb.usb_mode(..., port=2) # for second USB port
*/
-STATIC mp_obj_t pyb_usb_mode(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_vid, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = USBD_VID} },
@@ -210,7 +219,7 @@ STATIC mp_obj_t pyb_usb_mode(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
#if defined(USE_HOST_MODE)
return MP_OBJ_NEW_QSTR(MP_QSTR_host);
#elif defined(USE_DEVICE_MODE)
- uint8_t mode = USBD_GetMode();
+ uint8_t mode = USBD_GetMode(&usb_device.usbd_cdc_msc_hid_state);
switch (mode) {
case USBD_MODE_CDC:
return MP_OBJ_NEW_QSTR(MP_QSTR_VCP);
@@ -319,12 +328,12 @@ STATIC mp_obj_t pyb_usb_mode(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
return mp_const_none;
bad_mode:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad USB mode"));
+ mp_raise_ValueError("bad USB mode");
}
MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_mode_obj, 0, pyb_usb_mode);
/******************************************************************************/
-// Micro Python bindings for USB VCP
+// MicroPython bindings for USB VCP
/// \moduleref pyb
/// \class USB_VCP - USB virtual comm port
@@ -335,9 +344,10 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_mode_obj, 0, pyb_usb_mode);
typedef struct _pyb_usb_vcp_obj_t {
mp_obj_base_t base;
+ usb_device_t *usb_dev;
} pyb_usb_vcp_obj_t;
-STATIC const pyb_usb_vcp_obj_t pyb_usb_vcp_obj = {{&pyb_usb_vcp_type}};
+STATIC const pyb_usb_vcp_obj_t pyb_usb_vcp_obj = {{&pyb_usb_vcp_type}, &usb_device};
STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
mp_print_str(print, "USB_VCP()");
@@ -362,7 +372,8 @@ STATIC mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in)
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt);
STATIC mp_obj_t pyb_usb_vcp_isconnected(mp_obj_t self_in) {
- return mp_obj_new_bool(USBD_CDC_IsConnected());
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ return mp_obj_new_bool(usbd_cdc_is_connected(&self->usb_dev->usbd_cdc_itf));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_isconnected_obj, pyb_usb_vcp_isconnected);
@@ -375,7 +386,8 @@ MP_DEFINE_CONST_FUN_OBJ_0(pyb_have_cdc_obj, pyb_have_cdc);
/// \method any()
/// Return `True` if any characters waiting, else `False`.
STATIC mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) {
- if (USBD_CDC_RxNum() > 0) {
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ if (usbd_cdc_rx_num(&self->usb_dev->usbd_cdc_itf) > 0) {
return mp_const_true;
} else {
return mp_const_false;
@@ -396,8 +408,9 @@ STATIC const mp_arg_t pyb_usb_vcp_send_args[] = {
};
#define PYB_USB_VCP_SEND_NUM_ARGS MP_ARRAY_SIZE(pyb_usb_vcp_send_args)
-STATIC mp_obj_t pyb_usb_vcp_send(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_usb_vcp_send(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(args[0]);
mp_arg_val_t vals[PYB_USB_VCP_SEND_NUM_ARGS];
mp_arg_parse_all(n_args - 1, args + 1, kw_args, PYB_USB_VCP_SEND_NUM_ARGS, pyb_usb_vcp_send_args, vals);
@@ -407,7 +420,7 @@ STATIC mp_obj_t pyb_usb_vcp_send(mp_uint_t n_args, const mp_obj_t *args, mp_map_
pyb_buf_get_for_send(vals[0].u_obj, &bufinfo, data);
// send the data
- int ret = USBD_CDC_Tx(bufinfo.buf, bufinfo.len, vals[1].u_int);
+ int ret = usbd_cdc_tx(&self->usb_dev->usbd_cdc_itf, bufinfo.buf, bufinfo.len, vals[1].u_int);
return mp_obj_new_int(ret);
}
@@ -423,8 +436,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_send_obj, 1, pyb_usb_vcp_send);
///
/// Return value: if `data` is an integer then a new buffer of the bytes received,
/// otherwise the number of bytes read into `data` is returned.
-STATIC mp_obj_t pyb_usb_vcp_recv(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_usb_vcp_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(args[0]);
mp_arg_val_t vals[PYB_USB_VCP_SEND_NUM_ARGS];
mp_arg_parse_all(n_args - 1, args + 1, kw_args, PYB_USB_VCP_SEND_NUM_ARGS, pyb_usb_vcp_send_args, vals);
@@ -433,7 +447,7 @@ STATIC mp_obj_t pyb_usb_vcp_recv(mp_uint_t n_args, const mp_obj_t *args, mp_map_
mp_obj_t o_ret = pyb_buf_get_for_recv(vals[0].u_obj, &vstr);
// receive the data
- int ret = USBD_CDC_Rx((uint8_t*)vstr.buf, vstr.len, vals[1].u_int);
+ int ret = usbd_cdc_rx(&self->usb_dev->usbd_cdc_itf, (uint8_t*)vstr.buf, vstr.len, vals[1].u_int);
// return the received data
if (o_ret != MP_OBJ_NULL) {
@@ -445,7 +459,7 @@ STATIC mp_obj_t pyb_usb_vcp_recv(mp_uint_t n_args, const mp_obj_t *args, mp_map_
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_recv_obj, 1, pyb_usb_vcp_recv);
-mp_obj_t pyb_usb_vcp___exit__(mp_uint_t n_args, const mp_obj_t *args) {
+mp_obj_t pyb_usb_vcp___exit__(size_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_usb_vcp___exit___obj, 4, 4, pyb_usb_vcp___exit__);
@@ -470,7 +484,8 @@ STATIC const mp_rom_map_elem_t pyb_usb_vcp_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(pyb_usb_vcp_locals_dict, pyb_usb_vcp_locals_dict_table);
STATIC mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
- int ret = USBD_CDC_Rx((byte*)buf, size, 0);
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ int ret = usbd_cdc_rx(&self->usb_dev->usbd_cdc_itf, (byte*)buf, size, 0);
if (ret == 0) {
// return EAGAIN error to indicate non-blocking
*errcode = MP_EAGAIN;
@@ -480,7 +495,8 @@ STATIC mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, i
}
STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
- int ret = USBD_CDC_Tx((const byte*)buf, size, 0);
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ int ret = usbd_cdc_tx(&self->usb_dev->usbd_cdc_itf, (const byte*)buf, size, 0);
if (ret == 0) {
// return EAGAIN error to indicate non-blocking
*errcode = MP_EAGAIN;
@@ -491,13 +507,14 @@ STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t
STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
mp_uint_t ret;
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
ret = 0;
- if ((flags & MP_STREAM_POLL_RD) && USBD_CDC_RxNum() > 0) {
+ if ((flags & MP_STREAM_POLL_RD) && usbd_cdc_rx_num(&self->usb_dev->usbd_cdc_itf) > 0) {
ret |= MP_STREAM_POLL_RD;
}
- if ((flags & MP_STREAM_POLL_WR) && USBD_CDC_TxHalfEmpty()) {
+ if ((flags & MP_STREAM_POLL_WR) && usbd_cdc_tx_half_empty(&self->usb_dev->usbd_cdc_itf)) {
ret |= MP_STREAM_POLL_WR;
}
} else {
@@ -525,13 +542,14 @@ const mp_obj_type_t pyb_usb_vcp_type = {
};
/******************************************************************************/
-// Micro Python bindings for USB HID
+// MicroPython bindings for USB HID
typedef struct _pyb_usb_hid_obj_t {
mp_obj_base_t base;
+ usb_device_t *usb_dev;
} pyb_usb_hid_obj_t;
-STATIC const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}};
+STATIC const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}, &usb_device};
STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
// check arguments
@@ -553,13 +571,14 @@ STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, s
///
/// Return value: if `data` is an integer then a new buffer of the bytes received,
/// otherwise the number of bytes read into `data` is returned.
-STATIC mp_obj_t pyb_usb_hid_recv(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_usb_hid_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
};
// parse args
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(args[0]);
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals);
@@ -568,7 +587,7 @@ STATIC mp_obj_t pyb_usb_hid_recv(mp_uint_t n_args, const mp_obj_t *args, mp_map_
mp_obj_t o_ret = pyb_buf_get_for_recv(vals[0].u_obj, &vstr);
// receive the data
- int ret = USBD_HID_Rx(&hUSBDDevice, (uint8_t*)vstr.buf, vstr.len, vals[1].u_int);
+ int ret = usbd_hid_rx(&self->usb_dev->usbd_hid_itf, vstr.len, (uint8_t*)vstr.buf, vals[1].u_int);
// return the received data
if (o_ret != MP_OBJ_NULL) {
@@ -582,6 +601,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_hid_recv_obj, 1, pyb_usb_hid_recv);
STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) {
#ifdef USE_DEVICE_MODE
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_buffer_info_t bufinfo;
byte temp_buf[8];
// get the buffer to send from
@@ -590,7 +610,7 @@ STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) {
mp_obj_t *items;
mp_obj_get_array(report_in, &bufinfo.len, &items);
if (bufinfo.len > sizeof(temp_buf)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "tuple/list too large for HID report; use bytearray instead"));
+ mp_raise_ValueError("tuple/list too large for HID report; use bytearray instead");
}
for (int i = 0; i < bufinfo.len; i++) {
temp_buf[i] = mp_obj_get_int(items[i]);
@@ -599,7 +619,7 @@ STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) {
}
// send the data
- if (USBD_OK == USBD_HID_SendReport(&hUSBDDevice, bufinfo.buf, bufinfo.len)) {
+ if (USBD_OK == USBD_HID_SendReport(&self->usb_dev->usbd_cdc_msc_hid_state, bufinfo.buf, bufinfo.len)) {
return mp_obj_new_int(bufinfo.len);
} else {
return mp_obj_new_int(0);
@@ -612,7 +632,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_hid_send_obj, pyb_usb_hid_send);
// deprecated in favour of USB_HID.send
STATIC mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
- return pyb_usb_hid_send(MP_OBJ_NULL, arg);
+ return pyb_usb_hid_send(MP_OBJ_FROM_PTR(&pyb_usb_hid_obj), arg);
}
MP_DEFINE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj, pyb_hid_send_report);
@@ -624,14 +644,15 @@ STATIC const mp_rom_map_elem_t pyb_usb_hid_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(pyb_usb_hid_locals_dict, pyb_usb_hid_locals_dict_table);
STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
+ pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
ret = 0;
- if ((flags & MP_STREAM_POLL_RD) && USBD_HID_RxNum() > 0) {
+ if ((flags & MP_STREAM_POLL_RD) && usbd_hid_rx_num(&self->usb_dev->usbd_hid_itf) > 0) {
ret |= MP_STREAM_POLL_RD;
}
- if ((flags & MP_STREAM_POLL_WR) && USBD_HID_CanSendReport(&hUSBDDevice)) {
+ if ((flags & MP_STREAM_POLL_WR) && USBD_HID_CanSendReport(&self->usb_dev->usbd_cdc_msc_hid_state)) {
ret |= MP_STREAM_POLL_WR;
}
} else {
diff --git a/stmhal/usb.h b/ports/stm32/usb.h
similarity index 92%
rename from stmhal/usb.h
rename to ports/stm32/usb.h
index e04fe70d7..41c461fb2 100644
--- a/stmhal/usb.h
+++ b/ports/stm32/usb.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include "usbd_cdc_msc_hid0.h"
-#define PYB_USB_FLAG_DEV_ENABLED (0x0001)
#define PYB_USB_FLAG_USB_MODE_CALLED (0x0002)
// Windows needs a different PID to distinguish different device configurations
@@ -44,8 +43,8 @@ typedef enum {
} pyb_usb_storage_medium_t;
typedef enum {
- USB_PHY_FS_ID = 0,
- USB_PHY_HS_ID = 1,
+ USB_PHY_FS_ID = 0,
+ USB_PHY_HS_ID = 1,
} USB_PHY_ID;
extern mp_uint_t pyb_usb_flags;
@@ -64,7 +63,6 @@ void pyb_usb_dev_deinit(void);
bool usb_vcp_is_enabled(void);
int usb_vcp_recv_byte(uint8_t *c); // if a byte is available, return 1 and put the byte in *c, else return 0
void usb_vcp_send_strn(const char* str, int len);
-void usb_vcp_send_strn_cooked(const char *str, int len);
void pyb_usb_host_init(void);
void pyb_usb_host_process(void);
diff --git a/stmhal/usbd_cdc_interface.c b/ports/stm32/usbd_cdc_interface.c
similarity index 59%
rename from stmhal/usbd_cdc_interface.c
rename to ports/stm32/usbd_cdc_interface.c
index 3e107d418..2e9fba917 100644
--- a/stmhal/usbd_cdc_interface.c
+++ b/ports/stm32/usbd_cdc_interface.c
@@ -41,12 +41,9 @@
#include "usbd_cdc_interface.h"
#include "pendsv.h"
-#include "py/mpstate.h"
#include "py/obj.h"
#include "lib/utils/interrupt_char.h"
#include "irq.h"
-#include "timer.h"
-#include "usb.h"
// CDC control commands
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00
@@ -59,78 +56,31 @@
#define CDC_SET_CONTROL_LINE_STATE 0x22
#define CDC_SEND_BREAK 0x23
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-#define APP_RX_DATA_SIZE 1024 // this must be 2 or greater, and a power of 2
-#define APP_TX_DATA_SIZE 1024 // I think this can be any value (was 2048)
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-
-static __IO uint8_t dev_is_connected = 0; // indicates if we are connected
-
-static uint8_t cdc_rx_packet_buf[CDC_DATA_FS_MAX_PACKET_SIZE]; // received data from USB OUT endpoint is stored in this buffer
-static uint8_t cdc_rx_user_buf[APP_RX_DATA_SIZE]; // received data is buffered here until the user reads it
-static volatile uint16_t cdc_rx_buf_put = 0; // circular buffer index
-static uint16_t cdc_rx_buf_get = 0; // circular buffer index
-
-static uint8_t UserTxBuffer[APP_TX_DATA_SIZE]; // data for USB IN endpoind is stored in this buffer
-static uint16_t UserTxBufPtrIn = 0; // increment this pointer modulo APP_TX_DATA_SIZE when new data is available
-static __IO uint16_t UserTxBufPtrOut = 0; // increment this pointer modulo APP_TX_DATA_SIZE when data is drained
-static uint16_t UserTxBufPtrOutShadow = 0; // shadow of above
-static uint8_t UserTxBufPtrWaitCount = 0; // used to implement a timeout waiting for low-level USB driver
-static uint8_t UserTxNeedEmptyPacket = 0; // used to flush the USB IN endpoint if the last packet was exactly the endpoint packet size
-
-/* Private function prototypes -----------------------------------------------*/
-static int8_t CDC_Itf_Init (USBD_HandleTypeDef *pdev);
-static int8_t CDC_Itf_DeInit (void);
-static int8_t CDC_Itf_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length);
-static int8_t CDC_Itf_Receive (USBD_HandleTypeDef *pdev, uint8_t* pbuf, uint32_t *Len);
-
-const USBD_CDC_ItfTypeDef USBD_CDC_fops = {
- CDC_Itf_Init,
- CDC_Itf_DeInit,
- CDC_Itf_Control,
- CDC_Itf_Receive
-};
-
-/* Private functions ---------------------------------------------------------*/
-
-/**
- * @brief CDC_Itf_Init
- * Initializes the CDC media low layer
- * @param None
- * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
- */
-static int8_t CDC_Itf_Init(USBD_HandleTypeDef *pdev) {
- USBD_CDC_SetTxBuffer(pdev, UserTxBuffer, 0);
- USBD_CDC_SetRxBuffer(pdev, cdc_rx_packet_buf);
-
- cdc_rx_buf_put = 0;
- cdc_rx_buf_get = 0;
-
- return USBD_OK;
+uint8_t *usbd_cdc_init(usbd_cdc_itf_t *cdc, usbd_cdc_msc_hid_state_t *usbd) {
+ // Link the parent state
+ cdc->usbd = usbd;
+
+ // Reset all the CDC state
+ // Note: we don't reset tx_buf_ptr_in in order to allow the output buffer to
+ // be filled (by usbd_cdc_tx_always) before the USB device is connected.
+ cdc->rx_buf_put = 0;
+ cdc->rx_buf_get = 0;
+ cdc->tx_buf_ptr_out = 0;
+ cdc->tx_buf_ptr_out_shadow = 0;
+ cdc->tx_buf_ptr_wait_count = 0;
+ cdc->tx_need_empty_packet = 0;
+ cdc->dev_is_connected = 0;
+
+ // Return the buffer to place the first USB OUT packet
+ return cdc->rx_packet_buf;
}
-/**
- * @brief CDC_Itf_DeInit
- * DeInitializes the CDC media low layer
- * @param None
- * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
- */
-static int8_t CDC_Itf_DeInit(void) {
- return USBD_OK;
-}
-
-/**
- * @brief CDC_Itf_Control
- * Manage the CDC class requests
- * @param Cmd: Command code
- * @param Buf: Buffer containing command data (request parameters)
- * @param Len: Number of data to be sent (in bytes)
- * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
- */
-static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length) {
+// Manage the CDC class requests
+// cmd: command code
+// pbuf: buffer containing command data (request parameters)
+// length: number of data to be sent (in bytes)
+// Returns USBD_OK if all operations are OK else USBD_FAIL
+int8_t usbd_cdc_control(usbd_cdc_itf_t *cdc, uint8_t cmd, uint8_t* pbuf, uint16_t length) {
switch (cmd) {
case CDC_SEND_ENCAPSULATED_COMMAND:
/* Add your code here */
@@ -175,7 +125,7 @@ static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length) {
break;
case CDC_SET_CONTROL_LINE_STATE:
- dev_is_connected = length & 1; // wValue is passed in Len (bit of a hack)
+ cdc->dev_is_connected = length & 1; // wValue is passed in Len (bit of a hack)
break;
case CDC_SEND_BREAK:
@@ -193,53 +143,54 @@ static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length) {
// SOF (start of frame) callback so that it is called exactly at the time it is
// needed (reducing latency), and often enough (increasing bandwidth).
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
- if (!dev_is_connected) {
+ usbd_cdc_msc_hid_state_t *usbd = ((USBD_HandleTypeDef*)hpcd->pData)->pClassData;
+ usbd_cdc_itf_t *cdc = usbd->cdc;
+
+ if (cdc == NULL || !cdc->dev_is_connected) {
// CDC device is not connected to a host, so we are unable to send any data
return;
}
- if (UserTxBufPtrOut == UserTxBufPtrIn && !UserTxNeedEmptyPacket) {
+ if (cdc->tx_buf_ptr_out == cdc->tx_buf_ptr_in && !cdc->tx_need_empty_packet) {
// No outstanding data to send
return;
}
- if (UserTxBufPtrOut != UserTxBufPtrOutShadow) {
+ if (cdc->tx_buf_ptr_out != cdc->tx_buf_ptr_out_shadow) {
// We have sent data and are waiting for the low-level USB driver to
// finish sending it over the USB in-endpoint.
// SOF occurs every 1ms, so we have a 500 * 1ms = 500ms timeout
// We have a relatively large timeout because the USB host may be busy
// doing other things and we must give it a chance to read our data.
- if (UserTxBufPtrWaitCount < 500) {
+ if (cdc->tx_buf_ptr_wait_count < 500) {
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
if (USBx_INEP(CDC_IN_EP & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) {
// USB in-endpoint is still reading the data
- UserTxBufPtrWaitCount++;
+ cdc->tx_buf_ptr_wait_count++;
return;
}
}
- UserTxBufPtrOut = UserTxBufPtrOutShadow;
+ cdc->tx_buf_ptr_out = cdc->tx_buf_ptr_out_shadow;
}
- if (UserTxBufPtrOutShadow != UserTxBufPtrIn || UserTxNeedEmptyPacket) {
+ if (cdc->tx_buf_ptr_out_shadow != cdc->tx_buf_ptr_in || cdc->tx_need_empty_packet) {
uint32_t buffptr;
uint32_t buffsize;
- if (UserTxBufPtrOutShadow > UserTxBufPtrIn) { // rollback
- buffsize = APP_TX_DATA_SIZE - UserTxBufPtrOutShadow;
+ if (cdc->tx_buf_ptr_out_shadow > cdc->tx_buf_ptr_in) { // rollback
+ buffsize = USBD_CDC_TX_DATA_SIZE - cdc->tx_buf_ptr_out_shadow;
} else {
- buffsize = UserTxBufPtrIn - UserTxBufPtrOutShadow;
+ buffsize = cdc->tx_buf_ptr_in - cdc->tx_buf_ptr_out_shadow;
}
- buffptr = UserTxBufPtrOutShadow;
-
- USBD_CDC_SetTxBuffer(hpcd->pData, (uint8_t*)&UserTxBuffer[buffptr], buffsize);
+ buffptr = cdc->tx_buf_ptr_out_shadow;
- if (USBD_CDC_TransmitPacket(hpcd->pData) == USBD_OK) {
- UserTxBufPtrOutShadow += buffsize;
- if (UserTxBufPtrOutShadow == APP_TX_DATA_SIZE) {
- UserTxBufPtrOutShadow = 0;
+ if (USBD_CDC_TransmitPacket(cdc->usbd, buffsize, &cdc->tx_buf[buffptr]) == USBD_OK) {
+ cdc->tx_buf_ptr_out_shadow += buffsize;
+ if (cdc->tx_buf_ptr_out_shadow == USBD_CDC_TX_DATA_SIZE) {
+ cdc->tx_buf_ptr_out_shadow = 0;
}
- UserTxBufPtrWaitCount = 0;
+ cdc->tx_buf_ptr_wait_count = 0;
// According to the USB specification, a packet size of 64 bytes (CDC_DATA_FS_MAX_PACKET_SIZE)
// gets held at the USB host until the next packet is sent. This is because a
@@ -247,62 +198,51 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
// the host waits for all data to arrive (ie, waits for a packet < max packet size).
// To flush a packet of exactly max packet size, we need to send a zero-size packet.
// See eg http://www.cypress.com/?id=4&rID=92719
- UserTxNeedEmptyPacket = (buffsize > 0 && buffsize % CDC_DATA_FS_MAX_PACKET_SIZE == 0 && UserTxBufPtrOutShadow == UserTxBufPtrIn);
+ cdc->tx_need_empty_packet = (buffsize > 0 && buffsize % CDC_DATA_FS_MAX_PACKET_SIZE == 0 && cdc->tx_buf_ptr_out_shadow == cdc->tx_buf_ptr_in);
}
}
}
-/**
- * @brief CDC_Itf_DataRx
- * Data received over USB OUT endpoint is processed here.
- * @param Buf: Buffer of data received
- * @param Len: Number of data received (in bytes)
- * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
- * @note The buffer we are passed here is just cdc_rx_packet_buf, so we are
- * free to modify it.
- */
-static int8_t CDC_Itf_Receive(USBD_HandleTypeDef *pdev, uint8_t* Buf, uint32_t *Len) {
+// Data received over USB OUT endpoint is processed here.
+// len: number of bytes received into the buffer we passed to USBD_CDC_ReceivePacket
+// Returns USBD_OK if all operations are OK else USBD_FAIL
+int8_t usbd_cdc_receive(usbd_cdc_itf_t *cdc, size_t len) {
// copy the incoming data into the circular buffer
- for (uint8_t *src = Buf, *top = Buf + *Len; src < top; ++src) {
+ for (const uint8_t *src = cdc->rx_packet_buf, *top = cdc->rx_packet_buf + len; src < top; ++src) {
if (mp_interrupt_char != -1 && *src == mp_interrupt_char) {
pendsv_kbd_intr();
} else {
- uint16_t next_put = (cdc_rx_buf_put + 1) & (APP_RX_DATA_SIZE - 1);
- if (next_put == cdc_rx_buf_get) {
+ uint16_t next_put = (cdc->rx_buf_put + 1) & (USBD_CDC_RX_DATA_SIZE - 1);
+ if (next_put == cdc->rx_buf_get) {
// overflow, we just discard the rest of the chars
break;
}
- cdc_rx_user_buf[cdc_rx_buf_put] = *src;
- cdc_rx_buf_put = next_put;
+ cdc->rx_user_buf[cdc->rx_buf_put] = *src;
+ cdc->rx_buf_put = next_put;
}
}
// initiate next USB packet transfer
- USBD_CDC_SetRxBuffer(pdev, cdc_rx_packet_buf);
- USBD_CDC_ReceivePacket(pdev);
+ USBD_CDC_ReceivePacket(cdc->usbd, cdc->rx_packet_buf);
return USBD_OK;
}
-int USBD_CDC_IsConnected(void) {
- return dev_is_connected;
-}
-
-int USBD_CDC_TxHalfEmpty(void) {
- int32_t tx_waiting = (int32_t)UserTxBufPtrIn - (int32_t)UserTxBufPtrOut;
+int usbd_cdc_tx_half_empty(usbd_cdc_itf_t *cdc) {
+ int32_t tx_waiting = (int32_t)cdc->tx_buf_ptr_in - (int32_t)cdc->tx_buf_ptr_out;
if (tx_waiting < 0) {
- tx_waiting += APP_TX_DATA_SIZE;
+ tx_waiting += USBD_CDC_TX_DATA_SIZE;
}
- return tx_waiting <= APP_TX_DATA_SIZE / 2;
+ return tx_waiting <= USBD_CDC_TX_DATA_SIZE / 2;
}
// timout in milliseconds.
// Returns number of bytes written to the device.
-int USBD_CDC_Tx(const uint8_t *buf, uint32_t len, uint32_t timeout) {
+int usbd_cdc_tx(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len, uint32_t timeout) {
for (uint32_t i = 0; i < len; i++) {
// Wait until the device is connected and the buffer has space, with a given timeout
uint32_t start = HAL_GetTick();
- while (!dev_is_connected || ((UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1)) == UserTxBufPtrOut) {
+ while (!cdc->dev_is_connected || ((cdc->tx_buf_ptr_in + 1) & (USBD_CDC_TX_DATA_SIZE - 1)) == cdc->tx_buf_ptr_out) {
// Wraparound of tick is taken care of by 2's complement arithmetic.
if (HAL_GetTick() - start >= timeout) {
// timeout
@@ -316,8 +256,8 @@ int USBD_CDC_Tx(const uint8_t *buf, uint32_t len, uint32_t timeout) {
}
// Write data to device buffer
- UserTxBuffer[UserTxBufPtrIn] = buf[i];
- UserTxBufPtrIn = (UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1);
+ cdc->tx_buf[cdc->tx_buf_ptr_in] = buf[i];
+ cdc->tx_buf_ptr_in = (cdc->tx_buf_ptr_in + 1) & (USBD_CDC_TX_DATA_SIZE - 1);
}
// Success, return number of bytes read
@@ -327,18 +267,18 @@ int USBD_CDC_Tx(const uint8_t *buf, uint32_t len, uint32_t timeout) {
// Always write all of the data to the device tx buffer, even if the
// device is not connected, or if the buffer is full. Has a small timeout
// to wait for the buffer to be drained, in the case the device is connected.
-void USBD_CDC_TxAlways(const uint8_t *buf, uint32_t len) {
+void usbd_cdc_tx_always(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len) {
for (int i = 0; i < len; i++) {
// If the CDC device is not connected to the host then we don't have anyone to receive our data.
// The device may become connected in the future, so we should at least try to fill the buffer
// and hope that it doesn't overflow by the time the device connects.
// If the device is not connected then we should go ahead and fill the buffer straight away,
// ignoring overflow. Otherwise, we should make sure that we have enough room in the buffer.
- if (dev_is_connected) {
+ if (cdc->dev_is_connected) {
// If the buffer is full, wait until it gets drained, with a timeout of 500ms
// (wraparound of tick is taken care of by 2's complement arithmetic).
uint32_t start = HAL_GetTick();
- while (((UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1)) == UserTxBufPtrOut && HAL_GetTick() - start <= 500) {
+ while (((cdc->tx_buf_ptr_in + 1) & (USBD_CDC_TX_DATA_SIZE - 1)) == cdc->tx_buf_ptr_out && HAL_GetTick() - start <= 500) {
if (query_irq() == IRQ_STATE_DISABLED) {
// IRQs disabled so buffer will never be drained; exit loop
break;
@@ -365,28 +305,28 @@ void USBD_CDC_TxAlways(const uint8_t *buf, uint32_t len) {
*/
}
- UserTxBuffer[UserTxBufPtrIn] = buf[i];
- UserTxBufPtrIn = (UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1);
+ cdc->tx_buf[cdc->tx_buf_ptr_in] = buf[i];
+ cdc->tx_buf_ptr_in = (cdc->tx_buf_ptr_in + 1) & (USBD_CDC_TX_DATA_SIZE - 1);
}
}
// Returns number of bytes in the rx buffer.
-int USBD_CDC_RxNum(void) {
- int32_t rx_waiting = (int32_t)cdc_rx_buf_put - (int32_t)cdc_rx_buf_get;
+int usbd_cdc_rx_num(usbd_cdc_itf_t *cdc) {
+ int32_t rx_waiting = (int32_t)cdc->rx_buf_put - (int32_t)cdc->rx_buf_get;
if (rx_waiting < 0) {
- rx_waiting += APP_RX_DATA_SIZE;
+ rx_waiting += USBD_CDC_RX_DATA_SIZE;
}
return rx_waiting;
}
// timout in milliseconds.
// Returns number of bytes read from the device.
-int USBD_CDC_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
+int usbd_cdc_rx(usbd_cdc_itf_t *cdc, uint8_t *buf, uint32_t len, uint32_t timeout) {
// loop to read bytes
for (uint32_t i = 0; i < len; i++) {
// Wait until we have at least 1 byte to read
uint32_t start = HAL_GetTick();
- while (cdc_rx_buf_put == cdc_rx_buf_get) {
+ while (cdc->rx_buf_put == cdc->rx_buf_get) {
// Wraparound of tick is taken care of by 2's complement arithmetic.
if (HAL_GetTick() - start >= timeout) {
// timeout
@@ -400,8 +340,8 @@ int USBD_CDC_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
}
// Copy byte from device to user buffer
- buf[i] = cdc_rx_user_buf[cdc_rx_buf_get];
- cdc_rx_buf_get = (cdc_rx_buf_get + 1) & (APP_RX_DATA_SIZE - 1);
+ buf[i] = cdc->rx_user_buf[cdc->rx_buf_get];
+ cdc->rx_buf_get = (cdc->rx_buf_get + 1) & (USBD_CDC_RX_DATA_SIZE - 1);
}
// Success, return number of bytes read
diff --git a/ports/stm32/usbd_cdc_interface.h b/ports/stm32/usbd_cdc_interface.h
new file mode 100644
index 000000000..98b8fc077
--- /dev/null
+++ b/ports/stm32/usbd_cdc_interface.h
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ */
+#ifndef MICROPY_INCLUDED_STMHAL_USBD_CDC_INTERFACE_H
+#define MICROPY_INCLUDED_STMHAL_USBD_CDC_INTERFACE_H
+
+/**
+ ******************************************************************************
+ * @file USB_Device/CDC_Standalone/Inc/usbd_cdc_interface.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 26-February-2014
+ * @brief Header for usbd_cdc_interface.c file.
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+#define USBD_CDC_RX_DATA_SIZE (1024) // this must be 2 or greater, and a power of 2
+#define USBD_CDC_TX_DATA_SIZE (1024) // I think this can be any value (was 2048)
+
+typedef struct _usbd_cdc_itf_t {
+ usbd_cdc_msc_hid_state_t *usbd; // the parent USB device
+
+ uint8_t rx_packet_buf[CDC_DATA_FS_MAX_PACKET_SIZE]; // received data from USB OUT endpoint is stored in this buffer
+ uint8_t rx_user_buf[USBD_CDC_RX_DATA_SIZE]; // received data is buffered here until the user reads it
+ volatile uint16_t rx_buf_put; // circular buffer index
+ uint16_t rx_buf_get; // circular buffer index
+
+ uint8_t tx_buf[USBD_CDC_TX_DATA_SIZE]; // data for USB IN endpoind is stored in this buffer
+ uint16_t tx_buf_ptr_in; // increment this pointer modulo USBD_CDC_TX_DATA_SIZE when new data is available
+ volatile uint16_t tx_buf_ptr_out; // increment this pointer modulo USBD_CDC_TX_DATA_SIZE when data is drained
+ uint16_t tx_buf_ptr_out_shadow; // shadow of above
+ uint8_t tx_buf_ptr_wait_count; // used to implement a timeout waiting for low-level USB driver
+ uint8_t tx_need_empty_packet; // used to flush the USB IN endpoint if the last packet was exactly the endpoint packet size
+
+ volatile uint8_t dev_is_connected; // indicates if we are connected
+} usbd_cdc_itf_t;
+
+static inline int usbd_cdc_is_connected(usbd_cdc_itf_t *cdc) {
+ return cdc->dev_is_connected;
+}
+
+int usbd_cdc_tx_half_empty(usbd_cdc_itf_t *cdc);
+int usbd_cdc_tx(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len, uint32_t timeout);
+void usbd_cdc_tx_always(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len);
+
+int usbd_cdc_rx_num(usbd_cdc_itf_t *cdc);
+int usbd_cdc_rx(usbd_cdc_itf_t *cdc, uint8_t *buf, uint32_t len, uint32_t timeout);
+
+#endif // MICROPY_INCLUDED_STMHAL_USBD_CDC_INTERFACE_H
diff --git a/stmhal/usbd_conf.c b/ports/stm32/usbd_conf.c
similarity index 96%
rename from stmhal/usbd_conf.c
rename to ports/stm32/usbd_conf.c
index e2bd6c949..d39144851 100644
--- a/stmhal/usbd_conf.c
+++ b/ports/stm32/usbd_conf.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*/
/**
diff --git a/stmhal/usbd_conf.h b/ports/stm32/usbd_conf.h
similarity index 94%
rename from stmhal/usbd_conf.h
rename to ports/stm32/usbd_conf.h
index b69ba52c2..34ebe27b9 100644
--- a/stmhal/usbd_conf.h
+++ b/ports/stm32/usbd_conf.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*/
/**
diff --git a/stmhal/usbd_desc.c b/ports/stm32/usbd_desc.c
similarity index 60%
rename from stmhal/usbd_desc.c
rename to ports/stm32/usbd_desc.c
index 1ad960b46..1de75aee0 100644
--- a/stmhal/usbd_desc.c
+++ b/ports/stm32/usbd_desc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*/
/**
@@ -50,59 +50,45 @@
#define USBD_CONFIGURATION_FS_STRING "Pyboard Config"
#define USBD_INTERFACE_FS_STRING "Pyboard Interface"
-// USB Standard Device Descriptor
-// needs to be in RAM because we modify the VID and PID
-__ALIGN_BEGIN static uint8_t hUSBDDeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
- 0x12, // bLength
- USB_DESC_TYPE_DEVICE, // bDescriptorType
- 0x00, // bcdUSB
- 0x02,
- 0xef, // bDeviceClass: Miscellaneous Device Class
- 0x02, // bDeviceSubClass: Common Class
- 0x01, // bDeviceProtocol: Interface Association Descriptor
- USB_MAX_EP0_SIZE, // bMaxPacketSize
- LOBYTE(USBD_VID), // idVendor
- HIBYTE(USBD_VID), // idVendor
- LOBYTE(USBD_PID), // idVendor
- HIBYTE(USBD_PID), // idVendor
- 0x00, // bcdDevice rel. 2.00
- 0x02,
- USBD_IDX_MFC_STR, // Index of manufacturer string
- USBD_IDX_PRODUCT_STR, // Index of product string
- USBD_IDX_SERIAL_STR, // Index of serial number string
- USBD_MAX_NUM_CONFIGURATION // bNumConfigurations
-};
-
-__ALIGN_BEGIN static uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
+__ALIGN_BEGIN static const uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
USB_LEN_LANGID_STR_DESC,
USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING),
};
-__ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
-
// set the VID, PID and device release number
-void USBD_SetVIDPIDRelease(uint16_t vid, uint16_t pid, uint16_t device_release_num, int cdc_only) {
+void USBD_SetVIDPIDRelease(usbd_cdc_msc_hid_state_t *usbd, uint16_t vid, uint16_t pid, uint16_t device_release_num, int cdc_only) {
+ uint8_t *dev_desc = &usbd->usbd_device_desc[0];
+
+ dev_desc[0] = USB_LEN_DEV_DESC; // bLength
+ dev_desc[1] = USB_DESC_TYPE_DEVICE; // bDescriptorType
+ dev_desc[2] = 0x00; // bcdUSB
+ dev_desc[3] = 0x02; // bcdUSB
if (cdc_only) {
// Make it look like a Communications device if we're only
// using CDC. Otherwise, windows gets confused when we tell it that
// its a composite device with only a cdc serial interface.
- hUSBDDeviceDesc[4] = 0x02;
- hUSBDDeviceDesc[5] = 0x00;
- hUSBDDeviceDesc[6] = 0x00;
+ dev_desc[4] = 0x02; // bDeviceClass
+ dev_desc[5] = 0x00; // bDeviceSubClass
+ dev_desc[6] = 0x00; // bDeviceProtocol
} else {
// For the other modes, we make this look like a composite device.
- hUSBDDeviceDesc[4] = 0xef;
- hUSBDDeviceDesc[5] = 0x02;
- hUSBDDeviceDesc[6] = 0x01;
+ dev_desc[4] = 0xef; // bDeviceClass: Miscellaneous Device Class
+ dev_desc[5] = 0x02; // bDeviceSubClass: Common Class
+ dev_desc[6] = 0x01; // bDeviceProtocol: Interface Association Descriptor
}
- hUSBDDeviceDesc[8] = LOBYTE(vid);
- hUSBDDeviceDesc[9] = HIBYTE(vid);
- hUSBDDeviceDesc[10] = LOBYTE(pid);
- hUSBDDeviceDesc[11] = HIBYTE(pid);
- hUSBDDeviceDesc[12] = LOBYTE(device_release_num);
- hUSBDDeviceDesc[13] = HIBYTE(device_release_num);
+ dev_desc[7] = USB_MAX_EP0_SIZE; // bMaxPacketSize
+ dev_desc[8] = LOBYTE(vid); // idVendor
+ dev_desc[9] = HIBYTE(vid); // idVendor
+ dev_desc[10] = LOBYTE(pid); // idVendor
+ dev_desc[11] = HIBYTE(pid); // idVendor
+ dev_desc[12] = LOBYTE(device_release_num); // bcdDevice
+ dev_desc[13] = HIBYTE(device_release_num); // bcdDevice
+ dev_desc[14] = USBD_IDX_MFC_STR; // Index of manufacturer string
+ dev_desc[15] = USBD_IDX_PRODUCT_STR; // Index of product string
+ dev_desc[16] = USBD_IDX_SERIAL_STR; // Index of serial number string
+ dev_desc[17] = USBD_MAX_NUM_CONFIGURATION; // bNumConfigurations
}
/**
@@ -111,9 +97,10 @@ void USBD_SetVIDPIDRelease(uint16_t vid, uint16_t pid, uint16_t device_release_n
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
-STATIC uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- *length = sizeof(hUSBDDeviceDesc);
- return hUSBDDeviceDesc;
+STATIC uint8_t *USBD_DeviceDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
+ uint8_t *dev_desc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->usbd_device_desc;
+ *length = USB_LEN_DEV_DESC;
+ return dev_desc;
}
/**
@@ -122,9 +109,9 @@ STATIC uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
-STATIC uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
+STATIC uint8_t *USBD_LangIDStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
*length = sizeof(USBD_LangIDDesc);
- return USBD_LangIDDesc;
+ return (uint8_t*)USBD_LangIDDesc; // the data should only be read from this buf
}
/**
@@ -133,13 +120,14 @@ STATIC uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
-STATIC uint8_t *USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- if(speed == 0) {
- USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
+STATIC uint8_t *USBD_ProductStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
+ uint8_t *str_desc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->usbd_str_desc;
+ if (pdev->dev_speed == USBD_SPEED_HIGH) {
+ USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, str_desc, length);
} else {
- USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
+ USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, str_desc, length);
}
- return USBD_StrDesc;
+ return str_desc;
}
/**
@@ -148,9 +136,10 @@ STATIC uint8_t *USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *len
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
-STATIC uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
- return USBD_StrDesc;
+STATIC uint8_t *USBD_ManufacturerStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
+ uint8_t *str_desc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->usbd_str_desc;
+ USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, str_desc, length);
+ return str_desc;
}
/**
@@ -159,7 +148,7 @@ STATIC uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
-STATIC uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
+STATIC uint8_t *USBD_SerialStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
// This document: http://www.usb.org/developers/docs/devclass_docs/usbmassbulk_10.pdf
// says that the serial number has to be at least 12 digits long and that
// the last 12 digits need to be unique. It also stipulates that the valid
@@ -179,8 +168,9 @@ STATIC uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
"%02X%02X%02X%02X%02X%02X",
id[11], id[10] + id[2], id[9], id[8] + id[0], id[7], id[6]);
- USBD_GetString((uint8_t *)serial_buf, USBD_StrDesc, length);
- return USBD_StrDesc;
+ uint8_t *str_desc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->usbd_str_desc;
+ USBD_GetString((uint8_t *)serial_buf, str_desc, length);
+ return str_desc;
}
/**
@@ -189,13 +179,14 @@ STATIC uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
-STATIC uint8_t *USBD_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- if(speed == USBD_SPEED_HIGH) {
- USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
+STATIC uint8_t *USBD_ConfigStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
+ uint8_t *str_desc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->usbd_str_desc;
+ if (pdev->dev_speed == USBD_SPEED_HIGH) {
+ USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, str_desc, length);
} else {
- USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
+ USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, str_desc, length);
}
- return USBD_StrDesc;
+ return str_desc;
}
/**
@@ -204,13 +195,14 @@ STATIC uint8_t *USBD_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
-STATIC uint8_t *USBD_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- if(speed == 0) {
- USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
+STATIC uint8_t *USBD_InterfaceStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
+ uint8_t *str_desc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->usbd_str_desc;
+ if (pdev->dev_speed == USBD_SPEED_HIGH) {
+ USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, str_desc, length);
} else {
- USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
+ USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, str_desc, length);
}
- return USBD_StrDesc;
+ return str_desc;
}
const USBD_DescriptorsTypeDef USBD_Descriptors = {
diff --git a/stmhal/usbd_desc.h b/ports/stm32/usbd_desc.h
similarity index 85%
rename from stmhal/usbd_desc.h
rename to ports/stm32/usbd_desc.h
index f48e364e1..a4de6c681 100644
--- a/stmhal/usbd_desc.h
+++ b/ports/stm32/usbd_desc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,8 +26,10 @@
#ifndef MICROPY_INCLUDED_STMHAL_USBD_DESC_H
#define MICROPY_INCLUDED_STMHAL_USBD_DESC_H
+#include "usbd_cdc_msc_hid.h"
+
extern const USBD_DescriptorsTypeDef USBD_Descriptors;
-void USBD_SetVIDPIDRelease(uint16_t vid, uint16_t pid, uint16_t device_release_num, int cdc_only);
+void USBD_SetVIDPIDRelease(usbd_cdc_msc_hid_state_t *usbd, uint16_t vid, uint16_t pid, uint16_t device_release_num, int cdc_only);
#endif // MICROPY_INCLUDED_STMHAL_USBD_DESC_H
diff --git a/stmhal/usbd_hid_interface.c b/ports/stm32/usbd_hid_interface.c
similarity index 52%
rename from stmhal/usbd_hid_interface.c
rename to ports/stm32/usbd_hid_interface.c
index 11b3a3acd..4ee533c21 100644
--- a/stmhal/usbd_hid_interface.c
+++ b/ports/stm32/usbd_hid_interface.c
@@ -36,75 +36,46 @@
#include
-#include "usbd_cdc_msc_hid.h"
#include "usbd_hid_interface.h"
#include "py/obj.h"
#include "irq.h"
#include "usb.h"
-/* Private variables ---------------------------------------------------------*/
+uint8_t *usbd_hid_init(usbd_hid_itf_t *hid, usbd_cdc_msc_hid_state_t *usbd) {
+ hid->usbd = usbd;
+ hid->current_read_buffer = 0;
+ hid->last_read_len = 0;
+ hid->current_write_buffer = 0;
-static uint8_t buffer[2][HID_DATA_FS_MAX_PACKET_SIZE]; // pair of buffers to read individual packets into
-static int8_t current_read_buffer = 0; // which buffer to read from
-static uint32_t last_read_len = 0; // length of last read
-static int8_t current_write_buffer = 0; // which buffer to write to
-
-/* Private function prototypes -----------------------------------------------*/
-static int8_t HID_Itf_Init (USBD_HandleTypeDef *pdev);
-static int8_t HID_Itf_Receive (USBD_HandleTypeDef *pdev, uint8_t* pbuf, uint32_t Len);
-
-const USBD_HID_ItfTypeDef USBD_HID_fops = {
- HID_Itf_Init,
- HID_Itf_Receive
-};
-
-/**
- * @brief HID_Itf_Init
- * Initializes the HID media low layer
- * @param None
- * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
- */
-static int8_t HID_Itf_Init(USBD_HandleTypeDef *pdev)
-{
- current_read_buffer = 0;
- last_read_len = 0;
- current_write_buffer = 0;
- USBD_HID_SetRxBuffer(pdev, buffer[current_write_buffer]);
- return USBD_OK;
+ // Return the buffer to place the first USB OUT packet
+ return hid->buffer[hid->current_write_buffer];
}
-/**
- * @brief HID_Itf_Receive
- * Data received over USB OUT endpoint is processed here.
- * @param Buf: Buffer of data received
- * @param Len: Number of data received (in bytes)
- * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
- * @note The buffer we are passed here is just UserRxBuffer, so we are
- * free to modify it.
- */
-static int8_t HID_Itf_Receive(USBD_HandleTypeDef *pdev, uint8_t* Buf, uint32_t Len) {
- current_write_buffer = !current_write_buffer;
- last_read_len = Len;
+// Data received over USB OUT endpoint is processed here.
+// len: number of bytes received into the buffer we passed to USBD_HID_ReceivePacket
+// Returns USBD_OK if all operations are OK else USBD_FAIL
+int8_t usbd_hid_receive(usbd_hid_itf_t *hid, size_t len) {
+ hid->current_write_buffer = !hid->current_write_buffer;
+ hid->last_read_len = len;
// initiate next USB packet transfer, to append to existing data in buffer
- USBD_HID_SetRxBuffer(pdev, buffer[current_write_buffer]);
- USBD_HID_ReceivePacket(pdev);
+ USBD_HID_ReceivePacket(hid->usbd, hid->buffer[hid->current_write_buffer]);
// Set NAK to indicate we need to process read buffer
- USBD_HID_SetNAK(pdev);
+ USBD_HID_SetNAK(hid->usbd);
return USBD_OK;
}
// Returns number of ready rx buffers.
-int USBD_HID_RxNum(void) {
- return (current_read_buffer != current_write_buffer);
+int usbd_hid_rx_num(usbd_hid_itf_t *hid) {
+ return hid->current_read_buffer != hid->current_write_buffer;
}
// timout in milliseconds.
// Returns number of bytes read from the device.
-int USBD_HID_Rx(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len, uint32_t timeout) {
+int usbd_hid_rx(usbd_hid_itf_t *hid, size_t len, uint8_t *buf, uint32_t timeout) {
// Wait until we have buffer to read
uint32_t start = HAL_GetTick();
- while (current_read_buffer == current_write_buffer) {
+ while (hid->current_read_buffer == hid->current_write_buffer) {
// Wraparound of tick is taken care of by 2's complement arithmetic.
if (HAL_GetTick() - start >= timeout) {
// timeout
@@ -118,17 +89,17 @@ int USBD_HID_Rx(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len, uint32_t t
}
// There is not enough space in buffer
- if (len < last_read_len) {
+ if (len < hid->last_read_len) {
return 0;
}
// Copy bytes from device to user buffer
- memcpy(buf, buffer[current_read_buffer], last_read_len);
- current_read_buffer = !current_read_buffer;
+ memcpy(buf, hid->buffer[hid->current_read_buffer], hid->last_read_len);
+ hid->current_read_buffer = !hid->current_read_buffer;
// Clear NAK to indicate we are ready to read more data
- USBD_HID_ClearNAK(pdev);
+ USBD_HID_ClearNAK(hid->usbd);
// Success, return number of bytes read
- return last_read_len;
+ return hid->last_read_len;
}
diff --git a/ports/stm32/usbd_hid_interface.h b/ports/stm32/usbd_hid_interface.h
new file mode 100644
index 000000000..79040b57e
--- /dev/null
+++ b/ports/stm32/usbd_hid_interface.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ */
+#ifndef MICROPY_INCLUDED_STMHAL_USBD_HID_INTERFACE_H
+#define MICROPY_INCLUDED_STMHAL_USBD_HID_INTERFACE_H
+
+#include "usbd_cdc_msc_hid.h"
+
+typedef struct _usbd_hid_itf_t {
+ usbd_cdc_msc_hid_state_t *usbd; // the parent USB device
+
+ uint8_t buffer[2][HID_DATA_FS_MAX_PACKET_SIZE]; // pair of buffers to read individual packets into
+ int8_t current_read_buffer; // which buffer to read from
+ uint32_t last_read_len; // length of last read
+ int8_t current_write_buffer; // which buffer to write to
+} usbd_hid_itf_t;
+
+int usbd_hid_rx_num(usbd_hid_itf_t *hid);
+int usbd_hid_rx(usbd_hid_itf_t *hid, size_t len, uint8_t *buf, uint32_t timeout);
+
+#endif // MICROPY_INCLUDED_STMHAL_USBD_HID_INTERFACE_H
diff --git a/stmhal/usbd_msc_storage.c b/ports/stm32/usbd_msc_storage.c
similarity index 100%
rename from stmhal/usbd_msc_storage.c
rename to ports/stm32/usbd_msc_storage.c
diff --git a/stmhal/usbd_msc_storage.h b/ports/stm32/usbd_msc_storage.h
similarity index 95%
rename from stmhal/usbd_msc_storage.h
rename to ports/stm32/usbd_msc_storage.h
index a4bc8004a..6cc40d2d6 100644
--- a/stmhal/usbd_msc_storage.h
+++ b/ports/stm32/usbd_msc_storage.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/usbdev/Release_Notes.html b/ports/stm32/usbdev/Release_Notes.html
similarity index 100%
rename from stmhal/usbdev/Release_Notes.html
rename to ports/stm32/usbdev/Release_Notes.html
diff --git a/stmhal/usbdev/class/inc/usbd_cdc_msc_hid.h b/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h
similarity index 51%
rename from stmhal/usbdev/class/inc/usbd_cdc_msc_hid.h
rename to ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h
index 96617b107..a26b1df0d 100644
--- a/stmhal/usbdev/class/inc/usbd_cdc_msc_hid.h
+++ b/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h
@@ -6,6 +6,10 @@
#include "usbd_msc_scsi.h"
#include "usbd_ioreq.h"
+// Needed for the CDC+MSC+HID state and should be maximum of all template
+// config descriptors defined in usbd_cdc_msc_hid.c
+#define MAX_TEMPLATE_CONFIG_DESC_SIZE (107)
+
// CDC, MSC and HID packet sizes
#define CDC_DATA_FS_MAX_PACKET_SIZE (64) // endpoint IN & OUT packet size
#define MSC_MEDIA_PACKET (2048) // was 8192; how low can it go whilst still working?
@@ -27,31 +31,15 @@ typedef struct {
uint8_t datatype;
} USBD_CDC_LineCodingTypeDef;
-typedef struct _USBD_CDC_Itf {
- int8_t (* Init) (USBD_HandleTypeDef *pdev);
- int8_t (* DeInit) (void);
- int8_t (* Control) (uint8_t, uint8_t * , uint16_t);
- int8_t (* Receive) (USBD_HandleTypeDef *pdev, uint8_t *, uint32_t *);
-} USBD_CDC_ItfTypeDef;
-
typedef struct {
uint32_t data[CDC_DATA_FS_MAX_PACKET_SIZE/4]; /* Force 32bits alignment */
uint8_t CmdOpCode;
uint8_t CmdLength;
- uint8_t *RxBuffer;
- uint8_t *TxBuffer;
- uint32_t RxLength;
- uint32_t TxLength;
__IO uint32_t TxState;
__IO uint32_t RxState;
} USBD_CDC_HandleTypeDef;
-typedef struct _USBD_HID_Itf {
- int8_t (* Init) (USBD_HandleTypeDef *pdev);
- int8_t (* Receive)(USBD_HandleTypeDef *pdev, uint8_t *, uint32_t);
-} USBD_HID_ItfTypeDef;
-
typedef struct _USBD_STORAGE {
int8_t (* Init) (uint8_t lun);
int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size);
@@ -84,8 +72,48 @@ typedef struct {
uint32_t scsi_blk_addr_in_blks;
uint32_t scsi_blk_len;
+
+ // operations of the underlying block device
+ USBD_StorageTypeDef *bdev_ops;
} USBD_MSC_BOT_HandleTypeDef;
+typedef enum {
+ HID_IDLE = 0,
+ HID_BUSY,
+} HID_StateTypeDef;
+
+typedef struct {
+ uint32_t Protocol;
+ uint32_t IdleState;
+ uint32_t AltSetting;
+ HID_StateTypeDef state;
+} USBD_HID_HandleTypeDef;
+
+typedef struct _usbd_cdc_msc_hid_state_t {
+ USBD_HandleTypeDef *pdev;
+
+ uint8_t usbd_mode;
+ uint8_t cdc_iface_num;
+ uint8_t hid_in_ep;
+ uint8_t hid_out_ep;
+ uint8_t hid_iface_num;
+ uint8_t usbd_config_desc_size;
+ uint8_t *hid_desc;
+ const uint8_t *hid_report_desc;
+
+ USBD_CDC_HandleTypeDef CDC_ClassData;
+ USBD_MSC_BOT_HandleTypeDef MSC_BOT_ClassData;
+ USBD_HID_HandleTypeDef HID_ClassData;
+
+ // RAM to hold the current descriptors, which we configure on the fly
+ __ALIGN_BEGIN uint8_t usbd_device_desc[USB_LEN_DEV_DESC] __ALIGN_END;
+ __ALIGN_BEGIN uint8_t usbd_str_desc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
+ __ALIGN_BEGIN uint8_t usbd_config_desc[MAX_TEMPLATE_CONFIG_DESC_SIZE] __ALIGN_END;
+
+ void *cdc;
+ void *hid;
+} usbd_cdc_msc_hid_state_t;
+
#define USBD_HID_MOUSE_MAX_PACKET (4)
#define USBD_HID_MOUSE_REPORT_DESC_SIZE (74)
@@ -96,27 +124,35 @@ extern const uint8_t USBD_HID_MOUSE_ReportDesc[USBD_HID_MOUSE_REPORT_DESC_SIZE];
extern const uint8_t USBD_HID_KEYBOARD_ReportDesc[USBD_HID_KEYBOARD_REPORT_DESC_SIZE];
-extern USBD_ClassTypeDef USBD_CDC_MSC_HID;
+extern const USBD_ClassTypeDef USBD_CDC_MSC_HID;
// returns 0 on success, -1 on failure
-int USBD_SelectMode(uint32_t mode, USBD_HID_ModeInfoTypeDef *hid_info);
+int USBD_SelectMode(usbd_cdc_msc_hid_state_t *usbd, uint32_t mode, USBD_HID_ModeInfoTypeDef *hid_info);
// returns the current usb mode
-uint8_t USBD_GetMode();
-
-uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, USBD_CDC_ItfTypeDef *fops);
-uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint16_t length);
-uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, uint8_t *pbuff);
-uint8_t USBD_CDC_ReceivePacket (USBD_HandleTypeDef *pdev);
-uint8_t USBD_CDC_TransmitPacket (USBD_HandleTypeDef *pdev);
-
-uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef *fops);
-
-uint8_t USBD_HID_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_HID_ItfTypeDef *fops);
-uint8_t USBD_HID_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
-uint8_t USBD_HID_ReceivePacket(USBD_HandleTypeDef *pdev);
-int USBD_HID_CanSendReport(USBD_HandleTypeDef *pdev);
-uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len);
-uint8_t USBD_HID_SetNAK(USBD_HandleTypeDef *pdev);
-uint8_t USBD_HID_ClearNAK(USBD_HandleTypeDef *pdev);
+uint8_t USBD_GetMode(usbd_cdc_msc_hid_state_t *usbd);
+
+uint8_t USBD_CDC_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf);
+uint8_t USBD_CDC_TransmitPacket(usbd_cdc_msc_hid_state_t *usbd, size_t len, const uint8_t *buf);
+
+static inline void USBD_MSC_RegisterStorage(usbd_cdc_msc_hid_state_t *usbd, USBD_StorageTypeDef *fops) {
+ usbd->MSC_BOT_ClassData.bdev_ops = fops;
+}
+
+uint8_t USBD_HID_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf);
+int USBD_HID_CanSendReport(usbd_cdc_msc_hid_state_t *usbd);
+uint8_t USBD_HID_SendReport(usbd_cdc_msc_hid_state_t *usbd, uint8_t *report, uint16_t len);
+uint8_t USBD_HID_SetNAK(usbd_cdc_msc_hid_state_t *usbd);
+uint8_t USBD_HID_ClearNAK(usbd_cdc_msc_hid_state_t *usbd);
+
+// These are provided externally to implement the CDC interface
+struct _usbd_cdc_itf_t;
+uint8_t *usbd_cdc_init(struct _usbd_cdc_itf_t *cdc, usbd_cdc_msc_hid_state_t *usbd);
+int8_t usbd_cdc_control(struct _usbd_cdc_itf_t *cdc, uint8_t cmd, uint8_t* pbuf, uint16_t length);
+int8_t usbd_cdc_receive(struct _usbd_cdc_itf_t *cdc, size_t len);
+
+// These are provided externally to implement the HID interface
+struct _usbd_hid_itf_t;
+uint8_t *usbd_hid_init(struct _usbd_hid_itf_t *hid, usbd_cdc_msc_hid_state_t *usbd);
+int8_t usbd_hid_receive(struct _usbd_hid_itf_t *hid, size_t len);
#endif // _USB_CDC_MSC_CORE_H_
diff --git a/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h b/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid0.h
similarity index 96%
rename from stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h
rename to ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid0.h
index ec03c860a..08882bb1a 100644
--- a/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h
+++ b/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid0.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/usbdev/class/inc/usbd_msc_bot.h b/ports/stm32/usbdev/class/inc/usbd_msc_bot.h
similarity index 100%
rename from stmhal/usbdev/class/inc/usbd_msc_bot.h
rename to ports/stm32/usbdev/class/inc/usbd_msc_bot.h
diff --git a/stmhal/usbdev/class/inc/usbd_msc_data.h b/ports/stm32/usbdev/class/inc/usbd_msc_data.h
similarity index 100%
rename from stmhal/usbdev/class/inc/usbd_msc_data.h
rename to ports/stm32/usbdev/class/inc/usbd_msc_data.h
diff --git a/stmhal/usbdev/class/inc/usbd_msc_scsi.h b/ports/stm32/usbdev/class/inc/usbd_msc_scsi.h
similarity index 100%
rename from stmhal/usbdev/class/inc/usbd_msc_scsi.h
rename to ports/stm32/usbdev/class/inc/usbd_msc_scsi.h
diff --git a/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c
similarity index 79%
rename from stmhal/usbdev/class/src/usbd_cdc_msc_hid.c
rename to ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c
index e0edf1370..379a8f32c 100644
--- a/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c
+++ b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include "usbd_ioreq.h"
#include "usbd_cdc_msc_hid.h"
-#define MAX_TEMPLATE_CONFIG_DESC_SIZE (107) // should be maximum of all template config desc's
#define CDC_TEMPLATE_CONFIG_DESC_SIZE (67)
#define CDC_MSC_TEMPLATE_CONFIG_DESC_SIZE (98)
#define CDC_HID_TEMPLATE_CONFIG_DESC_SIZE (107)
@@ -72,40 +71,6 @@
#define HID_REQ_SET_IDLE (0x0a)
#define HID_REQ_GET_IDLE (0x02)
-typedef enum {
- HID_IDLE = 0,
- HID_BUSY,
-} HID_StateTypeDef;
-
-typedef struct {
- uint32_t Protocol;
- uint32_t IdleState;
- uint32_t AltSetting;
- HID_StateTypeDef state;
- uint8_t *RxBuffer;
- uint32_t RxLength;
-} USBD_HID_HandleTypeDef;
-
-static uint8_t usbd_mode;
-static uint8_t cdc_iface_num;
-static uint8_t hid_in_ep;
-static uint8_t hid_out_ep;
-static uint8_t hid_iface_num;
-static uint8_t usbd_config_desc_size;
-static uint8_t *hid_desc;
-static const uint8_t *hid_report_desc;
-
-static USBD_CDC_ItfTypeDef *CDC_fops;
-static USBD_StorageTypeDef *MSC_fops;
-static USBD_HID_ItfTypeDef *HID_fops;
-
-static USBD_CDC_HandleTypeDef CDC_ClassData;
-static USBD_MSC_BOT_HandleTypeDef MSC_BOT_ClassData;
-static USBD_HID_HandleTypeDef HID_ClassData;
-
-// RAM to hold the current configuration descriptor, which we configure on the fly
-__ALIGN_BEGIN static uint8_t usbd_config_desc[MAX_TEMPLATE_CONFIG_DESC_SIZE] __ALIGN_END;
-
/*
// this is used only in high-speed mode, which we don't support
// USB Standard Device Descriptor
@@ -578,36 +543,36 @@ __ALIGN_BEGIN const uint8_t USBD_HID_KEYBOARD_ReportDesc[USBD_HID_KEYBOARD_REPOR
};
// return the saved usb mode
-uint8_t USBD_GetMode() {
- return usbd_mode;
+uint8_t USBD_GetMode(usbd_cdc_msc_hid_state_t *usbd) {
+ return usbd->usbd_mode;
}
-int USBD_SelectMode(uint32_t mode, USBD_HID_ModeInfoTypeDef *hid_info) {
+int USBD_SelectMode(usbd_cdc_msc_hid_state_t *usbd, uint32_t mode, USBD_HID_ModeInfoTypeDef *hid_info) {
// save mode
- usbd_mode = mode;
+ usbd->usbd_mode = mode;
// construct config desc
- switch (usbd_mode) {
+ switch (usbd->usbd_mode) {
case USBD_MODE_CDC_MSC:
- usbd_config_desc_size = sizeof(cdc_msc_template_config_desc);
- memcpy(usbd_config_desc, cdc_msc_template_config_desc, sizeof(cdc_msc_template_config_desc));
- cdc_iface_num = CDC_IFACE_NUM_WITH_MSC;
+ usbd->usbd_config_desc_size = sizeof(cdc_msc_template_config_desc);
+ memcpy(usbd->usbd_config_desc, cdc_msc_template_config_desc, sizeof(cdc_msc_template_config_desc));
+ usbd->cdc_iface_num = CDC_IFACE_NUM_WITH_MSC;
break;
case USBD_MODE_CDC_HID:
- usbd_config_desc_size = sizeof(cdc_hid_template_config_desc);
- memcpy(usbd_config_desc, cdc_hid_template_config_desc, sizeof(cdc_hid_template_config_desc));
- cdc_iface_num = CDC_IFACE_NUM_WITH_HID;
- hid_in_ep = HID_IN_EP_WITH_CDC;
- hid_out_ep = HID_OUT_EP_WITH_CDC;
- hid_iface_num = HID_IFACE_NUM_WITH_CDC;
- hid_desc = usbd_config_desc + CDC_HID_TEMPLATE_HID_DESC_OFFSET;
+ usbd->usbd_config_desc_size = sizeof(cdc_hid_template_config_desc);
+ memcpy(usbd->usbd_config_desc, cdc_hid_template_config_desc, sizeof(cdc_hid_template_config_desc));
+ usbd->cdc_iface_num = CDC_IFACE_NUM_WITH_HID;
+ usbd->hid_in_ep = HID_IN_EP_WITH_CDC;
+ usbd->hid_out_ep = HID_OUT_EP_WITH_CDC;
+ usbd->hid_iface_num = HID_IFACE_NUM_WITH_CDC;
+ usbd->hid_desc = usbd->usbd_config_desc + CDC_HID_TEMPLATE_HID_DESC_OFFSET;
break;
case USBD_MODE_CDC:
- usbd_config_desc_size = sizeof(cdc_template_config_desc);
- memcpy(usbd_config_desc, cdc_template_config_desc, sizeof(cdc_template_config_desc));
- cdc_iface_num = CDC_IFACE_NUM_ALONE;
+ usbd->usbd_config_desc_size = sizeof(cdc_template_config_desc);
+ memcpy(usbd->usbd_config_desc, cdc_template_config_desc, sizeof(cdc_template_config_desc));
+ usbd->cdc_iface_num = CDC_IFACE_NUM_ALONE;
break;
/*
@@ -625,7 +590,8 @@ int USBD_SelectMode(uint32_t mode, USBD_HID_ModeInfoTypeDef *hid_info) {
}
// configure the HID descriptor, if needed
- if (usbd_mode & USBD_MODE_HID) {
+ if (usbd->usbd_mode & USBD_MODE_HID) {
+ uint8_t *hid_desc = usbd->hid_desc;
hid_desc[HID_DESC_OFFSET_SUBCLASS] = hid_info->subclass;
hid_desc[HID_DESC_OFFSET_PROTOCOL] = hid_info->protocol;
hid_desc[HID_DESC_OFFSET_REPORT_DESC_LEN] = hid_info->report_desc_len;
@@ -635,7 +601,7 @@ int USBD_SelectMode(uint32_t mode, USBD_HID_ModeInfoTypeDef *hid_info) {
hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_LO] = hid_info->max_packet_len;
hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_HI] = 0;
hid_desc[HID_DESC_OFFSET_POLLING_INTERVAL_OUT] = hid_info->polling_interval;
- hid_report_desc = hid_info->report_desc;
+ usbd->hid_report_desc = hid_info->report_desc;
}
return 0;
@@ -647,7 +613,9 @@ static uint8_t USBD_CDC_MSC_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
return 1;
}
- if (usbd_mode & USBD_MODE_CDC) {
+ usbd_cdc_msc_hid_state_t *usbd = pdev->pClassData;
+
+ if (usbd->usbd_mode & USBD_MODE_CDC) {
// CDC VCP component
// Open EP IN
@@ -669,17 +637,17 @@ static uint8_t USBD_CDC_MSC_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
CDC_CMD_PACKET_SIZE);
// Init physical Interface components
- CDC_fops->Init(pdev);
+ uint8_t *buf = usbd_cdc_init(usbd->cdc, usbd);
// Init Xfer states
- CDC_ClassData.TxState =0;
- CDC_ClassData.RxState =0;
+ usbd->CDC_ClassData.TxState = 0;
+ usbd->CDC_ClassData.RxState = 0;
// Prepare Out endpoint to receive next packet
- USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, CDC_ClassData.RxBuffer, CDC_DATA_OUT_PACKET_SIZE);
+ USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, buf, CDC_DATA_OUT_PACKET_SIZE);
}
- if (usbd_mode & USBD_MODE_MSC) {
+ if (usbd->usbd_mode & USBD_MODE_MSC) {
// MSC component
// Open EP OUT
@@ -694,61 +662,57 @@ static uint8_t USBD_CDC_MSC_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
USBD_EP_TYPE_BULK,
MSC_MAX_PACKET);
- // MSC uses the pClassData pointer because SCSI and BOT reference it
- pdev->pClassData = &MSC_BOT_ClassData;
-
// Init the BOT layer
MSC_BOT_Init(pdev);
}
- if (usbd_mode & USBD_MODE_HID) {
+ if (usbd->usbd_mode & USBD_MODE_HID) {
// HID component
// get max packet lengths from descriptor
uint16_t mps_in =
- hid_desc[HID_DESC_OFFSET_MAX_PACKET_LO]
- | (hid_desc[HID_DESC_OFFSET_MAX_PACKET_HI] << 8);
+ usbd->hid_desc[HID_DESC_OFFSET_MAX_PACKET_LO]
+ | (usbd->hid_desc[HID_DESC_OFFSET_MAX_PACKET_HI] << 8);
uint16_t mps_out =
- hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_LO]
- | (hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_HI] << 8);
+ usbd->hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_LO]
+ | (usbd->hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_HI] << 8);
// Open EP IN
USBD_LL_OpenEP(pdev,
- hid_in_ep,
+ usbd->hid_in_ep,
USBD_EP_TYPE_INTR,
mps_in);
// Open EP OUT
USBD_LL_OpenEP(pdev,
- hid_out_ep,
+ usbd->hid_out_ep,
USBD_EP_TYPE_INTR,
mps_out);
- HID_fops->Init(pdev);
+ uint8_t *buf = usbd_hid_init(usbd->hid, usbd);
// Prepare Out endpoint to receive next packet
- USBD_LL_PrepareReceive(pdev, hid_out_ep, HID_ClassData.RxBuffer, mps_out);
+ USBD_LL_PrepareReceive(pdev, usbd->hid_out_ep, buf, mps_out);
- HID_ClassData.state = HID_IDLE;
+ usbd->HID_ClassData.state = HID_IDLE;
}
return 0;
}
static uint8_t USBD_CDC_MSC_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
- if (usbd_mode & USBD_MODE_CDC) {
+ usbd_cdc_msc_hid_state_t *usbd = pdev->pClassData;
+
+ if ((usbd->usbd_mode & USBD_MODE_CDC) && usbd->cdc) {
// CDC VCP component
// close endpoints
USBD_LL_CloseEP(pdev, CDC_IN_EP);
USBD_LL_CloseEP(pdev, CDC_OUT_EP);
USBD_LL_CloseEP(pdev, CDC_CMD_EP);
-
- // DeInit physical Interface components
- CDC_fops->DeInit();
}
- if (usbd_mode & USBD_MODE_MSC) {
+ if (usbd->usbd_mode & USBD_MODE_MSC) {
// MSC component
// close endpoints
@@ -757,17 +721,14 @@ static uint8_t USBD_CDC_MSC_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
// DeInit the BOT layer
MSC_BOT_DeInit(pdev);
-
- // clear the pointer
- pdev->pClassData = NULL;
}
- if (usbd_mode & USBD_MODE_HID) {
+ if (usbd->usbd_mode & USBD_MODE_HID) {
// HID component
// close endpoints
- USBD_LL_CloseEP(pdev, hid_in_ep);
- USBD_LL_CloseEP(pdev, hid_out_ep);
+ USBD_LL_CloseEP(pdev, usbd->hid_in_ep);
+ USBD_LL_CloseEP(pdev, usbd->hid_out_ep);
}
return 0;
@@ -791,36 +752,38 @@ static uint8_t USBD_CDC_MSC_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTyp
SU: 21 20 0 1
*/
+ usbd_cdc_msc_hid_state_t *usbd = pdev->pClassData;
+
switch (req->bmRequest & USB_REQ_TYPE_MASK) {
// Class request
case USB_REQ_TYPE_CLASS:
// req->wIndex is the recipient interface number
- if ((usbd_mode & USBD_MODE_CDC) && req->wIndex == cdc_iface_num) {
+ if ((usbd->usbd_mode & USBD_MODE_CDC) && req->wIndex == usbd->cdc_iface_num) {
// CDC component
if (req->wLength) {
if (req->bmRequest & 0x80) {
// device-to-host request
- CDC_fops->Control(req->bRequest, (uint8_t*)CDC_ClassData.data, req->wLength);
- USBD_CtlSendData(pdev, (uint8_t*)CDC_ClassData.data, req->wLength);
+ usbd_cdc_control(usbd->cdc, req->bRequest, (uint8_t*)usbd->CDC_ClassData.data, req->wLength);
+ USBD_CtlSendData(pdev, (uint8_t*)usbd->CDC_ClassData.data, req->wLength);
} else {
// host-to-device request
- CDC_ClassData.CmdOpCode = req->bRequest;
- CDC_ClassData.CmdLength = req->wLength;
- USBD_CtlPrepareRx(pdev, (uint8_t*)CDC_ClassData.data, req->wLength);
+ usbd->CDC_ClassData.CmdOpCode = req->bRequest;
+ usbd->CDC_ClassData.CmdLength = req->wLength;
+ USBD_CtlPrepareRx(pdev, (uint8_t*)usbd->CDC_ClassData.data, req->wLength);
}
} else {
// Not a Data request
// Transfer the command to the interface layer
- return CDC_fops->Control(req->bRequest, NULL, req->wValue);
+ return usbd_cdc_control(usbd->cdc, req->bRequest, NULL, req->wValue);
}
- } else if ((usbd_mode & USBD_MODE_MSC) && req->wIndex == MSC_IFACE_NUM_WITH_CDC) {
+ } else if ((usbd->usbd_mode & USBD_MODE_MSC) && req->wIndex == MSC_IFACE_NUM_WITH_CDC) {
// MSC component
switch (req->bRequest) {
case BOT_GET_MAX_LUN:
if ((req->wValue == 0) && (req->wLength == 1) && ((req->bmRequest & 0x80) == 0x80)) {
- MSC_BOT_ClassData.max_lun = MSC_fops->GetMaxLun();
- USBD_CtlSendData(pdev, (uint8_t *)&MSC_BOT_ClassData.max_lun, 1);
+ usbd->MSC_BOT_ClassData.max_lun = usbd->MSC_BOT_ClassData.bdev_ops->GetMaxLun();
+ USBD_CtlSendData(pdev, (uint8_t *)&usbd->MSC_BOT_ClassData.max_lun, 1);
} else {
USBD_CtlError(pdev, req);
return USBD_FAIL;
@@ -840,22 +803,22 @@ static uint8_t USBD_CDC_MSC_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTyp
USBD_CtlError(pdev, req);
return USBD_FAIL;
}
- } else if ((usbd_mode & USBD_MODE_HID) && req->wIndex == hid_iface_num) {
+ } else if ((usbd->usbd_mode & USBD_MODE_HID) && req->wIndex == usbd->hid_iface_num) {
switch (req->bRequest) {
case HID_REQ_SET_PROTOCOL:
- HID_ClassData.Protocol = (uint8_t)(req->wValue);
+ usbd->HID_ClassData.Protocol = (uint8_t)(req->wValue);
break;
case HID_REQ_GET_PROTOCOL:
- USBD_CtlSendData (pdev, (uint8_t *)&HID_ClassData.Protocol, 1);
+ USBD_CtlSendData(pdev, (uint8_t *)&usbd->HID_ClassData.Protocol, 1);
break;
case HID_REQ_SET_IDLE:
- HID_ClassData.IdleState = (uint8_t)(req->wValue >> 8);
+ usbd->HID_ClassData.IdleState = (uint8_t)(req->wValue >> 8);
break;
case HID_REQ_GET_IDLE:
- USBD_CtlSendData (pdev, (uint8_t *)&HID_ClassData.IdleState, 1);
+ USBD_CtlSendData(pdev, (uint8_t *)&usbd->HID_ClassData.IdleState, 1);
break;
default:
@@ -867,14 +830,14 @@ static uint8_t USBD_CDC_MSC_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTyp
// Interface & Endpoint request
case USB_REQ_TYPE_STANDARD:
- if ((usbd_mode & USBD_MODE_MSC) && req->wIndex == MSC_IFACE_NUM_WITH_CDC) {
+ if ((usbd->usbd_mode & USBD_MODE_MSC) && req->wIndex == MSC_IFACE_NUM_WITH_CDC) {
switch (req->bRequest) {
case USB_REQ_GET_INTERFACE :
- USBD_CtlSendData(pdev, (uint8_t *)&MSC_BOT_ClassData.interface, 1);
+ USBD_CtlSendData(pdev, (uint8_t *)&usbd->MSC_BOT_ClassData.interface, 1);
break;
case USB_REQ_SET_INTERFACE :
- MSC_BOT_ClassData.interface = (uint8_t)(req->wValue);
+ usbd->MSC_BOT_ClassData.interface = (uint8_t)(req->wValue);
break;
case USB_REQ_CLEAR_FEATURE:
@@ -894,29 +857,29 @@ static uint8_t USBD_CDC_MSC_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTyp
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
break;
}
- } else if ((usbd_mode & USBD_MODE_HID) && req->wIndex == hid_iface_num) {
+ } else if ((usbd->usbd_mode & USBD_MODE_HID) && req->wIndex == usbd->hid_iface_num) {
switch (req->bRequest) {
case USB_REQ_GET_DESCRIPTOR: {
uint16_t len = 0;
const uint8_t *pbuf = NULL;
if (req->wValue >> 8 == HID_REPORT_DESC) {
- len = hid_desc[HID_DESC_OFFSET_REPORT_DESC_LEN];
+ len = usbd->hid_desc[HID_DESC_OFFSET_REPORT_DESC_LEN];
len = MIN(len, req->wLength);
- pbuf = hid_report_desc;
+ pbuf = usbd->hid_report_desc;
} else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE) {
len = MIN(HID_SUBDESC_LEN, req->wLength);
- pbuf = hid_desc + HID_DESC_OFFSET_SUBDESC;
+ pbuf = usbd->hid_desc + HID_DESC_OFFSET_SUBDESC;
}
USBD_CtlSendData(pdev, (uint8_t*)pbuf, len);
break;
}
case USB_REQ_GET_INTERFACE:
- USBD_CtlSendData (pdev, (uint8_t *)&HID_ClassData.AltSetting, 1);
+ USBD_CtlSendData(pdev, (uint8_t *)&usbd->HID_ClassData.AltSetting, 1);
break;
case USB_REQ_SET_INTERFACE:
- HID_ClassData.AltSetting = (uint8_t)(req->wValue);
+ usbd->HID_ClassData.AltSetting = (uint8_t)(req->wValue);
break;
}
}
@@ -931,25 +894,27 @@ static uint8_t EP0_TxSent(USBD_HandleTypeDef *pdev) {
*/
static uint8_t USBD_CDC_MSC_HID_EP0_RxReady(USBD_HandleTypeDef *pdev) {
- if ((CDC_fops != NULL) && (CDC_ClassData.CmdOpCode != 0xff)) {
- CDC_fops->Control(CDC_ClassData.CmdOpCode, (uint8_t*)CDC_ClassData.data, CDC_ClassData.CmdLength);
- CDC_ClassData.CmdOpCode = 0xff;
+ usbd_cdc_msc_hid_state_t *usbd = pdev->pClassData;
+ if (usbd->cdc != NULL && usbd->CDC_ClassData.CmdOpCode != 0xff) {
+ usbd_cdc_control(usbd->cdc, usbd->CDC_ClassData.CmdOpCode, (uint8_t*)usbd->CDC_ClassData.data, usbd->CDC_ClassData.CmdLength);
+ usbd->CDC_ClassData.CmdOpCode = 0xff;
}
return USBD_OK;
}
static uint8_t USBD_CDC_MSC_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) {
- if ((usbd_mode & USBD_MODE_CDC) && (epnum == (CDC_IN_EP & 0x7f) || epnum == (CDC_CMD_EP & 0x7f))) {
- CDC_ClassData.TxState = 0;
+ usbd_cdc_msc_hid_state_t *usbd = pdev->pClassData;
+ if ((usbd->usbd_mode & USBD_MODE_CDC) && (epnum == (CDC_IN_EP & 0x7f) || epnum == (CDC_CMD_EP & 0x7f))) {
+ usbd->CDC_ClassData.TxState = 0;
return USBD_OK;
- } else if ((usbd_mode & USBD_MODE_MSC) && epnum == (MSC_IN_EP & 0x7f)) {
+ } else if ((usbd->usbd_mode & USBD_MODE_MSC) && epnum == (MSC_IN_EP & 0x7f)) {
MSC_BOT_DataIn(pdev, epnum);
return USBD_OK;
- } else if ((usbd_mode & USBD_MODE_HID) && epnum == (hid_in_ep & 0x7f)) {
+ } else if ((usbd->usbd_mode & USBD_MODE_HID) && epnum == (usbd->hid_in_ep & 0x7f)) {
/* Ensure that the FIFO is empty before a new transfer, this condition could
be caused by a new transfer before the end of the previous transfer */
- HID_ClassData.state = HID_IDLE;
+ usbd->HID_ClassData.state = HID_IDLE;
return USBD_OK;
}
@@ -957,33 +922,35 @@ static uint8_t USBD_CDC_MSC_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
}
static uint8_t USBD_CDC_MSC_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) {
- if ((usbd_mode & USBD_MODE_CDC) && epnum == (CDC_OUT_EP & 0x7f)) {
+ usbd_cdc_msc_hid_state_t *usbd = pdev->pClassData;
+ if ((usbd->usbd_mode & USBD_MODE_CDC) && epnum == (CDC_OUT_EP & 0x7f)) {
/* Get the received data length */
- CDC_ClassData.RxLength = USBD_LL_GetRxDataSize (pdev, epnum);
+ size_t len = USBD_LL_GetRxDataSize (pdev, epnum);
/* USB data will be immediately processed, this allow next USB traffic being
NAKed till the end of the application Xfer */
- CDC_fops->Receive(pdev, CDC_ClassData.RxBuffer, &CDC_ClassData.RxLength);
+ usbd_cdc_receive(usbd->cdc, len);
return USBD_OK;
- } else if ((usbd_mode & USBD_MODE_MSC) && epnum == (MSC_OUT_EP & 0x7f)) {
+ } else if ((usbd->usbd_mode & USBD_MODE_MSC) && epnum == (MSC_OUT_EP & 0x7f)) {
MSC_BOT_DataOut(pdev, epnum);
return USBD_OK;
- } else if ((usbd_mode & USBD_MODE_HID) && epnum == (hid_out_ep & 0x7f)) {
- HID_ClassData.RxLength = USBD_LL_GetRxDataSize(pdev, epnum);
- HID_fops->Receive(pdev, HID_ClassData.RxBuffer, HID_ClassData.RxLength);
+ } else if ((usbd->usbd_mode & USBD_MODE_HID) && epnum == (usbd->hid_out_ep & 0x7f)) {
+ size_t len = USBD_LL_GetRxDataSize(pdev, epnum);
+ usbd_hid_receive(usbd->hid, len);
}
return USBD_OK;
}
-static uint8_t *USBD_CDC_MSC_HID_GetCfgDesc(uint16_t *length) {
- *length = usbd_config_desc_size;
- return usbd_config_desc;
+static uint8_t *USBD_CDC_MSC_HID_GetCfgDesc(USBD_HandleTypeDef *pdev, uint16_t *length) {
+ usbd_cdc_msc_hid_state_t *usbd = pdev->pClassData;
+ *length = usbd->usbd_config_desc_size;
+ return usbd->usbd_config_desc;
}
// this is used only in high-speed mode, which we don't support
-uint8_t *USBD_CDC_MSC_HID_GetDeviceQualifierDescriptor (uint16_t *length) {
+uint8_t *USBD_CDC_MSC_HID_GetDeviceQualifierDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) {
/*
*length = sizeof(USBD_CDC_MSC_HID_DeviceQualifierDesc);
return USBD_CDC_MSC_HID_DeviceQualifierDesc;
@@ -992,34 +959,14 @@ uint8_t *USBD_CDC_MSC_HID_GetDeviceQualifierDescriptor (uint16_t *length) {
return NULL;
}
-uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_CDC_ItfTypeDef *fops) {
- if (fops == NULL) {
- return USBD_FAIL;
- } else {
- CDC_fops = fops;
- return USBD_OK;
- }
-}
-
-uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint16_t length) {
- CDC_ClassData.TxBuffer = pbuff;
- CDC_ClassData.TxLength = length;
- return USBD_OK;
-}
-
-uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff) {
- CDC_ClassData.RxBuffer = pbuff;
- return USBD_OK;
-}
-
// data received on non-control OUT endpoint
-uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) {
- if (CDC_ClassData.TxState == 0) {
+uint8_t USBD_CDC_TransmitPacket(usbd_cdc_msc_hid_state_t *usbd, size_t len, const uint8_t *buf) {
+ if (usbd->CDC_ClassData.TxState == 0) {
// transmit next packet
- USBD_LL_Transmit(pdev, CDC_IN_EP, CDC_ClassData.TxBuffer, CDC_ClassData.TxLength);
+ USBD_LL_Transmit(usbd->pdev, CDC_IN_EP, (uint8_t*)buf, len);
// Tx transfer in progress
- CDC_ClassData.TxState = 1;
+ usbd->CDC_ClassData.TxState = 1;
return USBD_OK;
} else {
return USBD_BUSY;
@@ -1027,84 +974,60 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) {
}
// prepare OUT endpoint for reception
-uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) {
+uint8_t USBD_CDC_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf) {
// Suspend or Resume USB Out process
- if (pdev->dev_speed == USBD_SPEED_HIGH) {
+ if (usbd->pdev->dev_speed == USBD_SPEED_HIGH) {
return USBD_FAIL;
}
// Prepare Out endpoint to receive next packet
- USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, CDC_ClassData.RxBuffer, CDC_DATA_OUT_PACKET_SIZE);
-
- return USBD_OK;
-}
-
-uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef *fops) {
- if (fops == NULL) {
- return USBD_FAIL;
- } else {
- MSC_fops = fops;
- pdev->pUserData = fops; // MSC uses pUserData because SCSI and BOT reference it
- return USBD_OK;
- }
-}
+ USBD_LL_PrepareReceive(usbd->pdev, CDC_OUT_EP, buf, CDC_DATA_OUT_PACKET_SIZE);
-uint8_t USBD_HID_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_HID_ItfTypeDef *fops) {
- if (fops == NULL) {
- return USBD_FAIL;
- } else {
- HID_fops = fops;
- return USBD_OK;
- }
-}
-
-uint8_t USBD_HID_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff) {
- HID_ClassData.RxBuffer = pbuff;
return USBD_OK;
}
// prepare OUT endpoint for reception
-uint8_t USBD_HID_ReceivePacket(USBD_HandleTypeDef *pdev) {
+uint8_t USBD_HID_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf) {
// Suspend or Resume USB Out process
- if (pdev->dev_speed == USBD_SPEED_HIGH) {
+ if (usbd->pdev->dev_speed == USBD_SPEED_HIGH) {
return USBD_FAIL;
}
// Prepare Out endpoint to receive next packet
uint16_t mps_out =
- hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_LO]
- | (hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_HI] << 8);
- USBD_LL_PrepareReceive(pdev, hid_out_ep, HID_ClassData.RxBuffer, mps_out);
+ usbd->hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_LO]
+ | (usbd->hid_desc[HID_DESC_OFFSET_MAX_PACKET_OUT_HI] << 8);
+ USBD_LL_PrepareReceive(usbd->pdev, usbd->hid_out_ep, buf, mps_out);
return USBD_OK;
}
-int USBD_HID_CanSendReport(USBD_HandleTypeDef *pdev) {
- return pdev->dev_state == USBD_STATE_CONFIGURED && HID_ClassData.state == HID_IDLE;
+int USBD_HID_CanSendReport(usbd_cdc_msc_hid_state_t *usbd) {
+ return usbd->pdev->dev_state == USBD_STATE_CONFIGURED && usbd->HID_ClassData.state == HID_IDLE;
}
-uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len) {
- if (pdev->dev_state == USBD_STATE_CONFIGURED) {
- if (HID_ClassData.state == HID_IDLE) {
- HID_ClassData.state = HID_BUSY;
- USBD_LL_Transmit(pdev, hid_in_ep, report, len);
+uint8_t USBD_HID_SendReport(usbd_cdc_msc_hid_state_t *usbd, uint8_t *report, uint16_t len) {
+ if (usbd->pdev->dev_state == USBD_STATE_CONFIGURED) {
+ if (usbd->HID_ClassData.state == HID_IDLE) {
+ usbd->HID_ClassData.state = HID_BUSY;
+ USBD_LL_Transmit(usbd->pdev, usbd->hid_in_ep, report, len);
}
}
return USBD_OK;
}
-uint8_t USBD_HID_SetNAK(USBD_HandleTypeDef *pdev) {
+uint8_t USBD_HID_SetNAK(usbd_cdc_msc_hid_state_t *usbd) {
// get USBx object from pdev (needed for USBx_OUTEP macro below)
- PCD_HandleTypeDef *hpcd = pdev->pData;
+ PCD_HandleTypeDef *hpcd = usbd->pdev->pData;
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
// set NAK on HID OUT endpoint
USBx_OUTEP(HID_OUT_EP_WITH_CDC)->DOEPCTL |= USB_OTG_DOEPCTL_SNAK;
return USBD_OK;
}
-uint8_t USBD_HID_ClearNAK(USBD_HandleTypeDef *pdev) {
+uint8_t USBD_HID_ClearNAK(usbd_cdc_msc_hid_state_t *usbd) {
// get USBx object from pdev (needed for USBx_OUTEP macro below)
- PCD_HandleTypeDef *hpcd = pdev->pData;
+ PCD_HandleTypeDef *hpcd = usbd->pdev->pData;
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
// clear NAK on HID OUT endpoint
USBx_OUTEP(HID_OUT_EP_WITH_CDC)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
@@ -1112,7 +1035,7 @@ uint8_t USBD_HID_ClearNAK(USBD_HandleTypeDef *pdev) {
}
// CDC/MSC/HID interface class callback structure
-USBD_ClassTypeDef USBD_CDC_MSC_HID = {
+const USBD_ClassTypeDef USBD_CDC_MSC_HID = {
USBD_CDC_MSC_HID_Init,
USBD_CDC_MSC_HID_DeInit,
USBD_CDC_MSC_HID_Setup,
diff --git a/stmhal/usbdev/class/src/usbd_msc_bot.c b/ports/stm32/usbdev/class/src/usbd_msc_bot.c
similarity index 85%
rename from stmhal/usbdev/class/src/usbd_msc_bot.c
rename to ports/stm32/usbdev/class/src/usbd_msc_bot.c
index 3c06f3cf6..2fccd9e08 100644
--- a/stmhal/usbdev/class/src/usbd_msc_bot.c
+++ b/ports/stm32/usbdev/class/src/usbd_msc_bot.c
@@ -104,7 +104,7 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
*/
void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_state = USBD_BOT_IDLE;
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
@@ -112,7 +112,7 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
hmsc->scsi_sense_tail = 0;
hmsc->scsi_sense_head = 0;
- ((USBD_StorageTypeDef *)pdev->pUserData)->Init(0);
+ hmsc->bdev_ops->Init(0);
USBD_LL_FlushEP(pdev, MSC_OUT_EP);
USBD_LL_FlushEP(pdev, MSC_IN_EP);
@@ -132,7 +132,7 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
*/
void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_state = USBD_BOT_IDLE;
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
@@ -152,7 +152,7 @@ void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
*/
void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_state = USBD_BOT_IDLE;
}
@@ -166,7 +166,7 @@ void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
uint8_t epnum)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
switch (hmsc->bot_state)
{
@@ -199,7 +199,7 @@ void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
uint8_t epnum)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
switch (hmsc->bot_state)
{
@@ -231,7 +231,7 @@ void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
*/
static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->csw.dTag = hmsc->cbw.dTag;
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
@@ -300,7 +300,7 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev,
uint8_t* buf,
uint16_t len)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
len = MIN (hmsc->cbw.dDataLength, len);
hmsc->csw.dDataResidue -= len;
@@ -320,7 +320,7 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev,
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
uint8_t CSW_Status)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE;
hmsc->csw.bStatus = CSW_Status;
@@ -348,7 +348,7 @@ void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if ((hmsc->cbw.bmFlags == 0) &&
(hmsc->cbw.dDataLength != 0) &&
@@ -377,7 +377,7 @@ static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev)
void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, uint8_t epnum)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if(hmsc->bot_status == USBD_BOT_STATUS_ERROR )/* Bad CBW Signature */
{
diff --git a/stmhal/usbdev/class/src/usbd_msc_data.c b/ports/stm32/usbdev/class/src/usbd_msc_data.c
similarity index 100%
rename from stmhal/usbdev/class/src/usbd_msc_data.c
rename to ports/stm32/usbdev/class/src/usbd_msc_data.c
diff --git a/stmhal/usbdev/class/src/usbd_msc_scsi.c b/ports/stm32/usbdev/class/src/usbd_msc_scsi.c
similarity index 85%
rename from stmhal/usbdev/class/src/usbd_msc_scsi.c
rename to ports/stm32/usbdev/class/src/usbd_msc_scsi.c
index b2931b745..50cd5b971 100644
--- a/stmhal/usbdev/class/src/usbd_msc_scsi.c
+++ b/ports/stm32/usbdev/class/src/usbd_msc_scsi.c
@@ -190,7 +190,7 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev,
*/
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
/* case 9 : Hi > D0 */
if (hmsc->cbw.dDataLength != 0)
@@ -202,7 +202,7 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
return -1;
}
- if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) !=0 )
+ if(hmsc->bdev_ops->IsReady(lun) !=0 )
{
SCSI_SenseCode(pdev,
lun,
@@ -227,7 +227,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
{
uint8_t* pPage;
uint16_t len;
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if (params[1] & 0x01)/*Evpd is set*/
{
@@ -237,7 +237,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
else
{
- pPage = (uint8_t *)&((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
+ pPage = (uint8_t *)&hmsc->bdev_ops->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
len = pPage[4] + 5;
if (params[4] <= len)
@@ -264,9 +264,9 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
*/
static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
- if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
+ if(hmsc->bdev_ops->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
{
SCSI_SenseCode(pdev,
lun,
@@ -300,7 +300,7 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_
*/
static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
uint16_t blk_size;
uint32_t blk_nbr;
@@ -311,7 +311,7 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, ui
hmsc->bot_data[i] = 0;
}
- if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0)
+ if(hmsc->bdev_ops->GetCapacity(lun, &blk_nbr, &blk_size) != 0)
{
SCSI_SenseCode(pdev,
lun,
@@ -345,7 +345,7 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, ui
*/
static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
uint16_t len = 8 ;
hmsc->bot_data_length = len;
@@ -367,7 +367,7 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
{
uint16_t len = 8;
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_data_length = len;
@@ -381,7 +381,7 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
static int8_t SCSI_SynchronizeCache(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) {
// nothing to synchronize, so just return "success"
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_data_length = 0;
return 0;
}
@@ -397,7 +397,7 @@ static int8_t SCSI_SynchronizeCache(USBD_HandleTypeDef *pdev, uint8_t lun, uint
static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
{
uint8_t i;
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
for(i=0 ; i < REQUEST_SENSE_DATA_LEN ; i++)
{
@@ -439,7 +439,7 @@ static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
*/
void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->scsi_sense[hmsc->scsi_sense_tail].Skey = sKey;
hmsc->scsi_sense[hmsc->scsi_sense_tail].w.ASC = ASC << 8;
@@ -458,14 +458,14 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_
*/
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_data_length = 0;
// On Mac OS X, when the device is ejected a SCSI_START_STOP_UNIT command is sent.
// Bit 0 of params[4] is the START bit.
// If we get a stop, we must really stop the device so that the Mac does not
// automatically remount it.
- ((USBD_StorageTypeDef *)pdev->pUserData)->StartStopUnit(lun, params[4] & 1);
+ hmsc->bdev_ops->StartStopUnit(lun, params[4] & 1);
return 0;
}
@@ -479,9 +479,9 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
*/
static int8_t SCSI_AllowMediumRemoval(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_data_length = 0;
- ((USBD_StorageTypeDef *)pdev->pUserData)->PreventAllowMediumRemoval(lun, params[0]);
+ hmsc->bdev_ops->PreventAllowMediumRemoval(lun, params[0]);
return 0;
}
@@ -494,7 +494,7 @@ static int8_t SCSI_AllowMediumRemoval(USBD_HandleTypeDef *pdev, uint8_t lun, ui
*/
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if(hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
{
@@ -510,7 +510,7 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *para
return -1;
}
- if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) !=0 )
+ if(hmsc->bdev_ops->IsReady(lun) !=0 )
{
SCSI_SenseCode(pdev,
lun,
@@ -562,7 +562,7 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *para
static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
{
@@ -579,7 +579,7 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
}
/* Check whether Media is ready */
- if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) !=0 )
+ if(hmsc->bdev_ops->IsReady(lun) !=0 )
{
SCSI_SenseCode(pdev,
lun,
@@ -589,7 +589,7 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
}
/* Check If media is write-protected */
- if(((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) !=0 )
+ if(hmsc->bdev_ops->IsWriteProtected(lun) !=0 )
{
SCSI_SenseCode(pdev,
lun,
@@ -652,7 +652,7 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if ((params[1]& 0x02) == 0x02)
{
@@ -687,7 +687,7 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
*/
static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun , uint32_t blk_offset , uint16_t blk_nbr)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr )
{
@@ -708,12 +708,12 @@ static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun , u
*/
static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun)
{
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
uint32_t len;
len = MIN(hmsc->scsi_blk_len , MSC_MEDIA_PACKET);
- if( ((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun ,
+ if( hmsc->bdev_ops->Read(lun ,
hmsc->bot_data,
hmsc->scsi_blk_addr_in_blks,
len / hmsc->scsi_blk_size) < 0)
@@ -756,11 +756,11 @@ static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun)
static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun)
{
uint32_t len;
- USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData;
+ USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
len = MIN(hmsc->scsi_blk_len , MSC_MEDIA_PACKET);
- if(((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun ,
+ if(hmsc->bdev_ops->Write(lun ,
hmsc->bot_data,
hmsc->scsi_blk_addr_in_blks,
len / hmsc->scsi_blk_size) < 0)
diff --git a/stmhal/usbdev/core/inc/usbd_core.h b/ports/stm32/usbdev/core/inc/usbd_core.h
similarity index 96%
rename from stmhal/usbdev/core/inc/usbd_core.h
rename to ports/stm32/usbdev/core/inc/usbd_core.h
index 5360680b9..3178d4a4b 100644
--- a/stmhal/usbdev/core/inc/usbd_core.h
+++ b/ports/stm32/usbdev/core/inc/usbd_core.h
@@ -88,7 +88,7 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev);
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev);
-USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
+USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, const USBD_ClassTypeDef *pclass);
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev);
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
diff --git a/stmhal/usbdev/core/inc/usbd_ctlreq.h b/ports/stm32/usbdev/core/inc/usbd_ctlreq.h
similarity index 100%
rename from stmhal/usbdev/core/inc/usbd_ctlreq.h
rename to ports/stm32/usbdev/core/inc/usbd_ctlreq.h
diff --git a/stmhal/usbdev/core/inc/usbd_def.h b/ports/stm32/usbdev/core/inc/usbd_def.h
similarity index 87%
rename from stmhal/usbdev/core/inc/usbd_def.h
rename to ports/stm32/usbdev/core/inc/usbd_def.h
index 5c0506a14..888d426ef 100644
--- a/stmhal/usbdev/core/inc/usbd_def.h
+++ b/ports/stm32/usbdev/core/inc/usbd_def.h
@@ -168,10 +168,10 @@ typedef struct _Device_cb
uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
- uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
- uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
- uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
- uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
+ uint8_t *(*GetHSConfigDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetFSConfigDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetOtherSpeedConfigDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetDeviceQualifierDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
#if (USBD_SUPPORT_USER_STRING == 1)
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length);
#endif
@@ -193,16 +193,18 @@ typedef enum {
USBD_FAIL,
}USBD_StatusTypeDef;
+struct _USBD_HandleTypeDef;
+
/* USB Device descriptors structure */
typedef struct
{
- uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
+ uint8_t *(*GetDeviceDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetLangIDStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetManufacturerStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetProductStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetSerialStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetConfigurationStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetInterfaceStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
} USBD_DescriptorsTypeDef;
/* USB Device handle structure */
@@ -235,7 +237,7 @@ typedef struct _USBD_HandleTypeDef
USBD_SetupReqTypedef request;
USBD_DescriptorsTypeDef *pDesc;
- USBD_ClassTypeDef *pClass;
+ const USBD_ClassTypeDef *pClass;
void *pClassData;
void *pUserData;
void *pData;
diff --git a/stmhal/usbdev/core/inc/usbd_ioreq.h b/ports/stm32/usbdev/core/inc/usbd_ioreq.h
similarity index 100%
rename from stmhal/usbdev/core/inc/usbd_ioreq.h
rename to ports/stm32/usbdev/core/inc/usbd_ioreq.h
diff --git a/stmhal/usbdev/core/src/usbd_core.c b/ports/stm32/usbdev/core/src/usbd_core.c
similarity index 95%
rename from stmhal/usbdev/core/src/usbd_core.c
rename to ports/stm32/usbdev/core/src/usbd_core.c
index bb44513d7..ae5b99626 100644
--- a/stmhal/usbdev/core/src/usbd_core.c
+++ b/ports/stm32/usbdev/core/src/usbd_core.c
@@ -155,7 +155,7 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
* @param pclass: Class handle
* @retval USBD Status
*/
-USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
+USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, const USBD_ClassTypeDef *pclass)
{
USBD_StatusTypeDef status = USBD_OK;
if(pclass != 0)
diff --git a/stmhal/usbdev/core/src/usbd_ctlreq.c b/ports/stm32/usbdev/core/src/usbd_ctlreq.c
similarity index 91%
rename from stmhal/usbdev/core/src/usbd_ctlreq.c
rename to ports/stm32/usbdev/core/src/usbd_ctlreq.c
index 80b1da8ea..5fba322fa 100644
--- a/stmhal/usbdev/core/src/usbd_ctlreq.c
+++ b/ports/stm32/usbdev/core/src/usbd_ctlreq.c
@@ -330,18 +330,18 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
switch (req->wValue >> 8)
{
case USB_DESC_TYPE_DEVICE:
- pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetDeviceDescriptor(pdev, &len);
break;
case USB_DESC_TYPE_CONFIGURATION:
if(pdev->dev_speed == USBD_SPEED_HIGH )
{
- pbuf = (uint8_t *)pdev->pClass->GetHSConfigDescriptor(&len);
+ pbuf = (uint8_t *)pdev->pClass->GetHSConfigDescriptor(pdev, &len);
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
}
else
{
- pbuf = (uint8_t *)pdev->pClass->GetFSConfigDescriptor(&len);
+ pbuf = (uint8_t *)pdev->pClass->GetFSConfigDescriptor(pdev, &len);
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
}
break;
@@ -350,27 +350,27 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
switch ((uint8_t)(req->wValue))
{
case USBD_IDX_LANGID_STR:
- pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev, &len);
break;
case USBD_IDX_MFC_STR:
- pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev, &len);
break;
case USBD_IDX_PRODUCT_STR:
- pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetProductStrDescriptor(pdev, &len);
break;
case USBD_IDX_SERIAL_STR:
- pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev, &len);
break;
case USBD_IDX_CONFIG_STR:
- pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev, &len);
break;
case USBD_IDX_INTERFACE_STR:
- pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev, &len);
break;
default:
@@ -387,7 +387,7 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
if(pdev->dev_speed == USBD_SPEED_HIGH )
{
- pbuf = (uint8_t *)pdev->pClass->GetDeviceQualifierDescriptor(&len);
+ pbuf = (uint8_t *)pdev->pClass->GetDeviceQualifierDescriptor(pdev, &len);
break;
}
else
@@ -399,7 +399,7 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
if(pdev->dev_speed == USBD_SPEED_HIGH )
{
- pbuf = (uint8_t *)pdev->pClass->GetOtherSpeedConfigDescriptor(&len);
+ pbuf = (uint8_t *)pdev->pClass->GetOtherSpeedConfigDescriptor(pdev, &len);
pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION;
break;
}
@@ -479,7 +479,7 @@ static void USBD_SetConfig(USBD_HandleTypeDef *pdev ,
USBD_SetupReqTypedef *req)
{
- static uint8_t cfgidx;
+ uint8_t cfgidx;
cfgidx = (uint8_t)(req->wValue);
diff --git a/stmhal/usbdev/core/src/usbd_ioreq.c b/ports/stm32/usbdev/core/src/usbd_ioreq.c
similarity index 100%
rename from stmhal/usbdev/core/src/usbd_ioreq.c
rename to ports/stm32/usbdev/core/src/usbd_ioreq.c
diff --git a/stmhal/usbhost/Class/AUDIO/Inc/usbh_audio.h b/ports/stm32/usbhost/Class/AUDIO/Inc/usbh_audio.h
similarity index 100%
rename from stmhal/usbhost/Class/AUDIO/Inc/usbh_audio.h
rename to ports/stm32/usbhost/Class/AUDIO/Inc/usbh_audio.h
diff --git a/stmhal/usbhost/Class/AUDIO/Src/usbh_audio.c b/ports/stm32/usbhost/Class/AUDIO/Src/usbh_audio.c
similarity index 100%
rename from stmhal/usbhost/Class/AUDIO/Src/usbh_audio.c
rename to ports/stm32/usbhost/Class/AUDIO/Src/usbh_audio.c
diff --git a/stmhal/usbhost/Class/CDC/Inc/usbh_cdc.h b/ports/stm32/usbhost/Class/CDC/Inc/usbh_cdc.h
similarity index 100%
rename from stmhal/usbhost/Class/CDC/Inc/usbh_cdc.h
rename to ports/stm32/usbhost/Class/CDC/Inc/usbh_cdc.h
diff --git a/stmhal/usbhost/Class/CDC/Src/usbh_cdc.c b/ports/stm32/usbhost/Class/CDC/Src/usbh_cdc.c
similarity index 100%
rename from stmhal/usbhost/Class/CDC/Src/usbh_cdc.c
rename to ports/stm32/usbhost/Class/CDC/Src/usbh_cdc.c
diff --git a/stmhal/usbhost/Class/HID/Inc/usbh_hid.h b/ports/stm32/usbhost/Class/HID/Inc/usbh_hid.h
similarity index 100%
rename from stmhal/usbhost/Class/HID/Inc/usbh_hid.h
rename to ports/stm32/usbhost/Class/HID/Inc/usbh_hid.h
diff --git a/stmhal/usbhost/Class/HID/Inc/usbh_hid_keybd.h b/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_keybd.h
similarity index 100%
rename from stmhal/usbhost/Class/HID/Inc/usbh_hid_keybd.h
rename to ports/stm32/usbhost/Class/HID/Inc/usbh_hid_keybd.h
diff --git a/stmhal/usbhost/Class/HID/Inc/usbh_hid_mouse.h b/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_mouse.h
similarity index 100%
rename from stmhal/usbhost/Class/HID/Inc/usbh_hid_mouse.h
rename to ports/stm32/usbhost/Class/HID/Inc/usbh_hid_mouse.h
diff --git a/stmhal/usbhost/Class/HID/Inc/usbh_hid_parser.h b/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_parser.h
similarity index 100%
rename from stmhal/usbhost/Class/HID/Inc/usbh_hid_parser.h
rename to ports/stm32/usbhost/Class/HID/Inc/usbh_hid_parser.h
diff --git a/stmhal/usbhost/Class/HID/Inc/usbh_hid_usage.h b/ports/stm32/usbhost/Class/HID/Inc/usbh_hid_usage.h
similarity index 100%
rename from stmhal/usbhost/Class/HID/Inc/usbh_hid_usage.h
rename to ports/stm32/usbhost/Class/HID/Inc/usbh_hid_usage.h
diff --git a/stmhal/usbhost/Class/HID/Src/usbh_hid.c b/ports/stm32/usbhost/Class/HID/Src/usbh_hid.c
similarity index 100%
rename from stmhal/usbhost/Class/HID/Src/usbh_hid.c
rename to ports/stm32/usbhost/Class/HID/Src/usbh_hid.c
diff --git a/stmhal/usbhost/Class/HID/Src/usbh_hid_keybd.c b/ports/stm32/usbhost/Class/HID/Src/usbh_hid_keybd.c
similarity index 100%
rename from stmhal/usbhost/Class/HID/Src/usbh_hid_keybd.c
rename to ports/stm32/usbhost/Class/HID/Src/usbh_hid_keybd.c
diff --git a/stmhal/usbhost/Class/HID/Src/usbh_hid_mouse.c b/ports/stm32/usbhost/Class/HID/Src/usbh_hid_mouse.c
similarity index 100%
rename from stmhal/usbhost/Class/HID/Src/usbh_hid_mouse.c
rename to ports/stm32/usbhost/Class/HID/Src/usbh_hid_mouse.c
diff --git a/stmhal/usbhost/Class/HID/Src/usbh_hid_parser.c b/ports/stm32/usbhost/Class/HID/Src/usbh_hid_parser.c
similarity index 100%
rename from stmhal/usbhost/Class/HID/Src/usbh_hid_parser.c
rename to ports/stm32/usbhost/Class/HID/Src/usbh_hid_parser.c
diff --git a/stmhal/usbhost/Class/MSC/Inc/usbh_msc.h b/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc.h
similarity index 100%
rename from stmhal/usbhost/Class/MSC/Inc/usbh_msc.h
rename to ports/stm32/usbhost/Class/MSC/Inc/usbh_msc.h
diff --git a/stmhal/usbhost/Class/MSC/Inc/usbh_msc_bot.h b/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_bot.h
similarity index 100%
rename from stmhal/usbhost/Class/MSC/Inc/usbh_msc_bot.h
rename to ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_bot.h
diff --git a/stmhal/usbhost/Class/MSC/Inc/usbh_msc_scsi.h b/ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_scsi.h
similarity index 100%
rename from stmhal/usbhost/Class/MSC/Inc/usbh_msc_scsi.h
rename to ports/stm32/usbhost/Class/MSC/Inc/usbh_msc_scsi.h
diff --git a/stmhal/usbhost/Class/MSC/Src/usbh_msc.c b/ports/stm32/usbhost/Class/MSC/Src/usbh_msc.c
similarity index 100%
rename from stmhal/usbhost/Class/MSC/Src/usbh_msc.c
rename to ports/stm32/usbhost/Class/MSC/Src/usbh_msc.c
diff --git a/stmhal/usbhost/Class/MSC/Src/usbh_msc_bot.c b/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_bot.c
similarity index 100%
rename from stmhal/usbhost/Class/MSC/Src/usbh_msc_bot.c
rename to ports/stm32/usbhost/Class/MSC/Src/usbh_msc_bot.c
diff --git a/stmhal/usbhost/Class/MSC/Src/usbh_msc_scsi.c b/ports/stm32/usbhost/Class/MSC/Src/usbh_msc_scsi.c
similarity index 100%
rename from stmhal/usbhost/Class/MSC/Src/usbh_msc_scsi.c
rename to ports/stm32/usbhost/Class/MSC/Src/usbh_msc_scsi.c
diff --git a/stmhal/usbhost/Class/MTP/Inc/usbh_mtp.h b/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp.h
similarity index 100%
rename from stmhal/usbhost/Class/MTP/Inc/usbh_mtp.h
rename to ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp.h
diff --git a/stmhal/usbhost/Class/MTP/Inc/usbh_mtp_ptp.h b/ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp_ptp.h
similarity index 100%
rename from stmhal/usbhost/Class/MTP/Inc/usbh_mtp_ptp.h
rename to ports/stm32/usbhost/Class/MTP/Inc/usbh_mtp_ptp.h
diff --git a/stmhal/usbhost/Class/MTP/Src/usbh_mtp.c b/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp.c
similarity index 100%
rename from stmhal/usbhost/Class/MTP/Src/usbh_mtp.c
rename to ports/stm32/usbhost/Class/MTP/Src/usbh_mtp.c
diff --git a/stmhal/usbhost/Class/MTP/Src/usbh_mtp_ptp.c b/ports/stm32/usbhost/Class/MTP/Src/usbh_mtp_ptp.c
similarity index 100%
rename from stmhal/usbhost/Class/MTP/Src/usbh_mtp_ptp.c
rename to ports/stm32/usbhost/Class/MTP/Src/usbh_mtp_ptp.c
diff --git a/stmhal/usbhost/Class/Template/Inc/usbh_template.h b/ports/stm32/usbhost/Class/Template/Inc/usbh_template.h
similarity index 100%
rename from stmhal/usbhost/Class/Template/Inc/usbh_template.h
rename to ports/stm32/usbhost/Class/Template/Inc/usbh_template.h
diff --git a/stmhal/usbhost/Class/Template/Src/usbh_template.c b/ports/stm32/usbhost/Class/Template/Src/usbh_template.c
similarity index 100%
rename from stmhal/usbhost/Class/Template/Src/usbh_template.c
rename to ports/stm32/usbhost/Class/Template/Src/usbh_template.c
diff --git a/stmhal/usbhost/Core/Inc/usbh_conf_template.h b/ports/stm32/usbhost/Core/Inc/usbh_conf_template.h
similarity index 100%
rename from stmhal/usbhost/Core/Inc/usbh_conf_template.h
rename to ports/stm32/usbhost/Core/Inc/usbh_conf_template.h
diff --git a/stmhal/usbhost/Core/Inc/usbh_core.h b/ports/stm32/usbhost/Core/Inc/usbh_core.h
similarity index 100%
rename from stmhal/usbhost/Core/Inc/usbh_core.h
rename to ports/stm32/usbhost/Core/Inc/usbh_core.h
diff --git a/stmhal/usbhost/Core/Inc/usbh_ctlreq.h b/ports/stm32/usbhost/Core/Inc/usbh_ctlreq.h
similarity index 100%
rename from stmhal/usbhost/Core/Inc/usbh_ctlreq.h
rename to ports/stm32/usbhost/Core/Inc/usbh_ctlreq.h
diff --git a/stmhal/usbhost/Core/Inc/usbh_def.h b/ports/stm32/usbhost/Core/Inc/usbh_def.h
similarity index 100%
rename from stmhal/usbhost/Core/Inc/usbh_def.h
rename to ports/stm32/usbhost/Core/Inc/usbh_def.h
diff --git a/stmhal/usbhost/Core/Inc/usbh_ioreq.h b/ports/stm32/usbhost/Core/Inc/usbh_ioreq.h
similarity index 100%
rename from stmhal/usbhost/Core/Inc/usbh_ioreq.h
rename to ports/stm32/usbhost/Core/Inc/usbh_ioreq.h
diff --git a/stmhal/usbhost/Core/Inc/usbh_pipes.h b/ports/stm32/usbhost/Core/Inc/usbh_pipes.h
similarity index 100%
rename from stmhal/usbhost/Core/Inc/usbh_pipes.h
rename to ports/stm32/usbhost/Core/Inc/usbh_pipes.h
diff --git a/stmhal/usbhost/Core/Src/usbh_conf_template.c b/ports/stm32/usbhost/Core/Src/usbh_conf_template.c
similarity index 100%
rename from stmhal/usbhost/Core/Src/usbh_conf_template.c
rename to ports/stm32/usbhost/Core/Src/usbh_conf_template.c
diff --git a/stmhal/usbhost/Core/Src/usbh_core.c b/ports/stm32/usbhost/Core/Src/usbh_core.c
similarity index 100%
rename from stmhal/usbhost/Core/Src/usbh_core.c
rename to ports/stm32/usbhost/Core/Src/usbh_core.c
diff --git a/stmhal/usbhost/Core/Src/usbh_ctlreq.c b/ports/stm32/usbhost/Core/Src/usbh_ctlreq.c
similarity index 100%
rename from stmhal/usbhost/Core/Src/usbh_ctlreq.c
rename to ports/stm32/usbhost/Core/Src/usbh_ctlreq.c
diff --git a/stmhal/usbhost/Core/Src/usbh_ioreq.c b/ports/stm32/usbhost/Core/Src/usbh_ioreq.c
similarity index 100%
rename from stmhal/usbhost/Core/Src/usbh_ioreq.c
rename to ports/stm32/usbhost/Core/Src/usbh_ioreq.c
diff --git a/stmhal/usbhost/Core/Src/usbh_pipes.c b/ports/stm32/usbhost/Core/Src/usbh_pipes.c
similarity index 100%
rename from stmhal/usbhost/Core/Src/usbh_pipes.c
rename to ports/stm32/usbhost/Core/Src/usbh_pipes.c
diff --git a/stmhal/usbhost/Release_Notes.html b/ports/stm32/usbhost/Release_Notes.html
similarity index 100%
rename from stmhal/usbhost/Release_Notes.html
rename to ports/stm32/usbhost/Release_Notes.html
diff --git a/stmhal/usrsw.c b/ports/stm32/usrsw.c
similarity index 98%
rename from stmhal/usrsw.c
rename to ports/stm32/usrsw.c
index 63cd440d4..a7721ad77 100644
--- a/stmhal/usrsw.c
+++ b/ports/stm32/usrsw.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -63,7 +63,7 @@ int switch_get(void) {
}
/******************************************************************************/
-// Micro Python bindings
+// MicroPython bindings
typedef struct _pyb_switch_obj_t {
mp_obj_base_t base;
diff --git a/stmhal/usrsw.h b/ports/stm32/usrsw.h
similarity index 94%
rename from stmhal/usrsw.h
rename to ports/stm32/usrsw.h
index 9fbe6109d..d96e3c281 100644
--- a/stmhal/usrsw.h
+++ b/ports/stm32/usrsw.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/stmhal/wdt.c b/ports/stm32/wdt.c
similarity index 100%
rename from stmhal/wdt.c
rename to ports/stm32/wdt.c
diff --git a/stmhal/wdt.h b/ports/stm32/wdt.h
similarity index 100%
rename from stmhal/wdt.h
rename to ports/stm32/wdt.h
diff --git a/teensy/Makefile b/ports/teensy/Makefile
similarity index 96%
rename from teensy/Makefile
rename to ports/teensy/Makefile
index 575e15e54..08ecf0f91 100644
--- a/teensy/Makefile
+++ b/ports/teensy/Makefile
@@ -1,10 +1,10 @@
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
# If you set USE_ARDUINO_TOOLCHAIN=1 then this makefile will attempt to use
# the toolchain that comes with Teensyduino
@@ -30,8 +30,8 @@ CFLAGS_TEENSY = -DF_CPU=96000000 -DUSB_SERIAL -D__MK20DX256__
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float -mfloat-abi=soft -fsingle-precision-constant -Wdouble-promotion $(CFLAGS_TEENSY)
INC += -I.
-INC += -I..
-INC += -I../stmhal
+INC += -I$(TOP)
+INC += -I$(TOP)/ports/stm32
INC += -I$(BUILD)
INC += -Icore
@@ -91,14 +91,14 @@ SRC_C = \
uart.c \
usb.c \
-STM_SRC_C = $(addprefix stmhal/,\
+STM_SRC_C = $(addprefix ports/stm32/,\
gccollect.c \
irq.c \
pin.c \
pin_named_pins.c \
)
-STM_SRC_S = $(addprefix stmhal/,\
+STM_SRC_S = $(addprefix ports/stm32/,\
gchelper.s \
)
@@ -135,7 +135,7 @@ SRC_C += \
OBJ += $(BUILD)/memzip-files.o
-MAKE_MEMZIP = ../lib/memzip/make-memzip.py
+MAKE_MEMZIP = $(TOP)/lib/memzip/make-memzip.py
ifeq ($(MEMZIP_DIR),)
MEMZIP_DIR = memzip_files
endif
@@ -232,4 +232,4 @@ $(BUILD)/%.pp: $(BUILD)/%.c
$(ECHO) "PreProcess $<"
$(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/teensy/README.md b/ports/teensy/README.md
similarity index 100%
rename from teensy/README.md
rename to ports/teensy/README.md
diff --git a/teensy/add-memzip.sh b/ports/teensy/add-memzip.sh
similarity index 100%
rename from teensy/add-memzip.sh
rename to ports/teensy/add-memzip.sh
diff --git a/teensy/core/Arduino.h b/ports/teensy/core/Arduino.h
similarity index 100%
rename from teensy/core/Arduino.h
rename to ports/teensy/core/Arduino.h
diff --git a/teensy/core/HardwareSerial.h b/ports/teensy/core/HardwareSerial.h
similarity index 100%
rename from teensy/core/HardwareSerial.h
rename to ports/teensy/core/HardwareSerial.h
diff --git a/teensy/core/analog.c b/ports/teensy/core/analog.c
similarity index 100%
rename from teensy/core/analog.c
rename to ports/teensy/core/analog.c
diff --git a/teensy/core/avr_functions.h b/ports/teensy/core/avr_functions.h
similarity index 100%
rename from teensy/core/avr_functions.h
rename to ports/teensy/core/avr_functions.h
diff --git a/teensy/core/core_pins.h b/ports/teensy/core/core_pins.h
similarity index 100%
rename from teensy/core/core_pins.h
rename to ports/teensy/core/core_pins.h
diff --git a/teensy/core/mk20dx128.c b/ports/teensy/core/mk20dx128.c
similarity index 100%
rename from teensy/core/mk20dx128.c
rename to ports/teensy/core/mk20dx128.c
diff --git a/teensy/core/mk20dx128.h b/ports/teensy/core/mk20dx128.h
similarity index 100%
rename from teensy/core/mk20dx128.h
rename to ports/teensy/core/mk20dx128.h
diff --git a/teensy/core/pins_arduino.h b/ports/teensy/core/pins_arduino.h
similarity index 100%
rename from teensy/core/pins_arduino.h
rename to ports/teensy/core/pins_arduino.h
diff --git a/teensy/core/pins_teensy.c b/ports/teensy/core/pins_teensy.c
similarity index 100%
rename from teensy/core/pins_teensy.c
rename to ports/teensy/core/pins_teensy.c
diff --git a/teensy/core/usb_desc.c b/ports/teensy/core/usb_desc.c
similarity index 100%
rename from teensy/core/usb_desc.c
rename to ports/teensy/core/usb_desc.c
diff --git a/teensy/core/usb_desc.h b/ports/teensy/core/usb_desc.h
similarity index 100%
rename from teensy/core/usb_desc.h
rename to ports/teensy/core/usb_desc.h
diff --git a/teensy/core/usb_dev.c b/ports/teensy/core/usb_dev.c
similarity index 100%
rename from teensy/core/usb_dev.c
rename to ports/teensy/core/usb_dev.c
diff --git a/teensy/core/usb_dev.h b/ports/teensy/core/usb_dev.h
similarity index 100%
rename from teensy/core/usb_dev.h
rename to ports/teensy/core/usb_dev.h
diff --git a/teensy/core/usb_mem.c b/ports/teensy/core/usb_mem.c
similarity index 100%
rename from teensy/core/usb_mem.c
rename to ports/teensy/core/usb_mem.c
diff --git a/teensy/core/usb_mem.h b/ports/teensy/core/usb_mem.h
similarity index 100%
rename from teensy/core/usb_mem.h
rename to ports/teensy/core/usb_mem.h
diff --git a/teensy/core/usb_names.h b/ports/teensy/core/usb_names.h
similarity index 100%
rename from teensy/core/usb_names.h
rename to ports/teensy/core/usb_names.h
diff --git a/teensy/core/usb_serial.c b/ports/teensy/core/usb_serial.c
similarity index 100%
rename from teensy/core/usb_serial.c
rename to ports/teensy/core/usb_serial.c
diff --git a/teensy/core/usb_serial.h b/ports/teensy/core/usb_serial.h
similarity index 100%
rename from teensy/core/usb_serial.h
rename to ports/teensy/core/usb_serial.h
diff --git a/teensy/core/yield.c b/ports/teensy/core/yield.c
similarity index 100%
rename from teensy/core/yield.c
rename to ports/teensy/core/yield.c
diff --git a/teensy/hal_ftm.c b/ports/teensy/hal_ftm.c
similarity index 98%
rename from teensy/hal_ftm.c
rename to ports/teensy/hal_ftm.c
index 28992881b..3c031bf6d 100644
--- a/teensy/hal_ftm.c
+++ b/ports/teensy/hal_ftm.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/teensy/hal_ftm.h b/ports/teensy/hal_ftm.h
similarity index 99%
rename from teensy/hal_ftm.h
rename to ports/teensy/hal_ftm.h
index ad627358b..84fae8312 100644
--- a/teensy/hal_ftm.h
+++ b/ports/teensy/hal_ftm.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/teensy/hal_gpio.c b/ports/teensy/hal_gpio.c
similarity index 100%
rename from teensy/hal_gpio.c
rename to ports/teensy/hal_gpio.c
diff --git a/teensy/help.c b/ports/teensy/help.c
similarity index 96%
rename from teensy/help.c
rename to ports/teensy/help.c
index 3b3916b94..a2370c04d 100644
--- a/teensy/help.c
+++ b/ports/teensy/help.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,7 +26,7 @@
#include "py/builtin.h"
-const char *teensy_help_text =
+const char teensy_help_text[] =
"Welcome to MicroPython!\n"
"\n"
"For online help please visit http://micropython.org/help/.\n"
diff --git a/teensy/lcd.c b/ports/teensy/lcd.c
similarity index 87%
rename from teensy/lcd.c
rename to ports/teensy/lcd.c
index e79b7d5ac..e5d6115d7 100644
--- a/teensy/lcd.c
+++ b/ports/teensy/lcd.c
@@ -1,5 +1,5 @@
#include "py/obj.h"
-#include "../stmhal/lcd.h"
+#include "../stm32/lcd.h"
void lcd_init(void) {
}
diff --git a/teensy/led.c b/ports/teensy/led.c
similarity index 91%
rename from teensy/led.c
rename to ports/teensy/led.c
index c7ac8be1f..add052fad 100644
--- a/teensy/led.c
+++ b/ports/teensy/led.c
@@ -2,7 +2,6 @@
#include "Arduino.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "led.h"
@@ -81,7 +80,7 @@ void led_toggle(pyb_led_t led) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_led_obj_t *self = self_in;
@@ -127,10 +126,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle);
-STATIC const mp_map_elem_t led_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&led_obj_on_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&led_obj_off_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&led_obj_toggle_obj },
+STATIC const mp_rom_map_elem_t led_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&led_obj_on_obj) },
+ { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&led_obj_off_obj) },
+ { MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&led_obj_toggle_obj) },
};
STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table);
diff --git a/teensy/led.h b/ports/teensy/led.h
similarity index 100%
rename from teensy/led.h
rename to ports/teensy/led.h
diff --git a/teensy/lexerfrozen.c b/ports/teensy/lexerfrozen.c
similarity index 100%
rename from teensy/lexerfrozen.c
rename to ports/teensy/lexerfrozen.c
diff --git a/teensy/lexermemzip.h b/ports/teensy/lexermemzip.h
similarity index 100%
rename from teensy/lexermemzip.h
rename to ports/teensy/lexermemzip.h
diff --git a/teensy/main.c b/ports/teensy/main.c
similarity index 99%
rename from teensy/main.c
rename to ports/teensy/main.c
index 41bbeb5d9..3edaa28a0 100644
--- a/teensy/main.c
+++ b/ports/teensy/main.c
@@ -266,7 +266,7 @@ int main(void) {
// GC init
gc_init(&_heap_start, (void*)HEAP_END);
- // Micro Python init
+ // MicroPython init
mp_init();
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
diff --git a/teensy/make-pins.py b/ports/teensy/make-pins.py
similarity index 98%
rename from teensy/make-pins.py
rename to ports/teensy/make-pins.py
index f7ba7a04a..0f6c5f28d 100755
--- a/teensy/make-pins.py
+++ b/ports/teensy/make-pins.py
@@ -236,11 +236,11 @@ def parse_board_file(self, filename):
self.board_pins.append(NamedPin(row[0], pin))
def print_named(self, label, named_pins):
- print('STATIC const mp_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{'.format(label))
+ print('STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{'.format(label))
for named_pin in named_pins:
pin = named_pin.pin()
if pin.is_board_pin():
- print(' {{ MP_OBJ_NEW_QSTR(MP_QSTR_{:s}), (mp_obj_t)&pin_{:s} }},'.format(named_pin.name(), pin.cpu_pin_name()))
+ print(' {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}) }},'.format(named_pin.name(), pin.cpu_pin_name()))
print('};')
print('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);'.format(label, label));
diff --git a/teensy/memzip_files/boot.py b/ports/teensy/memzip_files/boot.py
similarity index 100%
rename from teensy/memzip_files/boot.py
rename to ports/teensy/memzip_files/boot.py
diff --git a/teensy/memzip_files/main.py b/ports/teensy/memzip_files/main.py
similarity index 100%
rename from teensy/memzip_files/main.py
rename to ports/teensy/memzip_files/main.py
diff --git a/teensy/mk20dx256.ld b/ports/teensy/mk20dx256.ld
similarity index 100%
rename from teensy/mk20dx256.ld
rename to ports/teensy/mk20dx256.ld
diff --git a/teensy/mk20dx256_af.csv b/ports/teensy/mk20dx256_af.csv
similarity index 100%
rename from teensy/mk20dx256_af.csv
rename to ports/teensy/mk20dx256_af.csv
diff --git a/teensy/mk20dx256_prefix.c b/ports/teensy/mk20dx256_prefix.c
similarity index 100%
rename from teensy/mk20dx256_prefix.c
rename to ports/teensy/mk20dx256_prefix.c
diff --git a/teensy/modpyb.c b/ports/teensy/modpyb.c
similarity index 76%
rename from teensy/modpyb.c
rename to ports/teensy/modpyb.c
index 9f601e327..e4c399fc8 100644
--- a/teensy/modpyb.c
+++ b/ports/teensy/modpyb.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -154,7 +154,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_sync_obj, pyb_sync);
/// \function millis()
/// Returns the number of milliseconds since the board was last reset.
///
-/// The result is always a micropython smallint (31-bit signed number), so
+/// The result is always a MicroPython smallint (31-bit signed number), so
/// after 2^30 milliseconds (about 12.4 days) this will start to return
/// negative numbers.
STATIC mp_obj_t pyb_millis(void) {
@@ -185,7 +185,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
/// \function micros()
/// Returns the number of microseconds since the board was last reset.
///
-/// The result is always a micropython smallint (31-bit signed number), so
+/// The result is always a MicroPython smallint (31-bit signed number), so
/// after 2^30 microseconds (about 17.8 minutes) this will start to return
/// negative numbers.
STATIC mp_obj_t pyb_micros(void) {
@@ -276,77 +276,77 @@ MP_DECLARE_CONST_FUN_OBJ_1(pyb_source_dir_obj); // defined in main.c
MP_DECLARE_CONST_FUN_OBJ_1(pyb_main_obj); // defined in main.c
MP_DECLARE_CONST_FUN_OBJ_1(pyb_usb_mode_obj); // defined in main.c
-STATIC const mp_map_elem_t pyb_module_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) },
+STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_bootloader), (mp_obj_t)&pyb_bootloader_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&pyb_unique_id_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_freq_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_repl_info), (mp_obj_t)&pyb_set_repl_info_obj },
+ { MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&pyb_bootloader_obj) },
+ { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&pyb_info_obj) },
+ { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&pyb_unique_id_obj) },
+ { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&pyb_freq_obj) },
+ { MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_wfi), (mp_obj_t)&pyb_wfi_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_disable_irq), (mp_obj_t)&pyb_disable_irq_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_enable_irq), (mp_obj_t)&pyb_enable_irq_obj },
+ { MP_ROM_QSTR(MP_QSTR_wfi), MP_ROM_PTR(&pyb_wfi_obj) },
+ { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&pyb_disable_irq_obj) },
+ { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&pyb_enable_irq_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_stop), (mp_obj_t)&pyb_stop_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_standby), (mp_obj_t)&pyb_standby_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_source_dir), (mp_obj_t)&pyb_source_dir_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_main), (mp_obj_t)&pyb_main_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_usb_mode), (mp_obj_t)&pyb_usb_mode_obj },
+ { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&pyb_stop_obj) },
+ { MP_ROM_QSTR(MP_QSTR_standby), MP_ROM_PTR(&pyb_standby_obj) },
+ { MP_ROM_QSTR(MP_QSTR_source_dir), MP_ROM_PTR(&pyb_source_dir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&pyb_main_obj) },
+ { MP_ROM_QSTR(MP_QSTR_usb_mode), MP_ROM_PTR(&pyb_usb_mode_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_have_cdc), (mp_obj_t)&pyb_have_cdc_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_hid), (mp_obj_t)&pyb_hid_send_report_obj },
+ { MP_ROM_QSTR(MP_QSTR_have_cdc), MP_ROM_PTR(&pyb_have_cdc_obj) },
+ { MP_ROM_QSTR(MP_QSTR_hid), MP_ROM_PTR(&pyb_hid_send_report_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_millis), (mp_obj_t)&pyb_millis_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_elapsed_millis), (mp_obj_t)&pyb_elapsed_millis_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_micros), (mp_obj_t)&pyb_micros_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_elapsed_micros), (mp_obj_t)&pyb_elapsed_micros_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_delay), (mp_obj_t)&pyb_delay_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_udelay), (mp_obj_t)&pyb_udelay_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&pyb_sync_obj },
+ { MP_ROM_QSTR(MP_QSTR_millis), MP_ROM_PTR(&pyb_millis_obj) },
+ { MP_ROM_QSTR(MP_QSTR_elapsed_millis), MP_ROM_PTR(&pyb_elapsed_millis_obj) },
+ { MP_ROM_QSTR(MP_QSTR_micros), MP_ROM_PTR(&pyb_micros_obj) },
+ { MP_ROM_QSTR(MP_QSTR_elapsed_micros), MP_ROM_PTR(&pyb_elapsed_micros_obj) },
+ { MP_ROM_QSTR(MP_QSTR_delay), MP_ROM_PTR(&pyb_delay_obj) },
+ { MP_ROM_QSTR(MP_QSTR_udelay), MP_ROM_PTR(&pyb_udelay_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&pyb_sync_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
+ { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&pyb_timer_type) },
//#if MICROPY_HW_ENABLE_RNG
-// { MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&pyb_rng_get_obj },
+// { MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&pyb_rng_get_obj) },
//#endif
//#if MICROPY_HW_ENABLE_RTC
-// { MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
+// { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&pyb_rtc_type) },
//#endif
- { MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_type },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_ExtInt), (mp_obj_t)&extint_type },
+ { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) },
+// { MP_ROM_QSTR(MP_QSTR_ExtInt), MP_ROM_PTR(&extint_type) },
#if MICROPY_HW_ENABLE_SERVO
- { MP_OBJ_NEW_QSTR(MP_QSTR_pwm), (mp_obj_t)&pyb_pwm_set_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_servo), (mp_obj_t)&pyb_servo_set_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Servo), (mp_obj_t)&pyb_servo_type },
+ { MP_ROM_QSTR(MP_QSTR_pwm), MP_ROM_PTR(&pyb_pwm_set_obj) },
+ { MP_ROM_QSTR(MP_QSTR_servo), MP_ROM_PTR(&pyb_servo_set_obj) },
+ { MP_ROM_QSTR(MP_QSTR_Servo), MP_ROM_PTR(&pyb_servo_type) },
#endif
#if MICROPY_HW_HAS_SWITCH
- { MP_OBJ_NEW_QSTR(MP_QSTR_Switch), (mp_obj_t)&pyb_switch_type },
+ { MP_ROM_QSTR(MP_QSTR_Switch), MP_ROM_PTR(&pyb_switch_type) },
#endif
//#if MICROPY_HW_HAS_SDCARD
-// { MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sdcard_obj },
+// { MP_ROM_QSTR(MP_QSTR_SD), MP_ROM_PTR(&pyb_sdcard_obj) },
//#endif
- { MP_OBJ_NEW_QSTR(MP_QSTR_LED), (mp_obj_t)&pyb_led_type },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_SPI), (mp_obj_t)&pyb_spi_type },
- { MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
+ { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pyb_led_type) },
+// { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&pyb_i2c_type) },
+// { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&pyb_spi_type) },
+ { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_ADCAll), (mp_obj_t)&pyb_adc_all_type },
+// { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&pyb_adc_type) },
+// { MP_ROM_QSTR(MP_QSTR_ADCAll), MP_ROM_PTR(&pyb_adc_all_type) },
//#if MICROPY_HW_ENABLE_DAC
-// { MP_OBJ_NEW_QSTR(MP_QSTR_DAC), (mp_obj_t)&pyb_dac_type },
+// { MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&pyb_dac_type) },
//#endif
//#if MICROPY_HW_HAS_MMA7660
-// { MP_OBJ_NEW_QSTR(MP_QSTR_Accel), (mp_obj_t)&pyb_accel_type },
+// { MP_ROM_QSTR(MP_QSTR_Accel), MP_ROM_PTR(&pyb_accel_type) },
//#endif
};
diff --git a/teensy/mpconfigport.h b/ports/teensy/mpconfigport.h
similarity index 96%
rename from teensy/mpconfigport.h
rename to ports/teensy/mpconfigport.h
index de30924d9..b45b5ad4e 100644
--- a/teensy/mpconfigport.h
+++ b/ports/teensy/mpconfigport.h
@@ -1,6 +1,6 @@
#include
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_ALLOC_PATH_MAX (128)
#define MICROPY_EMIT_THUMB (1)
@@ -38,11 +38,11 @@ extern const struct _mp_obj_module_t os_module;
extern const struct _mp_obj_module_t pyb_module;
extern const struct _mp_obj_module_t time_module;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
+ { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
// extra constants
#define MICROPY_PORT_CONSTANTS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
+ { MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
#define MP_STATE_PORT MP_STATE_VM
diff --git a/teensy/pin_defs_teensy.c b/ports/teensy/pin_defs_teensy.c
similarity index 100%
rename from teensy/pin_defs_teensy.c
rename to ports/teensy/pin_defs_teensy.c
diff --git a/teensy/pin_defs_teensy.h b/ports/teensy/pin_defs_teensy.h
similarity index 100%
rename from teensy/pin_defs_teensy.h
rename to ports/teensy/pin_defs_teensy.h
diff --git a/teensy/qstrdefsport.h b/ports/teensy/qstrdefsport.h
similarity index 100%
rename from teensy/qstrdefsport.h
rename to ports/teensy/qstrdefsport.h
diff --git a/teensy/reg.c b/ports/teensy/reg.c
similarity index 100%
rename from teensy/reg.c
rename to ports/teensy/reg.c
diff --git a/teensy/reg.h b/ports/teensy/reg.h
similarity index 100%
rename from teensy/reg.h
rename to ports/teensy/reg.h
diff --git a/teensy/servo.c b/ports/teensy/servo.c
similarity index 98%
rename from teensy/servo.c
rename to ports/teensy/servo.c
index 6ccdb05e9..262daaeb6 100644
--- a/teensy/servo.c
+++ b/ports/teensy/servo.c
@@ -217,7 +217,7 @@ mp_obj_t pyb_Servo(void) {
self->servo_id++;
}
m_del_obj(pyb_servo_obj_t, self);
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "No available servo ids"));
+ mp_raise_ValueError("No available servo ids");
return mp_const_none;
}
diff --git a/teensy/servo.h b/ports/teensy/servo.h
similarity index 100%
rename from teensy/servo.h
rename to ports/teensy/servo.h
diff --git a/teensy/std.h b/ports/teensy/std.h
similarity index 100%
rename from teensy/std.h
rename to ports/teensy/std.h
diff --git a/teensy/teensy_hal.c b/ports/teensy/teensy_hal.c
similarity index 96%
rename from teensy/teensy_hal.c
rename to ports/teensy/teensy_hal.c
index 4fcf99922..84d68cff8 100644
--- a/teensy/teensy_hal.c
+++ b/ports/teensy/teensy_hal.c
@@ -1,7 +1,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "usb.h"
@@ -61,5 +60,5 @@ void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio) {
}
void extint_register_pin(const void *pin, uint32_t mode, int hard_irq, mp_obj_t callback_obj) {
- mp_not_implemented(NULL);
+ mp_raise_NotImplementedError(NULL);
}
diff --git a/teensy/teensy_hal.h b/ports/teensy/teensy_hal.h
similarity index 100%
rename from teensy/teensy_hal.h
rename to ports/teensy/teensy_hal.h
diff --git a/teensy/teensy_pins.csv b/ports/teensy/teensy_pins.csv
similarity index 100%
rename from teensy/teensy_pins.csv
rename to ports/teensy/teensy_pins.csv
diff --git a/teensy/timer.c b/ports/teensy/timer.c
similarity index 89%
rename from teensy/timer.c
rename to ports/teensy/timer.c
index 45bcc2b8f..b823e6c3b 100644
--- a/teensy/timer.c
+++ b/ports/teensy/timer.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,7 +29,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
@@ -119,7 +118,7 @@ mp_uint_t get_prescaler_shift(mp_int_t prescaler) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
STATIC const mp_obj_type_t pyb_timer_channel_type;
@@ -255,7 +254,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const
// set prescaler and period from frequency
if (vals[0].u_int == 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "can't have 0 frequency"));
+ mp_raise_ValueError("can't have 0 frequency");
}
uint32_t period = MAX(1, F_BUS / vals[0].u_int);
@@ -277,7 +276,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "period must be between 0 and 65535, not %d", init->Period));
}
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "must specify either freq, or prescaler and period"));
+ mp_raise_TypeError("must specify either freq, or prescaler and period");
}
init->CounterMode = vals[3].u_int;
@@ -341,7 +340,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
return (mp_obj_t)tim;
}
-STATIC mp_obj_t pyb_timer_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pyb_timer_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init);
@@ -440,7 +439,7 @@ STATIC const mp_arg_t pyb_timer_channel_args[] = {
};
#define PYB_TIMER_CHANNEL_NUM_ARGS MP_ARRAY_SIZE(pyb_timer_channel_args)
-STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
pyb_timer_obj_t *self = args[0];
mp_int_t channel = mp_obj_get_int(args[1]);
@@ -498,7 +497,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *args, mp_map
mp_obj_t pin_obj = vals[1].u_obj;
if (pin_obj != mp_const_none) {
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "pin argument needs to be be a Pin type"));
+ mp_raise_ValueError("pin argument needs to be be a Pin type");
}
const pin_obj_t *pin = pin_obj;
const pin_af_obj_t *af = pin_find_af(pin, AF_FN_FTM, self->tim_id);
@@ -601,7 +600,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel);
/// \method counter([value])
/// Get or set the timer counter.
-STATIC mp_obj_t pyb_timer_counter(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
if (n_args == 1) {
// get
@@ -616,7 +615,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_counter_obj, 1, 2, pyb_time
/// \method prescaler([value])
/// Get or set the prescaler for the timer.
-STATIC mp_obj_t pyb_timer_prescaler(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_prescaler(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
if (n_args == 1) {
// get
@@ -637,7 +636,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_prescaler_obj, 1, 2, pyb_ti
/// \method period([value])
/// Get or set the period of the timer.
-STATIC mp_obj_t pyb_timer_period(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
if (n_args == 1) {
// get
@@ -668,7 +667,7 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) {
// start timer, so that it interrupts on overflow
HAL_FTM_Base_Start_IT(&self->ftm);
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object"));
+ mp_raise_ValueError("callback must be None or a callable object");
}
return mp_const_none;
}
@@ -708,32 +707,32 @@ mp_obj_t pyb_timer_reg(uint n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_reg_obj, 1, 3, pyb_timer_reg);
#endif // MICROPY_TIMER_REG
-STATIC const mp_map_elem_t pyb_timer_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_timer_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_timer_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_channel), (mp_obj_t)&pyb_timer_channel_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_counter), (mp_obj_t)&pyb_timer_counter_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_prescaler), (mp_obj_t)&pyb_timer_prescaler_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_period), (mp_obj_t)&pyb_timer_period_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&pyb_timer_callback_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_timer_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_timer_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&pyb_timer_channel_obj) },
+ { MP_ROM_QSTR(MP_QSTR_counter), MP_ROM_PTR(&pyb_timer_counter_obj) },
+ { MP_ROM_QSTR(MP_QSTR_prescaler), MP_ROM_PTR(&pyb_timer_prescaler_obj) },
+ { MP_ROM_QSTR(MP_QSTR_period), MP_ROM_PTR(&pyb_timer_period_obj) },
+ { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_timer_callback_obj) },
#if MICROPY_TIMER_REG
- { MP_OBJ_NEW_QSTR(MP_QSTR_reg), (mp_obj_t)&pyb_timer_reg_obj },
+ { MP_ROM_QSTR(MP_QSTR_reg), MP_ROM_PTR(&pyb_timer_reg_obj) },
#endif
- { MP_OBJ_NEW_QSTR(MP_QSTR_UP), MP_OBJ_NEW_SMALL_INT(FTM_COUNTERMODE_UP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_CENTER), MP_OBJ_NEW_SMALL_INT(FTM_COUNTERMODE_CENTER) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PWM), MP_OBJ_NEW_SMALL_INT(CHANNEL_MODE_PWM_NORMAL) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PWM_INVERTED), MP_OBJ_NEW_SMALL_INT(CHANNEL_MODE_PWM_INVERTED) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OC_TIMING), MP_OBJ_NEW_SMALL_INT(CHANNEL_MODE_OC_TIMING) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OC_ACTIVE), MP_OBJ_NEW_SMALL_INT(CHANNEL_MODE_OC_ACTIVE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OC_INACTIVE), MP_OBJ_NEW_SMALL_INT(CHANNEL_MODE_OC_INACTIVE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OC_TOGGLE), MP_OBJ_NEW_SMALL_INT(CHANNEL_MODE_OC_TOGGLE) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_IC), MP_OBJ_NEW_SMALL_INT(CHANNEL_MODE_IC) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_HIGH), MP_OBJ_NEW_SMALL_INT(FTM_OCPOLARITY_HIGH) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_LOW), MP_OBJ_NEW_SMALL_INT(FTM_OCPOLARITY_LOW) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_RISING), MP_OBJ_NEW_SMALL_INT(FTM_ICPOLARITY_RISING) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_FALLING), MP_OBJ_NEW_SMALL_INT(FTM_ICPOLARITY_FALLING) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_BOTH), MP_OBJ_NEW_SMALL_INT(FTM_ICPOLARITY_BOTH) },
+ { MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_INT(FTM_COUNTERMODE_UP) },
+ { MP_ROM_QSTR(MP_QSTR_CENTER), MP_ROM_INT(FTM_COUNTERMODE_CENTER) },
+ { MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_INT(CHANNEL_MODE_PWM_NORMAL) },
+ { MP_ROM_QSTR(MP_QSTR_PWM_INVERTED), MP_ROM_INT(CHANNEL_MODE_PWM_INVERTED) },
+ { MP_ROM_QSTR(MP_QSTR_OC_TIMING), MP_ROM_INT(CHANNEL_MODE_OC_TIMING) },
+ { MP_ROM_QSTR(MP_QSTR_OC_ACTIVE), MP_ROM_INT(CHANNEL_MODE_OC_ACTIVE) },
+ { MP_ROM_QSTR(MP_QSTR_OC_INACTIVE), MP_ROM_INT(CHANNEL_MODE_OC_INACTIVE) },
+ { MP_ROM_QSTR(MP_QSTR_OC_TOGGLE), MP_ROM_INT(CHANNEL_MODE_OC_TOGGLE) },
+ { MP_ROM_QSTR(MP_QSTR_IC), MP_ROM_INT(CHANNEL_MODE_IC) },
+ { MP_ROM_QSTR(MP_QSTR_HIGH), MP_ROM_INT(FTM_OCPOLARITY_HIGH) },
+ { MP_ROM_QSTR(MP_QSTR_LOW), MP_ROM_INT(FTM_OCPOLARITY_LOW) },
+ { MP_ROM_QSTR(MP_QSTR_RISING), MP_ROM_INT(FTM_ICPOLARITY_RISING) },
+ { MP_ROM_QSTR(MP_QSTR_FALLING), MP_ROM_INT(FTM_ICPOLARITY_FALLING) },
+ { MP_ROM_QSTR(MP_QSTR_BOTH), MP_ROM_INT(FTM_ICPOLARITY_BOTH) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table);
@@ -777,7 +776,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m
///
/// In edge aligned mode, a pulse_width of `period + 1` corresponds to a duty cycle of 100%
/// In center aligned mode, a pulse width of `period` corresponds to a duty cycle of 100%
-STATIC mp_obj_t pyb_timer_channel_capture_compare(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *self = args[0];
FTM_TypeDef *FTMx = self->timer->ftm.Instance;
if (n_args == 1) {
@@ -799,7 +798,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj
/// for which the pulse is active. The value can be an integer or
/// floating-point number for more accuracy. For example, a value of 25 gives
/// a duty cycle of 25%.
-STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(size_t n_args, const mp_obj_t *args) {
pyb_timer_channel_obj_t *self = args[0];
FTM_TypeDef *FTMx = self->timer->ftm.Instance;
uint32_t period = compute_period(self->timer);
@@ -846,7 +845,7 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
break;
}
} else {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object"));
+ mp_raise_ValueError("callback must be None or a callable object");
}
return mp_const_none;
}
@@ -867,15 +866,15 @@ mp_obj_t pyb_timer_channel_reg(uint n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_reg_obj, 1, 3, pyb_timer_channel_reg);
#endif
-STATIC const mp_map_elem_t pyb_timer_channel_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&pyb_timer_channel_callback_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_pulse_width), (mp_obj_t)&pyb_timer_channel_capture_compare_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_pulse_width_percent), (mp_obj_t)&pyb_timer_channel_pulse_width_percent_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_capture), (mp_obj_t)&pyb_timer_channel_capture_compare_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_compare), (mp_obj_t)&pyb_timer_channel_capture_compare_obj },
+ { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_timer_channel_callback_obj) },
+ { MP_ROM_QSTR(MP_QSTR_pulse_width), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) },
+ { MP_ROM_QSTR(MP_QSTR_pulse_width_percent), MP_ROM_PTR(&pyb_timer_channel_pulse_width_percent_obj) },
+ { MP_ROM_QSTR(MP_QSTR_capture), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) },
+ { MP_ROM_QSTR(MP_QSTR_compare), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) },
#if MICROPY_TIMER_REG
- { MP_OBJ_NEW_QSTR(MP_QSTR_reg), (mp_obj_t)&pyb_timer_channel_reg_obj },
+ { MP_ROM_QSTR(MP_QSTR_reg), MP_ROM_PTR(&pyb_timer_channel_reg_obj) },
#endif
};
STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table);
diff --git a/teensy/timer.h b/ports/teensy/timer.h
similarity index 94%
rename from teensy/timer.h
rename to ports/teensy/timer.h
index 89095b076..75c2e654e 100644
--- a/teensy/timer.h
+++ b/ports/teensy/timer.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/teensy/uart.c b/ports/teensy/uart.c
similarity index 96%
rename from teensy/uart.c
rename to ports/teensy/uart.c
index b4c0a4d5b..3d5111217 100644
--- a/teensy/uart.c
+++ b/ports/teensy/uart.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "bufhelper.h"
#include "uart.h"
@@ -221,7 +220,7 @@ void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len) {
}
/******************************************************************************/
-/* Micro Python bindings */
+/* MicroPython bindings */
STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_uart_obj_t *self = self_in;
@@ -468,13 +467,13 @@ STATIC mp_obj_t pyb_uart_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_recv_obj, 1, pyb_uart_recv);
-STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_uart_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_uart_deinit_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_any), (mp_obj_t)&pyb_uart_any_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&pyb_uart_send_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&pyb_uart_recv_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_uart_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_uart_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(&pyb_uart_any_obj) },
+ { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&pyb_uart_send_obj) },
+ { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&pyb_uart_recv_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table);
diff --git a/teensy/usb.c b/ports/teensy/usb.c
similarity index 100%
rename from teensy/usb.c
rename to ports/teensy/usb.c
diff --git a/teensy/usb.h b/ports/teensy/usb.h
similarity index 100%
rename from teensy/usb.h
rename to ports/teensy/usb.h
diff --git a/unix/.gitignore b/ports/unix/.gitignore
similarity index 100%
rename from unix/.gitignore
rename to ports/unix/.gitignore
diff --git a/unix/Makefile b/ports/unix/Makefile
similarity index 82%
rename from unix/Makefile
rename to ports/unix/Makefile
index 83c79ac96..b96391f69 100644
--- a/unix/Makefile
+++ b/ports/unix/Makefile
@@ -1,5 +1,5 @@
-include mpconfigport.mk
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
FROZEN_DIR = scripts
FROZEN_MPY_DIR = modules
@@ -14,10 +14,10 @@ QSTR_DEFS = qstrdefsport.h
UNAME_S := $(shell uname -s)
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
INC += -I.
-INC += -I..
+INC += -I$(TOP)
INC += -I$(BUILD)
# compiler settings
@@ -59,7 +59,7 @@ CFLAGS += -U _FORTIFY_SOURCE
endif
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
-# The unix port of micropython on OSX must be compiled with clang,
+# The unix port of MicroPython on OSX must be compiled with clang,
# while cross-compile ports require gcc, so we test here for OSX and
# if necessary override the value of 'CC' set in py/mkenv.mk
ifeq ($(UNAME_S),Darwin)
@@ -87,7 +87,7 @@ endif
endif
ifeq ($(MICROPY_USE_READLINE),1)
-INC += -I../lib/mp-readline
+INC += -I$(TOP)/lib/mp-readline
CFLAGS_MOD += -DMICROPY_USE_READLINE=1
LIB_SRC_C_EXTRA += mp-readline/readline.c
endif
@@ -97,7 +97,7 @@ SRC_MOD += modtermios.c
endif
ifeq ($(MICROPY_PY_SOCKET),1)
CFLAGS_MOD += -DMICROPY_PY_SOCKET=1
-SRC_MOD += modsocket.c
+SRC_MOD += modusocket.c
endif
ifeq ($(MICROPY_PY_THREAD),1)
CFLAGS_MOD += -DMICROPY_PY_THREAD=1 -DMICROPY_PY_THREAD_GIL=0
@@ -107,11 +107,11 @@ endif
ifeq ($(MICROPY_PY_FFI),1)
ifeq ($(MICROPY_STANDALONE),1)
-LIBFFI_CFLAGS_MOD := -I$(shell ls -1d ../lib/libffi/build_dir/out/lib/libffi-*/include)
+LIBFFI_CFLAGS_MOD := -I$(shell ls -1d $(TOP)/lib/libffi/build_dir/out/lib/libffi-*/include)
ifeq ($(MICROPY_FORCE_32BIT),1)
- LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib32/libffi.a
+ LIBFFI_LDFLAGS_MOD = $(TOP)/lib/libffi/build_dir/out/lib32/libffi.a
else
- LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib/libffi.a
+ LIBFFI_LDFLAGS_MOD = $(TOP)/lib/libffi/build_dir/out/lib/libffi.a
endif
else
LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi)
@@ -183,13 +183,13 @@ MPY_CROSS_FLAGS += -mcache-lookup-bc
endif
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
.PHONY: test
-test: $(PROG) ../tests/run-tests
- $(eval DIRNAME=$(notdir $(CURDIR)))
- cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests
+test: $(PROG) $(TOP)/tests/run-tests
+ $(eval DIRNAME=ports/$(notdir $(CURDIR)))
+ cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests
# install micropython in /usr/local/bin
TARGET = micropython
@@ -253,13 +253,13 @@ coverage:
BUILD=build-coverage PROG=micropython_coverage
coverage_test: coverage
- $(eval DIRNAME=$(notdir $(CURDIR)))
- cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests
- cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests -d thread
- cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native
- cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --via-mpy -d basics float
- gcov -o build-coverage/py ../py/*.c
- gcov -o build-coverage/extmod ../extmod/*.c
+ $(eval DIRNAME=ports/$(notdir $(CURDIR)))
+ cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests
+ cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests -d thread
+ cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native
+ cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --via-mpy -d basics float
+ gcov -o build-coverage/py $(TOP)/py/*.c
+ gcov -o build-coverage/extmod $(TOP)/extmod/*.c
# Value of configure's --host= option (required for cross-compilation).
# Deduce it from CROSS_COMPILE by default, but can be overridden.
@@ -274,21 +274,21 @@ deplibs: libffi axtls
# install-exec-recursive & install-data-am targets are used to avoid building
# docs and depending on makeinfo
libffi:
- cd ../lib/libffi; git clean -d -x -f
- cd ../lib/libffi; ./autogen.sh
- mkdir -p ../lib/libffi/build_dir; cd ../lib/libffi/build_dir; \
+ cd $(TOP)/lib/libffi; git clean -d -x -f
+ cd $(TOP)/lib/libffi; ./autogen.sh
+ mkdir -p $(TOP)/lib/libffi/build_dir; cd $(TOP)/lib/libffi/build_dir; \
../configure $(CROSS_COMPILE_HOST) --prefix=$$PWD/out --disable-structs CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="-Os -fomit-frame-pointer -fstrict-aliasing -ffast-math -fno-exceptions"; \
$(MAKE) install-exec-recursive; $(MAKE) -C include install-data-am
axtls: $(BUILD)/libaxtls.a
-$(BUILD)/libaxtls.a: ../lib/axtls/README | $(OBJ_DIRS)
- cd ../lib/axtls; cp config/upyconfig config/.config
- cd ../lib/axtls; $(MAKE) oldconfig -B
- cd ../lib/axtls; $(MAKE) clean
- cd ../lib/axtls; $(MAKE) all CC="$(CC)" LD="$(LD)"
- cp ../lib/axtls/_stage/libaxtls.a $@
+$(BUILD)/libaxtls.a: $(TOP)/lib/axtls/README | $(OBJ_DIRS)
+ cd $(TOP)/lib/axtls; cp config/upyconfig config/.config
+ cd $(TOP)/lib/axtls; $(MAKE) oldconfig -B
+ cd $(TOP)/lib/axtls; $(MAKE) clean
+ cd $(TOP)/lib/axtls; $(MAKE) all CC="$(CC)" LD="$(LD)"
+ cp $(TOP)/lib/axtls/_stage/libaxtls.a $@
-../lib/axtls/README:
+$(TOP)/lib/axtls/README:
@echo "You cloned without --recursive, fetching submodules for you."
- (cd ..; git submodule update --init --recursive)
+ (cd $(TOP); git submodule update --init --recursive)
diff --git a/unix/alloc.c b/ports/unix/alloc.c
similarity index 97%
rename from unix/alloc.c
rename to ports/unix/alloc.c
index 54fc1d3c4..ca12d025b 100644
--- a/unix/alloc.c
+++ b/ports/unix/alloc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/coverage-frzmpy/frzmpy1.py b/ports/unix/coverage-frzmpy/frzmpy1.py
similarity index 100%
rename from unix/coverage-frzmpy/frzmpy1.py
rename to ports/unix/coverage-frzmpy/frzmpy1.py
diff --git a/unix/coverage-frzmpy/frzmpy2.py b/ports/unix/coverage-frzmpy/frzmpy2.py
similarity index 100%
rename from unix/coverage-frzmpy/frzmpy2.py
rename to ports/unix/coverage-frzmpy/frzmpy2.py
diff --git a/unix/coverage-frzmpy/frzmpy_pkg1/__init__.py b/ports/unix/coverage-frzmpy/frzmpy_pkg1/__init__.py
similarity index 100%
rename from unix/coverage-frzmpy/frzmpy_pkg1/__init__.py
rename to ports/unix/coverage-frzmpy/frzmpy_pkg1/__init__.py
diff --git a/unix/coverage-frzmpy/frzmpy_pkg2/mod.py b/ports/unix/coverage-frzmpy/frzmpy_pkg2/mod.py
similarity index 100%
rename from unix/coverage-frzmpy/frzmpy_pkg2/mod.py
rename to ports/unix/coverage-frzmpy/frzmpy_pkg2/mod.py
diff --git a/unix/coverage-frzstr/frzstr1.py b/ports/unix/coverage-frzstr/frzstr1.py
similarity index 100%
rename from unix/coverage-frzstr/frzstr1.py
rename to ports/unix/coverage-frzstr/frzstr1.py
diff --git a/unix/coverage-frzstr/frzstr_pkg1/__init__.py b/ports/unix/coverage-frzstr/frzstr_pkg1/__init__.py
similarity index 100%
rename from unix/coverage-frzstr/frzstr_pkg1/__init__.py
rename to ports/unix/coverage-frzstr/frzstr_pkg1/__init__.py
diff --git a/unix/coverage-frzstr/frzstr_pkg2/mod.py b/ports/unix/coverage-frzstr/frzstr_pkg2/mod.py
similarity index 100%
rename from unix/coverage-frzstr/frzstr_pkg2/mod.py
rename to ports/unix/coverage-frzstr/frzstr_pkg2/mod.py
diff --git a/unix/coverage.c b/ports/unix/coverage.c
similarity index 96%
rename from unix/coverage.c
rename to ports/unix/coverage.c
index 4a9ab194b..651db0a94 100644
--- a/unix/coverage.c
+++ b/ports/unix/coverage.c
@@ -181,8 +181,21 @@ STATIC mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "%.*s\n", (int)vstr->len, vstr->buf);
VSTR_FIXED(fix, 4);
- vstr_add_str(&fix, "large");
- mp_printf(&mp_plat_print, "%.*s\n", (int)fix.len, fix.buf);
+ nlr_buf_t nlr;
+ if (nlr_push(&nlr) == 0) {
+ vstr_add_str(&fix, "large");
+ nlr_pop();
+ } else {
+ mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
+ }
+
+ fix.len = fix.alloc;
+ if (nlr_push(&nlr) == 0) {
+ vstr_null_terminated_str(&fix);
+ nlr_pop();
+ } else {
+ mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
+ }
}
// repl autocomplete
diff --git a/unix/fatfs_port.c b/ports/unix/fatfs_port.c
similarity index 100%
rename from unix/fatfs_port.c
rename to ports/unix/fatfs_port.c
diff --git a/unix/fdfile.h b/ports/unix/fdfile.h
similarity index 95%
rename from unix/fdfile.h
rename to ports/unix/fdfile.h
index 591159deb..69a9b6be4 100644
--- a/unix/fdfile.h
+++ b/ports/unix/fdfile.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/file.c b/ports/unix/file.c
similarity index 98%
rename from unix/file.c
rename to ports/unix/file.c
index a60840c81..84e918082 100644
--- a/unix/file.c
+++ b/ports/unix/file.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -31,7 +31,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "py/builtin.h"
@@ -47,7 +46,7 @@
#ifdef MICROPY_CPYTHON_COMPAT
STATIC void check_fd_is_open(const mp_obj_fdfile_t *o) {
if (o->fd < 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "I/O operation on closed file"));
+ mp_raise_ValueError("I/O operation on closed file");
}
}
#else
diff --git a/unix/gccollect.c b/ports/unix/gccollect.c
similarity index 98%
rename from unix/gccollect.c
rename to ports/unix/gccollect.c
index 4ec8c2bf5..02f6fc91a 100644
--- a/unix/gccollect.c
+++ b/ports/unix/gccollect.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/input.c b/ports/unix/input.c
similarity index 98%
rename from unix/input.c
rename to ports/unix/input.c
index 4b10350df..7d60b46cc 100644
--- a/unix/input.c
+++ b/ports/unix/input.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/input.h b/ports/unix/input.h
similarity index 100%
rename from unix/input.h
rename to ports/unix/input.h
diff --git a/unix/main.c b/ports/unix/main.c
similarity index 99%
rename from unix/main.c
rename to ports/unix/main.c
index 633144c86..e1cd33fc1 100644
--- a/unix/main.c
+++ b/ports/unix/main.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -37,8 +37,6 @@
#include
#include
-#include "py/mpstate.h"
-#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/builtin.h"
diff --git a/unix/modffi.c b/ports/unix/modffi.c
similarity index 98%
rename from unix/modffi.c
rename to ports/unix/modffi.c
index 8b392f1c3..78adccac1 100644
--- a/unix/modffi.c
+++ b/ports/unix/modffi.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -32,7 +32,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mperrno.h"
@@ -409,7 +408,7 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
}
error:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Don't know how to pass object to native function"));
+ mp_raise_TypeError("Don't know how to pass object to native function");
}
STATIC const mp_obj_type_t ffifunc_type = {
diff --git a/unix/modjni.c b/ports/unix/modjni.c
similarity index 95%
rename from unix/modjni.c
rename to ports/unix/modjni.c
index 0aeb0601f..f29c095cf 100644
--- a/unix/modjni.c
+++ b/ports/unix/modjni.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -30,8 +30,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/binary.h"
@@ -64,7 +62,7 @@ STATIC const mp_obj_type_t jmethod_type;
STATIC mp_obj_t new_jobject(jobject jo);
STATIC mp_obj_t new_jclass(jclass jc);
-STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, mp_uint_t n_args, const mp_obj_t *args);
+STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args);
STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out);
typedef struct _mp_obj_jclass_t {
@@ -168,9 +166,9 @@ STATIC mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
return call_method(self->cls, NULL, methods, true, n_args, args);
}
-STATIC const mp_map_elem_t jclass_locals_dict_table[] = {
-// { MP_OBJ_NEW_QSTR(MP_QSTR_get), (mp_obj_t)&ffivar_get_obj },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_set), (mp_obj_t)&ffivar_set_obj },
+STATIC const mp_rom_map_elem_t jclass_locals_dict_table[] = {
+// { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&ffivar_get_obj) },
+// { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&ffivar_set_obj) },
};
STATIC MP_DEFINE_CONST_DICT(jclass_locals_dict, jclass_locals_dict_table);
@@ -181,7 +179,7 @@ STATIC const mp_obj_type_t jclass_type = {
.print = jclass_print,
.attr = jclass_attr,
.call = jclass_call,
- .locals_dict = (mp_obj_t)&jclass_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&jclass_locals_dict,
};
STATIC mp_obj_t new_jclass(jclass jc) {
@@ -268,7 +266,7 @@ STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
return mp_const_none;
}
}
- mp_not_implemented("");
+ mp_raise_NotImplementedError(NULL);
}
if (!JJ(IsInstanceOf, self->obj, List_class)) {
@@ -293,7 +291,7 @@ STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
return MP_OBJ_NULL;
}
-STATIC mp_obj_t jobject_unary_op(mp_uint_t op, mp_obj_t self_in) {
+STATIC mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
mp_obj_jobject_t *self = self_in;
switch (op) {
case MP_UNARY_OP_BOOL:
@@ -331,7 +329,7 @@ STATIC const mp_obj_type_t jobject_type = {
.attr = jobject_attr,
.subscr = jobject_subscr,
.getiter = subscr_getiter,
-// .locals_dict = (mp_obj_t)&jobject_locals_dict,
+// .locals_dict = (mp_obj_dict_t*)&jobject_locals_dict,
};
STATIC mp_obj_t new_jobject(jobject jo) {
@@ -463,7 +461,7 @@ STATIC mp_obj_t jvalue2py(const char *jtypesig, jobject arg) {
}
#endif
-STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args) {
jvalue jargs[n_args];
// printf("methods=%p\n", methods);
jsize num_methods = JJ(GetArrayLength, methods);
@@ -578,7 +576,7 @@ STATIC const mp_obj_type_t jmethod_type = {
.print = jmethod_print,
.call = jmethod_call,
// .attr = jobject_attr,
-// .locals_dict = (mp_obj_t)&jobject_locals_dict,
+// .locals_dict = (mp_obj_dict_t*)&jobject_locals_dict,
};
#ifdef __ANDROID__
@@ -707,11 +705,11 @@ STATIC mp_obj_t mod_jni_env() {
}
MP_DEFINE_CONST_FUN_OBJ_0(mod_jni_env_obj, mod_jni_env);
-STATIC const mp_map_elem_t mp_module_jni_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_jni) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_cls), (mp_obj_t)&mod_jni_cls_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mod_jni_array_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_env), (mp_obj_t)&mod_jni_env_obj },
+STATIC const mp_rom_map_elem_t mp_module_jni_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jni) },
+ { MP_ROM_QSTR(MP_QSTR_cls), MP_ROM_PTR(&mod_jni_cls_obj) },
+ { MP_ROM_QSTR(MP_QSTR_array), MP_ROM_PTR(&mod_jni_array_obj) },
+ { MP_ROM_QSTR(MP_QSTR_env), MP_ROM_PTR(&mod_jni_env_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table);
diff --git a/unix/modmachine.c b/ports/unix/modmachine.c
similarity index 97%
rename from unix/modmachine.c
rename to ports/unix/modmachine.c
index 33a3b098e..48dddec0a 100644
--- a/unix/modmachine.c
+++ b/ports/unix/modmachine.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/modos.c b/ports/unix/modos.c
similarity index 98%
rename from unix/modos.c
rename to ports/unix/modos.c
index 8e746c163..327116a0a 100644
--- a/unix/modos.c
+++ b/ports/unix/modos.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -34,7 +34,6 @@
#include
#include "py/mpconfig.h"
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/objtuple.h"
#include "py/mphal.h"
@@ -58,7 +57,7 @@ STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) {
t->items[3] = MP_OBJ_NEW_SMALL_INT(sb.st_nlink);
t->items[4] = MP_OBJ_NEW_SMALL_INT(sb.st_uid);
t->items[5] = MP_OBJ_NEW_SMALL_INT(sb.st_gid);
- t->items[6] = MP_OBJ_NEW_SMALL_INT(sb.st_size);
+ t->items[6] = mp_obj_new_int_from_uint(sb.st_size);
t->items[7] = MP_OBJ_NEW_SMALL_INT(sb.st_atime);
t->items[8] = MP_OBJ_NEW_SMALL_INT(sb.st_mtime);
t->items[9] = MP_OBJ_NEW_SMALL_INT(sb.st_ctime);
diff --git a/unix/modtermios.c b/ports/unix/modtermios.c
similarity index 98%
rename from unix/modtermios.c
rename to ports/unix/modtermios.c
index 5e82e772a..fe19aac83 100644
--- a/unix/modtermios.c
+++ b/ports/unix/modtermios.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/modtime.c b/ports/unix/modtime.c
similarity index 98%
rename from unix/modtime.c
rename to ports/unix/modtime.c
index 2a6487df2..a74b81f37 100644
--- a/unix/modtime.c
+++ b/ports/unix/modtime.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/ports/unix/modules/upip.py b/ports/unix/modules/upip.py
new file mode 120000
index 000000000..130eb6901
--- /dev/null
+++ b/ports/unix/modules/upip.py
@@ -0,0 +1 @@
+../../../tools/upip.py
\ No newline at end of file
diff --git a/ports/unix/modules/upip_utarfile.py b/ports/unix/modules/upip_utarfile.py
new file mode 120000
index 000000000..d9653d6a6
--- /dev/null
+++ b/ports/unix/modules/upip_utarfile.py
@@ -0,0 +1 @@
+../../../tools/upip_utarfile.py
\ No newline at end of file
diff --git a/unix/moduos_vfs.c b/ports/unix/moduos_vfs.c
similarity index 100%
rename from unix/moduos_vfs.c
rename to ports/unix/moduos_vfs.c
diff --git a/unix/moduselect.c b/ports/unix/moduselect.c
similarity index 99%
rename from unix/moduselect.c
rename to ports/unix/moduselect.c
index 37a3a33b2..ba1c195ef 100644
--- a/unix/moduselect.c
+++ b/ports/unix/moduselect.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/modsocket.c b/ports/unix/modusocket.c
similarity index 95%
rename from unix/modsocket.c
rename to ports/unix/modusocket.c
index c1f88defc..cfb6a9f5e 100644
--- a/unix/modsocket.c
+++ b/ports/unix/modusocket.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -38,7 +38,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/objtuple.h"
#include "py/objstr.h"
#include "py/runtime.h"
@@ -61,8 +60,6 @@
should be add to separate modules (C or Python level).
*/
-#define MICROPY_SOCKET_EXTRA (0)
-
// This type must "inherit" from mp_obj_fdfile_t, i.e. matching subset of
// fields should have the same layout.
typedef struct _mp_obj_socket_t {
@@ -383,26 +380,6 @@ const mp_obj_type_t mp_type_socket = {
.locals_dict = (mp_obj_dict_t*)&usocket_locals_dict,
};
-#if MICROPY_SOCKET_EXTRA
-STATIC mp_obj_t mod_socket_htons(mp_obj_t arg) {
- return MP_OBJ_NEW_SMALL_INT(htons(MP_OBJ_SMALL_INT_VALUE(arg)));
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons);
-
-
-STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
- const char *s = mp_obj_str_get_str(arg);
- struct hostent *h = gethostbyname(s);
- if (h == NULL) {
- // CPython: socket.herror
- mp_raise_OSError(h_errno);
- }
- assert(h->h_length == 4);
- return mp_obj_new_int(*(int*)*h->h_addr_list);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_gethostbyname_obj, mod_socket_gethostbyname);
-#endif // MICROPY_SOCKET_EXTRA
-
#define BINADDR_MAX_LEN sizeof(struct in6_addr)
STATIC mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) {
int family = mp_obj_get_int(family_in);
@@ -550,10 +527,6 @@ STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_inet_pton), MP_ROM_PTR(&mod_socket_inet_pton_obj) },
{ MP_ROM_QSTR(MP_QSTR_inet_ntop), MP_ROM_PTR(&mod_socket_inet_ntop_obj) },
{ MP_ROM_QSTR(MP_QSTR_sockaddr), MP_ROM_PTR(&mod_socket_sockaddr_obj) },
-#if MICROPY_SOCKET_EXTRA
- { MP_ROM_QSTR(MP_QSTR_htons), MP_ROM_PTR(&mod_socket_htons_obj) },
- { MP_ROM_QSTR(MP_QSTR_gethostbyname), MP_ROM_PTR(&mod_socket_gethostbyname_obj) },
-#endif
#define C(name) { MP_ROM_QSTR(MP_QSTR_ ## name), MP_ROM_INT(name) }
C(AF_UNIX),
diff --git a/unix/mpconfigport.h b/ports/unix/mpconfigport.h
similarity index 97%
rename from unix/mpconfigport.h
rename to ports/unix/mpconfigport.h
index 047121fe6..db382e0a7 100644
--- a/unix/mpconfigport.h
+++ b/ports/unix/mpconfigport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_ALLOC_PATH_MAX (PATH_MAX)
#define MICROPY_PERSISTENT_CODE_LOAD (1)
@@ -85,6 +85,7 @@
#define MICROPY_PY_BUILTINS_POW3 (1)
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
+#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
#define MICROPY_PY_SYS_EXIT (1)
@@ -145,8 +146,11 @@
// names in exception messages (may require more RAM).
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
#define MICROPY_WARNINGS (1)
+#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
+extern const struct _mp_print_t mp_stderr_print;
+
// Define to 1 to use undertested inefficient GC helper implementation
// (if more efficient arch-specific one is not available).
#ifndef MICROPY_GCREGS_SETJMP
diff --git a/unix/mpconfigport.mk b/ports/unix/mpconfigport.mk
similarity index 100%
rename from unix/mpconfigport.mk
rename to ports/unix/mpconfigport.mk
diff --git a/unix/mpconfigport_coverage.h b/ports/unix/mpconfigport_coverage.h
similarity index 95%
rename from unix/mpconfigport_coverage.h
rename to ports/unix/mpconfigport_coverage.h
index 5fc8d7107..367b4853a 100644
--- a/unix/mpconfigport_coverage.h
+++ b/ports/unix/mpconfigport_coverage.h
@@ -35,8 +35,10 @@
#define MICROPY_FLOAT_HIGH_QUALITY_HASH (1)
#define MICROPY_ENABLE_SCHEDULER (1)
#define MICROPY_PY_DELATTR_SETATTR (1)
+#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
#define MICROPY_PY_BUILTINS_HELP (1)
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
+#define MICROPY_PY_SYS_GETSIZEOF (1)
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
#define MICROPY_PY_IO_BUFFEREDWRITER (1)
#undef MICROPY_VFS_FAT
diff --git a/unix/mpconfigport_fast.h b/ports/unix/mpconfigport_fast.h
similarity index 95%
rename from unix/mpconfigport_fast.h
rename to ports/unix/mpconfigport_fast.h
index b5be9f334..442159eb4 100644
--- a/unix/mpconfigport_fast.h
+++ b/ports/unix/mpconfigport_fast.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/mpconfigport_freedos.h b/ports/unix/mpconfigport_freedos.h
similarity index 100%
rename from unix/mpconfigport_freedos.h
rename to ports/unix/mpconfigport_freedos.h
diff --git a/unix/mpconfigport_minimal.h b/ports/unix/mpconfigport_minimal.h
similarity index 96%
rename from unix/mpconfigport_minimal.h
rename to ports/unix/mpconfigport_minimal.h
index b4d9f8143..ef7a1a09a 100644
--- a/unix/mpconfigport_minimal.h
+++ b/ports/unix/mpconfigport_minimal.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
-// options to control how Micro Python is built
+// options to control how MicroPython is built
#define MICROPY_ALLOC_QSTR_CHUNK_INIT (64)
#define MICROPY_ALLOC_PARSE_RULE_INIT (8)
@@ -97,7 +97,7 @@
extern const struct _mp_obj_module_t mp_module_os;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_os }, \
+ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \
#define MICROPY_PORT_ROOT_POINTERS \
diff --git a/unix/mpconfigport_nanbox.h b/ports/unix/mpconfigport_nanbox.h
similarity index 100%
rename from unix/mpconfigport_nanbox.h
rename to ports/unix/mpconfigport_nanbox.h
diff --git a/unix/mphalport.h b/ports/unix/mphalport.h
similarity index 96%
rename from unix/mphalport.h
rename to ports/unix/mphalport.h
index cf227872f..ff7a51567 100644
--- a/unix/mphalport.h
+++ b/ports/unix/mphalport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/mpthreadport.c b/ports/unix/mpthreadport.c
similarity index 99%
rename from unix/mpthreadport.c
rename to ports/unix/mpthreadport.c
index 09f5702e3..8c636a445 100644
--- a/unix/mpthreadport.c
+++ b/ports/unix/mpthreadport.c
@@ -28,7 +28,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/mpthread.h"
#include "py/gc.h"
diff --git a/unix/mpthreadport.h b/ports/unix/mpthreadport.h
similarity index 100%
rename from unix/mpthreadport.h
rename to ports/unix/mpthreadport.h
diff --git a/unix/qstrdefsport.h b/ports/unix/qstrdefsport.h
similarity index 93%
rename from unix/qstrdefsport.h
rename to ports/unix/qstrdefsport.h
index 8ab2db58f..ebfaa6cca 100644
--- a/unix/qstrdefsport.h
+++ b/ports/unix/qstrdefsport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/unix/unix_mphal.c b/ports/unix/unix_mphal.c
similarity index 90%
rename from unix/unix_mphal.c
rename to ports/unix/unix_mphal.c
index 800484498..f27c62fd1 100644
--- a/unix/unix_mphal.c
+++ b/ports/unix/unix_mphal.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,7 +29,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "extmod/misc.h"
@@ -109,11 +108,11 @@ void mp_hal_stdio_mode_orig(void) {
#endif
#if MICROPY_PY_OS_DUPTERM
-static int call_dupterm_read(void) {
+static int call_dupterm_read(size_t idx) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_obj_t read_m[3];
- mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_read, read_m);
+ mp_load_method(MP_STATE_VM(dupterm_objs[idx]), MP_QSTR_read, read_m);
read_m[2] = MP_OBJ_NEW_SMALL_INT(1);
mp_obj_t res = mp_call_method_n_kw(1, 0, read_m);
if (res == mp_const_none) {
@@ -123,18 +122,18 @@ static int call_dupterm_read(void) {
mp_get_buffer_raise(res, &bufinfo, MP_BUFFER_READ);
if (bufinfo.len == 0) {
mp_printf(&mp_plat_print, "dupterm: EOF received, deactivating\n");
- MP_STATE_PORT(term_obj) = NULL;
+ MP_STATE_VM(dupterm_objs[idx]) = MP_OBJ_NULL;
return -1;
}
nlr_pop();
return *(byte*)bufinfo.buf;
} else {
// Temporarily disable dupterm to avoid infinite recursion
- mp_obj_t save_term = MP_STATE_PORT(term_obj);
- MP_STATE_PORT(term_obj) = NULL;
+ mp_obj_t save_term = MP_STATE_VM(dupterm_objs[idx]);
+ MP_STATE_VM(dupterm_objs[idx]) = NULL;
mp_printf(&mp_plat_print, "dupterm: ");
mp_obj_print_exception(&mp_plat_print, nlr.ret_val);
- MP_STATE_PORT(term_obj) = save_term;
+ MP_STATE_VM(dupterm_objs[idx]) = save_term;
}
return -1;
@@ -144,10 +143,11 @@ static int call_dupterm_read(void) {
int mp_hal_stdin_rx_chr(void) {
unsigned char c;
#if MICROPY_PY_OS_DUPTERM
- if (MP_STATE_PORT(term_obj) != MP_OBJ_NULL) {
+ // TODO only support dupterm one slot at the moment
+ if (MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL) {
int c;
do {
- c = call_dupterm_read();
+ c = call_dupterm_read(0);
} while (c == -2);
if (c == -1) {
goto main_term;
diff --git a/windows/.appveyor.yml b/ports/windows/.appveyor.yml
similarity index 90%
rename from windows/.appveyor.yml
rename to ports/windows/.appveyor.yml
index 84060a116..a82cf5adc 100644
--- a/windows/.appveyor.yml
+++ b/ports/windows/.appveyor.yml
@@ -15,7 +15,7 @@ platform:
- x64
build:
- project: windows/micropython.vcxproj
+ project: ports/windows/micropython.vcxproj
verbosity: normal
test_script:
diff --git a/windows/.gitignore b/ports/windows/.gitignore
similarity index 100%
rename from windows/.gitignore
rename to ports/windows/.gitignore
diff --git a/windows/Makefile b/ports/windows/Makefile
similarity index 81%
rename from windows/Makefile
rename to ports/windows/Makefile
index 72c97381b..b6433300f 100644
--- a/windows/Makefile
+++ b/ports/windows/Makefile
@@ -1,4 +1,4 @@
-include ../py/mkenv.mk
+include ../../py/mkenv.mk
-include mpconfigport.mk
# define main target
@@ -8,10 +8,10 @@ PROG = micropython.exe
QSTR_DEFS = ../unix/qstrdefsport.h
# include py core make definitions
-include ../py/py.mk
+include $(TOP)/py/py.mk
INC += -I.
-INC += -I..
+INC += -I$(TOP)
INC += -I$(BUILD)
# compiler settings
@@ -28,13 +28,13 @@ endif
# source files
SRC_C = \
- unix/main.c \
- unix/file.c \
- unix/input.c \
- unix/modos.c \
- unix/modmachine.c \
- unix/modtime.c \
- unix/gccollect.c \
+ ports/unix/main.c \
+ ports/unix/file.c \
+ ports/unix/input.c \
+ ports/unix/modos.c \
+ ports/unix/modmachine.c \
+ ports/unix/modtime.c \
+ ports/unix/gccollect.c \
windows_mphal.c \
realpath.c \
init.c \
@@ -62,4 +62,4 @@ SRC_QSTR += $(SRC_C)
# SRC_QSTR
SRC_QSTR_AUTO_DEPS +=
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
diff --git a/windows/README.md b/ports/windows/README.md
similarity index 96%
rename from windows/README.md
rename to ports/windows/README.md
index 6d3249903..f1bd40551 100644
--- a/windows/README.md
+++ b/ports/windows/README.md
@@ -50,8 +50,8 @@ __Stack usage__
The msvc compiler is quite stack-hungry which might result in a "maximum recursion depth exceeded"
RuntimeError for code with lots of nested function calls.
There are several ways to deal with this:
-- increase the threshold used for detection by altering the argument to `mp_stack_set_limit` in `unix/main.c`
-- disable detection all together by setting `MICROPY_STACK_CHECK` to "0" in `windows/mpconfigport.h`
+- increase the threshold used for detection by altering the argument to `mp_stack_set_limit` in `ports/unix/main.c`
+- disable detection all together by setting `MICROPY_STACK_CHECK` to "0" in `ports/windows/mpconfigport.h`
- disable the /GL compiler flag by setting `WholeProgramOptimization` to "false"
See [issue 2927](https://github.com/micropython/micropython/issues/2927) for more information.
diff --git a/windows/fmode.c b/ports/windows/fmode.c
similarity index 100%
rename from windows/fmode.c
rename to ports/windows/fmode.c
diff --git a/windows/fmode.h b/ports/windows/fmode.h
similarity index 100%
rename from windows/fmode.h
rename to ports/windows/fmode.h
diff --git a/windows/init.c b/ports/windows/init.c
similarity index 97%
rename from windows/init.c
rename to ports/windows/init.c
index 669092347..09fa10417 100644
--- a/windows/init.c
+++ b/ports/windows/init.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/init.h b/ports/windows/init.h
similarity index 94%
rename from windows/init.h
rename to ports/windows/init.h
index 480befef6..c6fddb257 100644
--- a/windows/init.h
+++ b/ports/windows/init.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/micropython.vcxproj b/ports/windows/micropython.vcxproj
similarity index 100%
rename from windows/micropython.vcxproj
rename to ports/windows/micropython.vcxproj
diff --git a/windows/mpconfigport.h b/ports/windows/mpconfigport.h
similarity index 95%
rename from windows/mpconfigport.h
rename to ports/windows/mpconfigport.h
index f2f6cbd32..abad35282 100644
--- a/windows/mpconfigport.h
+++ b/ports/windows/mpconfigport.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
-// options to control how Micro Python is built
+// options to control how MicroPython is built
// Linking with GNU readline (MICROPY_USE_READLINE == 2) causes binary to be licensed under GPL
#ifndef MICROPY_USE_READLINE
@@ -164,14 +164,14 @@ void mp_hal_dupterm_tx_strn(const char *str, size_t len);
#endif
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
+ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
extern const struct _mp_obj_module_t mp_module_os;
extern const struct _mp_obj_module_t mp_module_time;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_time }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_umachine), (mp_obj_t)&mp_module_machine }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_os }, \
+ { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_time) }, \
+ { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \
+ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \
#if MICROPY_USE_READLINE == 1
#define MICROPY_PORT_ROOT_POINTERS \
diff --git a/windows/mpconfigport.mk b/ports/windows/mpconfigport.mk
similarity index 100%
rename from windows/mpconfigport.mk
rename to ports/windows/mpconfigport.mk
diff --git a/windows/msvc/common.props b/ports/windows/msvc/common.props
similarity index 100%
rename from windows/msvc/common.props
rename to ports/windows/msvc/common.props
diff --git a/windows/msvc/debug.props b/ports/windows/msvc/debug.props
similarity index 100%
rename from windows/msvc/debug.props
rename to ports/windows/msvc/debug.props
diff --git a/windows/msvc/dirent.c b/ports/windows/msvc/dirent.c
similarity index 100%
rename from windows/msvc/dirent.c
rename to ports/windows/msvc/dirent.c
diff --git a/windows/msvc/dirent.h b/ports/windows/msvc/dirent.h
similarity index 100%
rename from windows/msvc/dirent.h
rename to ports/windows/msvc/dirent.h
diff --git a/windows/msvc/genhdr.targets b/ports/windows/msvc/genhdr.targets
similarity index 99%
rename from windows/msvc/genhdr.targets
rename to ports/windows/msvc/genhdr.targets
index cac3e3ddc..ee030c906 100644
--- a/windows/msvc/genhdr.targets
+++ b/ports/windows/msvc/genhdr.targets
@@ -10,7 +10,7 @@
$(PyBuildDir)genhdr\
$(PyBaseDir)py\
- $(PyBaseDir)unix\qstrdefsport.h
+ $(PyBaseDir)ports\unix\qstrdefsport.h
$(PySrcDir)qstrdefs.h
$(DestDir)qstrdefscollected.h
$(DestDir)qstrdefs.generated.h
diff --git a/windows/msvc/gettimeofday.c b/ports/windows/msvc/gettimeofday.c
similarity index 96%
rename from windows/msvc/gettimeofday.c
rename to ports/windows/msvc/gettimeofday.c
index 6d7264ae7..5f816df70 100644
--- a/windows/msvc/gettimeofday.c
+++ b/ports/windows/msvc/gettimeofday.c
@@ -1,5 +1,5 @@
/*
-* This file is part of the Micro Python project, http://micropython.org/
+* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/msvc/paths.props b/ports/windows/msvc/paths.props
similarity index 74%
rename from windows/msvc/paths.props
rename to ports/windows/msvc/paths.props
index 716698243..db3af4c0f 100644
--- a/windows/msvc/paths.props
+++ b/ports/windows/msvc/paths.props
@@ -3,28 +3,28 @@
True
-
- $([System.IO.Path]::GetFullPath(`$(MSBuildThisFileDirectory)..\..`))\
- $(PyBaseDir)windows\
+ $([System.IO.Path]::GetFullPath(`$(MSBuildThisFileDirectory)..\..\..`))\
+ $(PyBaseDir)ports\windows\
$(PyWinDir)build\
diff --git a/windows/msvc/release.props b/ports/windows/msvc/release.props
similarity index 100%
rename from windows/msvc/release.props
rename to ports/windows/msvc/release.props
diff --git a/windows/msvc/sources.props b/ports/windows/msvc/sources.props
similarity index 67%
rename from windows/msvc/sources.props
rename to ports/windows/msvc/sources.props
index a97686cdc..b85295ebc 100644
--- a/windows/msvc/sources.props
+++ b/ports/windows/msvc/sources.props
@@ -3,16 +3,16 @@
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -31,7 +31,7 @@
-
-
+
+
diff --git a/windows/msvc/sys/time.h b/ports/windows/msvc/sys/time.h
similarity index 94%
rename from windows/msvc/sys/time.h
rename to ports/windows/msvc/sys/time.h
index a36648beb..7c95d409e 100644
--- a/windows/msvc/sys/time.h
+++ b/ports/windows/msvc/sys/time.h
@@ -1,5 +1,5 @@
/*
-* This file is part of the Micro Python project, http://micropython.org/
+* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/msvc/unistd.h b/ports/windows/msvc/unistd.h
similarity index 95%
rename from windows/msvc/unistd.h
rename to ports/windows/msvc/unistd.h
index 87787c3d8..1a1629be4 100644
--- a/windows/msvc/unistd.h
+++ b/ports/windows/msvc/unistd.h
@@ -1,5 +1,5 @@
/*
-* This file is part of the Micro Python project, http://micropython.org/
+* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/realpath.c b/ports/windows/realpath.c
similarity index 96%
rename from windows/realpath.c
rename to ports/windows/realpath.c
index c0ed6b84d..ac9adf812 100644
--- a/windows/realpath.c
+++ b/ports/windows/realpath.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/realpath.h b/ports/windows/realpath.h
similarity index 94%
rename from windows/realpath.h
rename to ports/windows/realpath.h
index c7bb3acd7..869fe80fa 100644
--- a/windows/realpath.h
+++ b/ports/windows/realpath.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/sleep.c b/ports/windows/sleep.c
similarity index 96%
rename from windows/sleep.c
rename to ports/windows/sleep.c
index b8f0a2e9b..6043ec7b7 100644
--- a/windows/sleep.c
+++ b/ports/windows/sleep.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/sleep.h b/ports/windows/sleep.h
similarity index 95%
rename from windows/sleep.h
rename to ports/windows/sleep.h
index 6c0c00332..430ec3a43 100644
--- a/windows/sleep.h
+++ b/ports/windows/sleep.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/windows_mphal.c b/ports/windows/windows_mphal.c
similarity index 98%
rename from windows/windows_mphal.c
rename to ports/windows/windows_mphal.c
index a73140e54..153b04423 100644
--- a/windows/windows_mphal.c
+++ b/ports/windows/windows_mphal.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/windows/windows_mphal.h b/ports/windows/windows_mphal.h
similarity index 92%
rename from windows/windows_mphal.h
rename to ports/windows/windows_mphal.h
index 854e14a7a..2b7aab44a 100644
--- a/windows/windows_mphal.h
+++ b/ports/windows/windows_mphal.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -25,7 +25,7 @@
*/
#include "sleep.h"
-#include "unix/mphalport.h"
+#include "ports/unix/mphalport.h"
#define MICROPY_HAL_HAS_VT100 (0)
diff --git a/zephyr/.gitignore b/ports/zephyr/.gitignore
similarity index 100%
rename from zephyr/.gitignore
rename to ports/zephyr/.gitignore
diff --git a/zephyr/Kbuild b/ports/zephyr/Kbuild
similarity index 100%
rename from zephyr/Kbuild
rename to ports/zephyr/Kbuild
diff --git a/zephyr/Makefile b/ports/zephyr/Makefile
similarity index 92%
rename from zephyr/Makefile
rename to ports/zephyr/Makefile
index c1337adf0..2e6cb41b9 100644
--- a/zephyr/Makefile
+++ b/ports/zephyr/Makefile
@@ -17,17 +17,20 @@ OUTDIR_PREFIX = $(BOARD)
MICROPY_HEAP_SIZE = 16384
FROZEN_DIR = scripts
+# Default target
+all:
+
# Zephyr (generated) config files - must be defined before include below
Z_EXPORTS = outdir/$(OUTDIR_PREFIX)/Makefile.export
ifneq ($(MAKECMDGOALS), clean)
include $(Z_EXPORTS)
endif
-include ../py/mkenv.mk
-include ../py/py.mk
+include ../../py/mkenv.mk
+include $(TOP)/py/py.mk
INC += -I.
-INC += -I..
+INC += -I$(TOP)
INC += -I$(BUILD)
INC += -I$(ZEPHYR_BASE)/net/ip
INC += -I$(ZEPHYR_BASE)/net/ip/contiki
@@ -56,7 +59,7 @@ OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
CFLAGS = $(KBUILD_CFLAGS) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \
-std=gnu99 -fomit-frame-pointer -DNDEBUG -DMICROPY_HEAP_SIZE=$(MICROPY_HEAP_SIZE) $(CFLAGS_EXTRA) $(INC)
-include ../py/mkrules.mk
+include $(TOP)/py/mkrules.mk
# We use single target here ($(Z_EXPORTS)) for simplicity, but actually
# number of things get generated here: 'initconfig' generates C header for
@@ -99,4 +102,4 @@ prj_$(BOARD)_merged.conf: prj_base.conf prj_$(BOARD).conf
$(PYTHON) makeprj.py prj_base.conf prj_$(BOARD).conf $@
test:
- cd ../tests && ./run-tests --target minimal --device "execpty:make -C ../zephyr run BOARD=$(BOARD) QEMU_PTY=1"
+ cd $(TOP)/tests && ./run-tests --target minimal --device "execpty:make -C ../ports/zephyr run BOARD=$(BOARD) QEMU_PTY=1"
diff --git a/zephyr/Makefile.zephyr b/ports/zephyr/Makefile.zephyr
similarity index 100%
rename from zephyr/Makefile.zephyr
rename to ports/zephyr/Makefile.zephyr
diff --git a/zephyr/README.md b/ports/zephyr/README.md
similarity index 100%
rename from zephyr/README.md
rename to ports/zephyr/README.md
diff --git a/zephyr/help.c b/ports/zephyr/help.c
similarity index 98%
rename from zephyr/help.c
rename to ports/zephyr/help.c
index 0c7f27940..becc203f6 100644
--- a/zephyr/help.c
+++ b/ports/zephyr/help.c
@@ -26,7 +26,7 @@
#include "py/builtin.h"
-const char *zephyr_help_text =
+const char zephyr_help_text[] =
"Welcome to MicroPython!\n"
"\n"
"Control commands:\n"
diff --git a/zephyr/machine_pin.c b/ports/zephyr/machine_pin.c
similarity index 88%
rename from zephyr/machine_pin.c
rename to ports/zephyr/machine_pin.c
index 38971399c..4dcd956cf 100644
--- a/zephyr/machine_pin.c
+++ b/ports/zephyr/machine_pin.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -32,7 +32,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
@@ -46,7 +45,7 @@ STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
}
// pin.init(mode, pull=None, *, value)
-STATIC mp_obj_t machine_pin_obj_init_helper(machine_pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+STATIC mp_obj_t machine_pin_obj_init_helper(machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_mode, ARG_pull, ARG_value };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT },
@@ -170,18 +169,18 @@ STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
return -1;
}
-STATIC const mp_map_elem_t machine_pin_locals_dict_table[] = {
+STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
// instance methods
- { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&machine_pin_init_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&machine_pin_value_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&machine_pin_off_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&machine_pin_on_obj },
+ { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj) },
+ { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&machine_pin_value_obj) },
+ { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&machine_pin_off_obj) },
+ { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&machine_pin_on_obj) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_IN), MP_OBJ_NEW_SMALL_INT(GPIO_DIR_IN) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_OUT), MP_OBJ_NEW_SMALL_INT(GPIO_DIR_OUT) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PULL_UP), MP_OBJ_NEW_SMALL_INT(GPIO_PUD_PULL_UP) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PULL_DOWN), MP_OBJ_NEW_SMALL_INT(GPIO_PUD_PULL_DOWN) },
+ { MP_ROM_QSTR(MP_QSTR_IN), MP_ROM_INT(GPIO_DIR_IN) },
+ { MP_ROM_QSTR(MP_QSTR_OUT), MP_ROM_INT(GPIO_DIR_OUT) },
+ { MP_ROM_QSTR(MP_QSTR_PULL_UP), MP_ROM_INT(GPIO_PUD_PULL_UP) },
+ { MP_ROM_QSTR(MP_QSTR_PULL_DOWN), MP_ROM_INT(GPIO_PUD_PULL_DOWN) },
};
STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table);
diff --git a/zephyr/main.c b/ports/zephyr/main.c
similarity index 97%
rename from zephyr/main.c
rename to ports/zephyr/main.c
index a4301629f..7eb9da3e1 100644
--- a/zephyr/main.c
+++ b/ports/zephyr/main.c
@@ -33,7 +33,6 @@
#include
#endif
-#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
@@ -61,7 +60,9 @@ static char *stack_top;
static char heap[MICROPY_HEAP_SIZE];
void init_zephyr(void) {
- // TODO: Make addresses configurable
+ // We now rely on CONFIG_NET_APP_SETTINGS to set up bootstrap
+ // network addresses.
+#if 0
#ifdef CONFIG_NETWORKING
if (net_if_get_default() == NULL) {
// If there's no default networking interface,
@@ -82,6 +83,7 @@ void init_zephyr(void) {
static struct in6_addr in6addr_my = {{{0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}};
net_if_ipv6_addr_add(net_if_get_default(), &in6addr_my, NET_ADDR_MANUAL, 0);
#endif
+#endif
}
int real_main(void) {
diff --git a/zephyr/make-minimal b/ports/zephyr/make-minimal
similarity index 100%
rename from zephyr/make-minimal
rename to ports/zephyr/make-minimal
diff --git a/zephyr/makeprj.py b/ports/zephyr/makeprj.py
similarity index 100%
rename from zephyr/makeprj.py
rename to ports/zephyr/makeprj.py
diff --git a/zephyr/modmachine.c b/ports/zephyr/modmachine.c
similarity index 100%
rename from zephyr/modmachine.c
rename to ports/zephyr/modmachine.c
diff --git a/zephyr/modmachine.h b/ports/zephyr/modmachine.h
similarity index 100%
rename from zephyr/modmachine.h
rename to ports/zephyr/modmachine.h
diff --git a/zephyr/modusocket.c b/ports/zephyr/modusocket.c
similarity index 54%
rename from zephyr/modusocket.c
rename to ports/zephyr/modusocket.c
index cec0eec7c..e021c3a44 100644
--- a/zephyr/modusocket.c
+++ b/ports/zephyr/modusocket.c
@@ -37,6 +37,9 @@
#include
#include
#include
+#ifdef CONFIG_NET_SOCKETS
+#include
+#endif
#define DEBUG_PRINT 0
#if DEBUG_PRINT // print debugging info
@@ -47,11 +50,7 @@
typedef struct _socket_obj_t {
mp_obj_base_t base;
- struct net_context *ctx;
- union {
- struct k_fifo recv_q;
- struct k_fifo accept_q;
- };
+ int ctx;
#define STATE_NEW 0
#define STATE_CONNECTING 1
@@ -62,42 +61,13 @@ typedef struct _socket_obj_t {
STATIC const mp_obj_type_t socket_type;
-// k_fifo extended API
-
-static inline void *_k_fifo_peek_head(struct k_fifo *fifo)
-{
-#if KERNEL_VERSION_NUMBER < 0x010763 /* 1.7.99 */
- return sys_slist_peek_head(&fifo->data_q);
-#else
- return sys_slist_peek_head(&fifo->_queue.data_q);
-#endif
-}
-
-static inline void *_k_fifo_peek_tail(struct k_fifo *fifo)
-{
-#if KERNEL_VERSION_NUMBER < 0x010763 /* 1.7.99 */
- return sys_slist_peek_tail(&fifo->data_q);
-#else
- return sys_slist_peek_tail(&fifo->_queue.data_q);
-#endif
-}
-
-static inline void _k_fifo_wait_non_empty(struct k_fifo *fifo, int32_t timeout)
-{
- struct k_poll_event events[] = {
- K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, K_POLL_MODE_NOTIFY_ONLY, fifo),
- };
-
- k_poll(events, MP_ARRAY_SIZE(events), timeout);
- DEBUG_printf("poll res: %d\n", events[0].state);
-}
-
// Helper functions
#define RAISE_ERRNO(x) { int _err = x; if (_err < 0) mp_raise_OSError(-_err); }
+#define RAISE_SOCK_ERRNO(x) { if ((int)(x) == -1) mp_raise_OSError(errno); }
STATIC void socket_check_closed(socket_obj_t *socket) {
- if (socket->ctx == NULL) {
+ if (socket->ctx == -1) {
// already closed
mp_raise_OSError(EBADF);
}
@@ -109,7 +79,7 @@ STATIC void parse_inet_addr(socket_obj_t *socket, mp_obj_t addr_in, struct socka
mp_obj_t *addr_items;
mp_obj_get_array_fixed_n(addr_in, 2, &addr_items);
- sockaddr_in->sin_family = net_context_get_family(socket->ctx);
+ sockaddr_in->sin_family = net_context_get_family((void*)socket->ctx);
RAISE_ERRNO(net_addr_pton(sockaddr_in->sin_family, mp_obj_str_get_str(addr_items[0]), &sockaddr_in->sin_addr));
sockaddr_in->sin_port = htons(mp_obj_get_int(addr_items[1]));
}
@@ -118,8 +88,8 @@ STATIC mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) {
// We employ the fact that port and address offsets are the same for IPv4 & IPv6
struct sockaddr_in6 *sockaddr_in6 = (struct sockaddr_in6*)addr;
char buf[40];
- net_addr_ntop(addr->family, &sockaddr_in6->sin6_addr, buf, sizeof(buf));
- mp_obj_tuple_t *tuple = mp_obj_new_tuple(addr->family == AF_INET ? 2 : 4, NULL);
+ net_addr_ntop(addr->sa_family, &sockaddr_in6->sin6_addr, buf, sizeof(buf));
+ mp_obj_tuple_t *tuple = mp_obj_new_tuple(addr->sa_family == AF_INET ? 2 : 4, NULL);
tuple->items[0] = mp_obj_new_str(buf, strlen(buf), false);
// We employ the fact that port offset is the same for IPv4 & IPv6
@@ -127,7 +97,7 @@ STATIC mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) {
//tuple->items[1] = mp_obj_new_int(ntohs(((struct sockaddr_in*)addr)->sin_port));
tuple->items[1] = port;
- if (addr->family == AF_INET6) {
+ if (addr->sa_family == AF_INET6) {
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0); // flow_info
tuple->items[3] = MP_OBJ_NEW_SMALL_INT(sockaddr_in6->sin6_scope_id);
}
@@ -135,78 +105,9 @@ STATIC mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) {
return MP_OBJ_FROM_PTR(tuple);
}
-// Copy data from Zephyr net_buf chain into linear buffer.
-// We don't use net_pkt_read(), because it's weird (e.g., we'd like to
-// free processed data fragment ASAP, while net_pkt_read() holds onto
-// the whole fragment chain to do its deeds, and that's minor comparing
-// to the fact that it copies data byte by byte).
-static char *net_pkt_gather(struct net_pkt *pkt, char *to, unsigned max_len) {
- struct net_buf *tmp = pkt->frags;
-
- while (tmp && max_len) {
- unsigned len = tmp->len;
- if (len > max_len) {
- len = max_len;
- }
- memcpy(to, tmp->data, len);
- to += len;
- max_len -= len;
- tmp = net_pkt_frag_del(pkt, NULL, tmp);
- }
-
- return to;
-}
-
-// Callback for incoming packets.
-static void sock_received_cb(struct net_context *context, struct net_pkt *pkt, int status, void *user_data) {
- socket_obj_t *socket = (socket_obj_t*)user_data;
- DEBUG_printf("recv cb: context: %p, status: %d, pkt: %p", context, status, pkt);
- if (pkt) {
- DEBUG_printf(" (appdatalen=%d), token: %p", pkt->appdatalen, net_pkt_token(pkt));
- }
- DEBUG_printf("\n");
- #if DEBUG_PRINT > 1
- net_pkt_print_frags(pkt);
- #endif
-
- // if net_buf == NULL, EOF
- if (pkt == NULL) {
- struct net_pkt *last_pkt = _k_fifo_peek_tail(&socket->recv_q);
- if (last_pkt == NULL) {
- socket->state = STATE_PEER_CLOSED;
- k_fifo_cancel_wait(&socket->recv_q);
- DEBUG_printf("Marked socket %p as peer-closed\n", socket);
- } else {
- // We abuse "buf_sent" flag to store EOF flag
- net_pkt_set_sent(last_pkt, true);
- DEBUG_printf("Set EOF flag on %p\n", last_pkt);
- }
- return;
- }
-
- // Make sure that "EOF flag" is not set
- net_pkt_set_sent(pkt, false);
-
- // We don't care about packet header, so get rid of it asap
- unsigned header_len = net_pkt_appdata(pkt) - pkt->frags->data;
- net_buf_pull(pkt->frags, header_len);
-
- k_fifo_put(&socket->recv_q, pkt);
-}
-
-// Callback for incoming connections.
-static void sock_accepted_cb(struct net_context *new_ctx, struct sockaddr *addr, socklen_t addrlen, int status, void *user_data) {
- socket_obj_t *socket = (socket_obj_t*)user_data;
- DEBUG_printf("accept cb: context: %p, status: %d, new ctx: %p\n", socket->ctx, status, new_ctx);
- DEBUG_printf("new_ctx ref_cnt: %d\n", new_ctx->refcount);
-
- k_fifo_put(&socket->accept_q, new_ctx);
-}
-
socket_obj_t *socket_new(void) {
socket_obj_t *socket = m_new_obj_with_finaliser(socket_obj_t);
socket->base.type = (mp_obj_t)&socket_type;
- k_fifo_init(&socket->recv_q);
socket->state = STATE_NEW;
return socket;
}
@@ -215,10 +116,10 @@ socket_obj_t *socket_new(void) {
STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
socket_obj_t *self = self_in;
- if (self->ctx == NULL) {
+ if (self->ctx == -1) {
mp_printf(print, "");
} else {
- struct net_context *ctx = self->ctx;
+ struct net_context *ctx = (void*)self->ctx;
mp_printf(print, "", ctx, net_context_get_type(ctx));
}
}
@@ -249,7 +150,8 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
}
}
- RAISE_ERRNO(net_context_get(family, socktype, proto, &socket->ctx));
+ socket->ctx = zsock_socket(family, socktype, proto);
+ RAISE_SOCK_ERRNO(socket->ctx);
return MP_OBJ_FROM_PTR(socket);
}
@@ -261,14 +163,9 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
struct sockaddr sockaddr;
parse_inet_addr(socket, addr_in, &sockaddr);
- RAISE_ERRNO(net_context_bind(socket->ctx, &sockaddr, sizeof(sockaddr)));
- // For DGRAM socket, we expect to receive packets after call to bind(),
- // but for STREAM socket, next expected operation is listen(), which
- // doesn't work if recv callback is set.
- if (net_context_get_type(socket->ctx) == SOCK_DGRAM) {
- DEBUG_printf("Setting recv cb after bind\n");
- RAISE_ERRNO(net_context_recv(socket->ctx, sock_received_cb, K_NO_WAIT, socket));
- }
+ int res = zsock_bind(socket->ctx, &sockaddr, sizeof(sockaddr));
+ RAISE_SOCK_ERRNO(res);
+
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
@@ -280,9 +177,9 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
struct sockaddr sockaddr;
parse_inet_addr(socket, addr_in, &sockaddr);
- RAISE_ERRNO(net_context_connect(socket->ctx, &sockaddr, sizeof(sockaddr), NULL, K_FOREVER, NULL));
- DEBUG_printf("Setting recv cb after connect()\n");
- RAISE_ERRNO(net_context_recv(socket->ctx, sock_received_cb, K_NO_WAIT, socket));
+ int res = zsock_connect(socket->ctx, &sockaddr, sizeof(sockaddr));
+ RAISE_SOCK_ERRNO(res);
+
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
@@ -292,8 +189,9 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) {
socket_check_closed(socket);
mp_int_t backlog = mp_obj_get_int(backlog_in);
- RAISE_ERRNO(net_context_listen(socket->ctx, backlog));
- RAISE_ERRNO(net_context_accept(socket->ctx, sock_accepted_cb, K_NO_WAIT, socket));
+ int res = zsock_listen(socket->ctx, backlog);
+ RAISE_SOCK_ERRNO(res);
+
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen);
@@ -302,14 +200,12 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
socket_obj_t *socket = self_in;
socket_check_closed(socket);
- struct net_context *ctx = k_fifo_get(&socket->accept_q, K_FOREVER);
- // Was overwritten by fifo
- ctx->refcount = 1;
+ struct sockaddr sockaddr;
+ socklen_t addrlen = sizeof(sockaddr);
+ int ctx = zsock_accept(socket->ctx, &sockaddr, &addrlen);
socket_obj_t *socket2 = socket_new();
socket2->ctx = ctx;
- DEBUG_printf("Setting recv cb after accept()\n");
- RAISE_ERRNO(net_context_recv(ctx, sock_received_cb, K_NO_WAIT, socket2));
mp_obj_tuple_t *client = mp_obj_new_tuple(2, NULL);
client->items[0] = MP_OBJ_FROM_PTR(socket2);
@@ -322,28 +218,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
STATIC mp_uint_t sock_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
socket_obj_t *socket = self_in;
- if (socket->ctx == NULL) {
+ if (socket->ctx == -1) {
// already closed
*errcode = EBADF;
return MP_STREAM_ERROR;
}
- struct net_pkt *send_pkt = net_pkt_get_tx(socket->ctx, K_FOREVER);
-
- unsigned len = net_if_get_mtu(net_context_get_iface(socket->ctx));
- // Arbitrary value to account for protocol headers
- len -= 64;
- if (len > size) {
- len = size;
- }
-
- // TODO: Return value of 0 is a hard case (as we wait forever, should
- // not happen).
- len = net_pkt_append(send_pkt, len, buf, K_FOREVER);
-
- int err = net_context_send(send_pkt, /*cb*/NULL, K_FOREVER, NULL, NULL);
- if (err < 0) {
- *errcode = -err;
+ ssize_t len = zsock_send(socket->ctx, buf, size, 0);
+ if (len == -1) {
+ *errcode = errno;
return MP_STREAM_ERROR;
}
@@ -364,81 +247,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send);
STATIC mp_uint_t sock_read(mp_obj_t self_in, void *buf, mp_uint_t max_len, int *errcode) {
socket_obj_t *socket = self_in;
- if (socket->ctx == NULL) {
+ if (socket->ctx == -1) {
// already closed
*errcode = EBADF;
return MP_STREAM_ERROR;
}
- enum net_sock_type sock_type = net_context_get_type(socket->ctx);
- unsigned recv_len;
-
- if (sock_type == SOCK_DGRAM) {
-
- struct net_pkt *pkt = k_fifo_get(&socket->recv_q, K_FOREVER);
-
- recv_len = net_pkt_appdatalen(pkt);
- DEBUG_printf("recv: pkt=%p, appdatalen: %d\n", pkt, recv_len);
-
- if (recv_len > max_len) {
- recv_len = max_len;
- }
-
- net_pkt_gather(pkt, buf, recv_len);
- net_pkt_unref(pkt);
-
- } else if (sock_type == SOCK_STREAM) {
-
- do {
-
- if (socket->state == STATE_PEER_CLOSED) {
- return 0;
- }
-
- _k_fifo_wait_non_empty(&socket->recv_q, K_FOREVER);
- struct net_pkt *pkt = _k_fifo_peek_head(&socket->recv_q);
- if (pkt == NULL) {
- DEBUG_printf("TCP recv: NULL return from fifo\n");
- continue;
- }
-
- DEBUG_printf("TCP recv: cur_pkt: %p\n", pkt);
-
- struct net_buf *frag = pkt->frags;
- if (frag == NULL) {
- printf("net_pkt has empty fragments on start!\n");
- assert(0);
- }
-
- unsigned frag_len = frag->len;
- recv_len = frag_len;
- if (recv_len > max_len) {
- recv_len = max_len;
- }
- DEBUG_printf("%d data bytes in head frag, going to read %d\n", frag_len, recv_len);
-
- memcpy(buf, frag->data, recv_len);
-
- if (recv_len != frag_len) {
- net_buf_pull(frag, recv_len);
- } else {
- frag = net_pkt_frag_del(pkt, NULL, frag);
- if (frag == NULL) {
- DEBUG_printf("Finished processing pkt %p\n", pkt);
- // Drop head packet from queue
- k_fifo_get(&socket->recv_q, K_NO_WAIT);
-
- // If "sent" flag was set, it's last packet and we reached EOF
- if (net_pkt_sent(pkt)) {
- socket->state = STATE_PEER_CLOSED;
- }
- net_pkt_unref(pkt);
- }
- }
- // Keep repeating while we're getting empty fragments
- // Zephyr IP stack appears to have fed empty net_buf's with empty
- // frags for various TCP control packets - in previous versions.
- } while (recv_len == 0);
+ ssize_t recv_len = zsock_recv(socket->ctx, buf, max_len, 0);
+ if (recv_len == -1) {
+ *errcode = errno;
+ return MP_STREAM_ERROR;
}
return recv_len;
@@ -483,30 +301,31 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_mak
STATIC mp_obj_t socket_close(mp_obj_t self_in) {
socket_obj_t *socket = self_in;
- if (socket->ctx != NULL) {
- RAISE_ERRNO(net_context_put(socket->ctx));
- socket->ctx = NULL;
+ if (socket->ctx != -1) {
+ int res = zsock_close(socket->ctx);
+ RAISE_SOCK_ERRNO(res);
+ socket->ctx = -1;
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close);
-STATIC const mp_map_elem_t socket_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&socket_close_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&socket_close_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_bind), (mp_obj_t)&socket_bind_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&socket_connect_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_listen), (mp_obj_t)&socket_listen_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_accept), (mp_obj_t)&socket_accept_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&socket_send_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&socket_recv_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_setsockopt), (mp_obj_t)&socket_setsockopt_obj },
-
- { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&socket_makefile_obj },
+STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&socket_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&socket_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) },
+ { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&socket_connect_obj) },
+ { MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&socket_listen_obj) },
+ { MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&socket_accept_obj) },
+ { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&socket_send_obj) },
+ { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&socket_recv_obj) },
+ { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socket_setsockopt_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
+ { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
+ { MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&socket_makefile_obj) },
};
STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
@@ -610,22 +429,22 @@ STATIC mp_obj_t pkt_get_info(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pkt_get_info_obj, pkt_get_info);
-STATIC const mp_map_elem_t mp_module_usocket_globals_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usocket) },
+STATIC const mp_rom_map_elem_t mp_module_usocket_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) },
// objects
- { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&socket_type },
+ { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) },
// class constants
- { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(AF_INET) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET6), MP_OBJ_NEW_SMALL_INT(AF_INET6) },
+ { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(AF_INET) },
+ { MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(AF_INET6) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(SOCK_STREAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(SOCK_DGRAM) },
+ { MP_ROM_QSTR(MP_QSTR_SOCK_STREAM), MP_ROM_INT(SOCK_STREAM) },
+ { MP_ROM_QSTR(MP_QSTR_SOCK_DGRAM), MP_ROM_INT(SOCK_DGRAM) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SOL_SOCKET), MP_OBJ_NEW_SMALL_INT(1) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_SO_REUSEADDR), MP_OBJ_NEW_SMALL_INT(2) },
+ { MP_ROM_QSTR(MP_QSTR_SOL_SOCKET), MP_ROM_INT(1) },
+ { MP_ROM_QSTR(MP_QSTR_SO_REUSEADDR), MP_ROM_INT(2) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_getaddrinfo_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_pkt_get_info), (mp_obj_t)&pkt_get_info_obj },
+ { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_getaddrinfo_obj) },
+ { MP_ROM_QSTR(MP_QSTR_pkt_get_info), MP_ROM_PTR(&pkt_get_info_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals_table);
diff --git a/zephyr/modutime.c b/ports/zephyr/modutime.c
similarity index 97%
rename from zephyr/modutime.c
rename to ports/zephyr/modutime.c
index 0c268046a..a5d32fe66 100644
--- a/zephyr/modutime.c
+++ b/ports/zephyr/modutime.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/zephyr/modzephyr.c b/ports/zephyr/modzephyr.c
similarity index 67%
rename from zephyr/modzephyr.c
rename to ports/zephyr/modzephyr.c
index 4bac5c970..265fc882d 100644
--- a/zephyr/modzephyr.c
+++ b/ports/zephyr/modzephyr.c
@@ -28,6 +28,7 @@
#if MICROPY_PY_ZEPHYR
#include
+#include
#include "py/runtime.h"
@@ -36,9 +37,38 @@ STATIC mp_obj_t mod_is_preempt_thread(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_is_preempt_thread_obj, mod_is_preempt_thread);
+STATIC mp_obj_t mod_current_tid(void) {
+ return MP_OBJ_NEW_SMALL_INT(k_current_get());
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid);
+
+STATIC mp_obj_t mod_stacks_analyze(void) {
+ k_call_stacks_analyze();
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_stacks_analyze_obj, mod_stacks_analyze);
+
+#ifdef CONFIG_NET_SHELL
+
+//int net_shell_cmd_iface(int argc, char *argv[]);
+
+STATIC mp_obj_t mod_shell_net_iface(void) {
+ net_shell_cmd_iface(0, NULL);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_shell_net_iface_obj, mod_shell_net_iface);
+
+#endif // CONFIG_NET_SHELL
+
STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zephyr) },
{ MP_ROM_QSTR(MP_QSTR_is_preempt_thread), MP_ROM_PTR(&mod_is_preempt_thread_obj) },
+ { MP_ROM_QSTR(MP_QSTR_current_tid), MP_ROM_PTR(&mod_current_tid_obj) },
+ { MP_ROM_QSTR(MP_QSTR_stacks_analyze), MP_ROM_PTR(&mod_stacks_analyze_obj) },
+
+ #ifdef CONFIG_NET_SHELL
+ { MP_ROM_QSTR(MP_QSTR_shell_net_iface), MP_ROM_PTR(&mod_shell_net_iface_obj) },
+ #endif
};
STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table);
diff --git a/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h
similarity index 95%
rename from zephyr/mpconfigport.h
rename to ports/zephyr/mpconfigport.h
index b4677f3ed..7ff05f45a 100644
--- a/zephyr/mpconfigport.h
+++ b/ports/zephyr/mpconfigport.h
@@ -112,7 +112,7 @@ extern const struct _mp_obj_module_t mp_module_zephyr;
#if MICROPY_PY_USOCKET
#define MICROPY_PY_USOCKET_DEF { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_usocket) },
-#define MICROPY_PY_USOCKET_WEAK_DEF { MP_OBJ_NEW_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_module_usocket) },
+#define MICROPY_PY_USOCKET_WEAK_DEF { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_module_usocket) },
#else
#define MICROPY_PY_USOCKET_DEF
#define MICROPY_PY_USOCKET_WEAK_DEF
@@ -131,13 +131,13 @@ extern const struct _mp_obj_module_t mp_module_zephyr;
#endif
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \
+ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
MICROPY_PY_USOCKET_DEF \
MICROPY_PY_UTIME_DEF \
MICROPY_PY_ZEPHYR_DEF \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_time) }, \
+ { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_time) }, \
MICROPY_PY_USOCKET_WEAK_DEF \
// extra built in names to add to the global namespace
diff --git a/zephyr/mpconfigport_minimal.h b/ports/zephyr/mpconfigport_minimal.h
similarity index 100%
rename from zephyr/mpconfigport_minimal.h
rename to ports/zephyr/mpconfigport_minimal.h
diff --git a/zephyr/mphalport.h b/ports/zephyr/mphalport.h
similarity index 100%
rename from zephyr/mphalport.h
rename to ports/zephyr/mphalport.h
diff --git a/zephyr/prj_96b_carbon.conf b/ports/zephyr/prj_96b_carbon.conf
similarity index 56%
rename from zephyr/prj_96b_carbon.conf
rename to ports/zephyr/prj_96b_carbon.conf
index 3e41e2532..40b57e69c 100644
--- a/zephyr/prj_96b_carbon.conf
+++ b/ports/zephyr/prj_96b_carbon.conf
@@ -1,2 +1,2 @@
# TODO: Enable networking
-CONFIG_NETWORKING=n
+CONFIG_NETWORKING=y
diff --git a/zephyr/prj_base.conf b/ports/zephyr/prj_base.conf
similarity index 58%
rename from zephyr/prj_base.conf
rename to ports/zephyr/prj_base.conf
index 4346f20bf..fbcedf260 100644
--- a/zephyr/prj_base.conf
+++ b/ports/zephyr/prj_base.conf
@@ -4,6 +4,12 @@ CONFIG_REBOOT=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_CONSOLE_HANDLER=y
CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS=y
+
+CONFIG_CONSOLE_PULL=y
+CONFIG_CONSOLE_GETCHAR=y
+CONFIG_CONSOLE_GETCHAR_BUFSIZE=128
+CONFIG_CONSOLE_PUTCHAR_BUFSIZE=128
+
CONFIG_NEWLIB_LIBC=y
CONFIG_FLOAT=y
CONFIG_MAIN_STACK_SIZE=4096
@@ -14,18 +20,35 @@ CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y
+CONFIG_NET_SOCKETS=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_NBUF_RX_COUNT=5
+CONFIG_NET_APP_SETTINGS=y
+CONFIG_NET_APP_INIT_TIMEOUT=3
+CONFIG_NET_APP_NEED_IPV6=y
+CONFIG_NET_APP_NEED_IPV4=y
+CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
+CONFIG_NET_APP_MY_IPV4_ADDR="192.0.2.1"
+CONFIG_NET_APP_MY_IPV4_GW="192.0.2.2"
+
# DNS
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_RESOLVER_ADDITIONAL_QUERIES=2
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_SERVER1="192.0.2.2"
+# Diagnostics and debugging
+
+# Required for zephyr.stack_analyze()
+CONFIG_INIT_STACKS=y
+
# Required for usocket.pkt_get_info()
CONFIG_NET_BUF_POOL_USAGE=y
+# Required for usocket.shell_*()
+#CONFIG_NET_SHELL=y
+
# Uncomment to enable "INFO" level net_buf logging
#CONFIG_NET_LOG=y
#CONFIG_NET_DEBUG_NET_BUF=y
diff --git a/zephyr/prj_frdm_k64f.conf b/ports/zephyr/prj_frdm_k64f.conf
similarity index 100%
rename from zephyr/prj_frdm_k64f.conf
rename to ports/zephyr/prj_frdm_k64f.conf
diff --git a/zephyr/prj_minimal.conf b/ports/zephyr/prj_minimal.conf
similarity index 100%
rename from zephyr/prj_minimal.conf
rename to ports/zephyr/prj_minimal.conf
diff --git a/ports/zephyr/prj_qemu_cortex_m3.conf b/ports/zephyr/prj_qemu_cortex_m3.conf
new file mode 100644
index 000000000..1ade981e2
--- /dev/null
+++ b/ports/zephyr/prj_qemu_cortex_m3.conf
@@ -0,0 +1,7 @@
+# Interrupt-driven UART console has emulation artifacts under QEMU,
+# disable it
+CONFIG_CONSOLE_PULL=n
+
+# Networking drivers
+# SLIP driver for QEMU
+CONFIG_NET_SLIP_TAP=y
diff --git a/zephyr/prj_qemu_x86.conf b/ports/zephyr/prj_qemu_x86.conf
similarity index 57%
rename from zephyr/prj_qemu_x86.conf
rename to ports/zephyr/prj_qemu_x86.conf
index ef60cfec9..9bc81259a 100644
--- a/zephyr/prj_qemu_x86.conf
+++ b/ports/zephyr/prj_qemu_x86.conf
@@ -1,3 +1,7 @@
+# Interrupt-driven UART console has emulation artifacts under QEMU,
+# disable it
+CONFIG_CONSOLE_PULL=n
+
# Networking drivers
# SLIP driver for QEMU
CONFIG_NET_SLIP_TAP=y
diff --git a/zephyr/src/Makefile b/ports/zephyr/src/Makefile
similarity index 100%
rename from zephyr/src/Makefile
rename to ports/zephyr/src/Makefile
diff --git a/zephyr/src/zephyr_getchar.c b/ports/zephyr/src/zephyr_getchar.c
similarity index 100%
rename from zephyr/src/zephyr_getchar.c
rename to ports/zephyr/src/zephyr_getchar.c
diff --git a/zephyr/src/zephyr_getchar.h b/ports/zephyr/src/zephyr_getchar.h
similarity index 100%
rename from zephyr/src/zephyr_getchar.h
rename to ports/zephyr/src/zephyr_getchar.h
diff --git a/zephyr/src/zephyr_start.c b/ports/zephyr/src/zephyr_start.c
similarity index 94%
rename from zephyr/src/zephyr_start.c
rename to ports/zephyr/src/zephyr_start.c
index 9e8a90beb..452e304ca 100644
--- a/zephyr/src/zephyr_start.c
+++ b/ports/zephyr/src/zephyr_start.c
@@ -24,11 +24,16 @@
* THE SOFTWARE.
*/
#include
+#include
#include "zephyr_getchar.h"
int real_main(void);
void main(void) {
+#ifdef CONFIG_CONSOLE_PULL
+ console_init();
+#else
zephyr_getchar_init();
+#endif
real_main();
}
diff --git a/zephyr/uart_core.c b/ports/zephyr/uart_core.c
similarity index 87%
rename from zephyr/uart_core.c
rename to ports/zephyr/uart_core.c
index 1e85053cd..e41fb9acc 100644
--- a/zephyr/uart_core.c
+++ b/ports/zephyr/uart_core.c
@@ -28,6 +28,7 @@
#include "src/zephyr_getchar.h"
// Zephyr headers
#include
+#include
/*
* Core UART functions to implement for a port
@@ -35,11 +36,23 @@
// Receive single character
int mp_hal_stdin_rx_chr(void) {
+#ifdef CONFIG_CONSOLE_PULL
+ return console_getchar();
+#else
return zephyr_getchar();
+#endif
}
// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+#ifdef CONFIG_CONSOLE_PULL
+ while (len--) {
+ char c = *str++;
+ while (console_putchar(c) == -1) {
+ k_sleep(1);
+ }
+ }
+#else
static struct device *uart_console_dev;
if (uart_console_dev == NULL) {
uart_console_dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME);
@@ -48,4 +61,5 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
while (len--) {
uart_poll_out(uart_console_dev, *str++);
}
+#endif
}
diff --git a/zephyr/z_config.mk b/ports/zephyr/z_config.mk
similarity index 100%
rename from zephyr/z_config.mk
rename to ports/zephyr/z_config.mk
diff --git a/py/argcheck.c b/py/argcheck.c
index 9f225345d..d53bca73a 100644
--- a/py/argcheck.c
+++ b/py/argcheck.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/runtime.h"
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw) {
@@ -134,14 +133,12 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args,
mp_arg_parse_all(n_pos, args, &kw_args, n_allowed, allowed, out_vals);
}
-#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE || _MSC_VER
NORETURN void mp_arg_error_terse_mismatch(void) {
mp_raise_TypeError("argument num/types mismatch");
}
-#endif
#if MICROPY_CPYTHON_COMPAT
NORETURN void mp_arg_error_unimpl_kw(void) {
- mp_not_implemented("keyword argument(s) not yet implemented - use normal args instead");
+ mp_raise_NotImplementedError("keyword argument(s) not yet implemented - use normal args instead");
}
#endif
diff --git a/py/asmarm.c b/py/asmarm.c
index ff22aba90..552fdfb34 100644
--- a/py/asmarm.c
+++ b/py/asmarm.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/asmarm.h b/py/asmarm.h
index c5900925f..a302b1590 100644
--- a/py/asmarm.h
+++ b/py/asmarm.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/asmthumb.c b/py/asmthumb.c
index 7e92e4de4..5316a7efb 100644
--- a/py/asmthumb.c
+++ b/py/asmthumb.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -33,6 +33,7 @@
// wrapper around everything in this file
#if MICROPY_EMIT_THUMB || MICROPY_EMIT_INLINE_THUMB
+#include "py/mphal.h"
#include "py/asmthumb.h"
#define UNSIGNED_FIT8(x) (((x) & 0xffffff00) == 0)
@@ -53,7 +54,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) {
#if defined(MCU_SERIES_F7)
if (as->base.pass == MP_ASM_PASS_EMIT) {
// flush D-cache, so the code emitted is stored in memory
- SCB_CleanDCache_by_Addr((uint32_t*)as->base.code_base, as->base.code_size);
+ MP_HAL_CLEAN_DCACHE(as->base.code_base, as->base.code_size);
// invalidate I-cache
SCB_InvalidateICache();
}
diff --git a/py/asmthumb.h b/py/asmthumb.h
index 589c481cd..7070e03ac 100644
--- a/py/asmthumb.h
+++ b/py/asmthumb.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/asmx64.c b/py/asmx64.c
index 6775e8e93..aa2a8ec7c 100644
--- a/py/asmx64.c
+++ b/py/asmx64.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/asmx64.h b/py/asmx64.h
index a384cca00..425bdf2d3 100644
--- a/py/asmx64.h
+++ b/py/asmx64.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/asmx86.c b/py/asmx86.c
index dd3ad0224..6a78fbd5e 100644
--- a/py/asmx86.c
+++ b/py/asmx86.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/asmx86.h b/py/asmx86.h
index fd34228d1..0a00e2e7c 100644
--- a/py/asmx86.h
+++ b/py/asmx86.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/bc.c b/py/bc.c
index 2e481bce7..89d8b74f9 100644
--- a/py/bc.c
+++ b/py/bc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,13 +29,11 @@
#include
#include
-#include "py/nlr.h"
-#include "py/objfun.h"
-#include "py/runtime0.h"
+#include "py/runtime.h"
#include "py/bc0.h"
#include "py/bc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#else // don't print debugging info
#define DEBUG_PRINT (0)
@@ -323,7 +321,7 @@ STATIC const byte opcode_format_table[64] = {
OC4(O, O, U, U), // 0x38-0x3b
OC4(U, O, B, O), // 0x3c-0x3f
OC4(O, B, B, O), // 0x40-0x43
- OC4(B, B, O, U), // 0x44-0x47
+ OC4(B, B, O, B), // 0x44-0x47
OC4(U, U, U, U), // 0x48-0x4b
OC4(U, U, U, U), // 0x4c-0x4f
OC4(V, V, U, V), // 0x50-0x53
@@ -363,7 +361,7 @@ STATIC const byte opcode_format_table[64] = {
OC4(B, B, B, B), // 0xcc-0xcf
OC4(B, B, B, B), // 0xd0-0xd3
- OC4(B, B, B, B), // 0xd4-0xd7
+ OC4(U, U, U, B), // 0xd4-0xd7
OC4(B, B, B, B), // 0xd8-0xdb
OC4(B, B, B, B), // 0xdc-0xdf
@@ -374,7 +372,7 @@ STATIC const byte opcode_format_table[64] = {
OC4(B, B, B, B), // 0xf0-0xf3
OC4(B, B, B, B), // 0xf4-0xf7
- OC4(B, B, B, U), // 0xf8-0xfb
+ OC4(U, U, U, U), // 0xf8-0xfb
OC4(U, U, U, U), // 0xfc-0xff
};
#undef OC4
diff --git a/py/bc.h b/py/bc.h
index c55d31fe4..ebfdeaac1 100644
--- a/py/bc.h
+++ b/py/bc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,7 +27,6 @@
#define MICROPY_INCLUDED_PY_BC_H
#include "py/runtime.h"
-#include "py/obj.h"
#include "py/objfun.h"
// bytecode layout:
diff --git a/py/bc0.h b/py/bc0.h
index be8ac6c15..70acfb0ca 100644
--- a/py/bc0.h
+++ b/py/bc0.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,7 +26,7 @@
#ifndef MICROPY_INCLUDED_PY_BC0_H
#define MICROPY_INCLUDED_PY_BC0_H
-// Micro Python byte-codes.
+// MicroPython byte-codes.
// The comment at the end of the line (if it exists) tells the arguments to the byte-code.
#define MP_BC_LOAD_CONST_FALSE (0x10)
@@ -113,7 +113,7 @@
#define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64)
#define MP_BC_LOAD_FAST_MULTI (0xb0) // + N(16)
#define MP_BC_STORE_FAST_MULTI (0xc0) // + N(16)
-#define MP_BC_UNARY_OP_MULTI (0xd0) // + op(7)
-#define MP_BC_BINARY_OP_MULTI (0xd7) // + op(36)
+#define MP_BC_UNARY_OP_MULTI (0xd0) // + op( sizeof(val)) {
int c = (is_signed(val_type) && (mp_int_t)val < 0) ? 0xff : 0x00;
- memset(p + sizeof(val), c, size - sizeof(val));
+ memset(p, c, size);
+ if (struct_type == '>') {
+ p += size - sizeof(val);
+ }
}
}
}
diff --git a/py/binary.h b/py/binary.h
index 04cc6d83b..0dae6a29e 100644
--- a/py/binary.h
+++ b/py/binary.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,8 +29,9 @@
#include "py/obj.h"
// Use special typecode to differentiate repr() of bytearray vs array.array('B')
-// (underlyingly they're same).
-#define BYTEARRAY_TYPECODE 0
+// (underlyingly they're same). Can't use 0 here because that's used to detect
+// type-specification errors due to end-of-string.
+#define BYTEARRAY_TYPECODE 1
size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index);
diff --git a/py/builtin.h b/py/builtin.h
index 4915383f2..84b99a8a4 100644
--- a/py/builtin.h
+++ b/py/builtin.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -118,6 +118,6 @@ extern const mp_obj_module_t mp_module_webrepl;
extern const mp_obj_module_t mp_module_framebuf;
extern const mp_obj_module_t mp_module_btree;
-extern const char *MICROPY_PY_BUILTINS_HELP_TEXT;
+extern const char MICROPY_PY_BUILTINS_HELP_TEXT[];
#endif // MICROPY_INCLUDED_PY_BUILTIN_H
diff --git a/py/builtinevex.c b/py/builtinevex.c
index 4390d0cc7..846603f46 100644
--- a/py/builtinevex.c
+++ b/py/builtinevex.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,7 +26,6 @@
#include
-#include "py/nlr.h"
#include "py/objfun.h"
#include "py/compile.h"
#include "py/runtime.h"
diff --git a/py/builtinhelp.c b/py/builtinhelp.c
index dbcd6e00f..c9992906d 100644
--- a/py/builtinhelp.c
+++ b/py/builtinhelp.c
@@ -32,7 +32,7 @@
#if MICROPY_PY_BUILTINS_HELP
-const char *mp_help_default_text =
+const char mp_help_default_text[] =
"Welcome to MicroPython!\n"
"\n"
"For online docs please visit http://docs.micropython.org/\n"
@@ -136,20 +136,19 @@ STATIC void mp_help_print_obj(const mp_obj_t obj) {
}
#endif
+ mp_obj_type_t *type = mp_obj_get_type(obj);
+
// try to print something sensible about the given object
mp_print_str(MP_PYTHON_PRINTER, "object ");
mp_obj_print(obj, PRINT_STR);
- mp_printf(MP_PYTHON_PRINTER, " is of type %s\n", mp_obj_get_type_str(obj));
+ mp_printf(MP_PYTHON_PRINTER, " is of type %q\n", type->name);
mp_map_t *map = NULL;
- if (MP_OBJ_IS_TYPE(obj, &mp_type_module)) {
+ if (type == &mp_type_module) {
map = mp_obj_dict_get_map(mp_obj_module_get_globals(obj));
} else {
- mp_obj_type_t *type;
- if (MP_OBJ_IS_TYPE(obj, &mp_type_type)) {
- type = obj;
- } else {
- type = mp_obj_get_type(obj);
+ if (type == &mp_type_type) {
+ type = MP_OBJ_TO_PTR(obj);
}
if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) {
map = mp_obj_dict_get_map(type->locals_dict);
diff --git a/py/builtinimport.c b/py/builtinimport.c
index e42360c11..095ce3610 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,7 +29,6 @@
#include
#include
-#include "py/nlr.h"
#include "py/compile.h"
#include "py/objmodule.h"
#include "py/persistentcode.h"
@@ -37,7 +36,7 @@
#include "py/builtin.h"
#include "py/frozenmod.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
diff --git a/py/compile.c b/py/compile.c
index d2e05d0b2..4e704abfb 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -569,7 +569,7 @@ STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int
for (int j = 0; j < this_scope->id_info_len; j++) {
id_info_t *id2 = &this_scope->id_info[j];
if (id2->kind == ID_INFO_KIND_FREE && id->qst == id2->qst) {
- // in Micro Python we load closures using LOAD_FAST
+ // in MicroPython we load closures using LOAD_FAST
EMIT_LOAD_FAST(id->qst, id->local_num);
nfree += 1;
}
@@ -613,13 +613,11 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
} else {
mp_parse_node_t pn_id;
- mp_parse_node_t pn_colon;
mp_parse_node_t pn_equal;
if (pn_kind == -1) {
// this parameter is just an id
pn_id = pn;
- pn_colon = MP_PARSE_NODE_NULL;
pn_equal = MP_PARSE_NODE_NULL;
} else if (pn_kind == PN_typedargslist_name) {
@@ -627,7 +625,7 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
pn_id = pns->nodes[0];
- pn_colon = pns->nodes[1];
+ //pn_colon = pns->nodes[1]; // unused
pn_equal = pns->nodes[2];
} else {
@@ -654,9 +652,9 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
if (comp->have_star) {
comp->num_dict_params += 1;
- // in Micro Python we put the default dict parameters into a dictionary using the bytecode
+ // in MicroPython we put the default dict parameters into a dictionary using the bytecode
if (comp->num_dict_params == 1) {
- // in Micro Python we put the default positional parameters into a tuple using the bytecode
+ // in MicroPython we put the default positional parameters into a tuple using the bytecode
// we need to do this here before we start building the map for the default keywords
if (comp->num_default_params > 0) {
EMIT_ARG(build_tuple, comp->num_default_params);
@@ -676,9 +674,6 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn)
compile_node(comp, pn_equal);
}
}
-
- // TODO pn_colon not implemented
- (void)pn_colon;
}
}
@@ -700,7 +695,7 @@ STATIC void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_n
return;
}
- // in Micro Python we put the default positional parameters into a tuple using the bytecode
+ // in MicroPython we put the default positional parameters into a tuple using the bytecode
// the default keywords args may have already made the tuple; if not, do it now
if (comp->num_default_params > 0 && comp->num_dict_params == 0) {
EMIT_ARG(build_tuple, comp->num_default_params);
@@ -3275,7 +3270,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
#endif
STATIC void scope_compute_things(scope_t *scope) {
- // in Micro Python we put the *x parameter after all other parameters (except **y)
+ // in MicroPython we put the *x parameter after all other parameters (except **y)
if (scope->scope_flags & MP_SCOPE_FLAG_VARARGS) {
id_info_t *id_param = NULL;
for (int i = scope->id_info_len - 1; i >= 0; i--) {
@@ -3313,7 +3308,7 @@ STATIC void scope_compute_things(scope_t *scope) {
// compute the index of cell vars
for (int i = 0; i < scope->id_info_len; i++) {
id_info_t *id = &scope->id_info[i];
- // in Micro Python the cells come right after the fast locals
+ // in MicroPython the cells come right after the fast locals
// parameters are not counted here, since they remain at the start
// of the locals, even if they are cell vars
if (id->kind == ID_INFO_KIND_CELL && !(id->flags & ID_FLAG_IS_PARAM)) {
@@ -3333,14 +3328,14 @@ STATIC void scope_compute_things(scope_t *scope) {
id_info_t *id2 = &scope->id_info[j];
if (id2->kind == ID_INFO_KIND_FREE && id->qst == id2->qst) {
assert(!(id2->flags & ID_FLAG_IS_PARAM)); // free vars should not be params
- // in Micro Python the frees come first, before the params
+ // in MicroPython the frees come first, before the params
id2->local_num = num_free;
num_free += 1;
}
}
}
}
- // in Micro Python shift all other locals after the free locals
+ // in MicroPython shift all other locals after the free locals
if (num_free > 0) {
for (int i = 0; i < scope->id_info_len; i++) {
id_info_t *id = &scope->id_info[i];
diff --git a/py/compile.h b/py/compile.h
index f6b262d18..3297e83ae 100644
--- a/py/compile.h
+++ b/py/compile.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/emit.h b/py/emit.h
index a58e20e3d..270a40633 100644
--- a/py/emit.h
+++ b/py/emit.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include "py/lexer.h"
#include "py/scope.h"
-#include "py/runtime0.h"
/* Notes on passes:
* We don't know exactly the opcodes in pass 1 because they depend on the
diff --git a/py/emitbc.c b/py/emitbc.c
index 127bf0bf9..3f4dfc178 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -550,7 +550,7 @@ void mp_emit_bc_load_const_obj(emit_t *emit, mp_obj_t obj) {
void mp_emit_bc_load_null(emit_t *emit) {
emit_bc_pre(emit, 1);
emit_write_bytecode_byte(emit, MP_BC_LOAD_NULL);
-};
+}
void mp_emit_bc_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
(void)qst;
diff --git a/py/emitcommon.c b/py/emitcommon.c
index e914431d3..07b1dbb4c 100644
--- a/py/emitcommon.c
+++ b/py/emitcommon.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/emitglue.c b/py/emitglue.c
index fb7a54926..d2add988f 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -35,7 +35,7 @@
#include "py/runtime0.h"
#include "py/bc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define WRITE_CODE (1)
#define DEBUG_printf DEBUG_printf
diff --git a/py/emitglue.h b/py/emitglue.h
index 309996596..43930333d 100644
--- a/py/emitglue.h
+++ b/py/emitglue.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c
index c1a4eac5d..577f65672 100644
--- a/py/emitinlinethumb.c
+++ b/py/emitinlinethumb.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/emitnative.c b/py/emitnative.c
index 99adc809c..8e97dda11 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -46,11 +46,10 @@
#include
#include
-#include "py/nlr.h"
#include "py/emit.h"
#include "py/bc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
@@ -124,6 +123,8 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
[MP_F_NEW_CELL] = 1,
[MP_F_MAKE_CLOSURE_FROM_RAW_CODE] = 3,
[MP_F_SETUP_CODE_STATE] = 5,
+ [MP_F_SMALL_INT_FLOOR_DIVIDE] = 2,
+ [MP_F_SMALL_INT_MODULO] = 2,
};
#include "py/asmx86.h"
@@ -824,7 +825,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de
break;
default:
// not handled
- mp_not_implemented("conversion to object");
+ mp_raise_NotImplementedError("conversion to object");
}
}
@@ -1824,18 +1825,20 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
vtype_kind_t vtype_lhs = peek_vtype(emit, 1);
vtype_kind_t vtype_rhs = peek_vtype(emit, 0);
if (vtype_lhs == VTYPE_INT && vtype_rhs == VTYPE_INT) {
+ // for integers, inplace and normal ops are equivalent, so use just normal ops
+ if (MP_BINARY_OP_INPLACE_OR <= op && op <= MP_BINARY_OP_INPLACE_POWER) {
+ op += MP_BINARY_OP_OR - MP_BINARY_OP_INPLACE_OR;
+ }
+
#if N_X64 || N_X86
// special cases for x86 and shifting
- if (op == MP_BINARY_OP_LSHIFT
- || op == MP_BINARY_OP_INPLACE_LSHIFT
- || op == MP_BINARY_OP_RSHIFT
- || op == MP_BINARY_OP_INPLACE_RSHIFT) {
+ if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_RSHIFT) {
#if N_X64
emit_pre_pop_reg_reg(emit, &vtype_rhs, ASM_X64_REG_RCX, &vtype_lhs, REG_RET);
#else
emit_pre_pop_reg_reg(emit, &vtype_rhs, ASM_X86_REG_ECX, &vtype_lhs, REG_RET);
#endif
- if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) {
+ if (op == MP_BINARY_OP_LSHIFT) {
ASM_LSL_REG(emit->as, REG_RET);
} else {
ASM_ASR_REG(emit->as, REG_RET);
@@ -1844,35 +1847,48 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
return;
}
#endif
+
+ // special cases for floor-divide and module because we dispatch to helper functions
+ if (op == MP_BINARY_OP_FLOOR_DIVIDE || op == MP_BINARY_OP_MODULO) {
+ emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_2, &vtype_lhs, REG_ARG_1);
+ if (op == MP_BINARY_OP_FLOOR_DIVIDE) {
+ emit_call(emit, MP_F_SMALL_INT_FLOOR_DIVIDE);
+ } else {
+ emit_call(emit, MP_F_SMALL_INT_MODULO);
+ }
+ emit_post_push_reg(emit, VTYPE_INT, REG_RET);
+ return;
+ }
+
int reg_rhs = REG_ARG_3;
emit_pre_pop_reg_flexible(emit, &vtype_rhs, ®_rhs, REG_RET, REG_ARG_2);
emit_pre_pop_reg(emit, &vtype_lhs, REG_ARG_2);
if (0) {
// dummy
#if !(N_X64 || N_X86)
- } else if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) {
+ } else if (op == MP_BINARY_OP_LSHIFT) {
ASM_LSL_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
- } else if (op == MP_BINARY_OP_RSHIFT || op == MP_BINARY_OP_INPLACE_RSHIFT) {
+ } else if (op == MP_BINARY_OP_RSHIFT) {
ASM_ASR_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
#endif
- } else if (op == MP_BINARY_OP_OR || op == MP_BINARY_OP_INPLACE_OR) {
+ } else if (op == MP_BINARY_OP_OR) {
ASM_OR_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
- } else if (op == MP_BINARY_OP_XOR || op == MP_BINARY_OP_INPLACE_XOR) {
+ } else if (op == MP_BINARY_OP_XOR) {
ASM_XOR_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
- } else if (op == MP_BINARY_OP_AND || op == MP_BINARY_OP_INPLACE_AND) {
+ } else if (op == MP_BINARY_OP_AND) {
ASM_AND_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
- } else if (op == MP_BINARY_OP_ADD || op == MP_BINARY_OP_INPLACE_ADD) {
+ } else if (op == MP_BINARY_OP_ADD) {
ASM_ADD_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
- } else if (op == MP_BINARY_OP_SUBTRACT || op == MP_BINARY_OP_INPLACE_SUBTRACT) {
+ } else if (op == MP_BINARY_OP_SUBTRACT) {
ASM_SUB_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
- } else if (op == MP_BINARY_OP_MULTIPLY || op == MP_BINARY_OP_INPLACE_MULTIPLY) {
+ } else if (op == MP_BINARY_OP_MULTIPLY) {
ASM_MUL_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
} else if (MP_BINARY_OP_LESS <= op && op <= MP_BINARY_OP_NOT_EQUAL) {
@@ -2158,7 +2174,7 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u
break;
default:
// this can happen when casting a cast: int(int)
- mp_not_implemented("casting");
+ mp_raise_NotImplementedError("casting");
}
} else {
assert(vtype_fun == VTYPE_PYOBJ);
@@ -2232,12 +2248,12 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) {
STATIC void emit_native_yield_value(emit_t *emit) {
// not supported (for now)
(void)emit;
- mp_not_implemented("native yield");
+ mp_raise_NotImplementedError("native yield");
}
STATIC void emit_native_yield_from(emit_t *emit) {
// not supported (for now)
(void)emit;
- mp_not_implemented("native yield from");
+ mp_raise_NotImplementedError("native yield from");
}
STATIC void emit_native_start_except_handler(emit_t *emit) {
diff --git a/py/formatfloat.c b/py/formatfloat.c
index 2f10d425a..4228f99ff 100644
--- a/py/formatfloat.c
+++ b/py/formatfloat.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -30,6 +30,7 @@
#include
#include
#include
+#include
#include "py/formatfloat.h"
/***********************************************************************
@@ -68,12 +69,10 @@ union floatbits {
uint32_t u;
};
static inline int fp_signbit(float x) { union floatbits fb = {x}; return fb.u & FLT_SIGN_MASK; }
-static inline int fp_isspecial(float x) { union floatbits fb = {x}; return (fb.u & FLT_EXP_MASK) == FLT_EXP_MASK; }
-static inline int fp_isinf(float x) { union floatbits fb = {x}; return (fb.u & FLT_MAN_MASK) == 0; }
+#define fp_isnan(x) isnan(x)
+#define fp_isinf(x) isinf(x)
static inline int fp_iszero(float x) { union floatbits fb = {x}; return fb.u == 0; }
static inline int fp_isless1(float x) { union floatbits fb = {x}; return fb.u < 0x3f800000; }
-// Assumes both fp_isspecial() and fp_isinf() were applied before
-#define fp_isnan(x) 1
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
@@ -82,9 +81,7 @@ static inline int fp_isless1(float x) { union floatbits fb = {x}; return fb.u <
#define FPROUND_TO_ONE 0.999999999995
#define FPDECEXP 256
#define FPMIN_BUF_SIZE 7 // +9e+199
-#include
#define fp_signbit(x) signbit(x)
-#define fp_isspecial(x) 1
#define fp_isnan(x) isnan(x)
#define fp_isinf(x) isinf(x)
#define fp_iszero(x) (x == 0)
@@ -118,11 +115,11 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
*s++ = '?';
}
if (buf_size >= 1) {
- *s++ = '\0';
+ *s = '\0';
}
return buf_size >= 2;
}
- if (fp_signbit(f)) {
+ if (fp_signbit(f) && !fp_isnan(f)) {
*s++ = '-';
f = -f;
} else {
@@ -135,7 +132,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
// It is buf_size minus room for the sign and null byte.
int buf_remaining = buf_size - 1 - (s - buf);
- if (fp_isspecial(f)) {
+ {
char uc = fmt & 0x20;
if (fp_isinf(f)) {
*s++ = 'I' ^ uc;
diff --git a/py/formatfloat.h b/py/formatfloat.h
index 9c8d137bb..9a1643b4d 100644
--- a/py/formatfloat.h
+++ b/py/formatfloat.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/frozenmod.c b/py/frozenmod.c
index 1eaaf574a..06d4f84c8 100644
--- a/py/frozenmod.c
+++ b/py/frozenmod.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/frozenmod.h b/py/frozenmod.h
index 6993167ac..8cddef681 100644
--- a/py/frozenmod.h
+++ b/py/frozenmod.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/gc.c b/py/gc.c
index 2af886c56..9752b3532 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,14 +28,12 @@
#include
#include
-#include "py/mpstate.h"
#include "py/gc.h"
-#include "py/obj.h"
#include "py/runtime.h"
#if MICROPY_ENABLE_GC
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
diff --git a/py/gc.h b/py/gc.h
index 136695517..739349c1f 100644
--- a/py/gc.h
+++ b/py/gc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/grammar.h b/py/grammar.h
index 0b70538d4..6abb1de8c 100644
--- a/py/grammar.h
+++ b/py/grammar.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -32,7 +32,7 @@
// # single_input is a single interactive statement;
// # file_input is a module or sequence of commands read from an input file;
// # eval_input is the input for the eval() functions.
-// # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in Micro Python
+// # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in MicroPython
// single_input: NEWLINE | simple_stmt | compound_stmt
// file_input: (NEWLINE | stmt)* ENDMARKER
// eval_input: testlist NEWLINE* ENDMARKER
diff --git a/py/lexer.c b/py/lexer.c
index 6e5cc18f4..6017d69d6 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,7 +28,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/reader.h"
#include "py/lexer.h"
#include "py/runtime.h"
@@ -341,7 +340,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
// 3MB of text; even gzip-compressed and with minimal structure, it'll take
// roughly half a meg of storage. This form of Unicode escape may be added
// later on, but it's definitely not a priority right now. -- CJA 20140607
- mp_not_implemented("unicode name escapes");
+ mp_raise_NotImplementedError("unicode name escapes");
break;
default:
if (c >= '0' && c <= '7') {
diff --git a/py/lexer.h b/py/lexer.h
index 435aa096b..a29709107 100644
--- a/py/lexer.h
+++ b/py/lexer.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -32,7 +32,7 @@
#include "py/qstr.h"
#include "py/reader.h"
-/* lexer.h -- simple tokeniser for Micro Python
+/* lexer.h -- simple tokeniser for MicroPython
*
* Uses (byte) length instead of null termination.
* Tokens are the same - UTF-8 with (byte) length.
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index 7249769f4..38fde1a9c 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -108,7 +108,15 @@ def parse_input_headers(infiles):
continue
# add the qstr to the list, with order number to retain original order in file
- qstrs[ident] = (len(qstrs), ident, qstr)
+ order = len(qstrs)
+ # but put special method names like __add__ at the top of list, so
+ # that their id's fit into a byte
+ if ident == "":
+ # Sort empty qstr above all still
+ order = -200000
+ elif ident.startswith("__"):
+ order -= 100000
+ qstrs[ident] = (order, ident, qstr)
if not qcfgs:
sys.stderr.write("ERROR: Empty preprocessor output - check for errors above\n")
diff --git a/py/malloc.c b/py/malloc.c
index f48cb8da4..ea1d4c4b9 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -32,7 +32,7 @@
#include "py/misc.h"
#include "py/mpstate.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(...) (void)0
@@ -46,7 +46,7 @@
#include "py/gc.h"
// We redirect standard alloc functions to GC heap - just for the rest of
-// this module. In the rest of micropython source, system malloc can be
+// this module. In the rest of MicroPython source, system malloc can be
// freely accessed - for interfacing with system and 3rd-party libs for
// example. On the other hand, some (e.g. bare-metal) ports may use GC
// heap as system heap, so, to avoid warnings, we do undef's first.
@@ -74,7 +74,7 @@ STATIC void *realloc_ext(void *ptr, size_t n_bytes, bool allow_move) {
void *m_malloc(size_t num_bytes) {
void *ptr = malloc(num_bytes);
if (ptr == NULL && num_bytes != 0) {
- return m_malloc_fail(num_bytes);
+ m_malloc_fail(num_bytes);
}
#if MICROPY_MEM_STATS
MP_STATE_MEM(total_bytes_allocated) += num_bytes;
@@ -100,7 +100,7 @@ void *m_malloc_maybe(size_t num_bytes) {
void *m_malloc_with_finaliser(size_t num_bytes) {
void *ptr = malloc_with_finaliser(num_bytes);
if (ptr == NULL && num_bytes != 0) {
- return m_malloc_fail(num_bytes);
+ m_malloc_fail(num_bytes);
}
#if MICROPY_MEM_STATS
MP_STATE_MEM(total_bytes_allocated) += num_bytes;
@@ -115,7 +115,7 @@ void *m_malloc_with_finaliser(size_t num_bytes) {
void *m_malloc0(size_t num_bytes) {
void *ptr = m_malloc(num_bytes);
if (ptr == NULL && num_bytes != 0) {
- return m_malloc_fail(num_bytes);
+ m_malloc_fail(num_bytes);
}
// If this config is set then the GC clears all memory, so we don't need to.
#if !MICROPY_GC_CONSERVATIVE_CLEAR
@@ -131,7 +131,7 @@ void *m_realloc(void *ptr, size_t new_num_bytes) {
#endif
void *new_ptr = realloc(ptr, new_num_bytes);
if (new_ptr == NULL && new_num_bytes != 0) {
- return m_malloc_fail(new_num_bytes);
+ m_malloc_fail(new_num_bytes);
}
#if MICROPY_MEM_STATS
// At first thought, "Total bytes allocated" should only grow,
diff --git a/py/map.c b/py/map.c
index 50d74f38f..4f76b9b16 100644
--- a/py/map.c
+++ b/py/map.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -31,7 +31,6 @@
#include "py/mpconfig.h"
#include "py/misc.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
// Fixed empty map. Useful when need to call kw-receiving functions
@@ -93,12 +92,6 @@ void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table) {
map->table = (mp_map_elem_t*)table;
}
-mp_map_t *mp_map_new(size_t n) {
- mp_map_t *map = m_new(mp_map_t, 1);
- mp_map_init(map, n);
- return map;
-}
-
// Differentiate from mp_map_clear() - semantics is different
void mp_map_deinit(mp_map_t *map) {
if (!map->is_fixed) {
@@ -107,11 +100,6 @@ void mp_map_deinit(mp_map_t *map) {
map->used = map->alloc = 0;
}
-void mp_map_free(mp_map_t *map) {
- mp_map_deinit(map);
- m_del_obj(mp_map_t, map);
-}
-
void mp_map_clear(mp_map_t *map) {
if (!map->is_fixed) {
m_del(mp_map_elem_t, map->table, map->alloc);
@@ -148,11 +136,8 @@ STATIC void mp_map_rehash(mp_map_t *map) {
// MP_MAP_LOOKUP_REMOVE_IF_FOUND behaviour:
// - returns NULL if not found, else the slot if was found in with key null and value non-null
mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind) {
-
- if (map->is_fixed && lookup_kind != MP_MAP_LOOKUP) {
- // can't add/remove from a fixed array
- return NULL;
- }
+ // If the map is a fixed array then we must only be called for a lookup
+ assert(!map->is_fixed || lookup_kind == MP_MAP_LOOKUP);
// Work out if we can compare just pointers
bool compare_only_ptrs = map->all_keys_are_qstrs;
diff --git a/py/misc.h b/py/misc.h
index cebbd38ea..b9f2dae90 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -92,7 +92,7 @@ void *m_realloc(void *ptr, size_t new_num_bytes);
void *m_realloc_maybe(void *ptr, size_t new_num_bytes, bool allow_move);
void m_free(void *ptr);
#endif
-NORETURN void *m_malloc_fail(size_t num_bytes);
+NORETURN void m_malloc_fail(size_t num_bytes);
#if MICROPY_MEM_STATS
size_t m_get_total_bytes_allocated(void);
diff --git a/py/mkenv.mk b/py/mkenv.mk
index b167b2533..8b637e9ac 100644
--- a/py/mkenv.mk
+++ b/py/mkenv.mk
@@ -59,7 +59,13 @@ LD += -m32
endif
MAKE_FROZEN = $(TOP)/tools/make-frozen.py
+# allow mpy-cross (for WSL) and mpy-cross.exe (for cygwin) to coexist
+ifeq ($(OS),Windows_NT)
+MPY_CROSS = $(TOP)/mpy-cross/mpy-cross.exe
+PROG_EXT = .exe
+else
MPY_CROSS = $(TOP)/mpy-cross/mpy-cross
+endif
MPY_TOOL = $(TOP)/tools/mpy-tool.py
all:
diff --git a/py/mkrules.mk b/py/mkrules.mk
index e66082001..fd579557f 100644
--- a/py/mkrules.mk
+++ b/py/mkrules.mk
@@ -47,7 +47,7 @@ $(BUILD)/%.o: %.c
$(call compile_c)
# List all native flags since the current build system doesn't have
-# the micropython configuration available. However, these flags are
+# the MicroPython configuration available. However, these flags are
# needed to extract all qstrings
QSTR_GEN_EXTRA_CFLAGS += -DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB -DN_ARM -DN_XTENSA
QSTR_GEN_EXTRA_CFLAGS += -I$(BUILD)/tmp
@@ -103,7 +103,7 @@ endif
ifneq ($(FROZEN_MPY_DIR),)
# to build the MicroPython cross compiler
-$(TOP)/mpy-cross/mpy-cross: $(TOP)/py/*.[ch] $(TOP)/mpy-cross/*.[ch] $(TOP)/windows/fmode.c
+$(TOP)/mpy-cross/mpy-cross: $(TOP)/py/*.[ch] $(TOP)/mpy-cross/*.[ch] $(TOP)/ports/windows/fmode.c
$(Q)$(MAKE) -C $(TOP)/mpy-cross
# make a list of all the .py files that need compiling and freezing
@@ -111,7 +111,7 @@ FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py' |
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/frozen_mpy/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
# to build .mpy files from .py files
-$(BUILD)/frozen_mpy/%.mpy: $(FROZEN_MPY_DIR)/%.py $(TOP)/mpy-cross/mpy-cross
+$(BUILD)/frozen_mpy/%.mpy: $(FROZEN_MPY_DIR)/%.py $(MPY_CROSS)
@$(ECHO) "MPY $<"
$(Q)$(MKDIR) -p $(dir $@)
$(Q)$(MPY_CROSS) -o $@ -s $(<:$(FROZEN_MPY_DIR)/%=%) $(MPY_CROSS_FLAGS) $<
@@ -133,13 +133,13 @@ $(PROG): $(OBJ)
# we may want to compile using Thumb, but link with non-Thumb libc.
$(Q)$(CC) -o $@ $^ $(LIB) $(LDFLAGS)
ifndef DEBUG
- $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
+ $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)$(PROG_EXT)
endif
- $(Q)$(SIZE) $(PROG)
+ $(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $(PROG)$(PROG_EXT)
clean: clean-prog
clean-prog:
- $(RM) -f $(PROG)
+ $(RM) -f $(PROG)$(PROG_EXT)
$(RM) -f $(PROG).map
.PHONY: clean-prog
diff --git a/py/modarray.c b/py/modarray.c
index 356e48bee..c0cdca928 100644
--- a/py/modarray.c
+++ b/py/modarray.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index 8fbf4daeb..65c03d523 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,12 +27,10 @@
#include
#include
-#include "py/nlr.h"
#include "py/smallint.h"
#include "py/objint.h"
#include "py/objstr.h"
#include "py/objtype.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/builtin.h"
#include "py/stream.h"
@@ -91,26 +89,7 @@ STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args)
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
- #if MICROPY_PY_BUILTINS_FLOAT
- if (mp_obj_is_float(o_in)) {
- mp_float_t value = mp_obj_float_get(o_in);
- // TODO check for NaN etc
- if (value < 0) {
- return mp_obj_new_float(-value);
- } else {
- return o_in;
- }
- #if MICROPY_PY_BUILTINS_COMPLEX
- } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_complex)) {
- mp_float_t real, imag;
- mp_obj_complex_get(o_in, &real, &imag);
- return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag));
- #endif
- }
- #endif
-
- // this will raise a TypeError if the argument is not integral
- return mp_obj_int_abs(o_in);
+ return mp_unary_op(MP_UNARY_OP_ABS, o_in);
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);
@@ -369,31 +348,16 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
if (MP_OBJ_IS_STR(o_in)) {
len = unichar_charlen(str, len);
if (len == 1) {
- if (!UTF8_IS_NONASCII(*str)) {
- goto return_first_byte;
- }
- mp_int_t ord = *str++ & 0x7F;
- for (mp_int_t mask = 0x40; ord & mask; mask >>= 1) {
- ord &= ~mask;
- }
- while (UTF8_IS_CONT(*str)) {
- ord = (ord << 6) | (*str++ & 0x3F);
- }
- return mp_obj_new_int(ord);
+ return mp_obj_new_int(utf8_get_char((const byte*)str));
}
- } else {
- // a bytes object
+ } else
+ #endif
+ {
+ // a bytes object, or a str without unicode support (don't sign extend the char)
if (len == 1) {
- return_first_byte:
return MP_OBJ_NEW_SMALL_INT(((const byte*)str)[0]);
}
}
- #else
- if (len == 1) {
- // don't sign extend when converting to ord
- return mp_obj_new_int(((const byte*)str)[0]);
- }
- #endif
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("ord expects a character");
@@ -540,7 +504,7 @@ STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_sorted_obj, 1, mp_builtin_sorted);
// See mp_load_attr() if making any changes
-STATIC inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) {
+static inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) {
mp_obj_t dest[2];
// use load_method, raising or not raising exception
((defval == MP_OBJ_NULL) ? mp_load_method : mp_load_method_maybe)(base, attr, dest);
diff --git a/py/modcmath.c b/py/modcmath.c
index 7ad8f5ad6..70fd542af 100644
--- a/py/modcmath.c
+++ b/py/modcmath.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -30,13 +30,7 @@
#include
-/// \module cmath - mathematical functions for complex numbers
-///
-/// The `cmath` module provides some basic mathematical funtions for
-/// working with complex numbers.
-
-/// \function phase(z)
-/// Returns the phase of the number `z`, in the range (-pi, +pi].
+// phase(z): returns the phase of the number z in the range (-pi, +pi]
STATIC mp_obj_t mp_cmath_phase(mp_obj_t z_obj) {
mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag);
@@ -44,8 +38,7 @@ STATIC mp_obj_t mp_cmath_phase(mp_obj_t z_obj) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_phase_obj, mp_cmath_phase);
-/// \function polar(z)
-/// Returns, as a tuple, the polar form of `z`.
+// polar(z): returns the polar form of z as a tuple
STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) {
mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag);
@@ -57,8 +50,7 @@ STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_polar_obj, mp_cmath_polar);
-/// \function rect(r, phi)
-/// Returns the complex number with modulus `r` and phase `phi`.
+// rect(r, phi): returns the complex number with modulus r and phase phi
STATIC mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) {
mp_float_t r = mp_obj_get_float(r_obj);
mp_float_t phi = mp_obj_get_float(phi_obj);
@@ -66,8 +58,7 @@ STATIC mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_cmath_rect_obj, mp_cmath_rect);
-/// \function exp(z)
-/// Return the exponential of `z`.
+// exp(z): return the exponential of z
STATIC mp_obj_t mp_cmath_exp(mp_obj_t z_obj) {
mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag);
@@ -76,8 +67,7 @@ STATIC mp_obj_t mp_cmath_exp(mp_obj_t z_obj) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_exp_obj, mp_cmath_exp);
-/// \function log(z)
-/// Return the natural logarithm of `z`. The branch cut is along the negative real axis.
+// log(z): return the natural logarithm of z, with branch cut along the negative real axis
// TODO can take second argument, being the base
STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) {
mp_float_t real, imag;
@@ -87,8 +77,7 @@ STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log);
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
-/// \function log10(z)
-/// Return the base-10 logarithm of `z`. The branch cut is along the negative real axis.
+// log10(z): return the base-10 logarithm of z, with branch cut along the negative real axis
STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) {
mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag);
@@ -97,8 +86,7 @@ STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10);
#endif
-/// \function sqrt(z)
-/// Return the square-root of `z`.
+// sqrt(z): return the square-root of z
STATIC mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) {
mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag);
@@ -108,8 +96,7 @@ STATIC mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sqrt_obj, mp_cmath_sqrt);
-/// \function cos(z)
-/// Return the cosine of `z`.
+// cos(z): return the cosine of z
STATIC mp_obj_t mp_cmath_cos(mp_obj_t z_obj) {
mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag);
@@ -117,8 +104,7 @@ STATIC mp_obj_t mp_cmath_cos(mp_obj_t z_obj) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_cos_obj, mp_cmath_cos);
-/// \function sin(z)
-/// Return the sine of `z`.
+// sin(z): return the sine of z
STATIC mp_obj_t mp_cmath_sin(mp_obj_t z_obj) {
mp_float_t real, imag;
mp_obj_get_complex(z_obj, &real, &imag);
diff --git a/py/modcollections.c b/py/modcollections.c
index e610a28d2..1a1560387 100644
--- a/py/modcollections.c
+++ b/py/modcollections.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/modgc.c b/py/modgc.c
index 24564622e..55e73defc 100644
--- a/py/modgc.c
+++ b/py/modgc.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -30,10 +30,7 @@
#if MICROPY_PY_GC && MICROPY_ENABLE_GC
-/// \module gc - control the garbage collector
-
-/// \function collect()
-/// Run a garbage collection.
+// collect(): run a garbage collection
STATIC mp_obj_t py_gc_collect(void) {
gc_collect();
#if MICROPY_PY_GC_COLLECT_RETVAL
@@ -44,16 +41,14 @@ STATIC mp_obj_t py_gc_collect(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(gc_collect_obj, py_gc_collect);
-/// \function disable()
-/// Disable the garbage collector.
+// disable(): disable the garbage collector
STATIC mp_obj_t gc_disable(void) {
MP_STATE_MEM(gc_auto_collect_enabled) = 0;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_0(gc_disable_obj, gc_disable);
-/// \function enable()
-/// Enable the garbage collector.
+// enable(): enable the garbage collector
STATIC mp_obj_t gc_enable(void) {
MP_STATE_MEM(gc_auto_collect_enabled) = 1;
return mp_const_none;
@@ -65,8 +60,7 @@ STATIC mp_obj_t gc_isenabled(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled);
-/// \function mem_free()
-/// Return the number of bytes of available heap RAM.
+// mem_free(): return the number of bytes of available heap RAM
STATIC mp_obj_t gc_mem_free(void) {
gc_info_t info;
gc_info(&info);
@@ -74,8 +68,7 @@ STATIC mp_obj_t gc_mem_free(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free);
-/// \function mem_alloc()
-/// Return the number of bytes of heap RAM that are allocated.
+// mem_alloc(): return the number of bytes of heap RAM that are allocated
STATIC mp_obj_t gc_mem_alloc(void) {
gc_info_t info;
gc_info(&info);
diff --git a/py/modio.c b/py/modio.c
index 2d317d022..353a00286 100644
--- a/py/modio.c
+++ b/py/modio.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -112,9 +112,9 @@ STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bufwriter_flush_obj, bufwriter_flush);
-STATIC const mp_map_elem_t bufwriter_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_flush), (mp_obj_t)&bufwriter_flush_obj },
+STATIC const mp_rom_map_elem_t bufwriter_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
+ { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&bufwriter_flush_obj) },
};
STATIC MP_DEFINE_CONST_DICT(bufwriter_locals_dict, bufwriter_locals_dict_table);
@@ -127,7 +127,7 @@ STATIC const mp_obj_type_t bufwriter_type = {
.name = MP_QSTR_BufferedWriter,
.make_new = bufwriter_make_new,
.protocol = &bufwriter_stream_p,
- .locals_dict = (mp_obj_t)&bufwriter_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&bufwriter_locals_dict,
};
#endif // MICROPY_PY_IO_BUFFEREDWRITER
diff --git a/py/modmath.c b/py/modmath.c
index d5d135fc1..7eda7594d 100644
--- a/py/modmath.c
+++ b/py/modmath.c
@@ -1,9 +1,9 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
- * Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2013-2017 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -35,23 +35,35 @@
// And by defining our own we can ensure it uses the correct const format.
#define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846)
-/// \module math - mathematical functions
-///
-/// The `math` module provides some basic mathematical funtions for
-/// working with floating-point numbers.
-
STATIC NORETURN void math_error(void) {
mp_raise_ValueError("math domain error");
}
+STATIC mp_obj_t math_generic_1(mp_obj_t x_obj, mp_float_t (*f)(mp_float_t)) {
+ mp_float_t x = mp_obj_get_float(x_obj);
+ mp_float_t ans = f(x);
+ if ((isnan(ans) && !isnan(x)) || (isinf(ans) && !isinf(x))) {
+ math_error();
+ }
+ return mp_obj_new_float(ans);
+}
+
+STATIC mp_obj_t math_generic_2(mp_obj_t x_obj, mp_obj_t y_obj, mp_float_t (*f)(mp_float_t, mp_float_t)) {
+ mp_float_t x = mp_obj_get_float(x_obj);
+ mp_float_t y = mp_obj_get_float(y_obj);
+ mp_float_t ans = f(x, y);
+ if ((isnan(ans) && !isnan(x) && !isnan(y)) || (isinf(ans) && !isinf(x))) {
+ math_error();
+ }
+ return mp_obj_new_float(ans);
+}
+
#define MATH_FUN_1(py_name, c_name) \
- STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \
+ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { \
+ return math_generic_1(x_obj, MICROPY_FLOAT_C_FUN(c_name)); \
+ } \
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
-#define MATH_FUN_2(py_name, c_name) \
- STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj, mp_obj_t y_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj), mp_obj_get_float(y_obj))); } \
- STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name);
-
#define MATH_FUN_1_TO_BOOL(py_name, c_name) \
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_bool(c_name(mp_obj_get_float(x_obj))); } \
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
@@ -60,95 +72,101 @@ STATIC NORETURN void math_error(void) {
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_int_from_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
-#define MATH_FUN_1_ERRCOND(py_name, c_name, error_condition) \
- STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { \
- mp_float_t x = mp_obj_get_float(x_obj); \
- if (error_condition) { \
- math_error(); \
- } \
- return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(x)); \
+#define MATH_FUN_2(py_name, c_name) \
+ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \
+ return math_generic_2(x_obj, y_obj, MICROPY_FLOAT_C_FUN(c_name)); \
} \
- STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
+ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name);
+
+#define MATH_FUN_2_FLT_INT(py_name, c_name) \
+ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \
+ return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj), mp_obj_get_int(y_obj))); \
+ } \
+ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name);
#if MP_NEED_LOG2
+#undef log2
+#undef log2f
// 1.442695040888963407354163704 is 1/_M_LN2
-#define log2(x) (log(x) * 1.442695040888963407354163704)
+mp_float_t MICROPY_FLOAT_C_FUN(log2)(mp_float_t x) {
+ return MICROPY_FLOAT_C_FUN(log)(x) * MICROPY_FLOAT_CONST(1.442695040888963407354163704);
+}
#endif
-/// \function sqrt(x)
-/// Returns the square root of `x`.
-MATH_FUN_1_ERRCOND(sqrt, sqrt, (x < (mp_float_t)0.0))
-/// \function pow(x, y)
-/// Returns `x` to the power of `y`.
+// sqrt(x): returns the square root of x
+MATH_FUN_1(sqrt, sqrt)
+// pow(x, y): returns x to the power of y
MATH_FUN_2(pow, pow)
-/// \function exp(x)
+// exp(x)
MATH_FUN_1(exp, exp)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
-/// \function expm1(x)
+// expm1(x)
MATH_FUN_1(expm1, expm1)
-/// \function log2(x)
-MATH_FUN_1_ERRCOND(log2, log2, (x <= (mp_float_t)0.0))
-/// \function log10(x)
-MATH_FUN_1_ERRCOND(log10, log10, (x <= (mp_float_t)0.0))
-/// \function cosh(x)
+// log2(x)
+MATH_FUN_1(log2, log2)
+// log10(x)
+MATH_FUN_1(log10, log10)
+// cosh(x)
MATH_FUN_1(cosh, cosh)
-/// \function sinh(x)
+// sinh(x)
MATH_FUN_1(sinh, sinh)
-/// \function tanh(x)
+// tanh(x)
MATH_FUN_1(tanh, tanh)
-/// \function acosh(x)
+// acosh(x)
MATH_FUN_1(acosh, acosh)
-/// \function asinh(x)
+// asinh(x)
MATH_FUN_1(asinh, asinh)
-/// \function atanh(x)
+// atanh(x)
MATH_FUN_1(atanh, atanh)
#endif
-/// \function cos(x)
+// cos(x)
MATH_FUN_1(cos, cos)
-/// \function sin(x)
+// sin(x)
MATH_FUN_1(sin, sin)
-/// \function tan(x)
+// tan(x)
MATH_FUN_1(tan, tan)
-/// \function acos(x)
+// acos(x)
MATH_FUN_1(acos, acos)
-/// \function asin(x)
+// asin(x)
MATH_FUN_1(asin, asin)
-/// \function atan(x)
+// atan(x)
MATH_FUN_1(atan, atan)
-/// \function atan2(y, x)
+// atan2(y, x)
MATH_FUN_2(atan2, atan2)
-/// \function ceil(x)
+// ceil(x)
MATH_FUN_1_TO_INT(ceil, ceil)
-/// \function copysign(x, y)
-MATH_FUN_2(copysign, copysign)
-/// \function fabs(x)
-MATH_FUN_1(fabs, fabs)
-/// \function floor(x)
+// copysign(x, y)
+STATIC mp_float_t MICROPY_FLOAT_C_FUN(copysign_func)(mp_float_t x, mp_float_t y) {
+ return MICROPY_FLOAT_C_FUN(copysign)(x, y);
+}
+MATH_FUN_2(copysign, copysign_func)
+// fabs(x)
+STATIC mp_float_t MICROPY_FLOAT_C_FUN(fabs_func)(mp_float_t x) {
+ return MICROPY_FLOAT_C_FUN(fabs)(x);
+}
+MATH_FUN_1(fabs, fabs_func)
+// floor(x)
MATH_FUN_1_TO_INT(floor, floor) //TODO: delegate to x.__floor__() if x is not a float
-/// \function fmod(x, y)
+// fmod(x, y)
MATH_FUN_2(fmod, fmod)
-/// \function isfinite(x)
+// isfinite(x)
MATH_FUN_1_TO_BOOL(isfinite, isfinite)
-/// \function isinf(x)
+// isinf(x)
MATH_FUN_1_TO_BOOL(isinf, isinf)
-/// \function isnan(x)
+// isnan(x)
MATH_FUN_1_TO_BOOL(isnan, isnan)
-/// \function trunc(x)
+// trunc(x)
MATH_FUN_1_TO_INT(trunc, trunc)
-/// \function ldexp(x, exp)
-MATH_FUN_2(ldexp, ldexp)
+// ldexp(x, exp)
+MATH_FUN_2_FLT_INT(ldexp, ldexp)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
-/// \function erf(x)
-/// Return the error function of `x`.
+// erf(x): return the error function of x
MATH_FUN_1(erf, erf)
-/// \function erfc(x)
-/// Return the complementary error function of `x`.
+// erfc(x): return the complementary error function of x
MATH_FUN_1(erfc, erfc)
-/// \function gamma(x)
-/// Return the gamma function of `x`.
+// gamma(x): return the gamma function of x
MATH_FUN_1(gamma, tgamma)
-/// \function lgamma(x)
-/// return the natural logarithm of the gamma function of `x`.
+// lgamma(x): return the natural logarithm of the gamma function of x
MATH_FUN_1(lgamma, lgamma)
#endif
//TODO: factorial, fsum
@@ -178,8 +196,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_math_log_obj, 1, 2, mp_math_log);
// Functions that return a tuple
-/// \function frexp(x)
-/// Converts a floating-point number to fractional and integral components.
+// frexp(x): converts a floating-point number to fractional and integral components
STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) {
int int_exponent = 0;
mp_float_t significand = MICROPY_FLOAT_C_FUN(frexp)(mp_obj_get_float(x_obj), &int_exponent);
@@ -190,7 +207,7 @@ STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp);
-/// \function modf(x)
+// modf(x)
STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) {
mp_float_t int_part = 0.0;
mp_float_t fractional_part = MICROPY_FLOAT_C_FUN(modf)(mp_obj_get_float(x_obj), &int_part);
@@ -203,13 +220,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf);
// Angular conversions
-/// \function radians(x)
+// radians(x)
STATIC mp_obj_t mp_math_radians(mp_obj_t x_obj) {
return mp_obj_new_float(mp_obj_get_float(x_obj) * (MP_PI / MICROPY_FLOAT_CONST(180.0)));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians);
-/// \function degrees(x)
+// degrees(x)
STATIC mp_obj_t mp_math_degrees(mp_obj_t x_obj) {
return mp_obj_new_float(mp_obj_get_float(x_obj) * (MICROPY_FLOAT_CONST(180.0) / MP_PI));
}
diff --git a/py/modmicropython.c b/py/modmicropython.c
index 46a3922e6..2aac53adc 100644
--- a/py/modmicropython.c
+++ b/py/modmicropython.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,7 +26,6 @@
#include
-#include "py/mpstate.h"
#include "py/builtin.h"
#include "py/stackctrl.h"
#include "py/runtime.h"
diff --git a/py/modstruct.c b/py/modstruct.c
index 3c99ef1d8..8617a8e0d 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -82,26 +82,10 @@ STATIC mp_uint_t get_fmt_num(const char **p) {
return val;
}
-STATIC uint calcsize_items(const char *fmt) {
- uint cnt = 0;
- while (*fmt) {
- int num = 1;
- if (unichar_isdigit(*fmt)) {
- num = get_fmt_num(&fmt);
- if (*fmt == 's') {
- num = 1;
- }
- }
- cnt += num;
- fmt++;
- }
- return cnt;
-}
-
-STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
- const char *fmt = mp_obj_str_get_str(fmt_in);
+STATIC size_t calc_size_items(const char *fmt, size_t *total_sz) {
char fmt_type = get_fmt_type(&fmt);
- mp_uint_t size;
+ size_t total_cnt = 0;
+ size_t size;
for (size = 0; *fmt; fmt++) {
mp_uint_t cnt = 1;
if (unichar_isdigit(*fmt)) {
@@ -109,8 +93,10 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
}
if (*fmt == 's') {
+ total_cnt += 1;
size += cnt;
} else {
+ total_cnt += cnt;
mp_uint_t align;
size_t sz = mp_binary_get_size(fmt_type, *fmt, &align);
while (cnt--) {
@@ -120,6 +106,14 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
}
}
}
+ *total_sz = size;
+ return total_cnt;
+}
+
+STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
+ const char *fmt = mp_obj_str_get_str(fmt_in);
+ size_t size;
+ calc_size_items(fmt, &size);
return MP_OBJ_NEW_SMALL_INT(size);
}
MP_DEFINE_CONST_FUN_OBJ_1(struct_calcsize_obj, struct_calcsize);
@@ -130,8 +124,9 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
// Since we implement unpack and unpack_from using the same function
// we relax the "exact" requirement, and only implement "big enough".
const char *fmt = mp_obj_str_get_str(args[0]);
+ size_t total_sz;
+ size_t num_items = calc_size_items(fmt, &total_sz);
char fmt_type = get_fmt_type(&fmt);
- uint num_items = calcsize_items(fmt);
mp_obj_tuple_t *res = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_items, NULL));
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
@@ -152,21 +147,23 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
p += offset;
}
- for (uint i = 0; i < num_items;) {
- mp_uint_t sz = 1;
+ // Check that the input buffer is big enough to unpack all the values
+ if (p + total_sz > end_p) {
+ mp_raise_ValueError("buffer too small");
+ }
+
+ for (size_t i = 0; i < num_items;) {
+ mp_uint_t cnt = 1;
if (unichar_isdigit(*fmt)) {
- sz = get_fmt_num(&fmt);
- }
- if (p + sz > end_p) {
- mp_raise_ValueError("buffer too small");
+ cnt = get_fmt_num(&fmt);
}
mp_obj_t item;
if (*fmt == 's') {
- item = mp_obj_new_bytes(p, sz);
- p += sz;
+ item = mp_obj_new_bytes(p, cnt);
+ p += cnt;
res->items[i++] = item;
} else {
- while (sz--) {
+ while (cnt--) {
item = mp_binary_get_val(fmt_type, *fmt, &p);
res->items[i++] = item;
}
@@ -177,36 +174,35 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_unpack_from_obj, 2, 3, struct_unpack_from);
-STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, byte* end_p, size_t n_args, const mp_obj_t *args) {
+// This function assumes there is enough room in p to store all the values
+STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, const mp_obj_t *args) {
const char *fmt = mp_obj_str_get_str(fmt_in);
char fmt_type = get_fmt_type(&fmt);
size_t i;
for (i = 0; i < n_args;) {
- mp_uint_t sz = 1;
+ mp_uint_t cnt = 1;
if (*fmt == '\0') {
// more arguments given than used by format string; CPython raises struct.error here
break;
}
if (unichar_isdigit(*fmt)) {
- sz = get_fmt_num(&fmt);
- }
- if (p + sz > end_p) {
- mp_raise_ValueError("buffer too small");
+ cnt = get_fmt_num(&fmt);
}
if (*fmt == 's') {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[i++], &bufinfo, MP_BUFFER_READ);
- mp_uint_t to_copy = sz;
+ mp_uint_t to_copy = cnt;
if (bufinfo.len < to_copy) {
to_copy = bufinfo.len;
}
memcpy(p, bufinfo.buf, to_copy);
- memset(p + to_copy, 0, sz - to_copy);
- p += sz;
+ memset(p + to_copy, 0, cnt - to_copy);
+ p += cnt;
} else {
- while (sz--) {
+ // If we run out of args then we just finish; CPython would raise struct.error
+ while (cnt-- && i < n_args) {
mp_binary_set_val(fmt_type, *fmt, args[i++], &p);
}
}
@@ -221,8 +217,7 @@ STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) {
vstr_init_len(&vstr, size);
byte *p = (byte*)vstr.buf;
memset(p, 0, size);
- byte *end_p = &p[size];
- struct_pack_into_internal(args[0], p, end_p, n_args - 1, &args[1]);
+ struct_pack_into_internal(args[0], p, n_args - 1, &args[1]);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack);
@@ -242,7 +237,13 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) {
byte *end_p = &p[bufinfo.len];
p += offset;
- struct_pack_into_internal(args[0], p, end_p, n_args - 3, &args[3]);
+ // Check that the output buffer is big enough to hold all the values
+ mp_int_t sz = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
+ if (p + sz > end_p) {
+ mp_raise_ValueError("buffer too small");
+ }
+
+ struct_pack_into_internal(args[0], p, n_args - 3, &args[3]);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_into_obj, 3, MP_OBJ_FUN_ARGS_MAX, struct_pack_into);
diff --git a/py/modsys.c b/py/modsys.c
index b8c427ba8..84a4eb0f4 100644
--- a/py/modsys.c
+++ b/py/modsys.c
@@ -1,9 +1,10 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2014-2017 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,22 +25,20 @@
* THE SOFTWARE.
*/
-#include "py/mpstate.h"
-#include "py/nlr.h"
#include "py/builtin.h"
#include "py/objlist.h"
#include "py/objtuple.h"
#include "py/objstr.h"
#include "py/objint.h"
+#include "py/objtype.h"
#include "py/stream.h"
#include "py/smallint.h"
+#include "py/runtime.h"
#if MICROPY_PY_SYS
#include "genhdr/mpversion.h"
-/// \module sys - system specific functions
-
// defined per port; type of these is irrelevant, just need pointer
extern struct _mp_dummy_t mp_sys_stdin_obj;
extern struct _mp_dummy_t mp_sys_stdout_obj;
@@ -49,10 +48,10 @@ extern struct _mp_dummy_t mp_sys_stderr_obj;
const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adaptor};
#endif
-/// \constant version - Python language version that this implementation conforms to, as a string
+// version - Python language version that this implementation conforms to, as a string
STATIC const MP_DEFINE_STR_OBJ(version_obj, "3.4.0");
-/// \constant version_info - Python language version that this implementation conforms to, as a tuple of ints
+// version_info - Python language version that this implementation conforms to, as a tuple of ints
#define I(n) MP_OBJ_NEW_SMALL_INT(n)
// TODO: CPython is now at 5-element array, but save 2 els so far...
STATIC const mp_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {I(3), I(4), I(0)}};
@@ -87,13 +86,11 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = {
#undef I
#ifdef MICROPY_PY_SYS_PLATFORM
-/// \constant platform - the platform that Micro Python is running on
+// platform - the platform that MicroPython is running on
STATIC const MP_DEFINE_STR_OBJ(platform_obj, MICROPY_PY_SYS_PLATFORM);
#endif
-/// \function exit([retval])
-/// Raise a `SystemExit` exception. If an argument is given, it is the
-/// value given to `SystemExit`.
+// exit([retval]): raise SystemExit, with optional argument given to the exception
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
mp_obj_t exc;
if (n_args == 0) {
@@ -143,6 +140,11 @@ STATIC mp_obj_t mp_sys_exc_info(void) {
MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info);
#endif
+STATIC mp_obj_t mp_sys_getsizeof(mp_obj_t obj) {
+ return mp_unary_op(MP_UNARY_OP_SIZEOF, obj);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof);
+
STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys) },
@@ -154,7 +156,6 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
#ifdef MICROPY_PY_SYS_PLATFORM
{ MP_ROM_QSTR(MP_QSTR_platform), MP_ROM_PTR(&platform_obj) },
#endif
- /// \constant byteorder - the byte order of the system ("little" or "big")
#if MP_ENDIANNESS_LITTLE
{ MP_ROM_QSTR(MP_QSTR_byteorder), MP_ROM_QSTR(MP_QSTR_little) },
#else
@@ -168,19 +169,17 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
// to not try to compare sys.maxsize to some literal number (as this
// number might not fit in available int size), but instead count number
// of "one" bits in sys.maxsize.
- { MP_ROM_QSTR(MP_QSTR_maxsize), MP_OBJ_NEW_SMALL_INT(MP_SMALL_INT_MAX) },
+ { MP_ROM_QSTR(MP_QSTR_maxsize), MP_ROM_INT(MP_SMALL_INT_MAX) },
#else
{ MP_ROM_QSTR(MP_QSTR_maxsize), MP_ROM_PTR(&mp_maxsize_obj) },
#endif
#endif
#if MICROPY_PY_SYS_EXIT
- // documented per-port
{ MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&mp_sys_exit_obj) },
#endif
#if MICROPY_PY_SYS_STDFILES
- // documented per-port
{ MP_ROM_QSTR(MP_QSTR_stdin), MP_ROM_PTR(&mp_sys_stdin_obj) },
{ MP_ROM_QSTR(MP_QSTR_stdout), MP_ROM_PTR(&mp_sys_stdout_obj) },
{ MP_ROM_QSTR(MP_QSTR_stderr), MP_ROM_PTR(&mp_sys_stderr_obj) },
@@ -192,6 +191,9 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
#if MICROPY_PY_SYS_EXC_INFO
{ MP_ROM_QSTR(MP_QSTR_exc_info), MP_ROM_PTR(&mp_sys_exc_info_obj) },
#endif
+ #if MICROPY_PY_SYS_GETSIZEOF
+ { MP_ROM_QSTR(MP_QSTR_getsizeof), MP_ROM_PTR(&mp_sys_getsizeof_obj) },
+ #endif
/*
* Extensions to CPython
diff --git a/py/modthread.c b/py/modthread.c
index 1d7602789..cb071d0f8 100644
--- a/py/modthread.c
+++ b/py/modthread.c
@@ -34,7 +34,7 @@
#include "py/mpthread.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
@@ -192,10 +192,10 @@ STATIC void *thread_entry(void *args_in) {
// swallow exception silently
} else {
// print exception out
- mp_printf(&mp_plat_print, "Unhandled exception in thread started by ");
- mp_obj_print_helper(&mp_plat_print, args->fun, PRINT_REPR);
- mp_printf(&mp_plat_print, "\n");
- mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(exc));
+ mp_printf(MICROPY_ERROR_PRINTER, "Unhandled exception in thread started by ");
+ mp_obj_print_helper(MICROPY_ERROR_PRINTER, args->fun, PRINT_REPR);
+ mp_printf(MICROPY_ERROR_PRINTER, "\n");
+ mp_obj_print_exception(MICROPY_ERROR_PRINTER, MP_OBJ_FROM_PTR(exc));
}
}
diff --git a/py/mpconfig.h b/py/mpconfig.h
index fb507a503..6a32ea2a6 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -373,11 +373,18 @@
#define MICROPY_DEBUG_PRINTERS (0)
#endif
+// Whether to enable all debugging outputs (it will be extremely verbose)
+#ifndef MICROPY_DEBUG_VERBOSE
+#define MICROPY_DEBUG_VERBOSE (0)
+#endif
+
/*****************************************************************************/
/* Optimisations */
// Whether to use computed gotos in the VM, or a switch
// Computed gotos are roughly 10% faster, and increase VM code size by a little
+// Note: enabling this will use the gcc-specific extensions of ranged designated
+// initialisers and addresses of labels, which are not part of the C99 standard.
#ifndef MICROPY_OPT_COMPUTED_GOTO
#define MICROPY_OPT_COMPUTED_GOTO (0)
#endif
@@ -526,6 +533,11 @@ typedef long long mp_longint_impl_t;
#define MICROPY_WARNINGS (0)
#endif
+// This macro is used when printing runtime warnings and errors
+#ifndef MICROPY_ERROR_PRINTER
+#define MICROPY_ERROR_PRINTER (&mp_plat_print)
+#endif
+
// Float and complex implementation
#define MICROPY_FLOAT_IMPL_NONE (0)
#define MICROPY_FLOAT_IMPL_FLOAT (1)
@@ -686,6 +698,11 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_STR_UNICODE (0)
#endif
+// Whether to check for valid UTF-8 when converting bytes to str
+#ifndef MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
+#define MICROPY_PY_BUILTINS_STR_UNICODE_CHECK (MICROPY_PY_BUILTINS_STR_UNICODE)
+#endif
+
// Whether str.center() method provided
#ifndef MICROPY_PY_BUILTINS_STR_CENTER
#define MICROPY_PY_BUILTINS_STR_CENTER (0)
@@ -748,12 +765,28 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_TIMEOUTERROR (0)
#endif
-// Whether to support complete set of special methods
-// for user classes, otherwise only the most used
+// Whether to support complete set of special methods for user
+// classes, or only the most used ones. "Inplace" methods are
+// controlled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS below.
+// "Reverse" methods are controlled by
+// MICROPY_PY_REVERSE_SPECIAL_METHODS below.
#ifndef MICROPY_PY_ALL_SPECIAL_METHODS
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
#endif
+// Whether to support all inplace arithmetic operarion methods
+// (__imul__, etc.)
+#ifndef MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS
+#define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (0)
+#endif
+
+// Whether to support reverse arithmetic operarion methods
+// (__radd__, etc.). Additionally gated by
+// MICROPY_PY_ALL_SPECIAL_METHODS.
+#ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS
+#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
+#endif
+
// Whether to support compile function
#ifndef MICROPY_PY_BUILTINS_COMPILE
#define MICROPY_PY_BUILTINS_COMPILE (0)
@@ -944,6 +977,11 @@ typedef double mp_float_t;
#define MICROPY_PY_SYS_EXIT (1)
#endif
+// Whether to provide "sys.getsizeof" function
+#ifndef MICROPY_PY_SYS_GETSIZEOF
+#define MICROPY_PY_SYS_GETSIZEOF (0)
+#endif
+
// Whether to provide sys.{stdin,stdout,stderr} objects
#ifndef MICROPY_PY_SYS_STDFILES
#define MICROPY_PY_SYS_STDFILES (0)
@@ -1071,6 +1109,8 @@ typedef double mp_float_t;
#ifndef MICROPY_PY_USSL
#define MICROPY_PY_USSL (0)
+// Whether to add finaliser code to ussl objects
+#define MICROPY_PY_USSL_FINALISER (0)
#endif
#ifndef MICROPY_PY_WEBSOCKET
diff --git a/py/mphal.h b/py/mphal.h
index 93a0a40ce..92de01d08 100644
--- a/py/mphal.h
+++ b/py/mphal.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/mpprint.c b/py/mpprint.c
index 0afd8ca3b..a569ef793 100644
--- a/py/mpprint.c
+++ b/py/mpprint.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -485,14 +485,17 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
case 's':
{
const char *str = va_arg(args, const char*);
- if (str) {
- if (prec < 0) {
- prec = strlen(str);
- }
- chrs += mp_print_strn(print, str, prec, flags, fill, width);
- } else {
+ #ifndef NDEBUG
+ // With debugging enabled, catch printing of null string pointers
+ if (prec != 0 && str == NULL) {
chrs += mp_print_strn(print, "(null)", 6, flags, fill, width);
+ break;
}
+ #endif
+ if (prec < 0) {
+ prec = strlen(str);
+ }
+ chrs += mp_print_strn(print, str, prec, flags, fill, width);
break;
}
case 'u':
diff --git a/py/mpprint.h b/py/mpprint.h
index 20bd875b4..07462bddc 100644
--- a/py/mpprint.h
+++ b/py/mpprint.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/mpstate.c b/py/mpstate.c
index 4fc8bc506..6ce64adfd 100644
--- a/py/mpstate.c
+++ b/py/mpstate.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/mpstate.h b/py/mpstate.h
index b09ba08cf..6a39ebdea 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -36,7 +36,7 @@
#include "py/objlist.h"
#include "py/objexcept.h"
-// This file contains structures defining the state of the Micro Python
+// This file contains structures defining the state of the MicroPython
// memory system, runtime and virtual machine. The state is a global
// variable, but in the future it is hoped that the state can become local.
@@ -168,7 +168,7 @@ typedef struct _mp_state_vm_t {
// root pointers for extmod
#if MICROPY_PY_OS_DUPTERM
- mp_obj_t term_obj;
+ mp_obj_t dupterm_objs[MICROPY_PY_OS_DUPTERM];
mp_obj_t dupterm_arr_obj;
#endif
diff --git a/py/mpz.c b/py/mpz.c
index f58e262e2..d300a8e5d 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/mpz.h b/py/mpz.h
index 55967cc4c..e2d0c30aa 100644
--- a/py/mpz.h
+++ b/py/mpz.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/nativeglue.c b/py/nativeglue.c
index c75e5ec04..e63c2fcda 100644
--- a/py/nativeglue.c
+++ b/py/nativeglue.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,13 +28,12 @@
#include
#include
-#include "py/nlr.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
+#include "py/smallint.h"
#include "py/emitglue.h"
#include "py/bc.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(...) (void)0
@@ -42,7 +41,7 @@
#if MICROPY_EMIT_NATIVE
-// convert a Micro Python object to a valid native value based on type
+// convert a MicroPython object to a valid native value based on type
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
DEBUG_printf("mp_convert_obj_to_native(%p, " UINT_FMT ")\n", obj, type);
switch (type & 0xf) {
@@ -66,7 +65,7 @@ mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
-// convert a native value to a Micro Python object based on type
+// convert a native value to a MicroPython object based on type
mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) {
DEBUG_printf("mp_convert_native_to_obj(" UINT_FMT ", " UINT_FMT ")\n", val, type);
switch (type & 0xf) {
@@ -172,6 +171,8 @@ void *const mp_fun_table[MP_F_NUMBER_OF] = {
mp_obj_new_cell,
mp_make_closure_from_raw_code,
mp_setup_code_state,
+ mp_small_int_floor_divide,
+ mp_small_int_modulo,
};
/*
diff --git a/py/nlr.h b/py/nlr.h
index 624e97307..63fe392d9 100644
--- a/py/nlr.h
+++ b/py/nlr.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/nlrsetjmp.c b/py/nlrsetjmp.c
index c3873e0b6..1fb459440 100644
--- a/py/nlrsetjmp.c
+++ b/py/nlrsetjmp.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/nlrthumb.c b/py/nlrthumb.c
index 08a71ac7d..6e7d71766 100644
--- a/py/nlrthumb.c
+++ b/py/nlrthumb.c
@@ -25,7 +25,6 @@
*/
#include "py/mpstate.h"
-#include "py/nlr.h"
#if (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
@@ -67,7 +66,14 @@ __attribute__((naked)) unsigned int nlr_push(nlr_buf_t *nlr) {
"str lr, [r0, #8] \n" // store lr into nlr_buf
#endif
+#if defined(__ARM_ARCH_6M__)
+ "ldr r1, nlr_push_tail_var \n"
+ "bx r1 \n" // do the rest in C
+ ".align 2 \n"
+ "nlr_push_tail_var: .word nlr_push_tail \n"
+#else
"b nlr_push_tail \n" // do the rest in C
+#endif
);
return 0; // needed to silence compiler warning
diff --git a/py/nlrx64.c b/py/nlrx64.c
index c23fd8fc6..847d10398 100644
--- a/py/nlrx64.c
+++ b/py/nlrx64.c
@@ -25,7 +25,6 @@
*/
#include "py/mpstate.h"
-#include "py/nlr.h"
#if !MICROPY_NLR_SETJMP && defined(__x86_64__)
@@ -34,7 +33,11 @@
// x86-64 callee-save registers are:
// rbx, rbp, rsp, r12, r13, r14, r15
-#define NLR_OS_WINDOWS (defined(_WIN32) || defined(__CYGWIN__))
+#if defined(_WIN32) || defined(__CYGWIN__)
+#define NLR_OS_WINDOWS 1
+#else
+#define NLR_OS_WINDOWS 0
+#endif
__attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr);
diff --git a/py/nlrx86.c b/py/nlrx86.c
index 58aaa1a57..094dea3cc 100644
--- a/py/nlrx86.c
+++ b/py/nlrx86.c
@@ -24,9 +24,7 @@
* THE SOFTWARE.
*/
-#include "py/mpconfig.h"
#include "py/mpstate.h"
-#include "py/nlr.h"
#if !MICROPY_NLR_SETJMP && defined(__i386__)
@@ -35,7 +33,11 @@
// For reference, x86 callee save regs are:
// ebx, esi, edi, ebp, esp, eip
-#define NLR_OS_WINDOWS (defined(_WIN32) || defined(__CYGWIN__))
+#if defined(_WIN32) || defined(__CYGWIN__)
+#define NLR_OS_WINDOWS 1
+#else
+#define NLR_OS_WINDOWS 0
+#endif
#if NLR_OS_WINDOWS
unsigned int nlr_push_tail(nlr_buf_t *nlr) asm("nlr_push_tail");
@@ -51,7 +53,7 @@ unsigned int nlr_push(nlr_buf_t *nlr) {
// by default.
// TODE: Better support for various x86 calling conventions
// (unfortunately, __attribute__((naked)) is not supported on x86).
- #ifndef __ZEPHYR__
+ #if !(defined(__ZEPHYR__) || defined(__ANDROID__))
"pop %ebp \n" // undo function's prelude
#endif
"mov 4(%esp), %edx \n" // load nlr_buf
diff --git a/py/nlrxtensa.c b/py/nlrxtensa.c
index ccac3597b..4520e7e7a 100644
--- a/py/nlrxtensa.c
+++ b/py/nlrxtensa.c
@@ -25,7 +25,6 @@
*/
#include "py/mpstate.h"
-#include "py/nlr.h"
#if !MICROPY_NLR_SETJMP && defined(__xtensa__)
diff --git a/py/obj.c b/py/obj.c
index 1238b7011..a1de89a03 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,12 +29,10 @@
#include
#include
-#include "py/nlr.h"
#include "py/obj.h"
#include "py/objtype.h"
#include "py/objint.h"
#include "py/objstr.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/stream.h" // for mp_obj_print
@@ -162,7 +160,16 @@ bool mp_obj_is_callable(mp_obj_t o_in) {
// comparison returns NotImplemented, == and != are decided by comparing the object
// pointer."
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
- if (o1 == o2) {
+ // Float (and complex) NaN is never equal to anything, not even itself,
+ // so we must have a special check here to cover those cases.
+ if (o1 == o2
+ #if MICROPY_PY_BUILTINS_FLOAT
+ && !mp_obj_is_float(o1)
+ #endif
+ #if MICROPY_PY_BUILTINS_COMPLEX
+ && !MP_OBJ_IS_TYPE(o1, &mp_type_complex)
+ #endif
+ ) {
return true;
}
if (o1 == mp_const_none || o2 == mp_const_none) {
@@ -264,20 +271,33 @@ bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value) {
}
#if MICROPY_PY_BUILTINS_FLOAT
-mp_float_t mp_obj_get_float(mp_obj_t arg) {
+bool mp_obj_get_float_maybe(mp_obj_t arg, mp_float_t *value) {
+ mp_float_t val;
+
if (arg == mp_const_false) {
- return 0;
+ val = 0;
} else if (arg == mp_const_true) {
- return 1;
+ val = 1;
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
- return MP_OBJ_SMALL_INT_VALUE(arg);
+ val = MP_OBJ_SMALL_INT_VALUE(arg);
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
- return mp_obj_int_as_float_impl(arg);
+ val = mp_obj_int_as_float_impl(arg);
#endif
} else if (mp_obj_is_float(arg)) {
- return mp_obj_float_get(arg);
+ val = mp_obj_float_get(arg);
} else {
+ return false;
+ }
+
+ *value = val;
+ return true;
+}
+
+mp_float_t mp_obj_get_float(mp_obj_t arg) {
+ mp_float_t val;
+
+ if (!mp_obj_get_float_maybe(arg, &val)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("can't convert to float");
} else {
@@ -285,6 +305,8 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
"can't convert %s to float", mp_obj_get_type_str(arg)));
}
}
+
+ return val;
}
#if MICROPY_PY_BUILTINS_COMPLEX
@@ -505,7 +527,7 @@ void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flag
}
}
-mp_obj_t mp_generic_unary_op(mp_uint_t op, mp_obj_t o_in) {
+mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
switch (op) {
case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT((mp_uint_t)o_in);
default: return MP_OBJ_NULL; // op not supported
diff --git a/py/obj.h b/py/obj.h
index f88c10004..77f0f2298 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -30,6 +30,7 @@
#include "py/misc.h"
#include "py/qstr.h"
#include "py/mpprint.h"
+#include "py/runtime0.h"
// This is the definition of the opaque MicroPython object type.
// All concrete objects have an encoding within this type and the
@@ -429,8 +430,8 @@ typedef struct _mp_obj_iter_buf_t {
typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind);
typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args);
-typedef mp_obj_t (*mp_unary_op_fun_t)(mp_uint_t op, mp_obj_t);
-typedef mp_obj_t (*mp_binary_op_fun_t)(mp_uint_t op, mp_obj_t, mp_obj_t);
+typedef mp_obj_t (*mp_unary_op_fun_t)(mp_unary_op_t op, mp_obj_t);
+typedef mp_obj_t (*mp_binary_op_fun_t)(mp_binary_op_t op, mp_obj_t, mp_obj_t);
typedef void (*mp_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
typedef mp_obj_t (*mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
typedef mp_obj_t (*mp_getiter_fun_t)(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
@@ -615,6 +616,7 @@ extern const mp_obj_type_t mp_type_ZeroDivisionError;
#define mp_const_true (MP_OBJ_FROM_PTR(&mp_const_true_obj))
#define mp_const_empty_bytes (MP_OBJ_FROM_PTR(&mp_const_empty_bytes_obj))
#define mp_const_empty_tuple (MP_OBJ_FROM_PTR(&mp_const_empty_tuple_obj))
+#define mp_const_notimplemented (MP_OBJ_FROM_PTR(&mp_const_notimplemented_obj))
extern const struct _mp_obj_none_t mp_const_none_obj;
extern const struct _mp_obj_bool_t mp_const_false_obj;
extern const struct _mp_obj_bool_t mp_const_true_obj;
@@ -628,7 +630,6 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj;
// General API for objects
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
-mp_obj_t mp_obj_new_none(void);
static inline mp_obj_t mp_obj_new_bool(mp_int_t x) { return x ? mp_const_true : mp_const_false; }
mp_obj_t mp_obj_new_cell(mp_obj_t obj);
mp_obj_t mp_obj_new_int(mp_int_t value);
@@ -684,6 +685,7 @@ mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg);
bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value);
#if MICROPY_PY_BUILTINS_FLOAT
mp_float_t mp_obj_get_float(mp_obj_t self_in);
+bool mp_obj_get_float_maybe(mp_obj_t arg, mp_float_t *value);
void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
#endif
//qstr mp_obj_get_qstr(mp_obj_t arg);
@@ -694,7 +696,7 @@ mp_obj_t mp_obj_id(mp_obj_t o_in);
mp_obj_t mp_obj_len(mp_obj_t o_in);
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
-mp_obj_t mp_generic_unary_op(mp_uint_t op, mp_obj_t o_in);
+mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in);
// cell
mp_obj_t mp_obj_cell_get(mp_obj_t self_in);
@@ -734,11 +736,11 @@ mp_int_t mp_float_hash(mp_float_t val);
#else
static inline mp_int_t mp_float_hash(mp_float_t val) { return (mp_int_t)val; }
#endif
-mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
+mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
// complex
void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
-mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NULL if op not supported
+mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NULL if op not supported
#else
#define mp_obj_is_float(o) (false)
#endif
diff --git a/py/objarray.c b/py/objarray.c
index 21479a800..7003ec9e7 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,8 +29,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/objstr.h"
@@ -231,7 +229,7 @@ STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args,
}
#endif
-STATIC mp_obj_t array_unary_op(mp_uint_t op, mp_obj_t o_in) {
+STATIC mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in);
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->len != 0);
@@ -240,7 +238,7 @@ STATIC mp_obj_t array_unary_op(mp_uint_t op, mp_obj_t o_in) {
}
}
-STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_array_t *lhs = MP_OBJ_TO_PTR(lhs_in);
switch (op) {
case MP_BINARY_OP_ADD: {
@@ -288,7 +286,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
// Otherwise, can only look for a scalar numeric value in an array
if (MP_OBJ_IS_INT(rhs_in) || mp_obj_is_float(rhs_in)) {
- mp_not_implemented("");
+ mp_raise_NotImplementedError(NULL);
}
return mp_const_false;
@@ -378,7 +376,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
} else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &slice)) {
- mp_not_implemented("only slices with step=1 (aka None) are supported");
+ mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported");
}
if (value != MP_OBJ_SENTINEL) {
#if MICROPY_PY_ARRAY_SLICE_ASSIGN
@@ -409,7 +407,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
src_len = bufinfo.len;
src_items = bufinfo.buf;
} else {
- mp_not_implemented("array/bytes required on right side");
+ mp_raise_NotImplementedError("array/bytes required on right side");
}
// TODO: check src/dst compat
diff --git a/py/objattrtuple.c b/py/objattrtuple.c
index 8c5e79575..3cc298d4e 100644
--- a/py/objattrtuple.c
+++ b/py/objattrtuple.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objbool.c b/py/objbool.c
index 5bc04bb6f..5755b188e 100644
--- a/py/objbool.c
+++ b/py/objbool.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,8 +26,6 @@
#include
-#include "py/obj.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
typedef struct _mp_obj_bool_t {
@@ -63,7 +61,7 @@ STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
}
}
-STATIC mp_obj_t bool_unary_op(mp_uint_t op, mp_obj_t o_in) {
+STATIC mp_obj_t bool_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
if (op == MP_UNARY_OP_LEN) {
return MP_OBJ_NULL;
}
@@ -71,7 +69,7 @@ STATIC mp_obj_t bool_unary_op(mp_uint_t op, mp_obj_t o_in) {
return mp_unary_op(op, MP_OBJ_NEW_SMALL_INT(self->value));
}
-STATIC mp_obj_t bool_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+STATIC mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_bool_t *self = MP_OBJ_TO_PTR(lhs_in);
return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(self->value), rhs_in);
}
diff --git a/py/objboundmeth.c b/py/objboundmeth.c
index 57be6a6cf..890f8b15b 100644
--- a/py/objboundmeth.c
+++ b/py/objboundmeth.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objcell.c b/py/objcell.c
index 06a88b954..111906412 100644
--- a/py/objcell.c
+++ b/py/objcell.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objclosure.c b/py/objclosure.c
index 3e12358bb..4eb9eb8b8 100644
--- a/py/objclosure.c
+++ b/py/objclosure.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objcomplex.c b/py/objcomplex.c
index e4fbed1e8..409d65666 100644
--- a/py/objcomplex.c
+++ b/py/objcomplex.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,10 +28,7 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/parsenum.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#if MICROPY_PY_BUILTINS_COMPLEX
@@ -117,18 +114,20 @@ STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, si
}
}
-STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) {
+STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in);
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->real != 0 || o->imag != 0);
case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT(mp_float_hash(o->real) ^ mp_float_hash(o->imag));
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag);
+ case MP_UNARY_OP_ABS:
+ return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(o->real*o->real + o->imag*o->imag));
default: return MP_OBJ_NULL; // op not supported
}
}
-STATIC mp_obj_t complex_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+STATIC mp_obj_t complex_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_complex_t *lhs = MP_OBJ_TO_PTR(lhs_in);
return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in);
}
@@ -171,7 +170,7 @@ void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag) {
*imag = self->imag;
}
-mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in) {
+mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in) {
mp_float_t rhs_real, rhs_imag;
mp_obj_get_complex(rhs_in, &rhs_real, &rhs_imag); // can be any type, this function will convert to float (if possible)
switch (op) {
@@ -229,7 +228,6 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
if (abs1 == 0) {
if (rhs_imag == 0 && rhs_real >= 0) {
lhs_real = (rhs_real == 0);
- rhs_real = 0;
} else {
mp_raise_msg(&mp_type_ZeroDivisionError, "0.0 to a complex power");
}
diff --git a/py/objdict.c b/py/objdict.c
index 23d3008b8..1553a83b4 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -27,9 +27,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/builtin.h"
#include "py/objtype.h"
@@ -100,16 +97,22 @@ STATIC mp_obj_t dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
return dict_out;
}
-STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) {
+STATIC mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->map.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used);
+ #if MICROPY_PY_SYS_GETSIZEOF
+ case MP_UNARY_OP_SIZEOF: {
+ size_t sz = sizeof(*self) + sizeof(*self->map.table) * self->map.alloc;
+ return MP_OBJ_NEW_SMALL_INT(sz);
+ }
+ #endif
default: return MP_OBJ_NULL; // op not supported
}
}
-STATIC mp_obj_t dict_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+STATIC mp_obj_t dict_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_dict_t *o = MP_OBJ_TO_PTR(lhs_in);
switch (op) {
case MP_BINARY_OP_IN: {
@@ -476,7 +479,7 @@ STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
mp_print_str(print, "])");
}
-STATIC mp_obj_t dict_view_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
// only supported for the 'keys' kind until sets and dicts are refactored
mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(lhs_in);
if (o->kind != MP_DICT_VIEW_KEYS) {
diff --git a/py/objenumerate.c b/py/objenumerate.c
index faae6516c..1a9d30f83 100644
--- a/py/objenumerate.c
+++ b/py/objenumerate.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objexcept.c b/py/objexcept.c
index 4722aca91..b87609a6b 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,7 +29,6 @@
#include
#include
-#include "py/mpstate.h"
#include "py/objlist.h"
#include "py/objstr.h"
#include "py/objtuple.h"
@@ -38,6 +37,12 @@
#include "py/gc.h"
#include "py/mperrno.h"
+// Number of items per traceback entry (file, line, block)
+#define TRACEBACK_ENTRY_LEN (3)
+
+// Number of traceback entries to reserve in the emergency exception buffer
+#define EMG_TRACEBACK_ALLOC (2 * TRACEBACK_ENTRY_LEN)
+
// Instance of MemoryError exception - needed by mp_malloc_fail
const mp_obj_exception_t mp_const_MemoryError_obj = {{&mp_type_MemoryError}, 0, 0, NULL, (mp_obj_tuple_t*)&mp_const_empty_tuple_obj};
@@ -127,18 +132,51 @@ STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false);
- mp_obj_exception_t *o = m_new_obj_var_maybe(mp_obj_exception_t, mp_obj_t, 0);
- if (o == NULL) {
- // Couldn't allocate heap memory; use local data instead.
- o = &MP_STATE_VM(mp_emergency_exception_obj);
- // We can't store any args.
- o->args = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj;
+
+ // Try to allocate memory for the exception, with fallback to emergency exception object
+ mp_obj_exception_t *o_exc = m_new_obj_maybe(mp_obj_exception_t);
+ if (o_exc == NULL) {
+ o_exc = &MP_STATE_VM(mp_emergency_exception_obj);
+ }
+
+ // Populate the exception object
+ o_exc->base.type = type;
+ o_exc->traceback_data = NULL;
+
+ mp_obj_tuple_t *o_tuple;
+ if (n_args == 0) {
+ // No args, can use the empty tuple straightaway
+ o_tuple = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj;
} else {
- o->args = MP_OBJ_TO_PTR(mp_obj_new_tuple(n_args, args));
+ // Try to allocate memory for the tuple containing the args
+ o_tuple = m_new_obj_var_maybe(mp_obj_tuple_t, mp_obj_t, n_args);
+
+ #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
+ // If we are called by mp_obj_new_exception_msg_varg then it will have
+ // reserved room (after the traceback data) for a tuple with 1 element.
+ // Otherwise we are free to use the whole buffer after the traceback data.
+ if (o_tuple == NULL && mp_emergency_exception_buf_size >=
+ EMG_TRACEBACK_ALLOC * sizeof(size_t) + sizeof(mp_obj_tuple_t) + n_args * sizeof(mp_obj_t)) {
+ o_tuple = (mp_obj_tuple_t*)
+ ((uint8_t*)MP_STATE_VM(mp_emergency_exception_buf) + EMG_TRACEBACK_ALLOC * sizeof(size_t));
+ }
+ #endif
+
+ if (o_tuple == NULL) {
+ // No memory for a tuple, fallback to an empty tuple
+ o_tuple = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj;
+ } else {
+ // Have memory for a tuple so populate it
+ o_tuple->base.type = &mp_type_tuple;
+ o_tuple->len = n_args;
+ memcpy(o_tuple->items, args, n_args * sizeof(mp_obj_t));
+ }
}
- o->base.type = type;
- o->traceback_data = NULL;
- return MP_OBJ_FROM_PTR(o);
+
+ // Store the tuple of args in the exception object
+ o_exc->args = o_tuple;
+
+ return MP_OBJ_FROM_PTR(o_exc);
}
// Get exception "value" - that is, first argument, or None
@@ -306,87 +344,95 @@ mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg
return mp_obj_new_exception_msg_varg(exc_type, msg);
}
-mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt, ...) {
- // check that the given type is an exception type
- assert(exc_type->make_new == mp_obj_exception_make_new);
-
- // make exception object
- mp_obj_exception_t *o = m_new_obj_var_maybe(mp_obj_exception_t, mp_obj_t, 0);
- if (o == NULL) {
- // Couldn't allocate heap memory; use local data instead.
- // Unfortunately, we won't be able to format the string...
- o = &MP_STATE_VM(mp_emergency_exception_obj);
- o->base.type = exc_type;
- o->traceback_data = NULL;
- o->args = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj;
-
-#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
- // If the user has provided a buffer, then we try to create a tuple
- // of length 1, which has a string object and the string data.
+// The following struct and function implement a simple printer that conservatively
+// allocates memory and truncates the output data if no more memory can be obtained.
+// It leaves room for a null byte at the end of the buffer.
- if (mp_emergency_exception_buf_size > (sizeof(mp_obj_tuple_t) + sizeof(mp_obj_str_t) + sizeof(mp_obj_t))) {
- mp_obj_tuple_t *tuple = (mp_obj_tuple_t *)MP_STATE_VM(mp_emergency_exception_buf);
- mp_obj_str_t *str = (mp_obj_str_t *)&tuple->items[1];
-
- tuple->base.type = &mp_type_tuple;
- tuple->len = 1;
- tuple->items[0] = MP_OBJ_FROM_PTR(str);
-
- byte *str_data = (byte *)&str[1];
- size_t max_len = (byte*)MP_STATE_VM(mp_emergency_exception_buf) + mp_emergency_exception_buf_size
- - str_data;
+struct _exc_printer_t {
+ bool allow_realloc;
+ size_t alloc;
+ size_t len;
+ byte *buf;
+};
- vstr_t vstr;
- vstr_init_fixed_buf(&vstr, max_len, (char *)str_data);
+STATIC void exc_add_strn(void *data, const char *str, size_t len) {
+ struct _exc_printer_t *pr = data;
+ if (pr->len + len >= pr->alloc) {
+ // Not enough room for data plus a null byte so try to grow the buffer
+ if (pr->allow_realloc) {
+ size_t new_alloc = pr->alloc + len + 16;
+ byte *new_buf = m_renew_maybe(byte, pr->buf, pr->alloc, new_alloc, true);
+ if (new_buf == NULL) {
+ pr->allow_realloc = false;
+ len = pr->alloc - pr->len - 1;
+ } else {
+ pr->alloc = new_alloc;
+ pr->buf = new_buf;
+ }
+ } else {
+ len = pr->alloc - pr->len - 1;
+ }
+ }
+ memcpy(pr->buf + pr->len, str, len);
+ pr->len += len;
+}
- va_list ap;
- va_start(ap, fmt);
- vstr_vprintf(&vstr, fmt, ap);
- va_end(ap);
+mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt, ...) {
+ assert(fmt != NULL);
- str->base.type = &mp_type_str;
- str->hash = qstr_compute_hash(str_data, str->len);
- str->len = vstr.len;
- str->data = str_data;
+ // Check that the given type is an exception type
+ assert(exc_type->make_new == mp_obj_exception_make_new);
- o->args = tuple;
+ // Try to allocate memory for the message
+ mp_obj_str_t *o_str = m_new_obj_maybe(mp_obj_str_t);
+ size_t o_str_alloc = strlen(fmt) + 1;
+ byte *o_str_buf = m_new_maybe(byte, o_str_alloc);
+
+ bool used_emg_buf = false;
+ #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
+ // If memory allocation failed and there is an emergency buffer then try to use
+ // that buffer to store the string object and its data (at least 16 bytes for
+ // the string data), reserving room at the start for the traceback and 1-tuple.
+ if ((o_str == NULL || o_str_buf == NULL)
+ && mp_emergency_exception_buf_size >= EMG_TRACEBACK_ALLOC * sizeof(size_t)
+ + sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t) + sizeof(mp_obj_str_t) + 16) {
+ used_emg_buf = true;
+ o_str = (mp_obj_str_t*)((uint8_t*)MP_STATE_VM(mp_emergency_exception_buf)
+ + EMG_TRACEBACK_ALLOC * sizeof(size_t) + sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t));
+ o_str_buf = (byte*)&o_str[1];
+ o_str_alloc = (uint8_t*)MP_STATE_VM(mp_emergency_exception_buf)
+ + mp_emergency_exception_buf_size - o_str_buf;
+ }
+ #endif
- size_t offset = &str_data[str->len] - (byte*)MP_STATE_VM(mp_emergency_exception_buf);
- offset += sizeof(void *) - 1;
- offset &= ~(sizeof(void *) - 1);
+ if (o_str == NULL) {
+ // No memory for the string object so create the exception with no args
+ return mp_obj_exception_make_new(exc_type, 0, 0, NULL);
+ }
- if ((mp_emergency_exception_buf_size - offset) > (sizeof(o->traceback_data[0]) * 3)) {
- // We have room to store some traceback.
- o->traceback_data = (size_t*)((byte *)MP_STATE_VM(mp_emergency_exception_buf) + offset);
- o->traceback_alloc = ((byte*)MP_STATE_VM(mp_emergency_exception_buf) + mp_emergency_exception_buf_size - (byte *)o->traceback_data) / sizeof(o->traceback_data[0]);
- o->traceback_len = 0;
- }
- }
-#endif // MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
+ if (o_str_buf == NULL) {
+ // No memory for the string buffer: assume that the fmt string is in ROM
+ // and use that data as the data of the string
+ o_str->len = o_str_alloc - 1; // will be equal to strlen(fmt)
+ o_str->data = (const byte*)fmt;
} else {
- o->base.type = exc_type;
- o->traceback_data = NULL;
- o->args = MP_OBJ_TO_PTR(mp_obj_new_tuple(1, NULL));
-
- assert(fmt != NULL);
- {
- if (strchr(fmt, '%') == NULL) {
- // no formatting substitutions, avoid allocating vstr.
- o->args->items[0] = mp_obj_new_str(fmt, strlen(fmt), false);
- } else {
- // render exception message and store as .args[0]
- va_list ap;
- vstr_t vstr;
- vstr_init(&vstr, 16);
- va_start(ap, fmt);
- vstr_vprintf(&vstr, fmt, ap);
- va_end(ap);
- o->args->items[0] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
- }
- }
+ // We have some memory to format the string
+ struct _exc_printer_t exc_pr = {!used_emg_buf, o_str_alloc, 0, o_str_buf};
+ mp_print_t print = {&exc_pr, exc_add_strn};
+ va_list ap;
+ va_start(ap, fmt);
+ mp_vprintf(&print, fmt, ap);
+ va_end(ap);
+ exc_pr.buf[exc_pr.len] = '\0';
+ o_str->len = exc_pr.len;
+ o_str->data = exc_pr.buf;
}
- return MP_OBJ_FROM_PTR(o);
+ // Create the string object and call mp_obj_exception_make_new to create the exception
+ o_str->base.type = &mp_type_str;
+ o_str->hash = qstr_compute_hash(o_str->data, o_str->len);
+ mp_obj_t arg = MP_OBJ_FROM_PTR(o_str);
+ return mp_obj_exception_make_new(exc_type, 1, 0, &arg);
}
// return true if the given object is an exception type
@@ -443,24 +489,46 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs
// if memory allocation fails (eg because gc is locked), just return
if (self->traceback_data == NULL) {
- self->traceback_data = m_new_maybe(size_t, 3);
+ self->traceback_data = m_new_maybe(size_t, TRACEBACK_ENTRY_LEN);
if (self->traceback_data == NULL) {
+ #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
+ if (mp_emergency_exception_buf_size >= EMG_TRACEBACK_ALLOC * sizeof(size_t)) {
+ // There is room in the emergency buffer for traceback data
+ size_t *tb = (size_t*)MP_STATE_VM(mp_emergency_exception_buf);
+ self->traceback_data = tb;
+ self->traceback_alloc = EMG_TRACEBACK_ALLOC;
+ } else {
+ // Can't allocate and no room in emergency buffer
+ return;
+ }
+ #else
+ // Can't allocate
return;
+ #endif
+ } else {
+ // Allocated the traceback data on the heap
+ self->traceback_alloc = TRACEBACK_ENTRY_LEN;
}
- self->traceback_alloc = 3;
self->traceback_len = 0;
- } else if (self->traceback_len + 3 > self->traceback_alloc) {
+ } else if (self->traceback_len + TRACEBACK_ENTRY_LEN > self->traceback_alloc) {
+ #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
+ if (self->traceback_data == (size_t*)MP_STATE_VM(mp_emergency_exception_buf)) {
+ // Can't resize the emergency buffer
+ return;
+ }
+ #endif
// be conservative with growing traceback data
- size_t *tb_data = m_renew_maybe(size_t, self->traceback_data, self->traceback_alloc, self->traceback_alloc + 3, true);
+ size_t *tb_data = m_renew_maybe(size_t, self->traceback_data, self->traceback_alloc,
+ self->traceback_alloc + TRACEBACK_ENTRY_LEN, true);
if (tb_data == NULL) {
return;
}
self->traceback_data = tb_data;
- self->traceback_alloc += 3;
+ self->traceback_alloc += TRACEBACK_ENTRY_LEN;
}
size_t *tb_data = &self->traceback_data[self->traceback_len];
- self->traceback_len += 3;
+ self->traceback_len += TRACEBACK_ENTRY_LEN;
tb_data[0] = file;
tb_data[1] = line;
tb_data[2] = block;
diff --git a/py/objexcept.h b/py/objexcept.h
index 2232e1e21..f67651a7e 100644
--- a/py/objexcept.h
+++ b/py/objexcept.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objfilter.c b/py/objfilter.c
index a655b8a78..cb965d8c3 100644
--- a/py/objfilter.c
+++ b/py/objfilter.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objfloat.c b/py/objfloat.c
index d0e616612..743287be6 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -29,9 +29,7 @@
#include
#include
-#include "py/nlr.h"
#include "py/parsenum.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#if MICROPY_PY_BUILTINS_FLOAT
@@ -155,18 +153,26 @@ STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size
}
}
-STATIC mp_obj_t float_unary_op(mp_uint_t op, mp_obj_t o_in) {
+STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
mp_float_t val = mp_obj_float_get(o_in);
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(val != 0);
case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT(mp_float_hash(val));
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-val);
+ case MP_UNARY_OP_ABS: {
+ // TODO check for NaN etc
+ if (val < 0) {
+ return mp_obj_new_float(-val);
+ } else {
+ return o_in;
+ }
+ }
default: return MP_OBJ_NULL; // op not supported
}
}
-STATIC mp_obj_t float_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+STATIC mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_float_t lhs_val = mp_obj_float_get(lhs_in);
#if MICROPY_PY_BUILTINS_COMPLEX
if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_complex)) {
@@ -239,8 +245,12 @@ STATIC void mp_obj_float_divmod(mp_float_t *x, mp_float_t *y) {
*y = mod;
}
-mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_in) {
- mp_float_t rhs_val = mp_obj_get_float(rhs_in); // can be any type, this function will convert to float (if possible)
+mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t rhs_in) {
+ mp_float_t rhs_val;
+ if (!mp_obj_get_float_maybe(rhs_in, &rhs_val)) {
+ return MP_OBJ_NULL; // op not supported
+ }
+
switch (op) {
case MP_BINARY_OP_ADD:
case MP_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break;
@@ -286,6 +296,13 @@ mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_i
if (lhs_val == 0 && rhs_val < 0) {
goto zero_division_error;
}
+ if (lhs_val < 0 && rhs_val != MICROPY_FLOAT_C_FUN(floor)(rhs_val)) {
+ #if MICROPY_PY_BUILTINS_COMPLEX
+ return mp_obj_complex_binary_op(MP_BINARY_OP_POWER, lhs_val, 0, rhs_in);
+ #else
+ mp_raise_ValueError("complex values not supported");
+ #endif
+ }
lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val);
break;
case MP_BINARY_OP_DIVMOD: {
diff --git a/py/objfun.c b/py/objfun.c
index 9f3589124..030b3f7cb 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,15 +28,13 @@
#include
#include
-#include "py/nlr.h"
#include "py/objtuple.h"
#include "py/objfun.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/bc.h"
#include "py/stackctrl.h"
-#if 0 // print debugging info
+#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
#else // don't print debugging info
#define DEBUG_PRINT (0)
@@ -480,7 +478,7 @@ typedef mp_uint_t (*inline_asm_fun_2_t)(mp_uint_t, mp_uint_t);
typedef mp_uint_t (*inline_asm_fun_3_t)(mp_uint_t, mp_uint_t, mp_uint_t);
typedef mp_uint_t (*inline_asm_fun_4_t)(mp_uint_t, mp_uint_t, mp_uint_t, mp_uint_t);
-// convert a Micro Python object to a sensible value for inline asm
+// convert a MicroPython object to a sensible value for inline asm
STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
// TODO for byte_array, pass pointer to the array
if (MP_OBJ_IS_SMALL_INT(obj)) {
diff --git a/py/objfun.h b/py/objfun.h
index 450c98f76..fbb351626 100644
--- a/py/objfun.h
+++ b/py/objfun.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objgenerator.c b/py/objgenerator.c
index 9d6e636b3..bf0bbb0e6 100644
--- a/py/objgenerator.c
+++ b/py/objgenerator.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,8 +28,6 @@
#include
#include
-#include "py/nlr.h"
-#include "py/obj.h"
#include "py/runtime.h"
#include "py/bc.h"
#include "py/objgenerator.h"
diff --git a/py/objgenerator.h b/py/objgenerator.h
index d61332a20..80bf9cd86 100644
--- a/py/objgenerator.h
+++ b/py/objgenerator.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c
index a3c754448..ec41c2c5b 100644
--- a/py/objgetitemiter.c
+++ b/py/objgetitemiter.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -26,7 +26,6 @@
#include
-#include "py/nlr.h"
#include "py/runtime.h"
// this is a wrapper object that turns something that has a __getitem__ method into an iterator
diff --git a/py/objint.c b/py/objint.c
index 2749ec51c..4f2e610a5 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,12 +28,10 @@
#include
#include
-#include "py/nlr.h"
#include "py/parsenum.h"
#include "py/smallint.h"
#include "py/objint.h"
#include "py/objstr.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/binary.h"
@@ -314,23 +312,13 @@ int mp_obj_int_sign(mp_obj_t self_in) {
}
}
-// This must handle int and bool types, and must raise a
-// TypeError if the argument is not integral
-mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
- mp_int_t val = mp_obj_get_int(self_in);
- if (val < 0) {
- val = -val;
- }
- return MP_OBJ_NEW_SMALL_INT(val);
-}
-
// This is called for operations on SMALL_INT that are not handled by mp_unary_op
-mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
+mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
return MP_OBJ_NULL; // op not supported
}
// This is called for operations on SMALL_INT that are not handled by mp_binary_op
-mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return mp_obj_int_binary_op_extra_cases(op, lhs_in, rhs_in);
}
@@ -382,7 +370,7 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
// This dispatcher function is expected to be independent of the implementation of long int
// It handles the extra cases for integer-like arithmetic
-mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
if (rhs_in == mp_const_false) {
// false acts as 0
return mp_binary_op(op, lhs_in, MP_OBJ_NEW_SMALL_INT(0));
diff --git a/py/objint.h b/py/objint.h
index f341306ed..4b95acde9 100644
--- a/py/objint.h
+++ b/py/objint.h
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -57,10 +57,9 @@ mp_int_t mp_obj_int_hash(mp_obj_t self_in);
mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf);
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf);
int mp_obj_int_sign(mp_obj_t self_in);
-mp_obj_t mp_obj_int_abs(mp_obj_t self_in);
-mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in);
-mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
-mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
+mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in);
+mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
+mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus);
#endif // MICROPY_INCLUDED_PY_OBJINT_H
diff --git a/py/objint_longlong.c b/py/objint_longlong.c
index 1d184a7dc..2e567c572 100644
--- a/py/objint_longlong.c
+++ b/py/objint_longlong.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,10 +28,8 @@
#include
#include
-#include "py/nlr.h"
#include "py/smallint.h"
#include "py/objint.h"
-#include "py/runtime0.h"
#include "py/runtime.h"
#if MICROPY_PY_BUILTINS_FLOAT
@@ -94,31 +92,7 @@ int mp_obj_int_sign(mp_obj_t self_in) {
}
}
-// This must handle int and bool types, and must raise a
-// TypeError if the argument is not integral
-mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
- if (MP_OBJ_IS_TYPE(self_in, &mp_type_int)) {
- mp_obj_int_t *self = self_in;
- self = mp_obj_new_int_from_ll(self->val);
- if (self->val < 0) {
- // TODO could overflow long long
- self->val = -self->val;
- }
- return self;
- } else {
- mp_int_t val = mp_obj_get_int(self_in);
- if (val == MP_SMALL_INT_MIN) {
- return mp_obj_new_int_from_ll(-val);
- } else {
- if (val < 0) {
- val = -val;
- }
- return MP_OBJ_NEW_SMALL_INT(val);
- }
- }
-}
-
-mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
+mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
mp_obj_int_t *o = o_in;
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->val != 0);
@@ -130,11 +104,21 @@ mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_int_from_ll(-o->val);
case MP_UNARY_OP_INVERT: return mp_obj_new_int_from_ll(~o->val);
+ case MP_UNARY_OP_ABS: {
+ mp_obj_int_t *self = MP_OBJ_TO_PTR(o_in);
+ if (self->val >= 0) {
+ return o_in;
+ }
+ self = mp_obj_new_int_from_ll(self->val);
+ // TODO could overflow long long
+ self->val = -self->val;
+ return MP_OBJ_FROM_PTR(self);
+ }
default: return MP_OBJ_NULL; // op not supported
}
}
-mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
long long lhs_val;
long long rhs_val;
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 26492aab4..7b5cb0b9d 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -1,5 +1,5 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
@@ -28,11 +28,9 @@
#include