43浏览
查看: 43|回复: 0

[教程] 树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试

[复制链接]
本帖最后由 yiD31Agzr1kQ 于 2025-5-3 05:39 编辑

树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试

近期有幸体验了DFRobot推出的Beetle-RP2350微型开发板,这款仅硬币大小的开发板给我留下了深刻印象。作为一款基于树莓派RP2350微控制器的产品,它拥有以下核心特性:
- 双核双架构,Arm Cortex-M33或Hazard3 RISC-V内核
- 150MHz主频,520KB RAM,2MB flash。

树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试图1

浏览了一下社区中关于Arduino生态的内容较为丰富,但出于对MicroPython的偏好,我决定采用MicroPython作为开发环境。本文将介绍在MacOS系统下搭建开发环境的完整过程,并通过基准测试其性能表现。




前期准备

开发环境如下

  • 系统: MacOS Catalina 10.15.7
  • IDE: PyCharm Pro + MicroPython + Tabby(终端工具)
  • 硬件: Beetle-RP2350

相关资料

1. 官方资料: https://www.raspberrypi.com/documentation/microcontrollers/silicon.html#rp2350

2. 固件地址:
  • https://micropython.org/download/?mcu=rp2350
  • https://micropython.org/download/RPI_PICO2/

3. MicroPython 教程地址: https://docs.micropython.org/en/latest/rp2/quickref.html

环境搭建

树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试图6

根据 MicroPython 官方文档指导,可以将RP2350连上USB进入大容量设备模式(类似于U盘),将下载好的固件( RPI_PICO2-20250415-v1.25.0.uf2 )拷贝进去即烧录成功自动重启。


1. 进入大容量模式:按住 BOOT 不放 + 点按 RST
2. 拖动拷贝固件到 `RP2350` 盘符,完成之后会自动弹出该盘符
3. 按下 RST 复位

树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试图5

上机测试

点灯测试

  1. from machine import Pin  
  2. import time  
  3. LED = Pin(25, Pin.OUT)  
  4. while True:  
  5.     LED.on()  
  6.     time.sleep(1)  
  7.     LED.off()  
  8.     time.sleep(1)
复制代码


树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试图3

树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试图2


跑分测试

摘录了以下RP2350和RP2040的性能表格,但是实际我这边测试出来与给出有点出入,仅供参考,建议以C/C++进行基准测试。

测试涵盖:
1. 基础运算性能(整数/浮点)
2. 复杂算法处理(Mandelbrot集计算)
3. 高精度计算(π值计算)

+ BenchMark: https://github.com/shaoziyang/micropython_benchmarks

树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试图7

注: 时间单位ms, 越小则性能越好。

