diff --git a/arch/arm/soc/st_stm32/Kconfig b/arch/arm/soc/st_stm32/Kconfig new file mode 100644 index 00000000000..f96632b1984 --- /dev/null +++ b/arch/arm/soc/st_stm32/Kconfig @@ -0,0 +1,23 @@ +# Kconfig - ST Microelectronics STM32 MCU line +# +# Copyright (c) 2016 Open-RnD Sp. z o.o. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +config SOC_STM32 + bool + # omit prompt to signify a "hidden" option + default n + +source "arch/arm/soc/st_stm32/*/Kconfig.soc.family" diff --git a/arch/arm/soc/st_stm32/Kconfig.soc b/arch/arm/soc/st_stm32/Kconfig.soc new file mode 100644 index 00000000000..e2be39e7ab7 --- /dev/null +++ b/arch/arm/soc/st_stm32/Kconfig.soc @@ -0,0 +1,24 @@ +# Kconfig - ST Microelectronics STM32 MCU line +# +# Copyright (c) 2016 Open-RnD Sp. z o.o. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +config SOC_STM32F1X + bool "STM32F1x Series MCU" + select CPU_CORTEX_M + select CPU_CORTEX_M3 + select SOC_STM32 + help + Enable support for STM32F1 MCU series diff --git a/arch/arm/soc/st_stm32/stm32f1/Kbuild b/arch/arm/soc/st_stm32/stm32f1/Kbuild new file mode 100644 index 00000000000..52341f86c0b --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/Kbuild @@ -0,0 +1 @@ +obj-y += soc.o diff --git a/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.family b/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.family new file mode 100644 index 00000000000..a063091f022 --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.family @@ -0,0 +1,64 @@ +# Kconfig - ST Microelectronics STM32F1 MCU line +# +# Copyright (c) 2016 Open-RnD Sp. z o.o. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +choice +prompt "STM32F1x MCU Selection" +depends on SOC_STM32F1X + +config SOC_STM32F103VE + bool "STM32F103VE" + +config SOC_STM32F103RB + bool "STM32F103RB" + +endchoice + +if SOC_STM32F1X + +source "arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.stm32f1*" + + +config SOC + default st_stm32/stm32f1 + +config SRAM_BASE_ADDRESS + default 0x20000000 + +config FLASH_BASE_ADDRESS + default 0x08000000 + +config NUM_IRQ_PRIO_BITS + int + default 4 + +config KERNEL_INIT_PRIORITY_DEFAULT + default 40 + +config KERNEL_INIT_PRIORITY_DEVICE + default 50 + +config UART_CONSOLE_PRIORITY + default 60 + +if UART_CONSOLE + +config UART_CONSOLE_ON_DEV_NAME + default "UART_0" + +endif # UART_CONSOLE + +endif # SOC_STM32F1X diff --git a/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.stm32f103rb b/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.stm32f103rb new file mode 100644 index 00000000000..d7d4342c1b4 --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.stm32f103rb @@ -0,0 +1,31 @@ +# Kconfig - ST Microelectronics STM32F103RB MCU +# +# Copyright (c) 2016 Open-RnD Sp. z o.o. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +if SOC_STM32F103RB + +config SRAM_SIZE + default 20 + +config FLASH_SIZE + default 128 + +config NUM_IRQS + int + default 59 + +endif # SOC_STM32F103RB + diff --git a/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.stm32f103ve b/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.stm32f103ve new file mode 100644 index 00000000000..f366765b0d7 --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/Kconfig.soc.stm32f103ve @@ -0,0 +1,31 @@ +# Kconfig - ST Microelectronics STM32F103VE MCU +# +# Copyright (c) 2016 Open-RnD Sp. z o.o. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +if SOC_STM32F103VE + +config SRAM_SIZE + default 64 + +config FLASH_SIZE + default 512 + +config NUM_IRQS + int + default 68 + +endif # SOC_STM32F103VE + diff --git a/arch/arm/soc/st_stm32/stm32f1/Makefile b/arch/arm/soc/st_stm32/stm32f1/Makefile new file mode 100644 index 00000000000..e7d49489052 --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/Makefile @@ -0,0 +1,7 @@ + +arch-cflags += $(call cc-option,-mthumb -mcpu=cortex-m3) \ + $(call cc-option,-mthumb -march=armv7-m) + +KBUILD_AFLAGS += $(arch-cflags) +KBUILD_CXXFLAGS += $(arch-cflags) +KBUILD_CFLAGS += $(arch-cflags) diff --git a/arch/arm/soc/st_stm32/stm32f1/linker.cmd b/arch/arm/soc/st_stm32/stm32f1/linker.cmd new file mode 100644 index 00000000000..654446204f6 --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/linker.cmd @@ -0,0 +1,19 @@ +/* linker.cmd - Linker command/script file */ + +/* + * Copyright (c) 2014-2016 Wind River Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include diff --git a/arch/arm/soc/st_stm32/stm32f1/soc.c b/arch/arm/soc/st_stm32/stm32f1/soc.c new file mode 100644 index 00000000000..6c29507e755 --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/soc.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 Open-RnD Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @brief System/hardware module for STM32F1 processor + */ + +#include +#include +#include +#include +#include + +/** + * @brief Perform basic hardware initialization at boot. + * + * This needs to be run from the very beginning. + * So the init priority has to be 0 (zero). + * + * @return 0 + */ +static int stm32f1_init(struct device *arg) +{ + uint32_t key; + + ARG_UNUSED(arg); + + key = irq_lock(); + + /* Setup the vector table offset register (VTOR), + * which is located at the beginning of flash area. + */ + _scs_relocate_vector_table((void *)CONFIG_FLASH_BASE_ADDRESS); + + /* Clear all faults */ + _ScbMemFaultAllFaultsReset(); + _ScbBusFaultAllFaultsReset(); + _ScbUsageFaultAllFaultsReset(); + + _ScbHardFaultAllFaultsReset(); + + /* Install default handler that simply resets the CPU + * if configured in the kernel, NOP otherwise + */ + NMI_INIT(); + + irq_unlock(key); + + return 0; +} + +SYS_INIT(stm32f1_init, PRIMARY, 0); diff --git a/arch/arm/soc/st_stm32/stm32f1/soc.h b/arch/arm/soc/st_stm32/stm32f1/soc.h new file mode 100644 index 00000000000..b2957314f56 --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/soc.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 Open-RnD Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file SoC configuration macros for the STM32F103 family processors. + * + * Based on reference manual: + * STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and STM32F107xx + * advanced ARM ® -based 32-bit MCUs + * + * Chapter 3.3: Memory Map + */ + + +#ifndef _STM32F1_SOC_H_ +#define _STM32F1_SOC_H_ + +/* peripherals start address */ +#define PERIPH_BASE 0x40000000 + +/* use naming consistent with STMF10x Peripherals Library */ +#define APB1PERIPH_BASE PERIPH_BASE +#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000) +#define AHBPERIPH_BASE (PERIPH_BASE + 0x20000) + +/* UART */ +#define USART1_ADDR (APB2PERIPH_BASE + 0x3800) +#define USART2_ADDR (APB1PERIPH_BASE + 0x4400) +#define USART3_ADDR (APB1PERIPH_BASE + 0x4800) + +/* Reset and Clock Control */ +#define RCC_BASE (AHBPERIPH_BASE + 0x1000) + +#define GPIO_REG_SIZE 0x400 +#define GPIOA_BASE (APB2PERIPH_BASE + 0x0800) +#define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00) +#define GPIOC_BASE (APB2PERIPH_BASE + 0x1000) +#define GPIOD_BASE (APB2PERIPH_BASE + 0x1400) +#define GPIOE_BASE (APB2PERIPH_BASE + 0x1800) +#define GPIOF_BASE (APB2PERIPH_BASE + 0x1C00) +#define GPIOG_BASE (APB2PERIPH_BASE + 0x2000) +/* base address for where GPIO registers start */ +#define GPIO_PORTS_BASE (GPIOA_BASE) + +#ifndef _ASMLANGUAGE + +#include +#include +#include + +#endif /* !_ASMLANGUAGE */ + +#endif /* _STM32F1_SOC_H_ */ diff --git a/arch/arm/soc/st_stm32/stm32f1/soc_registers.h b/arch/arm/soc/st_stm32/stm32f1/soc_registers.h new file mode 100644 index 00000000000..6327572c6a2 --- /dev/null +++ b/arch/arm/soc/st_stm32/stm32f1/soc_registers.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2016 Open-RnD Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _STM32F10X_SOC_REGISTERS_H_ +#define _STM32F10X_SOC_REGISTERS_H_ + +/* include register mapping headers */ + +#endif /* _STM32F10X_SOC_REGISTERS_H_ */