hwconfig: Fix pad config for SD SPI, move clockrate to hwconfig
Some checks failed
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m21s
Check code formatting / Check-C-Format (push) Successful in 8s
Check code formatting / Check-Python-Flake8 (push) Failing after 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 11s

The code snippet in hwconfig to adjust the drive strength was incorrect:
It was adjusting the wrong pins. This was probably not updated during
some pin shuffling in the breadboard phase.

Fix this by adjusting the correct pins. Experimentation shows that both
setting the slew rate to fast or setting the drive strength to 8 mA
(default: slow and 4 mA) is sufficient to make SD SPI work at 25 MHz on
the Rev1 PCB. For now, the combination 8 mA and slow is chosen (slow
slew rate should result in less high frequency EMI).

Also make the SD clock rate adjustable in hwconfig, and set it to 25 MHz
for Rev1 and 15 MHz for the breadboard setup.

Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This commit is contained in:
2025-10-12 12:03:30 +02:00
parent 4a15b2c221
commit 06777cb362
3 changed files with 9 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ SD_DI = Pin.board.GP3
SD_DO = Pin.board.GP4
SD_SCK = Pin.board.GP2
SD_CS = Pin.board.GP5
SD_CLOCKRATE = 25000000
# MAX98357
I2S_LRCLK = Pin.board.GP6
@@ -46,10 +47,11 @@ def board_init():
POWER_EN.init(mode=Pin.OUT)
POWER_EN.value(1)
# Set 8 mA drive strength and fast slew rate for SD SPI
machine.mem32[0x4001c004 + 6*4] = 0x67
machine.mem32[0x4001c004 + 7*4] = 0x67
machine.mem32[0x4001c004 + 8*4] = 0x67
# SD_DO / MISO input doesn't need any special configuration
# Set 8 mA drive strength for SCK and MOSI
machine.mem32[0x4001c004 + 2*4] = 0x60 # SCK
machine.mem32[0x4001c004 + 3*4] = 0x60 # MOSI
# SD_CS doesn't need any special configuration
# Permanently enable amplifier
# TODO: Implement amplifier power management

View File

@@ -9,6 +9,7 @@ SD_DI = Pin.board.GP3
SD_DO = Pin.board.GP4
SD_SCK = Pin.board.GP2
SD_CS = Pin.board.GP5
SD_CLOCKRATE = 15000000
# MAX98357
I2S_LRCLK = Pin.board.GP7
@@ -41,11 +42,7 @@ VBAT_ADC = Pin.board.GP26
def board_init():
# Set 8 mA drive strength and fast slew rate for SD SPI
machine.mem32[0x4001c004 + 6*4] = 0x67
machine.mem32[0x4001c004 + 7*4] = 0x67
machine.mem32[0x4001c004 + 8*4] = 0x67
pass
def get_battery_voltage():
# Not supported on breadboard

View File

@@ -62,7 +62,7 @@ def run():
# Setup MP3 player
with SDContext(mosi=hwconfig.SD_DI, miso=hwconfig.SD_DO, sck=hwconfig.SD_SCK, ss=hwconfig.SD_CS,
baudrate=15000000), \
baudrate=hwconfig.SD_CLOCKRATE), \
AudioContext(hwconfig.I2S_DIN, hwconfig.I2S_DCLK, hwconfig.I2S_LRCLK) as audioctx:
# Setup NFC