BenchMark:
  1. '''  
  2.     Simple benchmark for micropython and circuitpython.  
  3.     Compare the performance of different MCUs by performing operations such as addition, multiplication, exponentiation, complex numbers, and pi.  
  4. '''  
  5. import sys  
  6. import gc  
  7. try:  
  8.     from time import ticks_ms, ticks_diff  
  9.     import machine  
  10.     TEST_ENV = 'micropython'  
  11.     def freq():  
  12.         try:  
  13.             f = machine.freq() // 1000000  
  14.         except:  
  15.             f = machine.freq()[0] // 1000000  
  16.         return f  
  17. except:  
  18.     from time import monotonic_ns  
  19.     def ticks_ms():  
  20.         return monotonic_ns() // 1000000  
  21.     def ticks_diff(T2, T1):  
  22.         return T2 - T1  
  23.     try:  
  24.         import board  
  25.         TEST_ENV = 'circuitpython'  
  26.         import microcontroller  
  27.         def freq():  
  28.             return microcontroller.cpu.frequency // 1000000  
  29.     except:  
  30.         TEST_ENV = 'OTHER'  
  31.         try:  
  32.             import psutil  
  33.             def freq():  
  34.                 return psutil.cpu_freq().max  
  35.         except:  
  36.             def freq():  
  37.                 return 'unknow'  
  38. def memory():  
  39.     try:  
  40.         r = gc.mem_free() + gc.mem_alloc()  
  41.     except:  
  42.         try:  
  43.             r = psutil.virtual_memory().total  
  44.         except:  
  45.             r = 'unkonw'  
  46.     return r  
  47. PLATFORM = sys.platform  
  48. VERSION = sys.version  
  49. FREQ = freq()  
  50. MEMORY = memory()  
  51. def run_test(func, *param):  
  52.     gc.collect()  
  53.     try:  
  54.         t1 = ticks_ms()  
  55.         if param == None:  
  56.             func()  
  57.         else:  
  58.             func(*param)  
  59.         t2 = ticks_ms()  
  60.         dt = ticks_diff(t2, t1)  
  61.         print('Calculation time:', dt, 'ms\n')  
  62.         return dt  
  63.     except:  
  64.         print('Error occurred during operation!')  
  65. def mandelbrot_test(p):  
  66.     iter = p[0]  
  67.     def in_set(c):  
  68.         z = 0  
  69.         for i in range(iter):  
  70.             z = z * z + c  
  71.             if abs(z) > 4:  
  72.                 return False  
  73.         return True  
  74.     r = ''  
  75.     for v in range(31):  
  76.         for u in range(81):  
  77.             if in_set((u / 30 - 2) + (v / 15 - 1) * 1j):  
  78.                 r += ' '  
  79.             else:  
  80.                 r += '#'  
  81.         r += '\n'  
  82.     if len(p) > 1 and p[1]:  
  83.         print(r)  
  84. def pi_test(p):  
  85.     iter = p[0]  
  86.     extra = 8  
  87.     one = 10 ** (iter + extra)  
  88.     t, c, n, na, d, da = 3 * one, 3 * one, 1, 0, 0, 24  
  89.     while t > 1:  
  90.         n, na, d, da = n + na, na + 8, d + da, da + 32  
  91.         t = t * n // d  
  92.         c += t  
  93.     return c // (10 ** extra)  
  94. def add_test(p):  
  95.     for i in range(p[0]):  
  96.         C = p[1] + p[2]  
  97. def mul_test(p):  
  98.     for i in range(p[0]):  
  99.         C = p[1] * p[2]  
  100. def div_test(p):  
  101.     for i in range(p[0]):  
  102.         C = p[1] / p[2]  
  103. def pow_test(p):  
  104.     for i in range(p[0]):  
  105.         C = p[1] ** p[2]  
  106. INT_ADD_TEST_LIST = ('Integer addition {} times', add_test, [12345678, 56781234], 10000, 100000, 1000000)  
  107. INT_MUL_TEST_LIST = ('Integer multiplication {} times', mul_test, [12345678, 56781234], 10000, 100000, 1000000)  
  108. INT_DIV_TEST_LIST = ('Integer division {} times', div_test, [99999991, 45481], 10000, 100000, 1000000)  
  109. FLOAT_ADD_TEST_LIST = ('Float addition {} times', add_test, [12345678.1234, 56781234.5678], 10000, 100000, 1000000)  
  110. FLOAT_MUL_TEST_LIST = (  
  111. 'Float multiplication {} times', mul_test, [12345678.1234, 56781234.5678], 10000, 100000, 1000000)  
  112. FLOAT_DIV_TEST_LIST = ('Float division {} times', div_test, [99999991.2345, 45481.1357], 10000, 100000, 1000000)  
  113. POWER_TEST_LIST = ('Power calculation {} times', pow_test, [1234.5678, 2.3456], 10000, 100000, 1000000)  
  114. MAND_TEST_LIST = ('Mandelbrot iterating {} times', mandelbrot_test, [], 100, 500, 5000)  
  115. PI_TEST_LIST = ('Pi Calculation {} bits', pi_test, [], 1000, 5000, 10000, 100000, 200000)  
  116. TEST_LIST = (  
  117.     INT_ADD_TEST_LIST, INT_MUL_TEST_LIST, INT_DIV_TEST_LIST,  
  118.     FLOAT_ADD_TEST_LIST, FLOAT_MUL_TEST_LIST, FLOAT_DIV_TEST_LIST,  
  119.     POWER_TEST_LIST,  
  120.     MAND_TEST_LIST,  
  121.     PI_TEST_LIST  
  122. )  
  123. tr = []  
  124. def run():  
  125.     global tr  
  126.     for TEST in TEST_LIST:  
  127.         for item in TEST:  
  128.             if type(item) == int:  
  129.                 print(TEST[0].format(item))  
  130.                 p = TEST[2].copy()  
  131.                 p.insert(0, item)  
  132.                 r = run_test(TEST[1], p)  
  133.                 tr.append([TEST[0].format(item), str(r)])  
  134. def print_result():  
  135.     r1 = '| item | Platform | Version | Frequency | Memory |'  
  136.     r2 = '| - | - | - | - | - |'  
  137.     r3 = '| {} | {} | {} | {} | {} |'.format('result', PLATFORM, VERSION, FREQ, MEMORY)  
  138.     for i in range(len(tr)):  
  139.         r1 += ' {} |'.format(tr[0])  
  140.         r2 += ' - |'  
  141.         r3 += ' {} |'.format(tr[1])  
  142.     print(r1)  
  143.     print(r2)  
  144.     print(r3)  
  145. ###############################################################################  
  146. print('\n\n')  
  147. print('##############')  
  148. print('# Begin test #')  
  149. print('##############')  
  150. print('\nEnvironment:', TEST_ENV)  
  151. print('Platform:', PLATFORM)  
  152. print('Version:', VERSION)  
  153. print('Frequency:', FREQ)  
  154. print('Memory:', MEMORY)  
  155. print()  
  156. run()  
  157. print('\nTest finished.')  
  158. print('==============')  
  159. print_result()
