Skip to content

Commit

Permalink
w60x: Some small changes, including re-enabling machine.reset().
Browse files Browse the repository at this point in the history
- Rework README.md.
- Make README.md and Makefile consistent.
- Re-arrange the include section of main.c, machine_rtc.c and
  fatfs_port.c. Remove wm_include.h from main.c and modtime.c.
- Include stdint.h in mpconfigport.h which is needed by newer compilers.
- Add a LED pin to WAVGAT_AIR602/pins.csv. That LED exists at the
  otherwise compatible Thingsturn TB02 board.
- clear the Pin IRQ status flag when enabling/disabling Pin IRQ,
  avoiding false triggers.
- Re-enable machine.reset().

Signed-off-by: robert-hh <robert@hammelrath.com>
  • Loading branch information
robert-hh committed Jun 11, 2024
1 parent 83cf0d2 commit 3a6dcbe
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ports/w60x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ MICROPY_USE_FATFS ?= 0
MICROPY_USE_LITTLEFS = 1
MICROPY_PY_THREAD ?= 0
MACHINE_HSPI ?= 0
CODESIZE ?= 0xc0000 # 768 k reserved for code
CODESIZE ?= 0xb0000 # 704 k reserved for code

MICROPY_PY_SSL ?= 1
ifeq ($(MICROPY_PY_SSL),1)
Expand Down
45 changes: 26 additions & 19 deletions ports/w60x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ There are two main things to do here:
- Download WM_SDK and add to environment variables

The cross toolchain used is arm-none-eabi-gcc version where the download address is
[GNU Arm Embedded Toolchain](https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major)
[GNU Arm Embedded Toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads)

You will need to update your `PATH` environment variable to include the cross toolchain. For example, you can issue the following commands on (at least) Linux:

$ export PATH=$PATH:/opt/tools/arm-none-eabi-gcc/bin

You can put this command in your `.profile` or `.bash_login` (or `.bashrc` if using Github code-spaces).

WM_SDK initially required the 4.x version of the GCC cross-compiler for compiling. Note also that version 4.x of the cross-compiler is 32bit and you may need `sudo apt install lib32z1` if running on a 64bit Linux host (test by running `arm-none-eabi-gcc --version` -- if it runs, you're fine; if you get a bash "No such file or directory", first double check your $PATH and, if $PATH is correct, then it's the 32bit issue).
Newer 64 bit versions of the GCC cross compiler like 8.3, 10.3 and 11.2 have been verified to work as well.
64 bit versions of the GCC cross compiler as of 10.3, 11.2, and 12.2 have been verified to work. Building with gcc-arm-none-eabi version 13.2 fails.

