From 90534b3cf614fd78f43fc9aa393d0c51a74a928b Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Mon, 10 May 2021 19:27:58 +0200 Subject: [PATCH] stm32: portability enhancements Needed for e.g. stlinkv3 --- src/platforms/stm32/gpio.h | 8 ++++++-- src/platforms/stm32/usbuart.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/platforms/stm32/gpio.h b/src/platforms/stm32/gpio.h index dad20bb..5fb75e0 100644 --- a/src/platforms/stm32/gpio.h +++ b/src/platforms/stm32/gpio.h @@ -39,6 +39,7 @@ static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) { GPIO_BSRR(gpioport) = gpios; #ifdef STM32F4 + /* FIXME: Check if doubling is still needed */ GPIO_BSRR(gpioport) = gpios; #endif } @@ -46,11 +47,14 @@ static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) { -#ifndef STM32F4 +#if defined(STM32F4) + GPIO_BSRR(gpioport) = gpios<<16; + /* FIXME: Check if doubling is still needed */ + GPIO_BSRR(gpioport) = gpios<<16; +#elif defined(GPIO_BRR) GPIO_BRR(gpioport) = gpios; #else GPIO_BSRR(gpioport) = gpios<<16; - GPIO_BSRR(gpioport) = gpios<<16; #endif } #define gpio_clear _gpio_clear diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index 786bbc3..4775e1d 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -118,8 +118,14 @@ void usbuart_init(void) USBUSART_CR1 |= USART_CR1_IDLEIE; /* Setup USART TX DMA */ +#if !defined(USBUSART_TDR) && defined(USBUSART_DR) +# define USBUSART_TDR USBUSART_DR +#endif +#if !defined(USBUSART_RDR) && defined(USBUSART_DR) +# define USBUSART_RDR USBUSART_DR +#endif dma_channel_reset(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN); - dma_set_peripheral_address(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN, (uint32_t)&USBUSART_DR); + dma_set_peripheral_address(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN, (uint32_t)&USBUSART_TDR); dma_enable_memory_increment_mode(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN); dma_set_peripheral_size(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN, DMA_PSIZE_8BIT); dma_set_memory_size(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN, DMA_MSIZE_8BIT); @@ -136,7 +142,7 @@ void usbuart_init(void) /* Setup USART RX DMA */ dma_channel_reset(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN); - dma_set_peripheral_address(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN, (uint32_t)&USBUSART_DR); + dma_set_peripheral_address(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN, (uint32_t)&USBUSART_RDR); dma_set_memory_address(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN, (uint32_t)buf_rx); dma_set_number_of_data(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN, RX_FIFO_SIZE); dma_enable_memory_increment_mode(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN);