Skip to content

Commit

Permalink
GPIO Drive Strength Config for SDIO Pins
Browse files Browse the repository at this point in the history
  • Loading branch information
androda authored and erichelgeson committed Oct 26, 2024
1 parent c45bfd2 commit 336cfe1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ bool is202309a();
typedef void (*sd_callback_t)(uint32_t bytes_complete);
void platform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
void add_extra_sdio_delay(uint16_t additional_delay);
void set_sdio_drive_strength(long ini_setting);

// Reprogram firmware in main program area.
#ifndef RP2040_DISABLE_BOOTLOADER
Expand Down
25 changes: 25 additions & 0 deletions lib/BlueSCSI_platform_RP2040/sd_card_sdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ void add_extra_sdio_delay(uint16_t additional_delay) {
rp2040_sdio_delay_increment(additional_delay);
}

void set_sdio_drive_strength(long ini_setting) {
gpio_drive_strength drive_strength;
switch (ini_setting) {
case 1:
drive_strength = GPIO_DRIVE_STRENGTH_2MA;
break;
default:
case 2:
drive_strength = GPIO_DRIVE_STRENGTH_4MA;
break;
case 3:
drive_strength = GPIO_DRIVE_STRENGTH_8MA;
break;
case 4:
drive_strength = GPIO_DRIVE_STRENGTH_12MA;
break;
}
gpio_set_drive_strength(SDIO_CMD, drive_strength);
gpio_set_drive_strength(SDIO_CLK, drive_strength);
gpio_set_drive_strength(SDIO_D0, drive_strength);
gpio_set_drive_strength(SDIO_D1, drive_strength);
gpio_set_drive_strength(SDIO_D2, drive_strength);
gpio_set_drive_strength(SDIO_D3, drive_strength);
}

static sd_callback_t get_stream_callback(const uint8_t *buf, uint32_t count, const char *accesstype, uint32_t sector)
{
m_stream_count_start = m_stream_count;
Expand Down
14 changes: 14 additions & 0 deletions src/BlueSCSI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,18 @@ void check_and_apply_sdio_delay() {
}
}

void check_and_apply_sdio_drive_strength() {
long sdio_drive_strength = ini_getl("SDIO", "GPIODriveStrength", 0, CONFIGFILE);
if (sdio_drive_strength) {
if (sdio_drive_strength < 1 || sdio_drive_strength > 4) {
log("---- WARNING: GPIODriveStrength setting invalid (Expected 1 - 4), defaulting to setting 2.");
return;
}
log("INFO: Setting SDIO GPIO drive strength level ", (uint16_t)sdio_drive_strength, ".");
set_sdio_drive_strength(sdio_drive_strength);
}
}

extern "C" void bluescsi_setup(void)
{
pio_clear_instruction_memory(pio0);
Expand Down Expand Up @@ -621,6 +633,7 @@ extern "C" void bluescsi_setup(void)
log("SD card without filesystem!");
}
check_and_apply_sdio_delay();
check_and_apply_sdio_drive_strength();

print_sd_info();

Expand Down Expand Up @@ -759,6 +772,7 @@ extern "C" void bluescsi_main_loop(void)
{
log("SD card reinit succeeded");
check_and_apply_sdio_delay();
check_and_apply_sdio_drive_strength();
print_sd_info();

reinitSCSI();
Expand Down

0 comments on commit 336cfe1

Please sign in to comment.