WM_SDK download address is [W60X_SDK](http://www.winnermicro.com/en/html/1/156/158/497.html), under the Software Data tab. WM_SDK must be G3.01 and newer versions (G3.04 is latest as of end of 2022). You can also consider using the Github repo https://github.com/robert-hh/WM_SDK_W60X.
The initial version of the WM_SDK is located at [W60X_SDK](http://www.winnermicro.com/en/html/1/156/158/497.html), under the Software Data tab. WM_SDK must be G3.01 and newer versions (G3.04 is latest as of end of 2022).
**Since then a few changes have been made to the SDK. The updated version is at https://github.com/robert-hh/WM_SDK_W60X.**

You will need to update your `PATH` environment variable to include the path of WM_SDK. For example, you can issue the following commands on (at least) Linux:

Expand All @@ -70,15 +70,16 @@ The recommended components that can be turned off are:
Building the firmware
---------------------

Build MicroPython for a generic board:
```
bash
$ cd mpy-cross
$ make
$ cd ports/w60x
$ make submodules
$ make V=s BOARD=GENERIC
Clone the MicroPython and WM_SDK repositories and build MicroPython for a generic board:
```bash
git clone https://github.com/robert-hh/WM_SDK_W60X
export WMSDK_PATH=/your-path-to-the-current-directory/WM_SDK_W60X
git clone -b w60x https://github.com/robert-hh/micropython.git
cd micropython/mpy-cross
make
cd ../ports/w60x
make submodules
make BOARD=GENERIC
```
This will produce binary firmware images in the `build-GENERIC` subdirectory.
There are several options that can be modified in the Makefile.
Expand All @@ -103,12 +104,19 @@ The option

has to be set in FreeRTOS.h. Otherwise the firmware build fails.

Site specific definitions
-------------------------

If the build environments requires changes to the header files, these
can be placed into a file mpconfigsite.h, which will be included
at the top of mpconfigboard.h if it exists.

Makefile build options
----------------------

Make is called in the form:

make option1=value1 option2=value2 .... V=s target
make option1=value1 option2=value2 .... target

Options:

Expand All @@ -117,13 +125,13 @@ BOARD ?= GENERIC
Specifies the board for which the binary is built. The only
difference will be the Pin.board set of names.

SECBOOT ?= 0
SECBOOT ?= 1

Controls the use of the secondary bootloader by the firmware and
the bootloader. Without the secondary bootloader, 56k more space
is available for the flash file system.

CODESIZE ?= 0xc0000
CODESIZE ?= 0xb0000

The amount of flash reserved for the MicroPython code. Lowering
it increases the size of the flash file system, and the opposite.
Expand Down Expand Up @@ -160,9 +168,8 @@ Flashing the Firmware
-----------------------

To upload the firmware to the target board, please use the command
```
bash
make V=s flash
```bash
make flash
```
Some boards like the Wemos W600 require pushing reset at the start of the upload while the
upload tool waits for synchronisation with the target board.
Expand Down
1 change: 1 addition & 0 deletions ports/w60x/boards/WAVGAT_AIR602/pins.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CTS,PB9
RTS,PB10
RX1,PB11
TX1,PB12
LED,PB18
5 changes: 0 additions & 5 deletions ports/w60x/hal/fatfs_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "wm_sockets2.0.3.h"
#include <sys/time.h>

#include "wm_include.h"
#include "wm_rtc.h"
#include "modmachine.h"

#include "lib/oofatfs/ff.h"
#include "shared/timeutils/timeutils.h"

Expand Down
2 changes: 2 additions & 0 deletions ports/w60x/machine/machine_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,11 @@ static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_

if (handler != mp_const_none) {
tls_gpio_isr_register(self->id, machine_pin_isr_handler, irq);
tls_clr_gpio_irq_status(self->id);
tls_gpio_irq_enable(self->id, trigger - 1);
} else {
tls_gpio_irq_disable(self->id);
tls_clr_gpio_irq_status(self->id);
tls_gpio_isr_register(self->id, 0, 0);
}
}
Expand Down
8 changes: 3 additions & 5 deletions ports/w60x/machine/machine_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@
* THE SOFTWARE.
*/

#include "wm_include.h"
#include "wm_rtc.h"

#include "py/obj.h"
#include "py/runtime.h"
#include "py/obj.h"
#include "timeutils.h"

#include "extmod/modmachine.h"
#include "modmachine.h"

#include "wm_rtc.h"

typedef struct _machine_rtc_obj_t {
mp_obj_base_t base;
mp_uint_t alarm_seconds;
Expand Down
6 changes: 3 additions & 3 deletions ports/w60x/machine/machine_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define DEFAULT_SPI_FIRSTBIT (MICROPY_PY_MACHINE_SPI_MSB)

// Block SPI_DMA_TRANSFER since it is not working as expected.
// SPI_DMA_TRANSFER requires tranfer slicing to be enabled.
// SPI_DMA_TRANSFER requires transfer slicing to be enabled.
#define ENABLE_SPI_DMA_TRANSFER (0)

typedef struct _machine_spi_obj_t {
Expand Down Expand Up @@ -113,7 +113,7 @@ static u8 w600_spi_write(u8 *data, u32 len) {
cnt += SPI_DMA_BUF_MAX_SIZE;
}
}

return tls_spi_write(data + cnt, remain);
#else
return tls_spi_write(data, len);
Expand Down Expand Up @@ -320,7 +320,7 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
self->bits = DEFAULT_SPI_BITS;
self->firstbit = DEFAULT_SPI_FIRSTBIT;
self->sck = WM_IO_PB_16;
self->mosi = WM_IO_PB_18;
self->mosi = WM_IO_PB_18;
self->miso = WM_IO_PB_17;
self->cs = 0;
mp_map_t kw_args;
Expand Down
3 changes: 1 addition & 2 deletions ports/w60x/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* All rights reserved.
*
*****************************************************************************/
#include "py/runtime.h"
#include <string.h>
#include "wm_include.h"
#include "wm_mem.h"
#include "wm_crypto_hard.h"
#include "wm_rtc.h"
Expand All @@ -18,7 +18,6 @@
#include "py/stackctrl.h"
#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
#include "py/gc.h"
#include "py/mphal.h"
Expand Down
1 change: 0 additions & 1 deletion ports/w60x/modules/modtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "wm_include.h"
#include "wm_rtc.h"
#include "py/obj.h"
#include "shared/timeutils/timeutils.h"
Expand Down
2 changes: 2 additions & 0 deletions ports/w60x/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// overriding defaults in py/mpconfig.h.
// Board specific definitions
#include "mpconfigboard.h"
#include <stdint.h>

#define MICROPY_W600_VERSION "B1.6"

Expand Down Expand Up @@ -61,6 +62,7 @@
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/w60x/modules/modmachine.c"
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
#define MICROPY_PY_MACHINE_RESET (1)
#define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1)
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
#define MICROPY_PY_MACHINE_IRQ_TIMESTAMP (1)
Expand Down

0 comments on commit 3a6dcbe

Please sign in to comment.