16-bit SPI reads on STM32F413 - duplicated second byte
Port, board and/or hardware
stm32 port, NUCLEO-F413ZH board
MicroPython version
MicroPython v1.24.0-preview.449.g1b89c503d on 2024-10-20; NUCLEO-F413ZH with STM
32F413
Reproduction
Built with:
git clone git@github.com:micropython/micropython.git
cd micropython/ports/stm32
make BOARD=STM32F413ZH'
16-bit SPI reads work, with the same SPI device, on other platform(ESP32). On STM32 we observe two identical bytes, same as the 2nd one in normal operation
Expected behaviour
For reference, this is the same code (after initialization) run on ESP32
where it works like it should
MicroPython v1.23.0 on 2024-06-02; Generic ESP32 module with ESP32
Type "help()" for more information.
from machine import Pin, SPI
import struct, array
import binascii
spi=SPI(2)
spi.init(baudrate=1000000, polarity=0, phase=0, bits=16, firstbit=SPI.MSB, s
ck=Pin(18), miso=Pin(19), mosi=Pin(23))
cs = Pin(5, Pin.OUT, value=1)
bin = bytearray(2)
cs.off()
spi.write(struct.pack('>h', 0x5627))
spi.readinto(bin)
spi.readinto(bin)
binascii.hexlify(bin)
b'246a'
spi.write(struct.pack('>h', 0x5417))
spi.readinto(bin)
spi.readinto(bin)
binascii.hexlify(bin)
b'8f7b'
spi.write(struct.pack('>h', 0x5617))
spi.readinto(bin)
spi.readinto(bin)
binascii.hexlify(bin)
b'c840'
Observed behaviour
This is STM32 run. As we can see, the second byte of SPI.read is propagated
into the first one.
MicroPython v1.24.0-preview.449.g1b89c503d on 2024-10-20; NUCLEO-F413ZH with ST3
Type "help()" for more information.
from machine import Pin, SPI
import struct, array
import binascii
spi=SPI(2)
spi.init(baudrate=1000000, polarity=0, phase=0, bits=16, firstbit=SPI.MSB)
cs = Pin('B10', Pin.OUT, value=1)
miso = Pin('C2', Pin.AF_PP, pull=Pin.PULL_UP, af=Pin.AF5_SPI2)
mosi = Pin('B15', Pin.AF_PP, pull=Pin.PULL_UP, af=Pin.AF5_SPI2)
sck = Pin('B10', Pin.AF_PP, pull=Pin.PULL_UP, af=Pin.AF5_SPI2)cs.off()
bin = bytearray(2)
spi.write(struct.pack('>h', 0x5627))
spi.readinto(bin)
spi.readinto(bin)
binascii.hexlify(bin)
b'6a6a'
spi.write(struct.pack('>h', 0x5417))
spi.readinto(bin)
spi.readinto(bin)
binascii.hexlify(bin)
b'5151'
spi.write(struct.pack('>h', 0x5617))
spi.readinto(bin)
spi.readinto(bin)
binascii.hexlify(bin)
b'6a6a'
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
ESP32-S3: machine.bitstream() can't send 6 bytes
Port, board and/or hardware
ESP32-S3, octal SPIRAM on ESP32-S3-WROOM-1-N8R16 module
MicroPython version
MicroPython v1.23.0 on 2024-08-19; Generic ESP32S3 module with Octal-SPIRAM with ESP32S3
built using ESP-IDF v5.2.2
Reproduction
When I execute the following code and watch GPIO12 on an oscilloscope, I see 96 pulses instead of the expected 48:
from machine import Pin, bitstream
buf = bytearray(6)
bitstream(Pin(12, Pin.OUT), 0, (240, 480, 480, 240), buf)
I have tested with a buffer of between 1 and 19 bytes, and I only get the wrong number of pulses for 6 byte buffers.
Expected behaviour
I expect to get 48 pulses on my pin.
Observed behaviour
I see 96 pulses on the pin.
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree