Skip to content

Commit

Permalink
fix: SDIO issues after H7 support (#5260)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic authored Jul 10, 2024
1 parent 6419f7a commit b630982
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
2 changes: 2 additions & 0 deletions radio/src/hal/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ void gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t c
void gpio_init_analog(gpio_t pin);

void gpio_int_disable(gpio_t pin);
void gpio_set_af(gpio_t pin, gpio_af_t af);

gpio_mode_t gpio_get_mode(gpio_t pin);

int gpio_read(gpio_t pin);
void gpio_set(gpio_t pin);
void gpio_clear(gpio_t pin);
Expand Down
34 changes: 26 additions & 8 deletions radio/src/targets/common/arm/stm32/diskio_sdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@

#if defined(STM32H7) || defined(STM32H7RS) || defined(STM32F4)
extern uint32_t _sram;
extern uint32_t _eram;
extern uint32_t _heap_start;
#if defined(SDRAM)
#define _IS_DMA_BUFFER(addr) \
(((((intptr_t)(addr)) & 0xFF000000) == (((intptr_t)&_sram) & 0xFF000000)) || \
((((intptr_t)(addr)) & 0xFC000000) == (((intptr_t)&_heap_start) & 0xFC000000)))
#else
#define _IS_DMA_BUFFER(addr) \
((intptr_t)(addr) >= (intptr_t)&_sram && (intptr_t)(addr) <= (intptr_t)&_eram)
((((intptr_t)(addr)) & 0xFF000000) == (((intptr_t)&_sram) & 0xFF000000))
#endif
#else
#define _IS_DMA_BUFFER(addr) (true)
#endif
Expand Down Expand Up @@ -164,12 +170,24 @@ static void sdio_low_level_init(void)
{
_sd_sdio_clk_enable(SD_SDIO);

gpio_init_af(SD_SDIO_PIN_D0, SD_SDIO_AF_D0, GPIO_PIN_SPEED_HIGH);
gpio_init_af(SD_SDIO_PIN_D1, SD_SDIO_AF_D1, GPIO_PIN_SPEED_HIGH);
gpio_init_af(SD_SDIO_PIN_D2, SD_SDIO_AF_D2, GPIO_PIN_SPEED_HIGH);
gpio_init_af(SD_SDIO_PIN_D3, SD_SDIO_AF_D3, GPIO_PIN_SPEED_HIGH);
gpio_init_af(SD_SDIO_PIN_CMD, SD_SDIO_AF_CMD, GPIO_PIN_SPEED_HIGH);
gpio_init_af(SD_SDIO_PIN_CLK, SD_SDIO_AF_CLK, GPIO_PIN_SPEED_HIGH);
// data pins
gpio_init(SD_SDIO_PIN_D0, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
gpio_set_af(SD_SDIO_PIN_D0, SD_SDIO_AF_D0);

gpio_init(SD_SDIO_PIN_D1, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
gpio_set_af(SD_SDIO_PIN_D1, SD_SDIO_AF_D1);

gpio_init(SD_SDIO_PIN_D2, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
gpio_set_af(SD_SDIO_PIN_D2, SD_SDIO_AF_D2);

gpio_init(SD_SDIO_PIN_D3, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
gpio_set_af(SD_SDIO_PIN_D3, SD_SDIO_AF_D3);

gpio_init(SD_SDIO_PIN_CMD, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
gpio_set_af(SD_SDIO_PIN_CMD, SD_SDIO_AF_CMD);

gpio_init(SD_SDIO_PIN_CLK, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
gpio_set_af(SD_SDIO_PIN_CLK, SD_SDIO_AF_CLK);

#if defined(SD_SDIO_HAS_TRANSCEIVER)
gpio_init_af(SD_SDIO_PIN_CKIN, SD_SDIO_AF_CKIN, GPIO_PIN_SPEED_HIGH);
Expand Down
12 changes: 12 additions & 0 deletions radio/src/targets/common/arm/stm32/stm32_gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ void gpio_init_af(gpio_t pin, gpio_af_t af, gpio_speed_t speed)
_set_mode(port, pin_num, 2);
}

void gpio_set_af(gpio_t pin, gpio_af_t af)
{
GPIO_TypeDef* port = _port(pin);
int pin_num = _pin_num(pin);

// set selected function
port->AFR[(pin_num > 7) ? 1 : 0] &= ~(0xf << ((pin_num & 0x07) * 4));
port->AFR[(pin_num > 7) ? 1 : 0] |= (af << ((pin_num & 0x07) * 4));

_set_mode(port, pin_num, 2);
}

void gpio_init_analog(gpio_t pin)
{
GPIO_TypeDef* port = _port(pin);
Expand Down

0 comments on commit b630982

Please sign in to comment.