예전에 stellarisware(ti/cortex-m3) 쓸 때 이런 컨셉이 있었던 것 같은데, 플래시 용량 줄이는 것 외에는 큰 메리트가 있는지
몰랐는데 아키텍쳐의 차이인진 모르겠지만 벤치마크를 보니 꽤나 혹한다.
2.7.2. Floating-point Support The SDK provides a highly optimized single and double precision floating point implementation. In addition to being fast, many of the functions are actually implemented using support provided in the RP2040 bootrom. This means the interface from your code to the ROM floating point library has very minimal impact on your program size, certainly using dramatically less flash storage than including the standard floating point routines shipped with your compiler. The physical ROM storage on RP2040 has single-cycle access (with a dedicated arbiter on the RP2040 busfabric), and accessing code stored here does not put pressure on the flash cache or take up space in memory, so not only are the routines fast, the rest of your code will run faster due them being resident in ROM. This implementation is used by default as it is the best choice in the majority of cases, however it is also possible to switch to using the regular compiler soft floating point support.
bootrom에 있는 함수들을 이용하면 더욱 빠르게 부동소수점 연산이 가능하다는데
나누기 연산의 경우 GCC 라이브러리에 비해서 586% 감소한다고
아래 두개는 먼가 미친듯한 성능 차이가 있어서 끌어 와봄.
Function ROM/SDK (μs) GCC 9 (μs) Performance Ratio __aeabi_fdiv 74.7 437.5 586% __aeabi_f2lz 63.1 1240.5 1966% __aeabi_f2ulz 46.1 1157 2510%
27페이지에 나오는 내용인데(2021.07.07 기준)
GCC 라이브러리를 사용하여 계산하는 것과
SDK 라이브러리(RP2040 hardware divider)를 이용하는 것의 속도 차이가 어마어마하다고 한다.
while True:
# Check each pin
for key_pin in key_pin_array:
if not key_pin.value: # Is it grounded?
i = key_pin_array.index(key_pin)
print("Pin #{} is grounded.".format(i))
# Turn on the red LED
led.value = True
while not key_pin.value:
pass # Wait for it to be ungrounded!
# "Type" the Keycode or string
key = keys_pressed[i] # Get the corresponding Keycode or string
if isinstance(key, str): # If it's a string...
keyboard_layout.write(key) # ...Print the string
else: # If it's not a string...
keyboard.press(control_key, key) # "Press"...
keyboard.release_all() # ..."Release"!
# Turn off the red LED
led.value = False
time.sleep(0.01)
아무튼.. 원래 의도는 3V 전원에서 330옴 통해서 전류 제한해서 gpio로 3.3V가 들어가게 하는거였는데
import board import digitalio import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS from adafruit_hid.keycode import Keycode
# The Keycode sent for each button, will be paired with a control key keys_pressed = [Keycode.A, "Hello World!\n"] control_key = Keycode.SHIFT
# The keyboard object! time.sleep(1) # Sleep for a bit to avoid a race condition on some systems keyboard = Keyboard(usb_hid.devices) keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
while True: keyboard_layout.write('A') time.sleep(0.01)
Hello world 출력하는 키보드(!) 예제 ㅋㅋ
import time
import board import digitalio import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS from adafruit_hid.keycode import Keycode
# The keyboard object! time.sleep(1) # Sleep for a bit to avoid a race condition on some systems keyboard = Keyboard(usb_hid.devices) keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
VBUS(GP40, 우측 상단)에 연결하면 USB Host 모드로만 작동해야 한다는 의미 같은데
아마 USB device 모드라면 USB를 통해 전원을 입력받아야 하기 때문이려나?
Whilst it is possible to connect the Raspberry Pi’s 5V pin to the Raspberry Pi Pico VBUS pin, this is not recommended. Shorting the 5V rails together will mean that the Micro USB cannot be used. An exception is when using the Raspberry Pi Pico in USB host mode, in this case 5V must be connected to the VBUS pin.
GP0이 TX GP1이 RX
LED는 GPIO25에 연결되어 있고, TP5로도 연결이 되어있는데
BOOTSEL은 TP6에만 되어있고 GPIO로 연결은 되어 있지 않다.
TP1 – Ground (close coupled ground for differential USB signals) TP2 – USB DM TP3 – USB DP TP4 – GPIO23/SMPS PS pin (do not use) TP5 – GPIO25/LED (not recommended to be used) TP6 – BOOTSEL
[ 44.398531] usb 2-1.2: new full-speed USB device number 4 using ehci-pci [ 44.508833] usb 2-1.2: New USB device found, idVendor=2e8a, idProduct=0005, bcdDevice= 1.00 [ 44.508840] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 44.508845] usb 2-1.2: Product: Board in FS mode [ 44.508848] usb 2-1.2: Manufacturer: MicroPython [ 44.508852] usb 2-1.2: SerialNumber: e6609cb2d3440b2a [ 44.535497] cdc_acm 2-1.2:1.0: ttyACM0: USB ACM device [ 44.536117] usbcore: registered new interface driver cdc_acm [ 44.536119] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
동영상에서 본대로 해보니 되는데 일단은 ttyACM0을 sudo 없이 여는 법을 찾아봐야...(휠 설정을 찾아야 하나)
아무튼 rshell을 통해서 접속하면 /pyboard 라는 경로가 생기는데 이쪽으로 복사해야 된다.
USB 저장장소로 인식되는 건.. 펌웨어만 올리는 용도인가?
$ sudo pip3 install rshell Collecting rshell Downloading rshell-0.0.30.tar.gz (51 kB) |████████████████████████████████| 51 kB 514 kB/s Collecting pyserial Downloading pyserial-3.5-py2.py3-none-any.whl (90 kB) |████████████████████████████████| 90 kB 2.8 MB/s Collecting pyudev>=0.16 Downloading pyudev-0.22.0.tar.gz (85 kB) |████████████████████████████████| 85 kB 2.3 MB/s Requirement already satisfied: six in /usr/lib/python3/dist-packages (from pyudev>=0.16->rshell) (1.14.0) Building wheels for collected packages: rshell, pyudev Building wheel for rshell (setup.py) ... done Created wheel for rshell: filename=rshell-0.0.30-py3-none-any.whl size=52770 sha256=69461b75172bb35e222ba9bfd46158ac9463367a21b39f76cc59b930ecf91e60 Stored in directory: /root/.cache/pip/wheels/e4/ac/b5/2937f0e9ff638dc7ee71168edfa9245ca968438f4a3f7dff9d Building wheel for pyudev (setup.py) ... done Created wheel for pyudev: filename=pyudev-0.22.0-py3-none-any.whl size=63469 sha256=fad8e733a62171573d784a43062b27df75b2d4117cd364e446804b9210c93b2b Stored in directory: /root/.cache/pip/wheels/8b/d1/11/6a9855487e4bba54c63dfb07a09505787d50a5e27f90b0af33 Successfully built rshell pyudev Installing collected packages: pyserial, pyudev, rshell Successfully installed pyserial-3.5 pyudev-0.22.0 rshell-0.0.30
$ sudo rshell Connecting to /dev/ttyACM0 (buffer-size 128)... Trying to connect to REPL connected Retrieving sysname ... rp2 Testing if sys.stdin.buffer exists ... Y Retrieving root directories ... Setting time ... Jun 24, 2021 12:31:53 Evaluating board_name ... pyboard Retrieving time epoch ... Jan 01, 1970 Welcome to rshell. Use Control-D (or the exit command) to exit rshell. /home/minimonk> ls -al main.py 166 Jun 24 12:31 main.py /home/minimonk> ls -al /pyboard/ /home/minimonk> mount Unrecognized command: mount /home/minimonk> cp main.py /pyboard/main.py Copying '/home/minimonk/main.py' to '/pyboard/main.py' ... /home/minimonk> exit
$
+
thonny 를 윈도우에 깔고 시작!
음.. initial settings에 standard와 raspberry pi가 있는데 일단은.. pico가 라즈베리일려나?
Switch to regular mode 버튼을 눌러보면
tools - options - general 에 가서 바꿀수 있다는데 라즈베리 파이 모드에서는 안뜨는 메뉴인듯
재시작해보면 달라지긴 한데..
UI만 달라졌을뿐 큰 차이는 없는 듯?
암튼 우측 하단에 Python 이라고 된 걸 클릭해서
MicroPython (Raspberry Pi Pico) 로 바꾸면 설정 끝
빈걸 저장 눌러보니 어디다 저장할지 물어보는데 "Raspberry Pi Pico"를 누르면
데이터 시트 찾아보니 main.py를 쓰면 된다고 언급되어 있다. (최상위 디렉토리에 넣으면 안되는건가? 왜 안되지? ㅠㅠ)
If you "save a file to the device" and give it the special name main.py, then MicroPython starts running that script as soon as power is supplied to Raspberry Pi Pico in the future.