发帖
7 2 1

Micropython AI-M61, AI-M62, AI-WB2

Vdragon
新手上路

0

主题

0

回帖

10

积分

新手上路

积分
10
Ai-M61系列 56 7 4 小时前
本帖最后由 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:
  1. from machine import Pin, I2C
  2. import ssd1306, sys

  3. scl = Pin(None, alt="GPIO28_I2C0_SCL", schmitt_enable=True, mode=0)
  4. sda = Pin(None, alt="GPIO13_I2C0_SDA", schmitt_enable=True, mode=0)
  5. dummy = Pin(("gpio0", 0), mode=0)
  6. dummy = Pin(("gpio0", 1), mode=0)

  7. # scl = Pin(None, alt="GPIO0_I2C0_SCL", schmitt_enable=True, mode=0)
  8. # sda = Pin(None, alt="GPIO1_I2C0_SDA", schmitt_enable=True, mode=0)
  9. # dummy = Pin(("gpio0", 28), mode=0)
  10. # dummy = Pin(("gpio0", 13), mode=0)

  11. i2c = I2C('i2c0', scl=scl, sda=sda, freq=100000)
  12. display = ssd1306.SSD1306_I2C(128, 64, i2c)

  13. display.text('Hello World', 0, 0, 1)
  14. display.text('----------------', 0, 8, 1)
  15. display.text('  From Python', 0, 16, 1)
  16. display.text('   On Zephyr', 0, 24, 1)
  17. display.text('Running on', 18, 32, 1)
  18. name = ""
  19. for c in sys.implementation._machine[7:]:
  20.         if c != ' ':
  21.                 name = name + c
  22.         else:
  23.                 break
  24. display.text('{}'.format(name), 64 - int(len(name) * 8 / 2), 40, 1)
  25. display.show()

复制代码

Result of this code with 0.96' SSD1315
IMG_20251029_062210.jpg

  1. @micropython.viper
  2. def prime_viper(num:int) -> bool:
  3.     if num == 1:
  4.         return False
  5.     for i in range(2, num):
  6.         if (num % i) == 0:
  7.             return False
  8.     return True

  9. @micropython.native
  10. def prime_native(num:int) -> bool:
  11.     if num == 1:
  12.         return False
  13.     for i in range(2, num):
  14.         if (num % i) == 0:
  15.             return False
  16.     return True

  17. def prime_bc(num:int) -> bool:
  18.     if num == 1:
  19.         return False
  20.     for i in range(2, num):
  21.         if (num % i) == 0:
  22.             return False
  23.     return True

  24. def benchmark_viper():
  25.     import time
  26.     t = time.ticks_us()
  27.     assert prime_viper(99929)
  28.     t = time.ticks_diff(time.ticks_us(), t)
  29.     print(f"viper prime() took {t/1000:6.3f}ms")

  30. def benchmark_native():
  31.     import time
  32.     t = time.ticks_us()
  33.     assert prime_native(99929)
  34.     t = time.ticks_diff(time.ticks_us(), t)
  35.     print(f"native prime() took {t/1000:6.3f}ms")

  36. def benchmark_bc():
  37.     import time
  38.     t = time.ticks_us()
  39.     assert prime_bc(99929)
  40.     t = time.ticks_diff(time.ticks_us(), t)
  41.     print(f"prime() took {t/1000:6.3f}ms")

  42. benchmark_viper()
  43. benchmark_native()
  44. 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.
──── 2人觉得很赞 ────

使用道具 举报

Wow! Your work is amazing and gives us new insights. Thank you—looking forward to more of your posts!🥰
Nice work
well done!!!
Amazing !thank You!
Nobody knows MicroPython better than I do, except you!
特朗普 发表于 2025-10-29 16:17
Nobody knows MicroPython better than I do, except you!

Hello,Trump!
Good job
您需要登录后才可以回帖 立即登录
高级模式
返回
统计信息
  • 会员数: 30050 个
  • 话题数: 44034 篇