WIP: support for STM32F051 in addition to STM32F103

Related: SYS#5410
This commit is contained in:
Harald Welte 2021-03-28 18:38:26 +02:00
parent 8074b2cdc4
commit 645ed3a795
5 changed files with 69 additions and 5 deletions

View File

@ -8,6 +8,13 @@
#include <librfn/ringbuf.h>
/* STM32F0 has slightly different status register #defines */
#ifdef USART_ISR_RXNE
#define USART_SR_RXNE USART_ISR_RXNE
#define USART_SR_TXE USART_ISR_TXE
#define USART_SR(x) USART_ISR(x)
#endif
/* picolibc iob implementation for non-blocking I/O on USART via ring-buffer */
static uint32_t stdio_usart;

View File

@ -21,13 +21,16 @@ BINARY = rfdsatt
OBJS = attenuator.o board_rfdsatt_4ch.o
# when building for M0
#LDSCRIPT = ./stm32f051-openblt.ld
#LIBNAME = opencm3_stm32f0
#DEFS += -DSTM32F0
#FP_FLAGS ?= -msoft-float
#ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS)
LDSCRIPT = ./stm32f103-openblt.ld
# include ../../Makefile.include
LIBNAME = opencm3_stm32f1
DEFS += -DSTM32F1
FP_FLAGS ?= -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd

View File

@ -148,6 +148,10 @@ void attenuator_init(const struct attenuator_cfg *cfg,
if (!pins[k])
continue;
rcc_periph_clock_enable(periph[k]);
#ifdef STM32F1
gpio_set_mode(banks[k], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, pins[k]);
#else
gpio_mode_setup(banks[k], GPIO_MODE_OUTPUT, 0, pins[k]);
#endif
}
}

View File

@ -84,18 +84,24 @@ static void i2c_setup(void)
{
rcc_periph_clock_enable(RCC_I2C1);
#ifdef STM32F1
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN,
GPIO_I2C1_SCL | GPIO_I2C1_SDA);
#else
gpio_set_af(GPIOB, GPIO_AF1, GPIO8 | GPIO9);
#endif
/* disable before making config changes */
i2c_peripheral_disable(I2C1);
#ifdef STM32F1
/* APB1 runs at 24 MHz */
i2c_set_clock_frequency(I2C1, I2C_CR2_FREQ_24MHZ);
#endif
/* 400 kHz fast mode I2C */
//i2c_set_fast_mode(I2C1);
i2c_set_speed(I2C1, i2c_speed_fm_400k, 24);
//...
@ -107,8 +113,12 @@ static void usart_setup(void)
/* USART1: connected to debug header */
/* Setup GPIO pin GPIO_USART1_TX. */
#ifdef STM32F1
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
#else
gpio_set_af(GPIOA, GPIO_AF1, GPIO9 | GPIO10);
#endif
/* Setup UART parameters. */
usart_set_baudrate(USART1, 115200);
usart_set_databits(USART1, 8);
@ -122,8 +132,12 @@ static void usart_setup(void)
/* USART2: connected to 2.5mm stereo jack */
/* Setup GPIO pin GPIO_USART2_TX. */
#ifdef STM32F1
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
#else
gpio_set_af(GPIOA, GPIO_AF1, GPIO2 | GPIO13);
#endif
/* Setup UART parameters. */
usart_set_baudrate(USART2, 115200);
usart_set_databits(USART2, 8);
@ -137,9 +151,13 @@ static void usart_setup(void)
static void gpio_setup(void)
{
#ifdef STM32F1
/* Set GPIO15 (in GPIO port B) to 'output push-pull'. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
#else
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO15);
#endif
}
/***********************************************************************

View File

@ -0,0 +1,32 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/* Linker script for sysmcoom rfdn (STM32F051, 64K flash, 8K RAM). */
/* Define memory regions. */
MEMORY
{
/* first 0x2000 bytes reserved for bootloader */
rom (rx) : ORIGIN = 0x08002000, LENGTH = 62K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
}
/* Include the common ld script. */
INCLUDE cortex-m-generic.ld