概要
micropythonでshrike-lite、やってみた。
spi見つけたので、pythonから叩いてみた。
参考にしたページ
サンプルコード
from machine import Pin, SPI
import time
import shrike
SCK = 2
CS = 1
MOSI = 3
MISO = 0
FPGA_RESET = 14
print("ok0")
shrike.reset()
shrike.flash("template.bin")
print("ok1")
reset_pin = Pin(FPGA_RESET, Pin.OUT, value = 1)
reset_pin.value(0)
time.sleep_ms(100)
reset_pin.value(1)
time.sleep_ms(100)
cs = Pin(CS, Pin.OUT, value = 1)
spi = SPI(0, baudrate = 1_000_000, polarity = 0, phase = 0, bits = 8, firstbit = SPI.MSB, sck = Pin(SCK), mosi = Pin(MOSI), miso = Pin(MISO))
print("ok2")
def spi_exchange(value):
tx = bytes([value])
rx = bytearray(1)
cs.value(0)
spi.write_readinto(tx, rx)
cs.value(1)
return rx[0]
patterns = [0x00, 0x12, 0x7F, 0xFF]
expected_rx = 0x00
def test():
global expected_rx
for value in patterns:
received = spi_exchange(value)
result = "PASS" if received == expected_rx else "FAIL"
print("TX: 0x{:02X} RX: 0x{:02X} EXPECT: 0x{:02X} {}".format(value, received, expected_rx, result))
expected_rx = (value + 1) & 0xFF
time.sleep_ms(100)
print("ok3")
実行結果
>shrike0
Port open ok
ok0
[shrike_flash] FPGA reset done
[shrike_flash] FPGA reset Starting FPGA flash...
[shrike_fpga] flashing: template.bin
[shrike_flash] FPGA programming done.
ok1
ok2
ok3
MicroPython v1.26.0-preview.527.g599f545a3.dirty on 2025-10-11; Vicharak Shrike FPGA with RP2040
Type "help()" for more information.
test()
>>> test()
TX: 0x00 RX: 0x00 EXPECT: 0x00 PASS
TX: 0x12 RX: 0x01 EXPECT: 0x01 PASS
TX: 0x7F RX: 0x13 EXPECT: 0x13 PASS
TX: 0xFF RX: 0x80 EXPECT: 0x80 PASS
>>>
以上。