复制代码



树莓派 Beetle-RP2350 MacOS开发环境搭建及跑分测试图4

串口运行结果日志:
  1. Calculation time: 4259 ms                                                                                                   
  2. Integer multiplication 10000 times                                                                                          
  3. Calculation time: 161 ms                                                                                                   
  4. Integer multiplication 100000 times                                                                                         
  5. Calculation time: 1628 ms                                                                                                   
  6. Integer multiplication 1000000 times                                                                                       
  7. Calculation time: 16284 ms                                                                                                  
  8. Integer division 10000 times                                                                                                
  9. Calculation time: 62 ms                                                                                                     
  10. Integer division 100000 times                                                                                               
  11. Calculation time: 639 ms                                                                                                   
  12. Integer division 1000000 times                                                                                             
  13. Calculation time: 6400 ms                                                                                                   
  14. Float addition 10000 times                                                                                                  
  15. Calculation time: 69 ms                                                                                                     
  16. Float addition 100000 times                                                                                                
  17. Calculation time: 708 ms                                                                                                   
  18. Float addition 1000000 times                                                                                                
  19. Calculation time: 7094 ms                                                                                                   
  20. Float multiplication 10000 times                                                                                            
  21. Calculation time: 70 ms                                                                                                     
  22. Float multiplication 100000 times                                                                                          
  23. Calculation time: 710 ms                                                                                                   
  24. Float multiplication 1000000 times                                                                                          
  25. Calculation time: 7108 ms                                                                                                   
  26. Float division 10000 times                                                                                                  
  27. Calculation time: 71 ms                                                                                                     
  28. Float division 100000 times                                                                                                
  29. Calculation time: 720 ms                                                                                                   
  30. Float division 1000000 times                                                                                                
  31. Calculation time: 7208 ms                                                                                                   
  32. Power calculation 10000 times                                                                                               
  33. Calculation time: 116 ms                                                                                                   
  34. Power calculation 100000 times                                                                                             
  35. Calculation time: 1174 ms                                                                                                   
  36. Power calculation 1000000 times                                                                                             
  37. Calculation time: 11755 ms                                                                                                  
  38. Mandelbrot iterating 100 times                                                                                             
  39. Calculation time: 2608 ms                                                                                                   
  40. Mandelbrot iterating 500 times                                                                                             
  41. Calculation time: 9103 ms                                                                                                   
  42. Mandelbrot iterating 5000 times                                                                                             
  43. Calculation time: 81708 ms                                                                                                  
  44. Pi Calculation 1000 bits                                                                                                   
  45. Calculation time: 349 ms                                                                                                   
  46. Pi Calculation 5000 bits                                                                                                   
  47. Calculation time: 21192 ms                                                                                                  
  48. Pi Calculation 10000 bits                                                                                                   
  49. Calculation time: 58155 ms                                                                                                  
  50. Pi Calculation 100000 bits
复制代码



跑分结论大致如下:
  • CircuitPython(适用于大多数场景): 浮点运算速度快、内存占用低,运行复杂算法(如分形、高精度计算),推荐科学计算、图形渲染等场景。
  • MicroPython: 整数运算速度快(如嵌入式控制、传感器数据处理),短任务响应更敏感(如快速初始化)。

尾言

通过本次完整的开发体验,Beetle-RP2350展现出了优异的性能表现和开发便利性。其双核架构在保持低功耗的同时,提供了显著的性能提升。MicroPython生态的成熟度也使得快速原型开发成为可能。对于嵌入式开发者而言,这款开发板在物联网终端、智能控制等领域都具有广阔的应用前景。

> 后续计划:将进行环境监测系统实验,欢迎关注项目更新。





作者: Suroy |个人博客同步更新: https://suroy.cn/embeded/raspberry-pi-beetlerp2350-macos-development-environment-setup-and-benchmark-testing.html













您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail