本帖最后由 Vdragon 于 2025-10-29 13:26 编辑
你好,我在此分享关于Zephyr实时操作系统和MicroPython在Bouffalolab BL616/8及BL602(即M62、M61和WB2)上的开发成果。由于我不通晓中文,为避免糟糕的翻译造成阅读困扰,本文余下部分将以英文呈现。
Here is Micropython for the BFLB Ai-thinker modules and boards: https://github.com/VynDragon/bou ... g/future_preview002
It features all the basic functionalities of micropython such as saving files on filesystem and peripherals access, namely UART, I2C, SPI, GPIO. UART0 is used as the REPL.
On top of this, it features the following new things for Zephyr-Micropython:
- Dynamic pin assignment
- Machine code emitter (faster) for M61 and M62
- Overclocked versions for M61 and M62 (480MHz)
- PSRAM support for M61
- Filesystem backend is zephyr's
Please use bflb-mcu-tool-uart from bouffalolab to flash the firmware.
I recommend Ai-M61-32S (All) for best behavior, it is mostly tested on that.
Here are some example code using those features:
- from machine import Pin, I2C
- import ssd1306, sys
- scl = Pin(None, alt="GPIO28_I2C0_SCL", schmitt_enable=True, mode=0)
- sda = Pin(None, alt="GPIO13_I2C0_SDA", schmitt_enable=True, mode=0)
- dummy = Pin(("gpio0", 0), mode=0)
- dummy = Pin(("gpio0", 1), mode=0)
- # scl = Pin(None, alt="GPIO0_I2C0_SCL", schmitt_enable=True, mode=0)
- # sda = Pin(None, alt="GPIO1_I2C0_SDA", schmitt_enable=True, mode=0)
- # dummy = Pin(("gpio0", 28), mode=0)
- # dummy = Pin(("gpio0", 13), mode=0)
- i2c = I2C('i2c0', scl=scl, sda=sda, freq=100000)
- display = ssd1306.SSD1306_I2C(128, 64, i2c)
- display.text('Hello World', 0, 0, 1)
- display.text('----------------', 0, 8, 1)
- display.text(' From Python', 0, 16, 1)
- display.text(' On Zephyr', 0, 24, 1)
- display.text('Running on', 18, 32, 1)
- name = ""
- for c in sys.implementation._machine[7:]:
- if c != ' ':
- name = name + c
- else:
- break
- display.text('{}'.format(name), 64 - int(len(name) * 8 / 2), 40, 1)
- display.show()
复制代码
Result of this code with 0.96' SSD1315
- @micropython.viper
- def prime_viper(num:int) -> bool:
- if num == 1:
- return False
- for i in range(2, num):
- if (num % i) == 0:
- return False
- return True
- @micropython.native
- def prime_native(num:int) -> bool:
- if num == 1:
- return False
- for i in range(2, num):
- if (num % i) == 0:
- return False
- return True
- def prime_bc(num:int) -> bool:
- if num == 1:
- return False
- for i in range(2, num):
- if (num % i) == 0:
- return False
- return True
- def benchmark_viper():
- import time
- t = time.ticks_us()
- assert prime_viper(99929)
- t = time.ticks_diff(time.ticks_us(), t)
- print(f"viper prime() took {t/1000:6.3f}ms")
- def benchmark_native():
- import time
- t = time.ticks_us()
- assert prime_native(99929)
- t = time.ticks_diff(time.ticks_us(), t)
- print(f"native prime() took {t/1000:6.3f}ms")
- def benchmark_bc():
- import time
- t = time.ticks_us()
- assert prime_bc(99929)
- t = time.ticks_diff(time.ticks_us(), t)
- print(f"prime() took {t/1000:6.3f}ms")
- benchmark_viper()
- benchmark_native()
- benchmark_bc()
复制代码
List of possible pin assignements are listed in machine.Pin.Pinmux. Sometimes it is necessary to set the previously used pins to GPIO mode to have the peripherals work properly. If you are having issues with _OC overclocked firmware, use the other firmware.
|