├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile ├── README.md ├── examples ├── .gitignore ├── f411 │ ├── .cproject │ ├── .gitignore │ ├── .mxproject │ ├── .project │ ├── .settings │ │ ├── com.st.stm32cube.ide.mcu.sfrview.prefs │ │ └── stm32cubeide.project.prefs │ ├── Core │ │ ├── Inc │ │ │ ├── main.h │ │ │ ├── stm32f4xx_hal_conf.h │ │ │ └── stm32f4xx_it.h │ │ ├── Src │ │ │ ├── main.c │ │ │ ├── stm32f4xx_hal_msp.c │ │ │ ├── stm32f4xx_it.c │ │ │ ├── syscalls.c │ │ │ ├── sysmem.c │ │ │ └── system_stm32f4xx.c │ │ └── Startup │ │ │ └── startup_stm32f411ceux.s │ ├── Drivers │ │ ├── CMSIS │ │ │ ├── Device │ │ │ │ └── ST │ │ │ │ │ └── STM32F4xx │ │ │ │ │ ├── Include │ │ │ │ │ ├── stm32f411xe.h │ │ │ │ │ ├── stm32f4xx.h │ │ │ │ │ └── system_stm32f4xx.h │ │ │ │ │ └── LICENSE.txt │ │ │ ├── Include │ │ │ │ ├── cachel1_armv7.h │ │ │ │ ├── cmsis_armcc.h │ │ │ │ ├── cmsis_armclang.h │ │ │ │ ├── cmsis_armclang_ltm.h │ │ │ │ ├── cmsis_compiler.h │ │ │ │ ├── cmsis_gcc.h │ │ │ │ ├── cmsis_iccarm.h │ │ │ │ ├── cmsis_version.h │ │ │ │ ├── core_armv81mml.h │ │ │ │ ├── core_armv8mbl.h │ │ │ │ ├── core_armv8mml.h │ │ │ │ ├── core_cm0.h │ │ │ │ ├── core_cm0plus.h │ │ │ │ ├── core_cm1.h │ │ │ │ ├── core_cm23.h │ │ │ │ ├── core_cm3.h │ │ │ │ ├── core_cm33.h │ │ │ │ ├── core_cm35p.h │ │ │ │ ├── core_cm4.h │ │ │ │ ├── core_cm55.h │ │ │ │ ├── core_cm7.h │ │ │ │ ├── core_cm85.h │ │ │ │ ├── core_sc000.h │ │ │ │ ├── core_sc300.h │ │ │ │ ├── core_starmc1.h │ │ │ │ ├── mpu_armv7.h │ │ │ │ ├── mpu_armv8.h │ │ │ │ ├── pac_armv81.h │ │ │ │ ├── pmu_armv8.h │ │ │ │ └── tz_context.h │ │ │ └── LICENSE.txt │ │ └── STM32F4xx_HAL_Driver │ │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ └── stm32_hal_legacy.h │ │ │ ├── stm32f4xx_hal.h │ │ │ ├── stm32f4xx_hal_cortex.h │ │ │ ├── stm32f4xx_hal_def.h │ │ │ ├── stm32f4xx_hal_dma.h │ │ │ ├── stm32f4xx_hal_dma_ex.h │ │ │ ├── stm32f4xx_hal_exti.h │ │ │ ├── stm32f4xx_hal_flash.h │ │ │ ├── stm32f4xx_hal_flash_ex.h │ │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ │ ├── stm32f4xx_hal_gpio.h │ │ │ ├── stm32f4xx_hal_gpio_ex.h │ │ │ ├── stm32f4xx_hal_pwr.h │ │ │ ├── stm32f4xx_hal_pwr_ex.h │ │ │ ├── stm32f4xx_hal_rcc.h │ │ │ ├── stm32f4xx_hal_rcc_ex.h │ │ │ ├── stm32f4xx_hal_tim.h │ │ │ ├── stm32f4xx_hal_tim_ex.h │ │ │ ├── stm32f4xx_hal_uart.h │ │ │ ├── stm32f4xx_ll_bus.h │ │ │ ├── stm32f4xx_ll_cortex.h │ │ │ ├── stm32f4xx_ll_dma.h │ │ │ ├── stm32f4xx_ll_exti.h │ │ │ ├── stm32f4xx_ll_gpio.h │ │ │ ├── stm32f4xx_ll_pwr.h │ │ │ ├── stm32f4xx_ll_rcc.h │ │ │ ├── stm32f4xx_ll_system.h │ │ │ ├── stm32f4xx_ll_tim.h │ │ │ ├── stm32f4xx_ll_usart.h │ │ │ └── stm32f4xx_ll_utils.h │ │ │ ├── LICENSE.txt │ │ │ └── Src │ │ │ ├── stm32f4xx_hal.c │ │ │ ├── stm32f4xx_hal_cortex.c │ │ │ ├── stm32f4xx_hal_dma.c │ │ │ ├── stm32f4xx_hal_dma_ex.c │ │ │ ├── stm32f4xx_hal_exti.c │ │ │ ├── stm32f4xx_hal_flash.c │ │ │ ├── stm32f4xx_hal_flash_ex.c │ │ │ ├── stm32f4xx_hal_flash_ramfunc.c │ │ │ ├── stm32f4xx_hal_gpio.c │ │ │ ├── stm32f4xx_hal_pwr.c │ │ │ ├── stm32f4xx_hal_pwr_ex.c │ │ │ ├── stm32f4xx_hal_rcc.c │ │ │ ├── stm32f4xx_hal_rcc_ex.c │ │ │ ├── stm32f4xx_hal_tim.c │ │ │ ├── stm32f4xx_hal_tim_ex.c │ │ │ └── stm32f4xx_hal_uart.c │ ├── STM32F411CEUX_FLASH.ld │ ├── STM32F411CEUX_RAM.ld │ ├── f411 Debug.launch │ ├── f411.ioc │ └── ws2812 ├── libopencm3 │ ├── f1 │ │ ├── Makefile.include │ │ └── f103 │ │ │ ├── demo │ │ │ ├── .vscode │ │ │ │ ├── c_cpp_properties.json │ │ │ │ ├── launch.json │ │ │ │ └── settings.json │ │ │ ├── Makefile │ │ │ ├── demo.c │ │ │ ├── demo.d │ │ │ ├── demo.elf │ │ │ ├── demo.map │ │ │ └── demo.o │ │ │ └── f103.ld │ └── f4 │ │ ├── Makefile.include │ │ └── f411 │ │ ├── demo │ │ ├── .vscode │ │ │ ├── c_cpp_properties.json │ │ │ ├── launch.json │ │ │ └── settings.json │ │ ├── Makefile │ │ ├── demo.bin │ │ ├── demo.c │ │ ├── demo.d │ │ ├── demo.elf │ │ ├── demo.map │ │ └── demo.o │ │ └── f411.ld └── rules.mk ├── images ├── include_paths.png ├── source_locations.png ├── tim3_config1.png ├── tim3_dma.png ├── tim3_gpio.png └── tim3_params.png └── src ├── color_values.c ├── color_values.h ├── ws2812.c ├── ws2812.h ├── ws2812_demos.c └── ws2812_demos.h /.gitignore: -------------------------------------------------------------------------------- 1 | Debug/ 2 | language.settings.xml 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/.gitmodules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Pragmatic Software License (PSL-1.0) 2 | 3 | 1. Definitions 4 | 5 | "Software" means the source code, object code, documentation, and any associated 6 | files made available under this license. "You" (or "Your") means any individual 7 | or entity that receives, uses, or distributes the Software. 8 | 9 | "Contributor" means any entity that submits code or documentation to the 10 | Software. 11 | 12 | 2. Grant of License 13 | 14 | Subject to the terms of this License, the original author(s) and contributors 15 | grant You a worldwide, royalty-free, non-exclusive license to: 16 | 17 | Use, copy, modify, and distribute the Software and derivative works under the 18 | terms stated in this License. Modify and redistribute the Software under the 19 | same license terms, provided that proper attribution is maintained. 20 | 21 | 3. Usage Restrictions 22 | 23 | You may not use, distribute, or modify this Software in any project, product, or 24 | service that: 25 | 26 | * Promotes or enforces inclusivity, diversity, gender identity activism, or 27 | social justice causes. 28 | 29 | * Advocates for or is affiliated with environmental activism, veganism, or 30 | sustainability movements. 31 | 32 | * Incorporates policies or messaging aligned with woke ideology, identity 33 | politics, or political correctness culture. 34 | 35 | * Is designed for organizations, groups, or initiatives explicitly endorsing 36 | social justice activism or progressive ideology. 37 | 38 | * Uses, integrates, or depends on software released under any Open Source 39 | Initiative (OSI)-approved license. 40 | 41 | 4. Commercial License Requirement for Violations 42 | 43 | Failure to comply with the restrictions in Section 3 automatically revokes this 44 | license, and You must obtain a commercial license from the original copyright 45 | holder(s). The minimum fee for such a license shall be US$ 10,000, payable 46 | within 30 days of written notice of noncompliance. The copyright holder(s) 47 | reserve the right to increase this fee at their sole discretion based on the 48 | extent of the violation. 49 | 50 | 5. No Warranty 51 | 52 | The Software is provided "as is," without warranties of any kind, either express 53 | or implied. The authors and contributors disclaim any liability for damages 54 | resulting from the use or misuse of the Software. 55 | 56 | 6. Attribution 57 | 58 | Redistributions must include this license text, and any modifications must be 59 | clearly documented. 60 | 61 | 7. Termination 62 | 63 | If You violate any of the terms specified in Section 3, Your rights under this 64 | License are immediately and automatically revoked. Continued use of the Software 65 | after revocation constitutes unauthorized use and requires a commercial license 66 | as per Section 4. 67 | 68 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libopencm3 project. 3 | ## 4 | ## Copyright (C) 2009 Uwe Hermann 5 | ## 6 | ## This library is free software: you can redistribute it and/or modify 7 | ## it under the terms of the GNU Lesser General Public License as published by 8 | ## the Free Software Foundation, either version 3 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This library is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public License 17 | ## along with this library. If not, see . 18 | ## 19 | 20 | PREFIX ?= arm-none-eabi- 21 | 22 | TARGETS := stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4 23 | TARGETS += stm32/l0 stm32/l1 stm32/l4 24 | TARGETS += lpc/lpc13xx lpc/lpc17xx #lpc/lpc43xx 25 | TARGETS += tiva/lm3s tiva/lm4f 26 | TARGETS += efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg 27 | TARGETS += vf6xx 28 | TARGETS += sam/d 29 | 30 | # Be silent per default, but 'make V=1' will show all compiler calls. 31 | ifneq ($(V),1) 32 | Q := @ 33 | # Do not print "Entering directory ...". 34 | MAKEFLAGS += --no-print-directory 35 | endif 36 | 37 | OPENCM3_DIR ?= $(realpath libopencm3) 38 | EXAMPLE_RULES = elf 39 | 40 | all: build 41 | 42 | bin: EXAMPLE_RULES += bin 43 | hex: EXAMPLE_RULES += hex 44 | srec: EXAMPLE_RULES += srec 45 | list: EXAMPLE_RULES += list 46 | images: EXAMPLE_RULES += images 47 | 48 | bin: build 49 | hex: build 50 | srec: build 51 | list: build 52 | images: build 53 | 54 | build: lib examples 55 | 56 | lib: 57 | $(Q)if [ ! "`ls -A $(OPENCM3_DIR)`" ] ; then \ 58 | printf "######## ERROR ########\n"; \ 59 | printf "\tlibopencm3 is not initialized.\n"; \ 60 | printf "\tPlease run:\n"; \ 61 | printf "\t$$ git submodule init\n"; \ 62 | printf "\t$$ git submodule update\n"; \ 63 | printf "\tbefore running make.\n"; \ 64 | printf "######## ERROR ########\n"; \ 65 | exit 1; \ 66 | fi 67 | $(Q)$(MAKE) -C $(OPENCM3_DIR) 68 | 69 | EXAMPLE_DIRS:=$(sort $(dir $(wildcard $(addsuffix /*/*/Makefile,$(addprefix examples/,$(TARGETS)))))) 70 | $(EXAMPLE_DIRS): lib 71 | @printf " BUILD $@\n"; 72 | $(Q)$(MAKE) --directory=$@ OPENCM3_DIR=$(OPENCM3_DIR) $(EXAMPLE_RULES) 73 | 74 | examples: $(EXAMPLE_DIRS) 75 | $(Q)true 76 | 77 | examplesclean: $(EXAMPLE_DIRS:=.clean) 78 | 79 | clean: examplesclean styleclean 80 | $(Q)$(MAKE) -C libopencm3 clean 81 | 82 | stylecheck: $(EXAMPLE_DIRS:=.stylecheck) 83 | styleclean: $(EXAMPLE_DIRS:=.styleclean) 84 | 85 | 86 | %.clean: 87 | $(Q)if [ -d $* ]; then \ 88 | printf " CLEAN $*\n"; \ 89 | $(MAKE) -C $* clean OPENCM3_DIR=$(OPENCM3_DIR) || exit $?; \ 90 | fi; 91 | 92 | %.styleclean: 93 | $(Q)$(MAKE) -C $* styleclean OPENCM3_DIR=$(OPENCM3_DIR) 94 | 95 | %.stylecheck: 96 | $(Q)$(MAKE) -C $* stylecheck OPENCM3_DIR=$(OPENCM3_DIR) 97 | 98 | 99 | .PHONY: build lib examples $(EXAMPLE_DIRS) install clean stylecheck styleclean \ 100 | bin hex srec list images 101 | 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stm32-ws2812 2 | 3 | STM32 Library for WS2812 using DMA+PWM 4 | 5 | ## Wiki Page 6 | 7 | The primary documentation is on our wiki here: https://stm32world.com/wiki/STM32_WS2812_(NeoPixel_RGB_LED) 8 | 9 | Video showing it's use here: https://www.youtube.com/watch?v=mdZerUTFJUw 10 | 11 | ## STM32CubeIDE Setup 12 | 13 | The folder containing the library source will need to be included in STM32CubeIDE under Includes 14 | 15 | ![include paths](https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/master/images/include_paths.png) 16 | 17 | and under Sources: 18 | 19 | ![include paths](https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/master/images/source_locations.png) 20 | 21 | The ws2812 library uses a PWM timer channel to drive the LED string. This should be configured under timers: 22 | 23 | ![include paths](https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/master/images/tim3_config1.png) 24 | 25 | A DMA channel will have to be enabled as a circular buffer: 26 | 27 | ![include paths](https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/master/images/tim3_dma.png) 28 | 29 | ![include paths](https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/master/images/tim3_gpio.png) 30 | 31 | The "Counter value" is the most important value. It need to divide the timer clock so that the resulting PWM frequency is exactly 800 kHz. 32 | 33 | ![include paths](https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/master/images/tim3_params.png) 34 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | /.metadata/ 2 | -------------------------------------------------------------------------------- /examples/f411/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | -------------------------------------------------------------------------------- /examples/f411/.mxproject: -------------------------------------------------------------------------------- 1 | [PreviousLibFiles] 2 | LibFiles=Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dmamux.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dmamux.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f411xe.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/core_starmc1.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/cachel1_armv7.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/core_cm35p.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm55.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/pac_armv81.h;Drivers/CMSIS/Include/core_cm85.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/pmu_armv8.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/core_armv81mml.h;Drivers/CMSIS/Include/cmsis_armclang_ltm.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/cmsis_iccarm.h; 3 | 4 | [PreviousUsedCubeIDEFiles] 5 | SourceFiles=Core/Src/main.c;Core/Src/stm32f4xx_it.c;Core/Src/stm32f4xx_hal_msp.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;;; 6 | HeaderPath=Drivers/STM32F4xx_HAL_Driver/Inc;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;Drivers/CMSIS/Device/ST/STM32F4xx/Include;Drivers/CMSIS/Include;Core/Inc; 7 | CDefines=USE_HAL_DRIVER;STM32F411xE;USE_HAL_DRIVER;USE_HAL_DRIVER; 8 | 9 | [PreviousGenFiles] 10 | AdvancedFolderStructure=true 11 | HeaderFileListSize=3 12 | HeaderFiles#0=../Core/Inc/stm32f4xx_it.h 13 | HeaderFiles#1=../Core/Inc/stm32f4xx_hal_conf.h 14 | HeaderFiles#2=../Core/Inc/main.h 15 | HeaderFolderListSize=1 16 | HeaderPath#0=../Core/Inc 17 | HeaderFiles=; 18 | SourceFileListSize=3 19 | SourceFiles#0=../Core/Src/stm32f4xx_it.c 20 | SourceFiles#1=../Core/Src/stm32f4xx_hal_msp.c 21 | SourceFiles#2=../Core/Src/main.c 22 | SourceFolderListSize=1 23 | SourcePath#0=../Core/Src 24 | SourceFiles=; 25 | 26 | -------------------------------------------------------------------------------- /examples/f411/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | f411 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | com.st.stm32cube.ide.mcu.MCUCubeProjectNature 24 | org.eclipse.cdt.core.cnature 25 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature 26 | com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/f411/.settings/com.st.stm32cube.ide.mcu.sfrview.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | sfrviewstate={"fFavorites"\:{"fLists"\:{}},"fProperties"\:{"fNodeProperties"\:{}}} 3 | -------------------------------------------------------------------------------- /examples/f411/.settings/stm32cubeide.project.prefs: -------------------------------------------------------------------------------- 1 | 635E684B79701B039C64EA45C3F84D30=85C9BDD2863A39DA4F6210BA1AD263D8 2 | 66BE74F758C12D739921AEA421D593D3=1 3 | 8DF89ED150041C4CBC7CB9A9CAA90856=77372D1B316F94A23E0081AE2C8086CD 4 | DC22A860405A8BF2F2C095E5B6529F12=77372D1B316F94A23E0081AE2C8086CD 5 | eclipse.preferences.version=1 6 | -------------------------------------------------------------------------------- /examples/f411/Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Main program header 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2024 Lars Boegild Thomsen . 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __MAIN_H 22 | #define __MAIN_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal.h" 30 | 31 | /* Private includes ----------------------------------------------------------*/ 32 | /* USER CODE BEGIN Includes */ 33 | #ifdef DEBUG 34 | #include 35 | #endif 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); 54 | 55 | /* Exported functions prototypes ---------------------------------------------*/ 56 | void Error_Handler(void); 57 | 58 | /* USER CODE BEGIN EFP */ 59 | 60 | /* USER CODE END EFP */ 61 | 62 | /* Private defines -----------------------------------------------------------*/ 63 | #define LED_CNT 125 64 | #define LED_Pin GPIO_PIN_13 65 | #define LED_GPIO_Port GPIOC 66 | #define BTN_Pin GPIO_PIN_0 67 | #define BTN_GPIO_Port GPIOA 68 | 69 | /* USER CODE BEGIN Private defines */ 70 | #define LEDS 64 71 | /* USER CODE END Private defines */ 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /* __MAIN_H */ 78 | -------------------------------------------------------------------------------- /examples/f411/Core/Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_IT_H 22 | #define __STM32F4xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void MemManage_Handler(void); 52 | void BusFault_Handler(void); 53 | void UsageFault_Handler(void); 54 | void SVC_Handler(void); 55 | void DebugMon_Handler(void); 56 | void PendSV_Handler(void); 57 | void SysTick_Handler(void); 58 | void DMA1_Stream0_IRQHandler(void); 59 | /* USER CODE BEGIN EFP */ 60 | 61 | /* USER CODE END EFP */ 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __STM32F4xx_IT_H */ 68 | -------------------------------------------------------------------------------- /examples/f411/Core/Src/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2025 Lars Boegild Thomsen . 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "main.h" 21 | 22 | /* Private includes ----------------------------------------------------------*/ 23 | /* USER CODE BEGIN Includes */ 24 | #include "ws2812_demos.h" 25 | #include "ws2812.h" 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN PTD */ 30 | 31 | /* USER CODE END PTD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | 36 | /* USER CODE END PD */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN PM */ 40 | 41 | /* USER CODE END PM */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | TIM_HandleTypeDef htim4; 45 | DMA_HandleTypeDef hdma_tim4_ch1; 46 | 47 | UART_HandleTypeDef huart1; 48 | 49 | /* USER CODE BEGIN PV */ 50 | 51 | ws2812_handleTypeDef ws2812; // The WS2812 panel handler 52 | 53 | /* USER CODE END PV */ 54 | 55 | /* Private function prototypes -----------------------------------------------*/ 56 | void SystemClock_Config(void); 57 | static void MX_GPIO_Init(void); 58 | static void MX_DMA_Init(void); 59 | static void MX_USART1_UART_Init(void); 60 | static void MX_TIM4_Init(void); 61 | /* USER CODE BEGIN PFP */ 62 | 63 | /* USER CODE END PFP */ 64 | 65 | /* Private user code ---------------------------------------------------------*/ 66 | /* USER CODE BEGIN 0 */ 67 | int _write(int fd, char *ptr, int len) { 68 | HAL_StatusTypeDef hstatus; 69 | 70 | if (fd == 1 || fd == 2) { 71 | hstatus = HAL_UART_Transmit(&huart1, (uint8_t*) ptr, len, HAL_MAX_DELAY); 72 | if (hstatus == HAL_OK) 73 | return len; 74 | else 75 | return -1; 76 | } 77 | return -1; 78 | } 79 | 80 | // Done sending first half of the DMA buffer - this can now safely be updated 81 | void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim) { 82 | 83 | if (htim->Instance == TIM4) { 84 | ws2812_update_buffer(&ws2812, &ws2812.dma_buffer[0]); 85 | } 86 | 87 | } 88 | 89 | // Done sending the second half of the DMA buffer - this can now be safely updated 90 | void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) { 91 | 92 | if (htim->Instance == TIM4) { 93 | ws2812_update_buffer(&ws2812, &ws2812.dma_buffer[BUFFER_SIZE]); 94 | } 95 | 96 | } 97 | 98 | /* USER CODE END 0 */ 99 | 100 | /** 101 | * @brief The application entry point. 102 | * @retval int 103 | */ 104 | int main(void) 105 | { 106 | 107 | /* USER CODE BEGIN 1 */ 108 | 109 | /* USER CODE END 1 */ 110 | 111 | /* MCU Configuration--------------------------------------------------------*/ 112 | 113 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 114 | HAL_Init(); 115 | 116 | /* USER CODE BEGIN Init */ 117 | 118 | /* USER CODE END Init */ 119 | 120 | /* Configure the system clock */ 121 | SystemClock_Config(); 122 | 123 | /* USER CODE BEGIN SysInit */ 124 | 125 | /* USER CODE END SysInit */ 126 | 127 | /* Initialize all configured peripherals */ 128 | MX_GPIO_Init(); 129 | MX_DMA_Init(); 130 | MX_USART1_UART_Init(); 131 | MX_TIM4_Init(); 132 | /* USER CODE BEGIN 2 */ 133 | 134 | printf("WS2812 Demo\n"); 135 | 136 | ws2812_init(&ws2812, &htim4, TIM_CHANNEL_1, 64); 137 | 138 | ws2812_demos_set(&ws2812, 1); 139 | 140 | /* USER CODE END 2 */ 141 | 142 | /* Infinite loop */ 143 | /* USER CODE BEGIN WHILE */ 144 | 145 | uint32_t now = 0, next_blink = 500, next_tick = 1000, loop_count = 0; 146 | 147 | while (1) { 148 | 149 | now = uwTick; 150 | 151 | if (!(now % 10)) { // Just call every 10th loop 152 | ws2812_demos_tick(&ws2812); 153 | } 154 | 155 | if (now >= next_blink) { // Every 500 ms 156 | HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); 157 | next_blink = now + 500; 158 | } 159 | 160 | if (now >= next_tick) { 161 | printf("Tick %lu (count = %lu dma = %lu dat = %lu)\n", now / 1000, loop_count, ws2812.dma_cbs, ws2812.dat_cbs); 162 | loop_count = 0; 163 | next_tick = now + 1000; 164 | } 165 | 166 | ++loop_count; 167 | 168 | /* USER CODE END WHILE */ 169 | 170 | /* USER CODE BEGIN 3 */ 171 | } 172 | /* USER CODE END 3 */ 173 | } 174 | 175 | /** 176 | * @brief System Clock Configuration 177 | * @retval None 178 | */ 179 | void SystemClock_Config(void) 180 | { 181 | RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; 182 | RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; 183 | 184 | /** Configure the main internal regulator output voltage 185 | */ 186 | __HAL_RCC_PWR_CLK_ENABLE(); 187 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 188 | 189 | /** Initializes the RCC Oscillators according to the specified parameters 190 | * in the RCC_OscInitTypeDef structure. 191 | */ 192 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 193 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 194 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 195 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 196 | RCC_OscInitStruct.PLL.PLLM = 12; 197 | RCC_OscInitStruct.PLL.PLLN = 96; 198 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 199 | RCC_OscInitStruct.PLL.PLLQ = 4; 200 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 201 | { 202 | Error_Handler(); 203 | } 204 | 205 | /** Initializes the CPU, AHB and APB buses clocks 206 | */ 207 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK 208 | | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; 209 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 210 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 211 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 212 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 213 | 214 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) 215 | { 216 | Error_Handler(); 217 | } 218 | } 219 | 220 | /** 221 | * @brief TIM4 Initialization Function 222 | * @param None 223 | * @retval None 224 | */ 225 | static void MX_TIM4_Init(void) 226 | { 227 | 228 | /* USER CODE BEGIN TIM4_Init 0 */ 229 | 230 | /* USER CODE END TIM4_Init 0 */ 231 | 232 | TIM_ClockConfigTypeDef sClockSourceConfig = { 0 }; 233 | TIM_MasterConfigTypeDef sMasterConfig = { 0 }; 234 | TIM_OC_InitTypeDef sConfigOC = { 0 }; 235 | 236 | /* USER CODE BEGIN TIM4_Init 1 */ 237 | 238 | /* USER CODE END TIM4_Init 1 */ 239 | htim4.Instance = TIM4; 240 | htim4.Init.Prescaler = 0; 241 | htim4.Init.CounterMode = TIM_COUNTERMODE_UP; 242 | htim4.Init.Period = LED_CNT; 243 | htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; 244 | htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; 245 | if (HAL_TIM_Base_Init(&htim4) != HAL_OK) 246 | { 247 | Error_Handler(); 248 | } 249 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; 250 | if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK) 251 | { 252 | Error_Handler(); 253 | } 254 | if (HAL_TIM_PWM_Init(&htim4) != HAL_OK) 255 | { 256 | Error_Handler(); 257 | } 258 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; 259 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; 260 | if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK) 261 | { 262 | Error_Handler(); 263 | } 264 | sConfigOC.OCMode = TIM_OCMODE_PWM1; 265 | sConfigOC.Pulse = 0; 266 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; 267 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; 268 | if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) 269 | { 270 | Error_Handler(); 271 | } 272 | /* USER CODE BEGIN TIM4_Init 2 */ 273 | 274 | /* USER CODE END TIM4_Init 2 */ 275 | HAL_TIM_MspPostInit(&htim4); 276 | 277 | } 278 | 279 | /** 280 | * @brief USART1 Initialization Function 281 | * @param None 282 | * @retval None 283 | */ 284 | static void MX_USART1_UART_Init(void) 285 | { 286 | 287 | /* USER CODE BEGIN USART1_Init 0 */ 288 | 289 | /* USER CODE END USART1_Init 0 */ 290 | 291 | /* USER CODE BEGIN USART1_Init 1 */ 292 | 293 | /* USER CODE END USART1_Init 1 */ 294 | huart1.Instance = USART1; 295 | huart1.Init.BaudRate = 2000000; 296 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 297 | huart1.Init.StopBits = UART_STOPBITS_1; 298 | huart1.Init.Parity = UART_PARITY_NONE; 299 | huart1.Init.Mode = UART_MODE_TX_RX; 300 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 301 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 302 | if (HAL_UART_Init(&huart1) != HAL_OK) 303 | { 304 | Error_Handler(); 305 | } 306 | /* USER CODE BEGIN USART1_Init 2 */ 307 | 308 | /* USER CODE END USART1_Init 2 */ 309 | 310 | } 311 | 312 | /** 313 | * Enable DMA controller clock 314 | */ 315 | static void MX_DMA_Init(void) 316 | { 317 | 318 | /* DMA controller clock enable */ 319 | __HAL_RCC_DMA1_CLK_ENABLE(); 320 | 321 | /* DMA interrupt init */ 322 | /* DMA1_Stream0_IRQn interrupt configuration */ 323 | HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0); 324 | HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn); 325 | 326 | } 327 | 328 | /** 329 | * @brief GPIO Initialization Function 330 | * @param None 331 | * @retval None 332 | */ 333 | static void MX_GPIO_Init(void) 334 | { 335 | GPIO_InitTypeDef GPIO_InitStruct = { 0 }; 336 | /* USER CODE BEGIN MX_GPIO_Init_1 */ 337 | /* USER CODE END MX_GPIO_Init_1 */ 338 | 339 | /* GPIO Ports Clock Enable */ 340 | __HAL_RCC_GPIOC_CLK_ENABLE(); 341 | __HAL_RCC_GPIOH_CLK_ENABLE(); 342 | __HAL_RCC_GPIOA_CLK_ENABLE(); 343 | __HAL_RCC_GPIOB_CLK_ENABLE(); 344 | 345 | /*Configure GPIO pin Output Level */ 346 | HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET); 347 | 348 | /*Configure GPIO pin : LED_Pin */ 349 | GPIO_InitStruct.Pin = LED_Pin; 350 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; 351 | GPIO_InitStruct.Pull = GPIO_NOPULL; 352 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 353 | HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct); 354 | 355 | /*Configure GPIO pin : BTN_Pin */ 356 | GPIO_InitStruct.Pin = BTN_Pin; 357 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 358 | GPIO_InitStruct.Pull = GPIO_NOPULL; 359 | HAL_GPIO_Init(BTN_GPIO_Port, &GPIO_InitStruct); 360 | 361 | /* USER CODE BEGIN MX_GPIO_Init_2 */ 362 | /* USER CODE END MX_GPIO_Init_2 */ 363 | } 364 | 365 | /* USER CODE BEGIN 4 */ 366 | 367 | /* USER CODE END 4 */ 368 | 369 | /** 370 | * @brief This function is executed in case of error occurrence. 371 | * @retval None 372 | */ 373 | void Error_Handler(void) 374 | { 375 | /* USER CODE BEGIN Error_Handler_Debug */ 376 | /* User can add his own implementation to report the HAL error return state */ 377 | __disable_irq(); 378 | while (1) 379 | { 380 | } 381 | /* USER CODE END Error_Handler_Debug */ 382 | } 383 | 384 | #ifdef USE_FULL_ASSERT 385 | /** 386 | * @brief Reports the name of the source file and the source line number 387 | * where the assert_param error has occurred. 388 | * @param file: pointer to the source file name 389 | * @param line: assert_param error line source number 390 | * @retval None 391 | */ 392 | void assert_failed(uint8_t *file, uint32_t line) 393 | { 394 | /* USER CODE BEGIN 6 */ 395 | /* User can add his own implementation to report the file name and line number, 396 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 397 | /* USER CODE END 6 */ 398 | } 399 | #endif /* USE_FULL_ASSERT */ 400 | -------------------------------------------------------------------------------- /examples/f411/Core/Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | /* USER CODE BEGIN Includes */ 24 | 25 | /* USER CODE END Includes */ 26 | extern DMA_HandleTypeDef hdma_tim4_ch1; 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | 62 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); 63 | /** 64 | * Initializes the Global MSP. 65 | */ 66 | void HAL_MspInit(void) 67 | { 68 | 69 | /* USER CODE BEGIN MspInit 0 */ 70 | 71 | /* USER CODE END MspInit 0 */ 72 | 73 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 74 | __HAL_RCC_PWR_CLK_ENABLE(); 75 | 76 | /* System interrupt init*/ 77 | 78 | /* USER CODE BEGIN MspInit 1 */ 79 | 80 | /* USER CODE END MspInit 1 */ 81 | } 82 | 83 | /** 84 | * @brief TIM_Base MSP Initialization 85 | * This function configures the hardware resources used in this example 86 | * @param htim_base: TIM_Base handle pointer 87 | * @retval None 88 | */ 89 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) 90 | { 91 | if(htim_base->Instance==TIM4) 92 | { 93 | /* USER CODE BEGIN TIM4_MspInit 0 */ 94 | 95 | /* USER CODE END TIM4_MspInit 0 */ 96 | /* Peripheral clock enable */ 97 | __HAL_RCC_TIM4_CLK_ENABLE(); 98 | 99 | /* TIM4 DMA Init */ 100 | /* TIM4_CH1 Init */ 101 | hdma_tim4_ch1.Instance = DMA1_Stream0; 102 | hdma_tim4_ch1.Init.Channel = DMA_CHANNEL_2; 103 | hdma_tim4_ch1.Init.Direction = DMA_MEMORY_TO_PERIPH; 104 | hdma_tim4_ch1.Init.PeriphInc = DMA_PINC_DISABLE; 105 | hdma_tim4_ch1.Init.MemInc = DMA_MINC_ENABLE; 106 | hdma_tim4_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; 107 | hdma_tim4_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; 108 | hdma_tim4_ch1.Init.Mode = DMA_CIRCULAR; 109 | hdma_tim4_ch1.Init.Priority = DMA_PRIORITY_LOW; 110 | hdma_tim4_ch1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; 111 | if (HAL_DMA_Init(&hdma_tim4_ch1) != HAL_OK) 112 | { 113 | Error_Handler(); 114 | } 115 | 116 | __HAL_LINKDMA(htim_base,hdma[TIM_DMA_ID_CC1],hdma_tim4_ch1); 117 | 118 | /* USER CODE BEGIN TIM4_MspInit 1 */ 119 | 120 | /* USER CODE END TIM4_MspInit 1 */ 121 | 122 | } 123 | 124 | } 125 | 126 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) 127 | { 128 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 129 | if(htim->Instance==TIM4) 130 | { 131 | /* USER CODE BEGIN TIM4_MspPostInit 0 */ 132 | 133 | /* USER CODE END TIM4_MspPostInit 0 */ 134 | 135 | __HAL_RCC_GPIOB_CLK_ENABLE(); 136 | /**TIM4 GPIO Configuration 137 | PB6 ------> TIM4_CH1 138 | */ 139 | GPIO_InitStruct.Pin = GPIO_PIN_6; 140 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 141 | GPIO_InitStruct.Pull = GPIO_NOPULL; 142 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 143 | GPIO_InitStruct.Alternate = GPIO_AF2_TIM4; 144 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 145 | 146 | /* USER CODE BEGIN TIM4_MspPostInit 1 */ 147 | 148 | /* USER CODE END TIM4_MspPostInit 1 */ 149 | } 150 | 151 | } 152 | /** 153 | * @brief TIM_Base MSP De-Initialization 154 | * This function freeze the hardware resources used in this example 155 | * @param htim_base: TIM_Base handle pointer 156 | * @retval None 157 | */ 158 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) 159 | { 160 | if(htim_base->Instance==TIM4) 161 | { 162 | /* USER CODE BEGIN TIM4_MspDeInit 0 */ 163 | 164 | /* USER CODE END TIM4_MspDeInit 0 */ 165 | /* Peripheral clock disable */ 166 | __HAL_RCC_TIM4_CLK_DISABLE(); 167 | 168 | /* TIM4 DMA DeInit */ 169 | HAL_DMA_DeInit(htim_base->hdma[TIM_DMA_ID_CC1]); 170 | /* USER CODE BEGIN TIM4_MspDeInit 1 */ 171 | 172 | /* USER CODE END TIM4_MspDeInit 1 */ 173 | } 174 | 175 | } 176 | 177 | /** 178 | * @brief UART MSP Initialization 179 | * This function configures the hardware resources used in this example 180 | * @param huart: UART handle pointer 181 | * @retval None 182 | */ 183 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) 184 | { 185 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 186 | if(huart->Instance==USART1) 187 | { 188 | /* USER CODE BEGIN USART1_MspInit 0 */ 189 | 190 | /* USER CODE END USART1_MspInit 0 */ 191 | /* Peripheral clock enable */ 192 | __HAL_RCC_USART1_CLK_ENABLE(); 193 | 194 | __HAL_RCC_GPIOA_CLK_ENABLE(); 195 | /**USART1 GPIO Configuration 196 | PA9 ------> USART1_TX 197 | PA10 ------> USART1_RX 198 | */ 199 | GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10; 200 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 201 | GPIO_InitStruct.Pull = GPIO_NOPULL; 202 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 203 | GPIO_InitStruct.Alternate = GPIO_AF7_USART1; 204 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 205 | 206 | /* USER CODE BEGIN USART1_MspInit 1 */ 207 | 208 | /* USER CODE END USART1_MspInit 1 */ 209 | 210 | } 211 | 212 | } 213 | 214 | /** 215 | * @brief UART MSP De-Initialization 216 | * This function freeze the hardware resources used in this example 217 | * @param huart: UART handle pointer 218 | * @retval None 219 | */ 220 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 221 | { 222 | if(huart->Instance==USART1) 223 | { 224 | /* USER CODE BEGIN USART1_MspDeInit 0 */ 225 | 226 | /* USER CODE END USART1_MspDeInit 0 */ 227 | /* Peripheral clock disable */ 228 | __HAL_RCC_USART1_CLK_DISABLE(); 229 | 230 | /**USART1 GPIO Configuration 231 | PA9 ------> USART1_TX 232 | PA10 ------> USART1_RX 233 | */ 234 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); 235 | 236 | /* USER CODE BEGIN USART1_MspDeInit 1 */ 237 | 238 | /* USER CODE END USART1_MspDeInit 1 */ 239 | } 240 | 241 | } 242 | 243 | /* USER CODE BEGIN 1 */ 244 | 245 | /* USER CODE END 1 */ 246 | -------------------------------------------------------------------------------- /examples/f411/Core/Src/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | #include "stm32f4xx_it.h" 23 | /* Private includes ----------------------------------------------------------*/ 24 | /* USER CODE BEGIN Includes */ 25 | /* USER CODE END Includes */ 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* USER CODE BEGIN TD */ 29 | 30 | /* USER CODE END TD */ 31 | 32 | /* Private define ------------------------------------------------------------*/ 33 | /* USER CODE BEGIN PD */ 34 | 35 | /* USER CODE END PD */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN PM */ 39 | 40 | /* USER CODE END PM */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | /* USER CODE BEGIN PV */ 44 | 45 | /* USER CODE END PV */ 46 | 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* USER CODE BEGIN PFP */ 49 | 50 | /* USER CODE END PFP */ 51 | 52 | /* Private user code ---------------------------------------------------------*/ 53 | /* USER CODE BEGIN 0 */ 54 | 55 | /* USER CODE END 0 */ 56 | 57 | /* External variables --------------------------------------------------------*/ 58 | extern DMA_HandleTypeDef hdma_tim4_ch1; 59 | /* USER CODE BEGIN EV */ 60 | 61 | /* USER CODE END EV */ 62 | 63 | /******************************************************************************/ 64 | /* Cortex-M4 Processor Interruption and Exception Handlers */ 65 | /******************************************************************************/ 66 | /** 67 | * @brief This function handles Non maskable interrupt. 68 | */ 69 | void NMI_Handler(void) 70 | { 71 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 72 | 73 | /* USER CODE END NonMaskableInt_IRQn 0 */ 74 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 75 | while (1) 76 | { 77 | } 78 | /* USER CODE END NonMaskableInt_IRQn 1 */ 79 | } 80 | 81 | /** 82 | * @brief This function handles Hard fault interrupt. 83 | */ 84 | void HardFault_Handler(void) 85 | { 86 | /* USER CODE BEGIN HardFault_IRQn 0 */ 87 | 88 | /* USER CODE END HardFault_IRQn 0 */ 89 | while (1) 90 | { 91 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 92 | /* USER CODE END W1_HardFault_IRQn 0 */ 93 | } 94 | } 95 | 96 | /** 97 | * @brief This function handles Memory management fault. 98 | */ 99 | void MemManage_Handler(void) 100 | { 101 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 102 | 103 | /* USER CODE END MemoryManagement_IRQn 0 */ 104 | while (1) 105 | { 106 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 107 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 108 | } 109 | } 110 | 111 | /** 112 | * @brief This function handles Pre-fetch fault, memory access fault. 113 | */ 114 | void BusFault_Handler(void) 115 | { 116 | /* USER CODE BEGIN BusFault_IRQn 0 */ 117 | 118 | /* USER CODE END BusFault_IRQn 0 */ 119 | while (1) 120 | { 121 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 122 | /* USER CODE END W1_BusFault_IRQn 0 */ 123 | } 124 | } 125 | 126 | /** 127 | * @brief This function handles Undefined instruction or illegal state. 128 | */ 129 | void UsageFault_Handler(void) 130 | { 131 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 132 | 133 | /* USER CODE END UsageFault_IRQn 0 */ 134 | while (1) 135 | { 136 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 137 | /* USER CODE END W1_UsageFault_IRQn 0 */ 138 | } 139 | } 140 | 141 | /** 142 | * @brief This function handles System service call via SWI instruction. 143 | */ 144 | void SVC_Handler(void) 145 | { 146 | /* USER CODE BEGIN SVCall_IRQn 0 */ 147 | 148 | /* USER CODE END SVCall_IRQn 0 */ 149 | /* USER CODE BEGIN SVCall_IRQn 1 */ 150 | 151 | /* USER CODE END SVCall_IRQn 1 */ 152 | } 153 | 154 | /** 155 | * @brief This function handles Debug monitor. 156 | */ 157 | void DebugMon_Handler(void) 158 | { 159 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 160 | 161 | /* USER CODE END DebugMonitor_IRQn 0 */ 162 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 163 | 164 | /* USER CODE END DebugMonitor_IRQn 1 */ 165 | } 166 | 167 | /** 168 | * @brief This function handles Pendable request for system service. 169 | */ 170 | void PendSV_Handler(void) 171 | { 172 | /* USER CODE BEGIN PendSV_IRQn 0 */ 173 | 174 | /* USER CODE END PendSV_IRQn 0 */ 175 | /* USER CODE BEGIN PendSV_IRQn 1 */ 176 | 177 | /* USER CODE END PendSV_IRQn 1 */ 178 | } 179 | 180 | /** 181 | * @brief This function handles System tick timer. 182 | */ 183 | void SysTick_Handler(void) 184 | { 185 | /* USER CODE BEGIN SysTick_IRQn 0 */ 186 | 187 | /* USER CODE END SysTick_IRQn 0 */ 188 | HAL_IncTick(); 189 | /* USER CODE BEGIN SysTick_IRQn 1 */ 190 | 191 | /* USER CODE END SysTick_IRQn 1 */ 192 | } 193 | 194 | /******************************************************************************/ 195 | /* STM32F4xx Peripheral Interrupt Handlers */ 196 | /* Add here the Interrupt Handlers for the used peripherals. */ 197 | /* For the available peripheral interrupt handler names, */ 198 | /* please refer to the startup file (startup_stm32f4xx.s). */ 199 | /******************************************************************************/ 200 | 201 | /** 202 | * @brief This function handles DMA1 stream0 global interrupt. 203 | */ 204 | void DMA1_Stream0_IRQHandler(void) 205 | { 206 | /* USER CODE BEGIN DMA1_Stream0_IRQn 0 */ 207 | 208 | /* USER CODE END DMA1_Stream0_IRQn 0 */ 209 | HAL_DMA_IRQHandler(&hdma_tim4_ch1); 210 | /* USER CODE BEGIN DMA1_Stream0_IRQn 1 */ 211 | 212 | /* USER CODE END DMA1_Stream0_IRQn 1 */ 213 | } 214 | 215 | /* USER CODE BEGIN 1 */ 216 | 217 | /* USER CODE END 1 */ 218 | -------------------------------------------------------------------------------- /examples/f411/Core/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file syscalls.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief STM32CubeIDE Minimal System calls file 6 | * 7 | * For more information about which c-functions 8 | * need which of these lowlevel functions 9 | * please consult the Newlib libc-manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * Copyright (c) 2022 STMicroelectronics. 14 | * All rights reserved. 15 | * 16 | * This software is licensed under terms that can be found in the LICENSE file 17 | * in the root directory of this software component. 18 | * If no LICENSE file comes with this software, it is provided AS-IS. 19 | * 20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | /* Variables */ 35 | extern int __io_putchar(int ch) __attribute__((weak)); 36 | extern int __io_getchar(void) __attribute__((weak)); 37 | 38 | 39 | char *__env[1] = { 0 }; 40 | char **environ = __env; 41 | 42 | 43 | /* Functions */ 44 | void initialise_monitor_handles() 45 | { 46 | } 47 | 48 | int _getpid(void) 49 | { 50 | return 1; 51 | } 52 | 53 | int _kill(int pid, int sig) 54 | { 55 | errno = EINVAL; 56 | return -1; 57 | } 58 | 59 | void _exit (int status) 60 | { 61 | _kill(status, -1); 62 | while (1) {} /* Make sure we hang here */ 63 | } 64 | 65 | __attribute__((weak)) int _read(int file, char *ptr, int len) 66 | { 67 | int DataIdx; 68 | 69 | for (DataIdx = 0; DataIdx < len; DataIdx++) 70 | { 71 | *ptr++ = __io_getchar(); 72 | } 73 | 74 | return len; 75 | } 76 | 77 | __attribute__((weak)) int _write(int file, char *ptr, int len) 78 | { 79 | int DataIdx; 80 | 81 | for (DataIdx = 0; DataIdx < len; DataIdx++) 82 | { 83 | __io_putchar(*ptr++); 84 | } 85 | return len; 86 | } 87 | 88 | int _close(int file) 89 | { 90 | return -1; 91 | } 92 | 93 | 94 | int _fstat(int file, struct stat *st) 95 | { 96 | st->st_mode = S_IFCHR; 97 | return 0; 98 | } 99 | 100 | int _isatty(int file) 101 | { 102 | return 1; 103 | } 104 | 105 | int _lseek(int file, int ptr, int dir) 106 | { 107 | return 0; 108 | } 109 | 110 | int _open(char *path, int flags, ...) 111 | { 112 | /* Pretend like we always fail */ 113 | return -1; 114 | } 115 | 116 | int _wait(int *status) 117 | { 118 | errno = ECHILD; 119 | return -1; 120 | } 121 | 122 | int _unlink(char *name) 123 | { 124 | errno = ENOENT; 125 | return -1; 126 | } 127 | 128 | int _times(struct tms *buf) 129 | { 130 | return -1; 131 | } 132 | 133 | int _stat(char *file, struct stat *st) 134 | { 135 | st->st_mode = S_IFCHR; 136 | return 0; 137 | } 138 | 139 | int _link(char *old, char *new) 140 | { 141 | errno = EMLINK; 142 | return -1; 143 | } 144 | 145 | int _fork(void) 146 | { 147 | errno = EAGAIN; 148 | return -1; 149 | } 150 | 151 | int _execve(char *name, char **argv, char **env) 152 | { 153 | errno = ENOMEM; 154 | return -1; 155 | } 156 | -------------------------------------------------------------------------------- /examples/f411/Core/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sysmem.c 4 | * @author Generated by STM32CubeIDE 5 | * @brief STM32CubeIDE System Memory calls file 6 | * 7 | * For more information about which C functions 8 | * need which of these lowlevel functions 9 | * please consult the newlib libc manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * Copyright (c) 2022 STMicroelectronics. 14 | * All rights reserved. 15 | * 16 | * This software is licensed under terms that can be found in the LICENSE file 17 | * in the root directory of this software component. 18 | * If no LICENSE file comes with this software, it is provided AS-IS. 19 | * 20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes */ 24 | #include 25 | #include 26 | 27 | /** 28 | * Pointer to the current high watermark of the heap usage 29 | */ 30 | static uint8_t *__sbrk_heap_end = NULL; 31 | 32 | /** 33 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc 34 | * and others from the C library 35 | * 36 | * @verbatim 37 | * ############################################################################ 38 | * # .data # .bss # newlib heap # MSP stack # 39 | * # # # # Reserved by _Min_Stack_Size # 40 | * ############################################################################ 41 | * ^-- RAM start ^-- _end _estack, RAM end --^ 42 | * @endverbatim 43 | * 44 | * This implementation starts allocating at the '_end' linker symbol 45 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack 46 | * The implementation considers '_estack' linker symbol to be RAM end 47 | * NOTE: If the MSP stack, at any point during execution, grows larger than the 48 | * reserved size, please increase the '_Min_Stack_Size'. 49 | * 50 | * @param incr Memory size 51 | * @return Pointer to allocated memory 52 | */ 53 | void *_sbrk(ptrdiff_t incr) 54 | { 55 | extern uint8_t _end; /* Symbol defined in the linker script */ 56 | extern uint8_t _estack; /* Symbol defined in the linker script */ 57 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ 58 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; 59 | const uint8_t *max_heap = (uint8_t *)stack_limit; 60 | uint8_t *prev_heap_end; 61 | 62 | /* Initialize heap end at first call */ 63 | if (NULL == __sbrk_heap_end) 64 | { 65 | __sbrk_heap_end = &_end; 66 | } 67 | 68 | /* Protect heap from growing into the reserved MSP stack */ 69 | if (__sbrk_heap_end + incr > max_heap) 70 | { 71 | errno = ENOMEM; 72 | return (void *)-1; 73 | } 74 | 75 | prev_heap_end = __sbrk_heap_end; 76 | __sbrk_heap_end += incr; 77 | 78 | return (void *)prev_heap_end; 79 | } 80 | -------------------------------------------------------------------------------- /examples/f411/Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /** @addtogroup CMSIS 20 | * @{ 21 | */ 22 | 23 | /** @addtogroup stm32f4xx_system 24 | * @{ 25 | */ 26 | 27 | /** 28 | * @brief Define to prevent recursive inclusion 29 | */ 30 | #ifndef __SYSTEM_STM32F4XX_H 31 | #define __SYSTEM_STM32F4XX_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** @addtogroup STM32F4xx_System_Includes 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | 46 | /** @addtogroup STM32F4xx_System_Exported_types 47 | * @{ 48 | */ 49 | /* This variable is updated in three ways: 50 | 1) by calling CMSIS function SystemCoreClockUpdate() 51 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 52 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 53 | Note: If you use this function to configure the system clock; then there 54 | is no need to call the 2 first functions listed above, since SystemCoreClock 55 | variable is updated automatically. 56 | */ 57 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 58 | 59 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 60 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | -------------------------------------------------------------------------------- /examples/f411/Drivers/CMSIS/Device/ST/STM32F4xx/LICENSE.txt: -------------------------------------------------------------------------------- 1 | This software component is provided to you as part of a software package and 2 | applicable license terms are in the Package_license file. If you received this 3 | software component outside of a package or without applicable license terms, 4 | the terms of the Apache-2.0 license shall apply. 5 | You may obtain a copy of the Apache-2.0 at: 6 | https://opensource.org/licenses/Apache-2.0 7 | -------------------------------------------------------------------------------- /examples/f411/Drivers/CMSIS/Include/cmsis_compiler.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_compiler.h 3 | * @brief CMSIS compiler generic header file 4 | * @version V5.1.0 5 | * @date 09. October 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #ifndef __CMSIS_COMPILER_H 26 | #define __CMSIS_COMPILER_H 27 | 28 | #include 29 | 30 | /* 31 | * Arm Compiler 4/5 32 | */ 33 | #if defined ( __CC_ARM ) 34 | #include "cmsis_armcc.h" 35 | 36 | 37 | /* 38 | * Arm Compiler 6.6 LTM (armclang) 39 | */ 40 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100) 41 | #include "cmsis_armclang_ltm.h" 42 | 43 | /* 44 | * Arm Compiler above 6.10.1 (armclang) 45 | */ 46 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) 47 | #include "cmsis_armclang.h" 48 | 49 | 50 | /* 51 | * GNU Compiler 52 | */ 53 | #elif defined ( __GNUC__ ) 54 | #include "cmsis_gcc.h" 55 | 56 | 57 | /* 58 | * IAR Compiler 59 | */ 60 | #elif defined ( __ICCARM__ ) 61 | #include 62 | 63 | 64 | /* 65 | * TI Arm Compiler 66 | */ 67 | #elif defined ( __TI_ARM__ ) 68 | #include 69 | 70 | #ifndef __ASM 71 | #define __ASM __asm 72 | #endif 73 | #ifndef __INLINE 74 | #define __INLINE inline 75 | #endif 76 | #ifndef __STATIC_INLINE 77 | #define __STATIC_INLINE static inline 78 | #endif 79 | #ifndef __STATIC_FORCEINLINE 80 | #define __STATIC_FORCEINLINE __STATIC_INLINE 81 | #endif 82 | #ifndef __NO_RETURN 83 | #define __NO_RETURN __attribute__((noreturn)) 84 | #endif 85 | #ifndef __USED 86 | #define __USED __attribute__((used)) 87 | #endif 88 | #ifndef __WEAK 89 | #define __WEAK __attribute__((weak)) 90 | #endif 91 | #ifndef __PACKED 92 | #define __PACKED __attribute__((packed)) 93 | #endif 94 | #ifndef __PACKED_STRUCT 95 | #define __PACKED_STRUCT struct __attribute__((packed)) 96 | #endif 97 | #ifndef __PACKED_UNION 98 | #define __PACKED_UNION union __attribute__((packed)) 99 | #endif 100 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 101 | struct __attribute__((packed)) T_UINT32 { uint32_t v; }; 102 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 103 | #endif 104 | #ifndef __UNALIGNED_UINT16_WRITE 105 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 106 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 107 | #endif 108 | #ifndef __UNALIGNED_UINT16_READ 109 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 110 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 111 | #endif 112 | #ifndef __UNALIGNED_UINT32_WRITE 113 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 114 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 115 | #endif 116 | #ifndef __UNALIGNED_UINT32_READ 117 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 118 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 119 | #endif 120 | #ifndef __ALIGNED 121 | #define __ALIGNED(x) __attribute__((aligned(x))) 122 | #endif 123 | #ifndef __RESTRICT 124 | #define __RESTRICT __restrict 125 | #endif 126 | #ifndef __COMPILER_BARRIER 127 | #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 128 | #define __COMPILER_BARRIER() (void)0 129 | #endif 130 | 131 | 132 | /* 133 | * TASKING Compiler 134 | */ 135 | #elif defined ( __TASKING__ ) 136 | /* 137 | * The CMSIS functions have been implemented as intrinsics in the compiler. 138 | * Please use "carm -?i" to get an up to date list of all intrinsics, 139 | * Including the CMSIS ones. 140 | */ 141 | 142 | #ifndef __ASM 143 | #define __ASM __asm 144 | #endif 145 | #ifndef __INLINE 146 | #define __INLINE inline 147 | #endif 148 | #ifndef __STATIC_INLINE 149 | #define __STATIC_INLINE static inline 150 | #endif 151 | #ifndef __STATIC_FORCEINLINE 152 | #define __STATIC_FORCEINLINE __STATIC_INLINE 153 | #endif 154 | #ifndef __NO_RETURN 155 | #define __NO_RETURN __attribute__((noreturn)) 156 | #endif 157 | #ifndef __USED 158 | #define __USED __attribute__((used)) 159 | #endif 160 | #ifndef __WEAK 161 | #define __WEAK __attribute__((weak)) 162 | #endif 163 | #ifndef __PACKED 164 | #define __PACKED __packed__ 165 | #endif 166 | #ifndef __PACKED_STRUCT 167 | #define __PACKED_STRUCT struct __packed__ 168 | #endif 169 | #ifndef __PACKED_UNION 170 | #define __PACKED_UNION union __packed__ 171 | #endif 172 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 173 | struct __packed__ T_UINT32 { uint32_t v; }; 174 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 175 | #endif 176 | #ifndef __UNALIGNED_UINT16_WRITE 177 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 178 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 179 | #endif 180 | #ifndef __UNALIGNED_UINT16_READ 181 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 182 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 183 | #endif 184 | #ifndef __UNALIGNED_UINT32_WRITE 185 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 186 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 187 | #endif 188 | #ifndef __UNALIGNED_UINT32_READ 189 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 190 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 191 | #endif 192 | #ifndef __ALIGNED 193 | #define __ALIGNED(x) __align(x) 194 | #endif 195 | #ifndef __RESTRICT 196 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 197 | #define __RESTRICT 198 | #endif 199 | #ifndef __COMPILER_BARRIER 200 | #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 201 | #define __COMPILER_BARRIER() (void)0 202 | #endif 203 | 204 | 205 | /* 206 | * COSMIC Compiler 207 | */ 208 | #elif defined ( __CSMC__ ) 209 | #include 210 | 211 | #ifndef __ASM 212 | #define __ASM _asm 213 | #endif 214 | #ifndef __INLINE 215 | #define __INLINE inline 216 | #endif 217 | #ifndef __STATIC_INLINE 218 | #define __STATIC_INLINE static inline 219 | #endif 220 | #ifndef __STATIC_FORCEINLINE 221 | #define __STATIC_FORCEINLINE __STATIC_INLINE 222 | #endif 223 | #ifndef __NO_RETURN 224 | // NO RETURN is automatically detected hence no warning here 225 | #define __NO_RETURN 226 | #endif 227 | #ifndef __USED 228 | #warning No compiler specific solution for __USED. __USED is ignored. 229 | #define __USED 230 | #endif 231 | #ifndef __WEAK 232 | #define __WEAK __weak 233 | #endif 234 | #ifndef __PACKED 235 | #define __PACKED @packed 236 | #endif 237 | #ifndef __PACKED_STRUCT 238 | #define __PACKED_STRUCT @packed struct 239 | #endif 240 | #ifndef __PACKED_UNION 241 | #define __PACKED_UNION @packed union 242 | #endif 243 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 244 | @packed struct T_UINT32 { uint32_t v; }; 245 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 246 | #endif 247 | #ifndef __UNALIGNED_UINT16_WRITE 248 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 249 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 250 | #endif 251 | #ifndef __UNALIGNED_UINT16_READ 252 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 253 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 254 | #endif 255 | #ifndef __UNALIGNED_UINT32_WRITE 256 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 257 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 258 | #endif 259 | #ifndef __UNALIGNED_UINT32_READ 260 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 261 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 262 | #endif 263 | #ifndef __ALIGNED 264 | #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 265 | #define __ALIGNED(x) 266 | #endif 267 | #ifndef __RESTRICT 268 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 269 | #define __RESTRICT 270 | #endif 271 | #ifndef __COMPILER_BARRIER 272 | #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 273 | #define __COMPILER_BARRIER() (void)0 274 | #endif 275 | 276 | 277 | #else 278 | #error Unknown compiler. 279 | #endif 280 | 281 | 282 | #endif /* __CMSIS_COMPILER_H */ 283 | 284 | -------------------------------------------------------------------------------- /examples/f411/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.5 5 | * @date 02. February 2022 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2022 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 6U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /examples/f411/Drivers/CMSIS/Include/pac_armv81.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file pac_armv81.h 3 | * @brief CMSIS PAC key functions for Armv8.1-M PAC extension 4 | * @version V1.0.0 5 | * @date 23. March 2022 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2022 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef PAC_ARMV81_H 32 | #define PAC_ARMV81_H 33 | 34 | 35 | /* ################### PAC Key functions ########################### */ 36 | /** 37 | \ingroup CMSIS_Core_FunctionInterface 38 | \defgroup CMSIS_Core_PacKeyFunctions PAC Key functions 39 | \brief Functions that access the PAC keys. 40 | @{ 41 | */ 42 | 43 | #if (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1)) 44 | 45 | /** 46 | \brief read the PAC key used for privileged mode 47 | \details Reads the PAC key stored in the PAC_KEY_P registers. 48 | \param [out] pPacKey 128bit PAC key 49 | */ 50 | __STATIC_FORCEINLINE void __get_PAC_KEY_P (uint32_t* pPacKey) { 51 | __ASM volatile ( 52 | "mrs r1, pac_key_p_0\n" 53 | "str r1,[%0,#0]\n" 54 | "mrs r1, pac_key_p_1\n" 55 | "str r1,[%0,#4]\n" 56 | "mrs r1, pac_key_p_2\n" 57 | "str r1,[%0,#8]\n" 58 | "mrs r1, pac_key_p_3\n" 59 | "str r1,[%0,#12]\n" 60 | : : "r" (pPacKey) : "memory", "r1" 61 | ); 62 | } 63 | 64 | /** 65 | \brief write the PAC key used for privileged mode 66 | \details writes the given PAC key to the PAC_KEY_P registers. 67 | \param [in] pPacKey 128bit PAC key 68 | */ 69 | __STATIC_FORCEINLINE void __set_PAC_KEY_P (uint32_t* pPacKey) { 70 | __ASM volatile ( 71 | "ldr r1,[%0,#0]\n" 72 | "msr pac_key_p_0, r1\n" 73 | "ldr r1,[%0,#4]\n" 74 | "msr pac_key_p_1, r1\n" 75 | "ldr r1,[%0,#8]\n" 76 | "msr pac_key_p_2, r1\n" 77 | "ldr r1,[%0,#12]\n" 78 | "msr pac_key_p_3, r1\n" 79 | : : "r" (pPacKey) : "memory", "r1" 80 | ); 81 | } 82 | 83 | /** 84 | \brief read the PAC key used for unprivileged mode 85 | \details Reads the PAC key stored in the PAC_KEY_U registers. 86 | \param [out] pPacKey 128bit PAC key 87 | */ 88 | __STATIC_FORCEINLINE void __get_PAC_KEY_U (uint32_t* pPacKey) { 89 | __ASM volatile ( 90 | "mrs r1, pac_key_u_0\n" 91 | "str r1,[%0,#0]\n" 92 | "mrs r1, pac_key_u_1\n" 93 | "str r1,[%0,#4]\n" 94 | "mrs r1, pac_key_u_2\n" 95 | "str r1,[%0,#8]\n" 96 | "mrs r1, pac_key_u_3\n" 97 | "str r1,[%0,#12]\n" 98 | : : "r" (pPacKey) : "memory", "r1" 99 | ); 100 | } 101 | 102 | /** 103 | \brief write the PAC key used for unprivileged mode 104 | \details writes the given PAC key to the PAC_KEY_U registers. 105 | \param [in] pPacKey 128bit PAC key 106 | */ 107 | __STATIC_FORCEINLINE void __set_PAC_KEY_U (uint32_t* pPacKey) { 108 | __ASM volatile ( 109 | "ldr r1,[%0,#0]\n" 110 | "msr pac_key_u_0, r1\n" 111 | "ldr r1,[%0,#4]\n" 112 | "msr pac_key_u_1, r1\n" 113 | "ldr r1,[%0,#8]\n" 114 | "msr pac_key_u_2, r1\n" 115 | "ldr r1,[%0,#12]\n" 116 | "msr pac_key_u_3, r1\n" 117 | : : "r" (pPacKey) : "memory", "r1" 118 | ); 119 | } 120 | 121 | #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) 122 | 123 | /** 124 | \brief read the PAC key used for privileged mode (non-secure) 125 | \details Reads the PAC key stored in the non-secure PAC_KEY_P registers when in secure mode. 126 | \param [out] pPacKey 128bit PAC key 127 | */ 128 | __STATIC_FORCEINLINE void __TZ_get_PAC_KEY_P_NS (uint32_t* pPacKey) { 129 | __ASM volatile ( 130 | "mrs r1, pac_key_p_0_ns\n" 131 | "str r1,[%0,#0]\n" 132 | "mrs r1, pac_key_p_1_ns\n" 133 | "str r1,[%0,#4]\n" 134 | "mrs r1, pac_key_p_2_ns\n" 135 | "str r1,[%0,#8]\n" 136 | "mrs r1, pac_key_p_3_ns\n" 137 | "str r1,[%0,#12]\n" 138 | : : "r" (pPacKey) : "memory", "r1" 139 | ); 140 | } 141 | 142 | /** 143 | \brief write the PAC key used for privileged mode (non-secure) 144 | \details writes the given PAC key to the non-secure PAC_KEY_P registers when in secure mode. 145 | \param [in] pPacKey 128bit PAC key 146 | */ 147 | __STATIC_FORCEINLINE void __TZ_set_PAC_KEY_P_NS (uint32_t* pPacKey) { 148 | __ASM volatile ( 149 | "ldr r1,[%0,#0]\n" 150 | "msr pac_key_p_0_ns, r1\n" 151 | "ldr r1,[%0,#4]\n" 152 | "msr pac_key_p_1_ns, r1\n" 153 | "ldr r1,[%0,#8]\n" 154 | "msr pac_key_p_2_ns, r1\n" 155 | "ldr r1,[%0,#12]\n" 156 | "msr pac_key_p_3_ns, r1\n" 157 | : : "r" (pPacKey) : "memory", "r1" 158 | ); 159 | } 160 | 161 | /** 162 | \brief read the PAC key used for unprivileged mode (non-secure) 163 | \details Reads the PAC key stored in the non-secure PAC_KEY_U registers when in secure mode. 164 | \param [out] pPacKey 128bit PAC key 165 | */ 166 | __STATIC_FORCEINLINE void __TZ_get_PAC_KEY_U_NS (uint32_t* pPacKey) { 167 | __ASM volatile ( 168 | "mrs r1, pac_key_u_0_ns\n" 169 | "str r1,[%0,#0]\n" 170 | "mrs r1, pac_key_u_1_ns\n" 171 | "str r1,[%0,#4]\n" 172 | "mrs r1, pac_key_u_2_ns\n" 173 | "str r1,[%0,#8]\n" 174 | "mrs r1, pac_key_u_3_ns\n" 175 | "str r1,[%0,#12]\n" 176 | : : "r" (pPacKey) : "memory", "r1" 177 | ); 178 | } 179 | 180 | /** 181 | \brief write the PAC key used for unprivileged mode (non-secure) 182 | \details writes the given PAC key to the non-secure PAC_KEY_U registers when in secure mode. 183 | \param [in] pPacKey 128bit PAC key 184 | */ 185 | __STATIC_FORCEINLINE void __TZ_set_PAC_KEY_U_NS (uint32_t* pPacKey) { 186 | __ASM volatile ( 187 | "ldr r1,[%0,#0]\n" 188 | "msr pac_key_u_0_ns, r1\n" 189 | "ldr r1,[%0,#4]\n" 190 | "msr pac_key_u_1_ns, r1\n" 191 | "ldr r1,[%0,#8]\n" 192 | "msr pac_key_u_2_ns, r1\n" 193 | "ldr r1,[%0,#12]\n" 194 | "msr pac_key_u_3_ns, r1\n" 195 | : : "r" (pPacKey) : "memory", "r1" 196 | ); 197 | } 198 | 199 | #endif /* (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) */ 200 | 201 | #endif /* (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1)) */ 202 | 203 | /*@} end of CMSIS_Core_PacKeyFunctions */ 204 | 205 | 206 | #endif /* PAC_ARMV81_H */ 207 | -------------------------------------------------------------------------------- /examples/f411/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /examples/f411/Drivers/CMSIS/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /examples/f411/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2017 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_DEF 22 | #define __STM32F4xx_HAL_DEF 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx.h" 30 | #include "Legacy/stm32_hal_legacy.h" 31 | #include 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | 35 | /** 36 | * @brief HAL Status structures definition 37 | */ 38 | typedef enum 39 | { 40 | HAL_OK = 0x00U, 41 | HAL_ERROR = 0x01U, 42 | HAL_BUSY = 0x02U, 43 | HAL_TIMEOUT = 0x03U 44 | } HAL_StatusTypeDef; 45 | 46 | /** 47 | * @brief HAL Lock structures definition 48 | */ 49 | typedef enum 50 | { 51 | HAL_UNLOCKED = 0x00U, 52 | HAL_LOCKED = 0x01U 53 | } HAL_LockTypeDef; 54 | 55 | /* Exported macro ------------------------------------------------------------*/ 56 | 57 | #if !defined(UNUSED) 58 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 59 | #endif /* UNUSED */ 60 | 61 | #define HAL_MAX_DELAY 0xFFFFFFFFU 62 | 63 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 64 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 65 | 66 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 67 | do{ \ 68 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 69 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 70 | } while(0U) 71 | 72 | /** @brief Reset the Handle's State field. 73 | * @param __HANDLE__ specifies the Peripheral Handle. 74 | * @note This macro can be used for the following purpose: 75 | * - When the Handle is declared as local variable; before passing it as parameter 76 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 77 | * to set to 0 the Handle's "State" field. 78 | * Otherwise, "State" field may have any random value and the first time the function 79 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 80 | * (i.e. HAL_PPP_MspInit() will not be executed). 81 | * - When there is a need to reconfigure the low level hardware: instead of calling 82 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 83 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 84 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 85 | * @retval None 86 | */ 87 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 88 | 89 | #if (USE_RTOS == 1U) 90 | /* Reserved for future use */ 91 | #error "USE_RTOS should be 0 in the current HAL release" 92 | #else 93 | #define __HAL_LOCK(__HANDLE__) \ 94 | do{ \ 95 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 96 | { \ 97 | return HAL_BUSY; \ 98 | } \ 99 | else \ 100 | { \ 101 | (__HANDLE__)->Lock = HAL_LOCKED; \ 102 | } \ 103 | }while (0U) 104 | 105 | #define __HAL_UNLOCK(__HANDLE__) \ 106 | do{ \ 107 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 108 | }while (0U) 109 | #endif /* USE_RTOS */ 110 | 111 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 112 | #ifndef __weak 113 | #define __weak __attribute__((weak)) 114 | #endif 115 | #ifndef __packed 116 | #define __packed __attribute__((packed)) 117 | #endif 118 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 119 | #ifndef __weak 120 | #define __weak __attribute__((weak)) 121 | #endif /* __weak */ 122 | #ifndef __packed 123 | #define __packed __attribute__((__packed__)) 124 | #endif /* __packed */ 125 | #endif /* __GNUC__ */ 126 | 127 | 128 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 129 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 130 | #ifndef __ALIGN_BEGIN 131 | #define __ALIGN_BEGIN 132 | #endif 133 | #ifndef __ALIGN_END 134 | #define __ALIGN_END __attribute__ ((aligned (4))) 135 | #endif 136 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 137 | #ifndef __ALIGN_END 138 | #define __ALIGN_END __attribute__ ((aligned (4))) 139 | #endif /* __ALIGN_END */ 140 | #ifndef __ALIGN_BEGIN 141 | #define __ALIGN_BEGIN 142 | #endif /* __ALIGN_BEGIN */ 143 | #else 144 | #ifndef __ALIGN_END 145 | #define __ALIGN_END 146 | #endif /* __ALIGN_END */ 147 | #ifndef __ALIGN_BEGIN 148 | #if defined (__CC_ARM) /* ARM Compiler V5*/ 149 | #define __ALIGN_BEGIN __align(4) 150 | #elif defined (__ICCARM__) /* IAR Compiler */ 151 | #define __ALIGN_BEGIN 152 | #endif /* __CC_ARM */ 153 | #endif /* __ALIGN_BEGIN */ 154 | #endif /* __GNUC__ */ 155 | 156 | 157 | /** 158 | * @brief __RAM_FUNC definition 159 | */ 160 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) 161 | /* ARM Compiler V4/V5 and V6 162 | -------------------------- 163 | RAM functions are defined using the toolchain options. 164 | Functions that are executed in RAM should reside in a separate source module. 165 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 166 | area of a module to a memory space in physical RAM. 167 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 168 | dialog. 169 | */ 170 | #define __RAM_FUNC 171 | 172 | #elif defined ( __ICCARM__ ) 173 | /* ICCARM Compiler 174 | --------------- 175 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 176 | */ 177 | #define __RAM_FUNC __ramfunc 178 | 179 | #elif defined ( __GNUC__ ) 180 | /* GNU Compiler 181 | ------------ 182 | RAM functions are defined using a specific toolchain attribute 183 | "__attribute__((section(".RamFunc")))". 184 | */ 185 | #define __RAM_FUNC __attribute__((section(".RamFunc"))) 186 | 187 | #endif 188 | 189 | /** 190 | * @brief __NOINLINE definition 191 | */ 192 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ ) 193 | /* ARM V4/V5 and V6 & GNU Compiler 194 | ------------------------------- 195 | */ 196 | #define __NOINLINE __attribute__ ( (noinline) ) 197 | 198 | #elif defined ( __ICCARM__ ) 199 | /* ICCARM Compiler 200 | --------------- 201 | */ 202 | #define __NOINLINE _Pragma("optimize = no_inline") 203 | 204 | #endif 205 | 206 | #ifdef __cplusplus 207 | } 208 | #endif 209 | 210 | #endif /* ___STM32F4xx_HAL_DEF */ 211 | 212 | 213 | -------------------------------------------------------------------------------- /examples/f411/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file in 13 | * the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __STM32F4xx_HAL_DMA_EX_H 21 | #define __STM32F4xx_HAL_DMA_EX_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32f4xx_hal_def.h" 29 | 30 | /** @addtogroup STM32F4xx_HAL_Driver 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup DMAEx 35 | * @{ 36 | */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 40 | * @brief DMAEx Exported types 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief HAL DMA Memory definition 46 | */ 47 | typedef enum 48 | { 49 | MEMORY0 = 0x00U, /*!< Memory 0 */ 50 | MEMORY1 = 0x01U /*!< Memory 1 */ 51 | }HAL_DMA_MemoryTypeDef; 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | /* Exported functions --------------------------------------------------------*/ 58 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 59 | * @brief DMAEx Exported functions 60 | * @{ 61 | */ 62 | 63 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 64 | * @brief Extended features functions 65 | * @{ 66 | */ 67 | 68 | /* IO operation functions *******************************************************/ 69 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 72 | 73 | /** 74 | * @} 75 | */ 76 | /** 77 | * @} 78 | */ 79 | 80 | /* Private functions ---------------------------------------------------------*/ 81 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 82 | * @brief DMAEx Private functions 83 | * @{ 84 | */ 85 | /** 86 | * @} 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 102 | 103 | -------------------------------------------------------------------------------- /examples/f411/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file in 13 | * the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | ****************************************************************************** 16 | */ 17 | 18 | /* Define to prevent recursive inclusion -------------------------------------*/ 19 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 20 | #define __STM32F4xx_FLASH_RAMFUNC_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 26 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup FLASH_RAMFUNC 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported functions --------------------------------------------------------*/ 42 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 43 | * @{ 44 | */ 45 | 46 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 47 | * @{ 48 | */ 49 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 50 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 53 | /** 54 | * @} 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | 75 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 76 | 77 | -------------------------------------------------------------------------------- /examples/f411/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_ll_utils.h 4 | * @author MCD Application Team 5 | * @brief Header file of UTILS LL module. 6 | @verbatim 7 | ============================================================================== 8 | ##### How to use this driver ##### 9 | ============================================================================== 10 | [..] 11 | The LL UTILS driver contains a set of generic APIs that can be 12 | used by user: 13 | (+) Device electronic signature 14 | (+) Timing functions 15 | (+) PLL configuration functions 16 | 17 | @endverbatim 18 | ****************************************************************************** 19 | * @attention 20 | * 21 | * Copyright (c) 2017 STMicroelectronics. 22 | * All rights reserved. 23 | * 24 | * This software is licensed under terms that can be found in the LICENSE file 25 | * in the root directory of this software component. 26 | * If no LICENSE file comes with this software, it is provided AS-IS. 27 | * 28 | ****************************************************************************** 29 | */ 30 | 31 | /* Define to prevent recursive inclusion -------------------------------------*/ 32 | #ifndef __STM32F4xx_LL_UTILS_H 33 | #define __STM32F4xx_LL_UTILS_H 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* Includes ------------------------------------------------------------------*/ 40 | #include "stm32f4xx.h" 41 | 42 | /** @addtogroup STM32F4xx_LL_Driver 43 | * @{ 44 | */ 45 | 46 | /** @defgroup UTILS_LL UTILS 47 | * @{ 48 | */ 49 | 50 | /* Private types -------------------------------------------------------------*/ 51 | /* Private variables ---------------------------------------------------------*/ 52 | 53 | /* Private constants ---------------------------------------------------------*/ 54 | /** @defgroup UTILS_LL_Private_Constants UTILS Private Constants 55 | * @{ 56 | */ 57 | 58 | /* Max delay can be used in LL_mDelay */ 59 | #define LL_MAX_DELAY 0xFFFFFFFFU 60 | 61 | /** 62 | * @brief Unique device ID register base address 63 | */ 64 | #define UID_BASE_ADDRESS UID_BASE 65 | 66 | /** 67 | * @brief Flash size data register base address 68 | */ 69 | #define FLASHSIZE_BASE_ADDRESS FLASHSIZE_BASE 70 | 71 | /** 72 | * @brief Package data register base address 73 | */ 74 | #define PACKAGE_BASE_ADDRESS PACKAGE_BASE 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /* Private macros ------------------------------------------------------------*/ 81 | /** @defgroup UTILS_LL_Private_Macros UTILS Private Macros 82 | * @{ 83 | */ 84 | /** 85 | * @} 86 | */ 87 | /* Exported types ------------------------------------------------------------*/ 88 | /** @defgroup UTILS_LL_ES_INIT UTILS Exported structures 89 | * @{ 90 | */ 91 | /** 92 | * @brief UTILS PLL structure definition 93 | */ 94 | typedef struct 95 | { 96 | uint32_t PLLM; /*!< Division factor for PLL VCO input clock. 97 | This parameter can be a value of @ref RCC_LL_EC_PLLM_DIV 98 | 99 | This feature can be modified afterwards using unitary function 100 | @ref LL_RCC_PLL_ConfigDomain_SYS(). */ 101 | 102 | uint32_t PLLN; /*!< Multiplication factor for PLL VCO output clock. 103 | This parameter must be a number between Min_Data = @ref RCC_PLLN_MIN_VALUE 104 | and Max_Data = @ref RCC_PLLN_MIN_VALUE 105 | 106 | This feature can be modified afterwards using unitary function 107 | @ref LL_RCC_PLL_ConfigDomain_SYS(). */ 108 | 109 | uint32_t PLLP; /*!< Division for the main system clock. 110 | This parameter can be a value of @ref RCC_LL_EC_PLLP_DIV 111 | 112 | This feature can be modified afterwards using unitary function 113 | @ref LL_RCC_PLL_ConfigDomain_SYS(). */ 114 | } LL_UTILS_PLLInitTypeDef; 115 | 116 | /** 117 | * @brief UTILS System, AHB and APB buses clock configuration structure definition 118 | */ 119 | typedef struct 120 | { 121 | uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK). 122 | This parameter can be a value of @ref RCC_LL_EC_SYSCLK_DIV 123 | 124 | This feature can be modified afterwards using unitary function 125 | @ref LL_RCC_SetAHBPrescaler(). */ 126 | 127 | uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK). 128 | This parameter can be a value of @ref RCC_LL_EC_APB1_DIV 129 | 130 | This feature can be modified afterwards using unitary function 131 | @ref LL_RCC_SetAPB1Prescaler(). */ 132 | 133 | uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK). 134 | This parameter can be a value of @ref RCC_LL_EC_APB2_DIV 135 | 136 | This feature can be modified afterwards using unitary function 137 | @ref LL_RCC_SetAPB2Prescaler(). */ 138 | 139 | } LL_UTILS_ClkInitTypeDef; 140 | 141 | /** 142 | * @} 143 | */ 144 | 145 | /* Exported constants --------------------------------------------------------*/ 146 | /** @defgroup UTILS_LL_Exported_Constants UTILS Exported Constants 147 | * @{ 148 | */ 149 | 150 | /** @defgroup UTILS_EC_HSE_BYPASS HSE Bypass activation 151 | * @{ 152 | */ 153 | #define LL_UTILS_HSEBYPASS_OFF 0x00000000U /*!< HSE Bypass is not enabled */ 154 | #define LL_UTILS_HSEBYPASS_ON 0x00000001U /*!< HSE Bypass is enabled */ 155 | /** 156 | * @} 157 | */ 158 | 159 | /** @defgroup UTILS_EC_PACKAGETYPE PACKAGE TYPE 160 | * @{ 161 | */ 162 | #define LL_UTILS_PACKAGETYPE_WLCSP36_UFQFPN48_LQFP64 0x00000000U /*!< WLCSP36 or UFQFPN48 or LQFP64 package type */ 163 | #define LL_UTILS_PACKAGETYPE_WLCSP168_FBGA169_LQFP100_LQFP64_UFQFPN48 0x00000100U /*!< WLCSP168 or FBGA169 or LQFP100 or LQFP64 or UFQFPN48 package type */ 164 | #define LL_UTILS_PACKAGETYPE_WLCSP64_WLCSP81_LQFP176_UFBGA176 0x00000200U /*!< WLCSP64 or WLCSP81 or LQFP176 or UFBGA176 package type */ 165 | #define LL_UTILS_PACKAGETYPE_LQFP144_UFBGA144_UFBGA144_UFBGA100 0x00000300U /*!< LQFP144 or UFBGA144 or UFBGA144 or UFBGA100 package type */ 166 | #define LL_UTILS_PACKAGETYPE_LQFP100_LQFP208_TFBGA216 0x00000400U /*!< LQFP100 or LQFP208 or TFBGA216 package type */ 167 | #define LL_UTILS_PACKAGETYPE_LQFP208_TFBGA216 0x00000500U /*!< LQFP208 or TFBGA216 package type */ 168 | #define LL_UTILS_PACKAGETYPE_TQFP64_UFBGA144_LQFP144 0x00000700U /*!< TQFP64 or UFBGA144 or LQFP144 package type */ 169 | /** 170 | * @} 171 | */ 172 | 173 | /** 174 | * @} 175 | */ 176 | 177 | /* Exported macro ------------------------------------------------------------*/ 178 | 179 | /* Exported functions --------------------------------------------------------*/ 180 | /** @defgroup UTILS_LL_Exported_Functions UTILS Exported Functions 181 | * @{ 182 | */ 183 | 184 | /** @defgroup UTILS_EF_DEVICE_ELECTRONIC_SIGNATURE DEVICE ELECTRONIC SIGNATURE 185 | * @{ 186 | */ 187 | 188 | /** 189 | * @brief Get Word0 of the unique device identifier (UID based on 96 bits) 190 | * @retval UID[31:0] 191 | */ 192 | __STATIC_INLINE uint32_t LL_GetUID_Word0(void) 193 | { 194 | return (uint32_t)(READ_REG(*((uint32_t *)UID_BASE_ADDRESS))); 195 | } 196 | 197 | /** 198 | * @brief Get Word1 of the unique device identifier (UID based on 96 bits) 199 | * @retval UID[63:32] 200 | */ 201 | __STATIC_INLINE uint32_t LL_GetUID_Word1(void) 202 | { 203 | return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 4U)))); 204 | } 205 | 206 | /** 207 | * @brief Get Word2 of the unique device identifier (UID based on 96 bits) 208 | * @retval UID[95:64] 209 | */ 210 | __STATIC_INLINE uint32_t LL_GetUID_Word2(void) 211 | { 212 | return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 8U)))); 213 | } 214 | 215 | /** 216 | * @brief Get Flash memory size 217 | * @note This bitfield indicates the size of the device Flash memory expressed in 218 | * Kbytes. As an example, 0x040 corresponds to 64 Kbytes. 219 | * @retval FLASH_SIZE[15:0]: Flash memory size 220 | */ 221 | __STATIC_INLINE uint32_t LL_GetFlashSize(void) 222 | { 223 | return (uint32_t)(READ_REG(*((uint32_t *)FLASHSIZE_BASE_ADDRESS)) & 0xFFFF); 224 | } 225 | 226 | /** 227 | * @brief Get Package type 228 | * @retval Returned value can be one of the following values: 229 | * @arg @ref LL_UTILS_PACKAGETYPE_WLCSP36_UFQFPN48_LQFP64 (*) 230 | * @arg @ref LL_UTILS_PACKAGETYPE_WLCSP168_FBGA169_LQFP100_LQFP64_UFQFPN48 (*) 231 | * @arg @ref LL_UTILS_PACKAGETYPE_WLCSP64_WLCSP81_LQFP176_UFBGA176 (*) 232 | * @arg @ref LL_UTILS_PACKAGETYPE_LQFP144_UFBGA144_UFBGA144_UFBGA100 (*) 233 | * @arg @ref LL_UTILS_PACKAGETYPE_LQFP100_LQFP208_TFBGA216 (*) 234 | * @arg @ref LL_UTILS_PACKAGETYPE_LQFP208_TFBGA216 (*) 235 | * @arg @ref LL_UTILS_PACKAGETYPE_TQFP64_UFBGA144_LQFP144 (*) 236 | * 237 | * (*) value not defined in all devices. 238 | */ 239 | __STATIC_INLINE uint32_t LL_GetPackageType(void) 240 | { 241 | return (uint32_t)(READ_REG(*((uint32_t *)PACKAGE_BASE_ADDRESS)) & 0x0700U); 242 | } 243 | 244 | /** 245 | * @} 246 | */ 247 | 248 | /** @defgroup UTILS_LL_EF_DELAY DELAY 249 | * @{ 250 | */ 251 | 252 | /** 253 | * @brief This function configures the Cortex-M SysTick source of the time base. 254 | * @param HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro) 255 | * @note When a RTOS is used, it is recommended to avoid changing the SysTick 256 | * configuration by calling this function, for a delay use rather osDelay RTOS service. 257 | * @param Ticks Frequency of Ticks (Hz) 258 | * @retval None 259 | */ 260 | __STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks) 261 | { 262 | /* Configure the SysTick to have interrupt in 1ms time base */ 263 | SysTick->LOAD = (uint32_t)((HCLKFrequency / Ticks) - 1UL); /* set reload register */ 264 | SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ 265 | SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | 266 | SysTick_CTRL_ENABLE_Msk; /* Enable the Systick Timer */ 267 | } 268 | 269 | void LL_Init1msTick(uint32_t HCLKFrequency); 270 | void LL_mDelay(uint32_t Delay); 271 | 272 | /** 273 | * @} 274 | */ 275 | 276 | /** @defgroup UTILS_EF_SYSTEM SYSTEM 277 | * @{ 278 | */ 279 | 280 | void LL_SetSystemCoreClock(uint32_t HCLKFrequency); 281 | ErrorStatus LL_SetFlashLatency(uint32_t HCLK_Frequency); 282 | ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, 283 | LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct); 284 | ErrorStatus LL_PLL_ConfigSystemClock_HSE(uint32_t HSEFrequency, uint32_t HSEBypass, 285 | LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct); 286 | 287 | /** 288 | * @} 289 | */ 290 | 291 | /** 292 | * @} 293 | */ 294 | 295 | /** 296 | * @} 297 | */ 298 | 299 | /** 300 | * @} 301 | */ 302 | 303 | #ifdef __cplusplus 304 | } 305 | #endif 306 | 307 | #endif /* __STM32F4xx_LL_UTILS_H */ 308 | -------------------------------------------------------------------------------- /examples/f411/Drivers/STM32F4xx_HAL_Driver/LICENSE.txt: -------------------------------------------------------------------------------- 1 | This software component is provided to you as part of a software package and 2 | applicable license terms are in the Package_license file. If you received this 3 | software component outside of a package or without applicable license terms, 4 | the terms of the BSD-3-Clause license shall apply. 5 | You may obtain a copy of the BSD-3-Clause at: 6 | https://opensource.org/licenses/BSD-3-Clause 7 | -------------------------------------------------------------------------------- /examples/f411/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.c 4 | * @author MCD Application Team 5 | * @brief DMA Extension HAL module driver 6 | * This file provides firmware functions to manage the following 7 | * functionalities of the DMA Extension peripheral: 8 | * + Extended features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### How to use this driver ##### 13 | ============================================================================== 14 | [..] 15 | The DMA Extension HAL driver can be used as follows: 16 | (#) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function 17 | for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode. 18 | 19 | -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed. 20 | -@- When Multi (Double) Buffer mode is enabled the, transfer is circular by default. 21 | -@- In Multi (Double) buffer mode, it is possible to update the base address for 22 | the AHB memory port on the fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled. 23 | 24 | @endverbatim 25 | ****************************************************************************** 26 | * @attention 27 | * 28 | * Copyright (c) 2017 STMicroelectronics. 29 | * All rights reserved. 30 | * 31 | * This software is licensed under terms that can be found in the LICENSE file in 32 | * the root directory of this software component. 33 | * If no LICENSE file comes with this software, it is provided AS-IS. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Includes ------------------------------------------------------------------*/ 39 | #include "stm32f4xx_hal.h" 40 | 41 | /** @addtogroup STM32F4xx_HAL_Driver 42 | * @{ 43 | */ 44 | 45 | /** @defgroup DMAEx DMAEx 46 | * @brief DMA Extended HAL module driver 47 | * @{ 48 | */ 49 | 50 | #ifdef HAL_DMA_MODULE_ENABLED 51 | 52 | /* Private types -------------------------------------------------------------*/ 53 | /* Private variables ---------------------------------------------------------*/ 54 | /* Private Constants ---------------------------------------------------------*/ 55 | /* Private macros ------------------------------------------------------------*/ 56 | /* Private functions ---------------------------------------------------------*/ 57 | /** @addtogroup DMAEx_Private_Functions 58 | * @{ 59 | */ 60 | static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); 61 | /** 62 | * @} 63 | */ 64 | 65 | /* Exported functions ---------------------------------------------------------*/ 66 | 67 | /** @addtogroup DMAEx_Exported_Functions 68 | * @{ 69 | */ 70 | 71 | 72 | /** @addtogroup DMAEx_Exported_Functions_Group1 73 | * 74 | @verbatim 75 | =============================================================================== 76 | ##### Extended features functions ##### 77 | =============================================================================== 78 | [..] This section provides functions allowing to: 79 | (+) Configure the source, destination address and data length and 80 | Start MultiBuffer DMA transfer 81 | (+) Configure the source, destination address and data length and 82 | Start MultiBuffer DMA transfer with interrupt 83 | (+) Change on the fly the memory0 or memory1 address. 84 | 85 | @endverbatim 86 | * @{ 87 | */ 88 | 89 | 90 | /** 91 | * @brief Starts the multi_buffer DMA Transfer. 92 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 93 | * the configuration information for the specified DMA Stream. 94 | * @param SrcAddress The source memory Buffer address 95 | * @param DstAddress The destination memory Buffer address 96 | * @param SecondMemAddress The second memory Buffer address in case of multi buffer Transfer 97 | * @param DataLength The length of data to be transferred from source to destination 98 | * @retval HAL status 99 | */ 100 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength) 101 | { 102 | HAL_StatusTypeDef status = HAL_OK; 103 | 104 | /* Check the parameters */ 105 | assert_param(IS_DMA_BUFFER_SIZE(DataLength)); 106 | 107 | /* Memory-to-memory transfer not supported in double buffering mode */ 108 | if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY) 109 | { 110 | hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED; 111 | status = HAL_ERROR; 112 | } 113 | else 114 | { 115 | /* Process Locked */ 116 | __HAL_LOCK(hdma); 117 | 118 | if(HAL_DMA_STATE_READY == hdma->State) 119 | { 120 | /* Change DMA peripheral state */ 121 | hdma->State = HAL_DMA_STATE_BUSY; 122 | 123 | /* Enable the double buffer mode */ 124 | hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM; 125 | 126 | /* Configure DMA Stream destination address */ 127 | hdma->Instance->M1AR = SecondMemAddress; 128 | 129 | /* Configure the source, destination address and the data length */ 130 | DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength); 131 | 132 | /* Enable the peripheral */ 133 | __HAL_DMA_ENABLE(hdma); 134 | } 135 | else 136 | { 137 | /* Return error status */ 138 | status = HAL_BUSY; 139 | } 140 | } 141 | return status; 142 | } 143 | 144 | /** 145 | * @brief Starts the multi_buffer DMA Transfer with interrupt enabled. 146 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 147 | * the configuration information for the specified DMA Stream. 148 | * @param SrcAddress The source memory Buffer address 149 | * @param DstAddress The destination memory Buffer address 150 | * @param SecondMemAddress The second memory Buffer address in case of multi buffer Transfer 151 | * @param DataLength The length of data to be transferred from source to destination 152 | * @retval HAL status 153 | */ 154 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength) 155 | { 156 | HAL_StatusTypeDef status = HAL_OK; 157 | 158 | /* Check the parameters */ 159 | assert_param(IS_DMA_BUFFER_SIZE(DataLength)); 160 | 161 | /* Memory-to-memory transfer not supported in double buffering mode */ 162 | if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY) 163 | { 164 | hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED; 165 | return HAL_ERROR; 166 | } 167 | 168 | /* Check callback functions */ 169 | if ((NULL == hdma->XferCpltCallback) || (NULL == hdma->XferM1CpltCallback) || (NULL == hdma->XferErrorCallback)) 170 | { 171 | hdma->ErrorCode = HAL_DMA_ERROR_PARAM; 172 | return HAL_ERROR; 173 | } 174 | 175 | /* Process locked */ 176 | __HAL_LOCK(hdma); 177 | 178 | if(HAL_DMA_STATE_READY == hdma->State) 179 | { 180 | /* Change DMA peripheral state */ 181 | hdma->State = HAL_DMA_STATE_BUSY; 182 | 183 | /* Initialize the error code */ 184 | hdma->ErrorCode = HAL_DMA_ERROR_NONE; 185 | 186 | /* Enable the Double buffer mode */ 187 | hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM; 188 | 189 | /* Configure DMA Stream destination address */ 190 | hdma->Instance->M1AR = SecondMemAddress; 191 | 192 | /* Configure the source, destination address and the data length */ 193 | DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength); 194 | 195 | /* Clear all flags */ 196 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); 197 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); 198 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); 199 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma)); 200 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma)); 201 | 202 | /* Enable Common interrupts*/ 203 | hdma->Instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME; 204 | hdma->Instance->FCR |= DMA_IT_FE; 205 | 206 | if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL)) 207 | { 208 | hdma->Instance->CR |= DMA_IT_HT; 209 | } 210 | 211 | /* Enable the peripheral */ 212 | __HAL_DMA_ENABLE(hdma); 213 | } 214 | else 215 | { 216 | /* Process unlocked */ 217 | __HAL_UNLOCK(hdma); 218 | 219 | /* Return error status */ 220 | status = HAL_BUSY; 221 | } 222 | return status; 223 | } 224 | 225 | /** 226 | * @brief Change the memory0 or memory1 address on the fly. 227 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 228 | * the configuration information for the specified DMA Stream. 229 | * @param Address The new address 230 | * @param memory the memory to be changed, This parameter can be one of 231 | * the following values: 232 | * MEMORY0 / 233 | * MEMORY1 234 | * @note The MEMORY0 address can be changed only when the current transfer use 235 | * MEMORY1 and the MEMORY1 address can be changed only when the current 236 | * transfer use MEMORY0. 237 | * @retval HAL status 238 | */ 239 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory) 240 | { 241 | if(memory == MEMORY0) 242 | { 243 | /* change the memory0 address */ 244 | hdma->Instance->M0AR = Address; 245 | } 246 | else 247 | { 248 | /* change the memory1 address */ 249 | hdma->Instance->M1AR = Address; 250 | } 251 | 252 | return HAL_OK; 253 | } 254 | 255 | /** 256 | * @} 257 | */ 258 | 259 | /** 260 | * @} 261 | */ 262 | 263 | /** @addtogroup DMAEx_Private_Functions 264 | * @{ 265 | */ 266 | 267 | /** 268 | * @brief Set the DMA Transfer parameter. 269 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 270 | * the configuration information for the specified DMA Stream. 271 | * @param SrcAddress The source memory Buffer address 272 | * @param DstAddress The destination memory Buffer address 273 | * @param DataLength The length of data to be transferred from source to destination 274 | * @retval HAL status 275 | */ 276 | static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) 277 | { 278 | /* Configure DMA Stream data length */ 279 | hdma->Instance->NDTR = DataLength; 280 | 281 | /* Peripheral to Memory */ 282 | if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) 283 | { 284 | /* Configure DMA Stream destination address */ 285 | hdma->Instance->PAR = DstAddress; 286 | 287 | /* Configure DMA Stream source address */ 288 | hdma->Instance->M0AR = SrcAddress; 289 | } 290 | /* Memory to Peripheral */ 291 | else 292 | { 293 | /* Configure DMA Stream source address */ 294 | hdma->Instance->PAR = SrcAddress; 295 | 296 | /* Configure DMA Stream destination address */ 297 | hdma->Instance->M0AR = DstAddress; 298 | } 299 | } 300 | 301 | /** 302 | * @} 303 | */ 304 | 305 | #endif /* HAL_DMA_MODULE_ENABLED */ 306 | /** 307 | * @} 308 | */ 309 | 310 | /** 311 | * @} 312 | */ 313 | 314 | -------------------------------------------------------------------------------- /examples/f411/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.c 4 | * @author MCD Application Team 5 | * @brief FLASH RAMFUNC module driver. 6 | * This file provides a FLASH firmware functions which should be 7 | * executed from internal SRAM 8 | * + Stop/Start the flash interface while System Run 9 | * + Enable/Disable the flash sleep while System Run 10 | @verbatim 11 | ============================================================================== 12 | ##### APIs executed from Internal RAM ##### 13 | ============================================================================== 14 | [..] 15 | *** ARM Compiler *** 16 | -------------------- 17 | [..] RAM functions are defined using the toolchain options. 18 | Functions that are be executed in RAM should reside in a separate 19 | source module. Using the 'Options for File' dialog you can simply change 20 | the 'Code / Const' area of a module to a memory space in physical RAM. 21 | Available memory areas are declared in the 'Target' tab of the 22 | Options for Target' dialog. 23 | 24 | *** ICCARM Compiler *** 25 | ----------------------- 26 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 27 | 28 | *** GNU Compiler *** 29 | -------------------- 30 | [..] RAM functions are defined using a specific toolchain attribute 31 | "__attribute__((section(".RamFunc")))". 32 | 33 | @endverbatim 34 | ****************************************************************************** 35 | * @attention 36 | * 37 | * Copyright (c) 2017 STMicroelectronics. 38 | * All rights reserved. 39 | * 40 | * This software is licensed under terms that can be found in the LICENSE file in 41 | * the root directory of this software component. 42 | * If no LICENSE file comes with this software, it is provided AS-IS. 43 | ****************************************************************************** 44 | */ 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f4xx_hal.h" 48 | 49 | /** @addtogroup STM32F4xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @defgroup FLASH_RAMFUNC FLASH RAMFUNC 54 | * @brief FLASH functions executed from RAM 55 | * @{ 56 | */ 57 | #ifdef HAL_FLASH_MODULE_ENABLED 58 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ 59 | defined(STM32F412Rx) || defined(STM32F412Cx) 60 | 61 | /* Private typedef -----------------------------------------------------------*/ 62 | /* Private define ------------------------------------------------------------*/ 63 | /* Private macro -------------------------------------------------------------*/ 64 | /* Private variables ---------------------------------------------------------*/ 65 | /* Private function prototypes -----------------------------------------------*/ 66 | /* Exported functions --------------------------------------------------------*/ 67 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions 68 | * @{ 69 | */ 70 | 71 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM 72 | * @brief Peripheral Extended features functions 73 | * 74 | @verbatim 75 | 76 | =============================================================================== 77 | ##### ramfunc functions ##### 78 | =============================================================================== 79 | [..] 80 | This subsection provides a set of functions that should be executed from RAM 81 | transfers. 82 | 83 | @endverbatim 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @brief Stop the flash interface while System Run 89 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 90 | * @note This mode couldn't be set while executing with the flash itself. 91 | * It should be done with specific routine executed from RAM. 92 | * @retval HAL status 93 | */ 94 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void) 95 | { 96 | /* Enable Power ctrl clock */ 97 | __HAL_RCC_PWR_CLK_ENABLE(); 98 | /* Stop the flash interface while System Run */ 99 | SET_BIT(PWR->CR, PWR_CR_FISSR); 100 | 101 | return HAL_OK; 102 | } 103 | 104 | /** 105 | * @brief Start the flash interface while System Run 106 | * @note This mode is only available for STM32F411xx/STM32F446xx devices. 107 | * @note This mode couldn't be set while executing with the flash itself. 108 | * It should be done with specific routine executed from RAM. 109 | * @retval HAL status 110 | */ 111 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void) 112 | { 113 | /* Enable Power ctrl clock */ 114 | __HAL_RCC_PWR_CLK_ENABLE(); 115 | /* Start the flash interface while System Run */ 116 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR); 117 | 118 | return HAL_OK; 119 | } 120 | 121 | /** 122 | * @brief Enable the flash sleep while System Run 123 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 124 | * @note This mode could n't be set while executing with the flash itself. 125 | * It should be done with specific routine executed from RAM. 126 | * @retval HAL status 127 | */ 128 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void) 129 | { 130 | /* Enable Power ctrl clock */ 131 | __HAL_RCC_PWR_CLK_ENABLE(); 132 | /* Enable the flash sleep while System Run */ 133 | SET_BIT(PWR->CR, PWR_CR_FMSSR); 134 | 135 | return HAL_OK; 136 | } 137 | 138 | /** 139 | * @brief Disable the flash sleep while System Run 140 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 141 | * @note This mode couldn't be set while executing with the flash itself. 142 | * It should be done with specific routine executed from RAM. 143 | * @retval HAL status 144 | */ 145 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void) 146 | { 147 | /* Enable Power ctrl clock */ 148 | __HAL_RCC_PWR_CLK_ENABLE(); 149 | /* Disable the flash sleep while System Run */ 150 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR); 151 | 152 | return HAL_OK; 153 | } 154 | 155 | /** 156 | * @} 157 | */ 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 164 | #endif /* HAL_FLASH_MODULE_ENABLED */ 165 | /** 166 | * @} 167 | */ 168 | 169 | /** 170 | * @} 171 | */ 172 | 173 | -------------------------------------------------------------------------------- /examples/f411/STM32F411CEUX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** @brief : Linker script for STM32F411CEUx Device from STM32F4 series 9 | ** 512KBytes FLASH 10 | ** 128KBytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed as is, without any warranty 20 | ** of any kind. 21 | ** 22 | ****************************************************************************** 23 | ** @attention 24 | ** 25 | ** Copyright (c) 2024 STMicroelectronics. 26 | ** All rights reserved. 27 | ** 28 | ** This software is licensed under terms that can be found in the LICENSE file 29 | ** in the root directory of this software component. 30 | ** If no LICENSE file comes with this software, it is provided AS-IS. 31 | ** 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Entry Point */ 36 | ENTRY(Reset_Handler) 37 | 38 | /* Highest address of the user mode stack */ 39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 40 | 41 | _Min_Heap_Size = 0x200; /* required amount of heap */ 42 | _Min_Stack_Size = 0x400; /* required amount of stack */ 43 | 44 | /* Memories definition */ 45 | MEMORY 46 | { 47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 48 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K 49 | } 50 | 51 | /* Sections */ 52 | SECTIONS 53 | { 54 | /* The startup code into "FLASH" Rom type memory */ 55 | .isr_vector : 56 | { 57 | . = ALIGN(4); 58 | KEEP(*(.isr_vector)) /* Startup code */ 59 | . = ALIGN(4); 60 | } >FLASH 61 | 62 | /* The program code and other data into "FLASH" Rom type memory */ 63 | .text : 64 | { 65 | . = ALIGN(4); 66 | *(.text) /* .text sections (code) */ 67 | *(.text*) /* .text* sections (code) */ 68 | *(.glue_7) /* glue arm to thumb code */ 69 | *(.glue_7t) /* glue thumb to arm code */ 70 | *(.eh_frame) 71 | 72 | KEEP (*(.init)) 73 | KEEP (*(.fini)) 74 | 75 | . = ALIGN(4); 76 | _etext = .; /* define a global symbols at end of code */ 77 | } >FLASH 78 | 79 | /* Constant data into "FLASH" Rom type memory */ 80 | .rodata : 81 | { 82 | . = ALIGN(4); 83 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 84 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 85 | . = ALIGN(4); 86 | } >FLASH 87 | 88 | .ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 89 | { 90 | . = ALIGN(4); 91 | *(.ARM.extab* .gnu.linkonce.armextab.*) 92 | . = ALIGN(4); 93 | } >FLASH 94 | 95 | .ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 96 | { 97 | . = ALIGN(4); 98 | __exidx_start = .; 99 | *(.ARM.exidx*) 100 | __exidx_end = .; 101 | . = ALIGN(4); 102 | } >FLASH 103 | 104 | .preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 105 | { 106 | . = ALIGN(4); 107 | PROVIDE_HIDDEN (__preinit_array_start = .); 108 | KEEP (*(.preinit_array*)) 109 | PROVIDE_HIDDEN (__preinit_array_end = .); 110 | . = ALIGN(4); 111 | } >FLASH 112 | 113 | .init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 114 | { 115 | . = ALIGN(4); 116 | PROVIDE_HIDDEN (__init_array_start = .); 117 | KEEP (*(SORT(.init_array.*))) 118 | KEEP (*(.init_array*)) 119 | PROVIDE_HIDDEN (__init_array_end = .); 120 | . = ALIGN(4); 121 | } >FLASH 122 | 123 | .fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 124 | { 125 | . = ALIGN(4); 126 | PROVIDE_HIDDEN (__fini_array_start = .); 127 | KEEP (*(SORT(.fini_array.*))) 128 | KEEP (*(.fini_array*)) 129 | PROVIDE_HIDDEN (__fini_array_end = .); 130 | . = ALIGN(4); 131 | } >FLASH 132 | 133 | /* Used by the startup to initialize data */ 134 | _sidata = LOADADDR(.data); 135 | 136 | /* Initialized data sections into "RAM" Ram type memory */ 137 | .data : 138 | { 139 | . = ALIGN(4); 140 | _sdata = .; /* create a global symbol at data start */ 141 | *(.data) /* .data sections */ 142 | *(.data*) /* .data* sections */ 143 | *(.RamFunc) /* .RamFunc sections */ 144 | *(.RamFunc*) /* .RamFunc* sections */ 145 | 146 | . = ALIGN(4); 147 | _edata = .; /* define a global symbol at data end */ 148 | 149 | } >RAM AT> FLASH 150 | 151 | /* Uninitialized data section into "RAM" Ram type memory */ 152 | . = ALIGN(4); 153 | .bss : 154 | { 155 | /* This is used by the startup in order to initialize the .bss section */ 156 | _sbss = .; /* define a global symbol at bss start */ 157 | __bss_start__ = _sbss; 158 | *(.bss) 159 | *(.bss*) 160 | *(COMMON) 161 | 162 | . = ALIGN(4); 163 | _ebss = .; /* define a global symbol at bss end */ 164 | __bss_end__ = _ebss; 165 | } >RAM 166 | 167 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 168 | ._user_heap_stack : 169 | { 170 | . = ALIGN(8); 171 | PROVIDE ( end = . ); 172 | PROVIDE ( _end = . ); 173 | . = . + _Min_Heap_Size; 174 | . = . + _Min_Stack_Size; 175 | . = ALIGN(8); 176 | } >RAM 177 | 178 | /* Remove information from the compiler libraries */ 179 | /DISCARD/ : 180 | { 181 | libc.a ( * ) 182 | libm.a ( * ) 183 | libgcc.a ( * ) 184 | } 185 | 186 | .ARM.attributes 0 : { *(.ARM.attributes) } 187 | } 188 | -------------------------------------------------------------------------------- /examples/f411/STM32F411CEUX_RAM.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld (debug in RAM dedicated) 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** @brief : Linker script for STM32F411CEUx Device from STM32F4 series 9 | ** 512KBytes FLASH 10 | ** 128KBytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed as is, without any warranty 20 | ** of any kind. 21 | ** 22 | ****************************************************************************** 23 | ** @attention 24 | ** 25 | ** Copyright (c) 2024 STMicroelectronics. 26 | ** All rights reserved. 27 | ** 28 | ** This software is licensed under terms that can be found in the LICENSE file 29 | ** in the root directory of this software component. 30 | ** If no LICENSE file comes with this software, it is provided AS-IS. 31 | ** 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Entry Point */ 36 | ENTRY(Reset_Handler) 37 | 38 | /* Highest address of the user mode stack */ 39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 40 | 41 | _Min_Heap_Size = 0x200; /* required amount of heap */ 42 | _Min_Stack_Size = 0x400; /* required amount of stack */ 43 | 44 | /* Memories definition */ 45 | MEMORY 46 | { 47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 48 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K 49 | } 50 | 51 | /* Sections */ 52 | SECTIONS 53 | { 54 | /* The startup code into "RAM" Ram type memory */ 55 | .isr_vector : 56 | { 57 | . = ALIGN(4); 58 | KEEP(*(.isr_vector)) /* Startup code */ 59 | . = ALIGN(4); 60 | } >RAM 61 | 62 | /* The program code and other data into "RAM" Ram type memory */ 63 | .text : 64 | { 65 | . = ALIGN(4); 66 | *(.text) /* .text sections (code) */ 67 | *(.text*) /* .text* sections (code) */ 68 | *(.glue_7) /* glue arm to thumb code */ 69 | *(.glue_7t) /* glue thumb to arm code */ 70 | *(.eh_frame) 71 | *(.RamFunc) /* .RamFunc sections */ 72 | *(.RamFunc*) /* .RamFunc* sections */ 73 | 74 | KEEP (*(.init)) 75 | KEEP (*(.fini)) 76 | 77 | . = ALIGN(4); 78 | _etext = .; /* define a global symbols at end of code */ 79 | } >RAM 80 | 81 | /* Constant data into "RAM" Ram type memory */ 82 | .rodata : 83 | { 84 | . = ALIGN(4); 85 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 86 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 87 | . = ALIGN(4); 88 | } >RAM 89 | 90 | .ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 91 | { 92 | . = ALIGN(4); 93 | *(.ARM.extab* .gnu.linkonce.armextab.*) 94 | . = ALIGN(4); 95 | } >RAM 96 | 97 | .ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 98 | { 99 | . = ALIGN(4); 100 | __exidx_start = .; 101 | *(.ARM.exidx*) 102 | __exidx_end = .; 103 | . = ALIGN(4); 104 | } >RAM 105 | 106 | .preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 107 | { 108 | . = ALIGN(4); 109 | PROVIDE_HIDDEN (__preinit_array_start = .); 110 | KEEP (*(.preinit_array*)) 111 | PROVIDE_HIDDEN (__preinit_array_end = .); 112 | . = ALIGN(4); 113 | } >RAM 114 | 115 | .init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 116 | { 117 | . = ALIGN(4); 118 | PROVIDE_HIDDEN (__init_array_start = .); 119 | KEEP (*(SORT(.init_array.*))) 120 | KEEP (*(.init_array*)) 121 | PROVIDE_HIDDEN (__init_array_end = .); 122 | . = ALIGN(4); 123 | } >RAM 124 | 125 | .fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 126 | { 127 | . = ALIGN(4); 128 | PROVIDE_HIDDEN (__fini_array_start = .); 129 | KEEP (*(SORT(.fini_array.*))) 130 | KEEP (*(.fini_array*)) 131 | PROVIDE_HIDDEN (__fini_array_end = .); 132 | . = ALIGN(4); 133 | } >RAM 134 | 135 | /* Used by the startup to initialize data */ 136 | _sidata = LOADADDR(.data); 137 | 138 | /* Initialized data sections into "RAM" Ram type memory */ 139 | .data : 140 | { 141 | . = ALIGN(4); 142 | _sdata = .; /* create a global symbol at data start */ 143 | *(.data) /* .data sections */ 144 | *(.data*) /* .data* sections */ 145 | 146 | . = ALIGN(4); 147 | _edata = .; /* define a global symbol at data end */ 148 | 149 | } >RAM 150 | 151 | /* Uninitialized data section into "RAM" Ram type memory */ 152 | . = ALIGN(4); 153 | .bss : 154 | { 155 | /* This is used by the startup in order to initialize the .bss section */ 156 | _sbss = .; /* define a global symbol at bss start */ 157 | __bss_start__ = _sbss; 158 | *(.bss) 159 | *(.bss*) 160 | *(COMMON) 161 | 162 | . = ALIGN(4); 163 | _ebss = .; /* define a global symbol at bss end */ 164 | __bss_end__ = _ebss; 165 | } >RAM 166 | 167 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 168 | ._user_heap_stack : 169 | { 170 | . = ALIGN(8); 171 | PROVIDE ( end = . ); 172 | PROVIDE ( _end = . ); 173 | . = . + _Min_Heap_Size; 174 | . = . + _Min_Stack_Size; 175 | . = ALIGN(8); 176 | } >RAM 177 | 178 | /* Remove information from the compiler libraries */ 179 | /DISCARD/ : 180 | { 181 | libc.a ( * ) 182 | libm.a ( * ) 183 | libgcc.a ( * ) 184 | } 185 | 186 | .ARM.attributes 0 : { *(.ARM.attributes) } 187 | } 188 | -------------------------------------------------------------------------------- /examples/f411/f411 Debug.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /examples/f411/f411.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | ARM.CMSIS.5.6.0_SwParameter=CMSISJjDSP\:Source;CMSISJjCORE\:true; 3 | CAD.formats= 4 | CAD.pinconfig= 5 | CAD.provider= 6 | Dma.Request0=TIM4_CH1 7 | Dma.RequestsNb=1 8 | Dma.TIM4_CH1.0.Direction=DMA_MEMORY_TO_PERIPH 9 | Dma.TIM4_CH1.0.FIFOMode=DMA_FIFOMODE_DISABLE 10 | Dma.TIM4_CH1.0.Instance=DMA1_Stream0 11 | Dma.TIM4_CH1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD 12 | Dma.TIM4_CH1.0.MemInc=DMA_MINC_ENABLE 13 | Dma.TIM4_CH1.0.Mode=DMA_CIRCULAR 14 | Dma.TIM4_CH1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD 15 | Dma.TIM4_CH1.0.PeriphInc=DMA_PINC_DISABLE 16 | Dma.TIM4_CH1.0.Priority=DMA_PRIORITY_LOW 17 | Dma.TIM4_CH1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode 18 | File.Version=6 19 | KeepUserPlacement=false 20 | Mcu.CPN=STM32F411CEU6 21 | Mcu.Family=STM32F4 22 | Mcu.IP0=DMA 23 | Mcu.IP1=NVIC 24 | Mcu.IP2=RCC 25 | Mcu.IP3=SYS 26 | Mcu.IP4=TIM4 27 | Mcu.IP5=USART1 28 | Mcu.IPNb=6 29 | Mcu.Name=STM32F411C(C-E)Ux 30 | Mcu.Package=UFQFPN48 31 | Mcu.Pin0=PC13-ANTI_TAMP 32 | Mcu.Pin1=PH0 - OSC_IN 33 | Mcu.Pin10=VP_SYS_VS_Systick 34 | Mcu.Pin11=VP_TIM4_VS_ClockSourceINT 35 | Mcu.Pin2=PH1 - OSC_OUT 36 | Mcu.Pin3=PA0-WKUP 37 | Mcu.Pin4=PA9 38 | Mcu.Pin5=PA10 39 | Mcu.Pin6=PA13 40 | Mcu.Pin7=PA14 41 | Mcu.Pin8=PB3 42 | Mcu.Pin9=PB6 43 | Mcu.PinsNb=12 44 | Mcu.ThirdParty0=ARM.CMSIS.5.6.0 45 | Mcu.ThirdPartyNb=1 46 | Mcu.UserConstants=LED_CNT,125 47 | Mcu.UserName=STM32F411CEUx 48 | MxCube.Version=6.13.0 49 | MxDb.Version=DB.6.0.130 50 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 51 | NVIC.DMA1_Stream0_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true 52 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 53 | NVIC.ForceEnableDMAVector=true 54 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 55 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 56 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 57 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 58 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 59 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 60 | NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false 61 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 62 | PA0-WKUP.GPIOParameters=GPIO_Label 63 | PA0-WKUP.GPIO_Label=BTN 64 | PA0-WKUP.Locked=true 65 | PA0-WKUP.Signal=GPXTI0 66 | PA10.Mode=Asynchronous 67 | PA10.Signal=USART1_RX 68 | PA13.Mode=Trace_Asynchronous_SW 69 | PA13.Signal=SYS_JTMS-SWDIO 70 | PA14.Mode=Trace_Asynchronous_SW 71 | PA14.Signal=SYS_JTCK-SWCLK 72 | PA9.Mode=Asynchronous 73 | PA9.Signal=USART1_TX 74 | PB3.Mode=Trace_Asynchronous_SW 75 | PB3.Signal=SYS_JTDO-SWO 76 | PB6.Signal=S_TIM4_CH1 77 | PC13-ANTI_TAMP.GPIOParameters=PinState,GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultOutputPP 78 | PC13-ANTI_TAMP.GPIO_Label=LED 79 | PC13-ANTI_TAMP.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD 80 | PC13-ANTI_TAMP.GPIO_PuPd=GPIO_NOPULL 81 | PC13-ANTI_TAMP.Locked=true 82 | PC13-ANTI_TAMP.PinState=GPIO_PIN_SET 83 | PC13-ANTI_TAMP.Signal=GPIO_Output 84 | PH0\ -\ OSC_IN.Mode=HSE-External-Oscillator 85 | PH0\ -\ OSC_IN.Signal=RCC_OSC_IN 86 | PH1\ -\ OSC_OUT.Mode=HSE-External-Oscillator 87 | PH1\ -\ OSC_OUT.Signal=RCC_OSC_OUT 88 | PinOutPanel.RotationAngle=0 89 | ProjectManager.AskForMigrate=true 90 | ProjectManager.BackupPrevious=false 91 | ProjectManager.CompilerOptimize=6 92 | ProjectManager.ComputerToolchain=false 93 | ProjectManager.CoupleFile=false 94 | ProjectManager.CustomerFirmwarePackage= 95 | ProjectManager.DefaultFWLocation=true 96 | ProjectManager.DeletePrevious=true 97 | ProjectManager.DeviceId=STM32F411CEUx 98 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.28.1 99 | ProjectManager.FreePins=false 100 | ProjectManager.HalAssertFull=false 101 | ProjectManager.HeapSize=0x200 102 | ProjectManager.KeepUserCode=true 103 | ProjectManager.LastFirmware=true 104 | ProjectManager.LibraryCopy=1 105 | ProjectManager.MainLocation=Core/Src 106 | ProjectManager.NoMain=false 107 | ProjectManager.PreviousToolchain= 108 | ProjectManager.ProjectBuild=false 109 | ProjectManager.ProjectFileName=f411.ioc 110 | ProjectManager.ProjectName=f411 111 | ProjectManager.ProjectStructure= 112 | ProjectManager.RegisterCallBack=TIM 113 | ProjectManager.StackSize=0x400 114 | ProjectManager.TargetToolchain=STM32CubeIDE 115 | ProjectManager.ToolChainLocation= 116 | ProjectManager.UAScriptAfterPath= 117 | ProjectManager.UAScriptBeforePath= 118 | ProjectManager.UnderRoot=true 119 | ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_TIM4_Init-TIM4-false-HAL-true 120 | RCC.48MHZClocksFreq_Value=50000000 121 | RCC.AHBFreq_Value=100000000 122 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 123 | RCC.APB1Freq_Value=50000000 124 | RCC.APB1TimFreq_Value=100000000 125 | RCC.APB2Freq_Value=100000000 126 | RCC.APB2TimFreq_Value=100000000 127 | RCC.CortexFreq_Value=100000000 128 | RCC.EthernetFreq_Value=100000000 129 | RCC.FCLKCortexFreq_Value=100000000 130 | RCC.FamilyName=M 131 | RCC.HCLKFreq_Value=100000000 132 | RCC.HSE_VALUE=25000000 133 | RCC.HSI_VALUE=16000000 134 | RCC.I2SClocksFreq_Value=150000000 135 | RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,PLLCLKFreq_Value,PLLM,PLLN,PLLQCLKFreq_Value,PLLSourceVirtual,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOInputMFreq_Value,VCOOutputFreq_Value,VcooutputI2S 136 | RCC.LSE_VALUE=32768 137 | RCC.LSI_VALUE=32000 138 | RCC.PLLCLKFreq_Value=100000000 139 | RCC.PLLM=12 140 | RCC.PLLN=96 141 | RCC.PLLQCLKFreq_Value=50000000 142 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 143 | RCC.RTCFreq_Value=32000 144 | RCC.RTCHSEDivFreq_Value=12500000 145 | RCC.SYSCLKFreq_VALUE=100000000 146 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 147 | RCC.VCOI2SOutputFreq_Value=300000000 148 | RCC.VCOInputFreq_Value=2083333.3333333333 149 | RCC.VCOInputMFreq_Value=1562500 150 | RCC.VCOOutputFreq_Value=200000000 151 | RCC.VcooutputI2S=150000000 152 | SH.GPXTI0.0=GPIO_EXTI0 153 | SH.GPXTI0.ConfNb=1 154 | SH.S_TIM4_CH1.0=TIM4_CH1,PWM Generation1 CH1 155 | SH.S_TIM4_CH1.ConfNb=1 156 | TIM4.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 157 | TIM4.IPParameters=Channel-PWM Generation1 CH1,Period 158 | TIM4.Period=LED_CNT 159 | USART1.BaudRate=2000000 160 | USART1.IPParameters=VirtualMode,BaudRate 161 | USART1.VirtualMode=VM_ASYNC 162 | VP_SYS_VS_Systick.Mode=SysTick 163 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 164 | VP_TIM4_VS_ClockSourceINT.Mode=Internal 165 | VP_TIM4_VS_ClockSourceINT.Signal=TIM4_VS_ClockSourceINT 166 | board=custom 167 | isbadioc=false 168 | -------------------------------------------------------------------------------- /examples/f411/ws2812: -------------------------------------------------------------------------------- 1 | ../../src/ -------------------------------------------------------------------------------- /examples/libopencm3/f1/Makefile.include: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libopencm3 project. 3 | ## 4 | ## Copyright (C) 2009 Uwe Hermann 5 | ## Copyright (C) 2010 Piotr Esden-Tempski 6 | ## 7 | ## This library is free software: you can redistribute it and/or modify 8 | ## it under the terms of the GNU Lesser General Public License as published by 9 | ## the Free Software Foundation, either version 3 of the License, or 10 | ## (at your option) any later version. 11 | ## 12 | ## This library is distributed in the hope that it will be useful, 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ## GNU Lesser General Public License for more details. 16 | ## 17 | ## You should have received a copy of the GNU Lesser General Public License 18 | ## along with this library. If not, see . 19 | ## 20 | 21 | LIBNAME = opencm3_stm32f1 22 | DEFS += -DSTM32F1 23 | 24 | FP_FLAGS ?= -msoft-float 25 | ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd 26 | 27 | ################################################################################ 28 | # OpenOCD specific variables 29 | 30 | OOCD ?= openocd 31 | OOCD_INTERFACE ?= stlink 32 | OOCD_TARGET ?= stm32f1x 33 | 34 | ################################################################################ 35 | # Black Magic Probe specific variables 36 | # Set the BMP_PORT to a serial port and then BMP is used for flashing 37 | BMP_PORT ?= 38 | 39 | ################################################################################ 40 | # texane/stlink specific variables 41 | #STLINK_PORT ?= :4242 42 | 43 | 44 | include ../../../../rules.mk 45 | -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/demo/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "${workspaceFolder}/../../../../../libopencm3/include/libopencm3/**" 8 | ], 9 | "browse": { 10 | "path": [ 11 | "${workspaceFolder}/**", 12 | "${workspaceFolder}/../../../../../libopencm3/include/libopencm3/**" 13 | ] 14 | }, 15 | "defines": [ 16 | "_DEBUG", 17 | "STM32F405", 18 | "STM32F4xx", 19 | "STM32F4", 20 | "UNICODE", 21 | "_UNICODE" 22 | ], 23 | "compilerPath": "/usr/bin/gcc", 24 | "cStandard": "c17", 25 | "cppStandard": "gnu++17", 26 | "intelliSenseMode": "linux-gcc-x64", 27 | "configurationProvider": "ms-vscode.makefile-tools" 28 | } 29 | ], 30 | "version": 4 31 | } -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/demo/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "cortex-debug", 9 | "request": "launch", 10 | "name": "Debug (OpenOCD)", 11 | "servertype": "openocd", 12 | "cwd": "${workspaceFolder}", 13 | "runToEntryPoint": "main", 14 | "executable": "./demo.elf", 15 | "liveWatch": { 16 | "enabled": true, 17 | "samplesPerSecond": 4 18 | }, 19 | "device": "STM32F103RGT6", 20 | "configFiles": [ 21 | "interface/stlink-dap.cfg", 22 | "target/stm32f1x.cfg" 23 | ], 24 | "showDevDebugOutput": "none", 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/demo/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "stm32-for-vscode.openOCDPath": "/home/lth/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.12.0-2.1/.content/bin/openocd", 3 | "cortex-debug.armToolchainPath": "/home/lth/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/12.3.1-1.2.1/.content/bin", 4 | "cortex-debug.openocdPath": "/home/lth/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.12.0-2.1/.content/bin/openocd", 5 | "files.associations": { 6 | "*.js": "javascript", 7 | "gpio.h": "c" 8 | } 9 | } -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/demo/Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libopencm3 project. 3 | ## 4 | ## Copyright (C) 2009 Uwe Hermann 5 | ## 6 | ## This library is free software: you can redistribute it and/or modify 7 | ## it under the terms of the GNU Lesser General Public License as published by 8 | ## the Free Software Foundation, either version 3 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This library is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public License 17 | ## along with this library. If not, see . 18 | ## 19 | 20 | BINARY = demo 21 | 22 | LDSCRIPT = ../f103.ld 23 | 24 | include ../../Makefile.include 25 | 26 | -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/demo/demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2024 Lars Boegild Thomsen 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | uint32_t systick = 0; 27 | 28 | void sys_tick_handler(void) { 29 | ++systick; 30 | } 31 | 32 | /* Set STM32 to 72 MHz. */ 33 | static void clock_setup(void) { 34 | 35 | rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE16_72MHZ]); 36 | 37 | /* 72MHz / 8 => 9000000 counts per second */ 38 | systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); 39 | 40 | /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */ 41 | /* SysTick interrupt every N clock pulses: set reload to N-1 */ 42 | systick_set_reload(8999); 43 | 44 | systick_interrupt_enable(); 45 | 46 | /* Start counting. */ 47 | systick_counter_enable(); 48 | 49 | /* Enable GPIOB, GPIOC, and AFIO clocks. */ 50 | rcc_periph_clock_enable(RCC_GPIOB); 51 | rcc_periph_clock_enable(RCC_GPIOC); 52 | rcc_periph_clock_enable(RCC_AFIO); 53 | } 54 | 55 | static void gpio_setup(void) { 56 | /* Set GPIO13 (in GPIO port C) to 'output push-pull'. */ 57 | gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, 58 | GPIO_CNF_OUTPUT_OPENDRAIN, GPIO13); 59 | 60 | AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST; 61 | 62 | /* Preconfigure the LEDs. */ 63 | gpio_clear(GPIOC, GPIO13); /* Switch on LED. */ 64 | } 65 | 66 | int main(void) { 67 | uint32_t now = 0, last_blink = 0; 68 | 69 | clock_setup(); 70 | gpio_setup(); 71 | 72 | /* Blink the LEDs (PC13) on the board. */ 73 | while (1) 74 | { 75 | 76 | now = systick; 77 | 78 | if (now - last_blink >= 500) 79 | { 80 | gpio_toggle(GPIOC, GPIO13); /* LED on/off */ 81 | last_blink = now; 82 | } 83 | } 84 | 85 | return 0; 86 | 87 | } 88 | -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/demo/demo.d: -------------------------------------------------------------------------------- 1 | demo.o: demo.c ../../../../../libopencm3//include/libopencm3/stm32/rcc.h \ 2 | ../../../../../libopencm3//include/libopencm3/cm3/common.h \ 3 | /usr/lib/gcc/arm-none-eabi/13.2.1/include/stdint.h \ 4 | /usr/lib/gcc/arm-none-eabi/13.2.1/include/stdbool.h \ 5 | ../../../../../libopencm3//include/libopencm3/stm32/memorymap.h \ 6 | ../../../../../libopencm3//include/libopencm3/stm32/f1/memorymap.h \ 7 | ../../../../../libopencm3//include/libopencm3/cm3/memorymap.h \ 8 | ../../../../../libopencm3//include/libopencm3/stm32/f1/rcc.h \ 9 | ../../../../../libopencm3//include/libopencm3/stm32/common/rcc_common_all.h \ 10 | ../../../../../libopencm3//include/libopencm3/stm32/gpio.h \ 11 | ../../../../../libopencm3//include/libopencm3/stm32/f1/gpio.h \ 12 | ../../../../../libopencm3//include/libopencm3/stm32/common/gpio_common_all.h \ 13 | ../../../../../libopencm3//include/libopencm3/stm32/dma.h \ 14 | ../../../../../libopencm3//include/libopencm3/stm32/f1/dma.h \ 15 | ../../../../../libopencm3//include/libopencm3/stm32/common/dma_common_l1f013.h \ 16 | ../../../../../libopencm3//include/libopencm3/cm3/nvic.h \ 17 | ../../../../../libopencm3//include/libopencm3/dispatch/nvic.h \ 18 | ../../../../../libopencm3//include/libopencm3/stm32/f1/nvic.h \ 19 | ../../../../../libopencm3//include/libopencm3/cm3/systick.h 20 | -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/demo/demo.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/examples/libopencm3/f1/f103/demo/demo.elf -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/demo/demo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/examples/libopencm3/f1/f103/demo/demo.o -------------------------------------------------------------------------------- /examples/libopencm3/f1/f103/f103.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for Lisa-M (STM32F103RBT6, 128K flash, 20K RAM). */ 21 | /* TODO: Chip name and sizes correct? */ 22 | 23 | /* Define memory regions. */ 24 | MEMORY 25 | { 26 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K 27 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 28 | } 29 | 30 | /* Include the common ld script. */ 31 | INCLUDE cortex-m-generic.ld 32 | 33 | -------------------------------------------------------------------------------- /examples/libopencm3/f4/Makefile.include: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libopencm3 project. 3 | ## 4 | ## Copyright (C) 2009 Uwe Hermann 5 | ## Copyright (C) 2010 Piotr Esden-Tempski 6 | ## 7 | ## This library is free software: you can redistribute it and/or modify 8 | ## it under the terms of the GNU Lesser General Public License as published by 9 | ## the Free Software Foundation, either version 3 of the License, or 10 | ## (at your option) any later version. 11 | ## 12 | ## This library is distributed in the hope that it will be useful, 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ## GNU Lesser General Public License for more details. 16 | ## 17 | ## You should have received a copy of the GNU Lesser General Public License 18 | ## along with this library. If not, see . 19 | ## 20 | 21 | LIBNAME = opencm3_stm32f1 22 | DEFS += -DSTM32F1 23 | 24 | FP_FLAGS ?= -msoft-float 25 | ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd 26 | 27 | ################################################################################ 28 | # OpenOCD specific variables 29 | 30 | OOCD ?= openocd 31 | OOCD_INTERFACE ?= stlink 32 | OOCD_TARGET ?= stm32f1x 33 | 34 | ################################################################################ 35 | # Black Magic Probe specific variables 36 | # Set the BMP_PORT to a serial port and then BMP is used for flashing 37 | BMP_PORT ?= 38 | 39 | ################################################################################ 40 | # texane/stlink specific variables 41 | #STLINK_PORT ?= :4242 42 | 43 | 44 | include ../../../../rules.mk 45 | -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "${workspaceFolder}/../../../../../libopencm3/include/libopencm3/**" 8 | ], 9 | "browse": { 10 | "path": [ 11 | "${workspaceFolder}/**", 12 | "${workspaceFolder}/../../../../../libopencm3/include/libopencm3/**" 13 | ] 14 | }, 15 | "defines": [ 16 | "_DEBUG", 17 | "STM32F405", 18 | "STM32F4xx", 19 | "STM32F4", 20 | "UNICODE", 21 | "_UNICODE" 22 | ], 23 | "compilerPath": "/usr/bin/gcc", 24 | "cStandard": "c17", 25 | "cppStandard": "gnu++17", 26 | "intelliSenseMode": "linux-gcc-x64", 27 | "configurationProvider": "ms-vscode.makefile-tools" 28 | } 29 | ], 30 | "version": 4 31 | } -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "cortex-debug", 9 | "request": "launch", 10 | "name": "Debug (OpenOCD)", 11 | "servertype": "openocd", 12 | "cwd": "${workspaceFolder}", 13 | "runToEntryPoint": "main", 14 | "executable": "./demo.elf", 15 | "liveWatch": { 16 | "enabled": true, 17 | "samplesPerSecond": 4 18 | }, 19 | "device": "STM32F103RGT6", 20 | "configFiles": [ 21 | "interface/stlink-dap.cfg", 22 | "target/stm32f1x.cfg" 23 | ], 24 | "showDevDebugOutput": "none", 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "stm32-for-vscode.openOCDPath": "/home/lth/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.12.0-2.1/.content/bin/openocd", 3 | "cortex-debug.armToolchainPath": "/home/lth/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/12.3.1-1.2.1/.content/bin", 4 | "cortex-debug.openocdPath": "/home/lth/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.12.0-2.1/.content/bin/openocd", 5 | "files.associations": { 6 | "*.js": "javascript", 7 | "gpio.h": "c" 8 | } 9 | } -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libopencm3 project. 3 | ## 4 | ## Copyright (C) 2009 Uwe Hermann 5 | ## 6 | ## This library is free software: you can redistribute it and/or modify 7 | ## it under the terms of the GNU Lesser General Public License as published by 8 | ## the Free Software Foundation, either version 3 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This library is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public License 17 | ## along with this library. If not, see . 18 | ## 19 | 20 | BINARY = demo 21 | 22 | LDSCRIPT = ../f411.ld 23 | 24 | include ../../Makefile.include 25 | 26 | -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/demo.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/examples/libopencm3/f4/f411/demo/demo.bin -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2024 Lars Boegild Thomsen 5 | * 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | uint32_t systick = 0; 15 | 16 | void sys_tick_handler(void) { 17 | ++systick; 18 | } 19 | 20 | /* Set STM32 to 72 MHz. */ 21 | static void clock_setup(void) { 22 | 23 | rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_96MHZ]); 24 | 25 | /* 72MHz / 8 => 9000000 counts per second */ 26 | systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); 27 | 28 | /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */ 29 | /* SysTick interrupt every N clock pulses: set reload to N-1 */ 30 | systick_set_reload(8999); 31 | 32 | systick_interrupt_enable(); 33 | 34 | /* Start counting. */ 35 | systick_counter_enable(); 36 | 37 | /* Enable GPIOB, GPIOC, and AFIO clocks. */ 38 | rcc_periph_clock_enable(RCC_GPIOB); 39 | rcc_periph_clock_enable(RCC_GPIOC); 40 | rcc_periph_clock_enable(RCC_AFIO); 41 | } 42 | 43 | static void gpio_setup(void) { 44 | /* Set GPIO13 (in GPIO port C) to 'output push-pull'. */ 45 | gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, 46 | GPIO_CNF_OUTPUT_OPENDRAIN, GPIO13); 47 | 48 | AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST; 49 | 50 | /* Preconfigure the LEDs. */ 51 | gpio_clear(GPIOC, GPIO13); /* Switch on LED. */ 52 | } 53 | 54 | int main(void) { 55 | uint32_t now = 0, last_blink = 0; 56 | 57 | clock_setup(); 58 | gpio_setup(); 59 | 60 | /* Blink the LEDs (PC13) on the board. */ 61 | while (1) 62 | { 63 | 64 | now = systick; 65 | 66 | if (now - last_blink >= 500) 67 | { 68 | gpio_toggle(GPIOC, GPIO13); /* LED on/off */ 69 | last_blink = now; 70 | } 71 | } 72 | 73 | return 0; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/demo.d: -------------------------------------------------------------------------------- 1 | demo.o: demo.c ../../../../../libopencm3//include/libopencm3/stm32/rcc.h \ 2 | ../../../../../libopencm3//include/libopencm3/cm3/common.h \ 3 | /usr/lib/gcc/arm-none-eabi/13.2.1/include/stdint.h \ 4 | /usr/lib/gcc/arm-none-eabi/13.2.1/include/stdbool.h \ 5 | ../../../../../libopencm3//include/libopencm3/stm32/memorymap.h \ 6 | ../../../../../libopencm3//include/libopencm3/stm32/f1/memorymap.h \ 7 | ../../../../../libopencm3//include/libopencm3/cm3/memorymap.h \ 8 | ../../../../../libopencm3//include/libopencm3/stm32/f1/rcc.h \ 9 | ../../../../../libopencm3//include/libopencm3/stm32/common/rcc_common_all.h \ 10 | ../../../../../libopencm3//include/libopencm3/stm32/gpio.h \ 11 | ../../../../../libopencm3//include/libopencm3/stm32/f1/gpio.h \ 12 | ../../../../../libopencm3//include/libopencm3/stm32/common/gpio_common_all.h \ 13 | ../../../../../libopencm3//include/libopencm3/stm32/dma.h \ 14 | ../../../../../libopencm3//include/libopencm3/stm32/f1/dma.h \ 15 | ../../../../../libopencm3//include/libopencm3/stm32/common/dma_common_l1f013.h \ 16 | ../../../../../libopencm3//include/libopencm3/cm3/nvic.h \ 17 | ../../../../../libopencm3//include/libopencm3/dispatch/nvic.h \ 18 | ../../../../../libopencm3//include/libopencm3/stm32/f1/nvic.h \ 19 | ../../../../../libopencm3//include/libopencm3/cm3/systick.h 20 | -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/demo.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/examples/libopencm3/f4/f411/demo/demo.elf -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/demo/demo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/examples/libopencm3/f4/f411/demo/demo.o -------------------------------------------------------------------------------- /examples/libopencm3/f4/f411/f411.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for Lisa-M (STM32F411CE, 512K flash, 128K RAM). */ 21 | 22 | /* Define memory regions. */ 23 | MEMORY 24 | { 25 | ram (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 26 | rom (rx) : ORIGIN = 0x8000000, LENGTH = 512K 27 | } 28 | 29 | /* Include the common ld script. */ 30 | INCLUDE cortex-m-generic.ld 31 | 32 | -------------------------------------------------------------------------------- /examples/rules.mk: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is part of the libopencm3 project. 3 | ## 4 | ## Copyright (C) 2009 Uwe Hermann 5 | ## Copyright (C) 2010 Piotr Esden-Tempski 6 | ## Copyright (C) 2013 Frantisek Burian 7 | ## 8 | ## This library is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU Lesser General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This library is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU Lesser General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU Lesser General Public License 19 | ## along with this library. If not, see . 20 | ## 21 | 22 | # Be silent per default, but 'make V=1' will show all compiler calls. 23 | ifneq ($(V),1) 24 | Q := @ 25 | NULL := 2>/dev/null 26 | endif 27 | 28 | ############################################################################### 29 | # Executables 30 | 31 | PREFIX ?= arm-none-eabi- 32 | 33 | CC := $(PREFIX)gcc 34 | CXX := $(PREFIX)g++ 35 | LD := $(PREFIX)gcc 36 | AR := $(PREFIX)ar 37 | AS := $(PREFIX)as 38 | OBJCOPY := $(PREFIX)objcopy 39 | OBJDUMP := $(PREFIX)objdump 40 | GDB := $(PREFIX)gdb 41 | STFLASH = $(shell which st-flash) 42 | STYLECHECK := /checkpatch.pl 43 | STYLECHECKFLAGS := --no-tree -f --terse --mailback 44 | STYLECHECKFILES := $(shell find . -name '*.[ch]') 45 | OPT := -Os 46 | DEBUG := -ggdb3 47 | CSTD ?= -std=c99 48 | 49 | 50 | ############################################################################### 51 | # Source files 52 | 53 | OBJS += $(BINARY).o 54 | 55 | 56 | ifeq ($(strip $(OPENCM3_DIR)),) 57 | # user has not specified the library path, so we try to detect it 58 | 59 | # where we search for the library 60 | LIBPATHS := ./libopencm3 ../../../../libopencm3 ../../../../../libopencm3 61 | 62 | OPENCM3_DIR := $(wildcard $(LIBPATHS:=/locm3.sublime-project)) 63 | OPENCM3_DIR := $(firstword $(dir $(OPENCM3_DIR))) 64 | 65 | ifeq ($(strip $(OPENCM3_DIR)),) 66 | $(warning Cannot find libopencm3 library in the standard search paths.) 67 | $(error Please specify it through OPENCM3_DIR variable!) 68 | endif 69 | endif 70 | 71 | ifeq ($(V),1) 72 | $(info Using $(OPENCM3_DIR) path to library) 73 | endif 74 | 75 | define ERR_DEVICE_LDSCRIPT_CONFLICT 76 | You can either specify DEVICE=blah, and have the LDSCRIPT generated, 77 | or you can provide LDSCRIPT, and ensure CPPFLAGS, LDFLAGS and LDLIBS 78 | all contain the correct values for the target you wish to use. 79 | You cannot provide both! 80 | endef 81 | 82 | ifeq ($(strip $(DEVICE)),) 83 | # Old style, assume LDSCRIPT exists 84 | DEFS += -I$(OPENCM3_DIR)/include 85 | LDFLAGS += -L$(OPENCM3_DIR)/lib 86 | LDLIBS += -l$(LIBNAME) 87 | LDSCRIPT ?= $(BINARY).ld 88 | else 89 | # New style, assume device is provided, and we're generating the rest. 90 | ifneq ($(strip $(LDSCRIPT)),) 91 | $(error $(ERR_DEVICE_LDSCRIPT_CONFLICT)) 92 | endif 93 | include $(OPENCM3_DIR)/mk/genlink-config.mk 94 | endif 95 | 96 | OPENCM3_SCRIPT_DIR = $(OPENCM3_DIR)/scripts 97 | EXAMPLES_SCRIPT_DIR = $(OPENCM3_DIR)/../scripts 98 | 99 | ############################################################################### 100 | # C flags 101 | 102 | TGT_CFLAGS += $(OPT) $(CSTD) $(DEBUG) 103 | TGT_CFLAGS += $(ARCH_FLAGS) 104 | TGT_CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration 105 | TGT_CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes 106 | TGT_CFLAGS += -fno-common -ffunction-sections -fdata-sections 107 | 108 | ############################################################################### 109 | # C++ flags 110 | 111 | TGT_CXXFLAGS += $(OPT) $(CXXSTD) $(DEBUG) 112 | TGT_CXXFLAGS += $(ARCH_FLAGS) 113 | TGT_CXXFLAGS += -Wextra -Wshadow -Wredundant-decls -Weffc++ 114 | TGT_CXXFLAGS += -fno-common -ffunction-sections -fdata-sections 115 | 116 | ############################################################################### 117 | # C & C++ preprocessor common flags 118 | 119 | TGT_CPPFLAGS += -MD 120 | TGT_CPPFLAGS += -Wall -Wundef 121 | TGT_CPPFLAGS += $(DEFS) 122 | 123 | ############################################################################### 124 | # Linker flags 125 | 126 | TGT_LDFLAGS += --static -nostartfiles 127 | TGT_LDFLAGS += -T$(LDSCRIPT) 128 | TGT_LDFLAGS += $(ARCH_FLAGS) $(DEBUG) 129 | TGT_LDFLAGS += -Wl,-Map=$(*).map -Wl,--cref 130 | TGT_LDFLAGS += -Wl,--gc-sections 131 | ifeq ($(V),99) 132 | TGT_LDFLAGS += -Wl,--print-gc-sections 133 | endif 134 | 135 | ############################################################################### 136 | # Used libraries 137 | 138 | LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group 139 | 140 | ############################################################################### 141 | ############################################################################### 142 | ############################################################################### 143 | 144 | .SUFFIXES: .elf .bin .hex .srec .list .map .images 145 | .SECONDEXPANSION: 146 | .SECONDARY: 147 | 148 | all: elf 149 | 150 | elf: $(BINARY).elf 151 | bin: $(BINARY).bin 152 | hex: $(BINARY).hex 153 | srec: $(BINARY).srec 154 | list: $(BINARY).list 155 | GENERATED_BINARIES=$(BINARY).elf $(BINARY).bin $(BINARY).hex $(BINARY).srec $(BINARY).list $(BINARY).map 156 | 157 | images: $(BINARY).images 158 | flash: $(BINARY).stlink-flash 159 | 160 | # Either verify the user provided LDSCRIPT exists, or generate it. 161 | ifeq ($(strip $(DEVICE)),) 162 | $(LDSCRIPT): 163 | ifeq (,$(wildcard $(LDSCRIPT))) 164 | $(error Unable to find specified linker script: $(LDSCRIPT)) 165 | endif 166 | else 167 | include $(OPENCM3_DIR)/mk/genlink-rules.mk 168 | endif 169 | 170 | $(OPENCM3_DIR)/lib/lib$(LIBNAME).a: 171 | ifeq (,$(wildcard $@)) 172 | $(warning $(LIBNAME).a not found, attempting to rebuild in $(OPENCM3_DIR)) 173 | $(MAKE) -C $(OPENCM3_DIR) 174 | endif 175 | 176 | # Define a helper macro for debugging make errors online 177 | # you can type "make print-OPENCM3_DIR" and it will show you 178 | # how that ended up being resolved by all of the included 179 | # makefiles. 180 | print-%: 181 | @echo $*=$($*) 182 | 183 | %.images: %.bin %.hex %.srec %.list %.map 184 | @#printf "*** $* images generated ***\n" 185 | 186 | %.bin: %.elf 187 | @#printf " OBJCOPY $(*).bin\n" 188 | $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin 189 | 190 | %.hex: %.elf 191 | @#printf " OBJCOPY $(*).hex\n" 192 | $(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex 193 | 194 | %.srec: %.elf 195 | @#printf " OBJCOPY $(*).srec\n" 196 | $(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec 197 | 198 | %.list: %.elf 199 | @#printf " OBJDUMP $(*).list\n" 200 | $(Q)$(OBJDUMP) -S $(*).elf > $(*).list 201 | 202 | %.elf %.map: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/lib$(LIBNAME).a 203 | @#printf " LD $(*).elf\n" 204 | $(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $(*).elf 205 | 206 | %.o: %.c 207 | @#printf " CC $(*).c\n" 208 | $(Q)$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).c 209 | 210 | %.o: %.cxx 211 | @#printf " CXX $(*).cxx\n" 212 | $(Q)$(CXX) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).cxx 213 | 214 | %.o: %.cpp 215 | @#printf " CXX $(*).cpp\n" 216 | $(Q)$(CXX) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).cpp 217 | 218 | clean: 219 | @#printf " CLEAN\n" 220 | $(Q)$(RM) $(GENERATED_BINARIES) generated.* $(OBJS) $(OBJS:%.o=%.d) 221 | 222 | stylecheck: $(STYLECHECKFILES:=.stylecheck) 223 | styleclean: $(STYLECHECKFILES:=.styleclean) 224 | 225 | # the cat is due to multithreaded nature - we like to have consistent chunks of text on the output 226 | %.stylecheck: % 227 | $(Q)$(OPENCM3_SCRIPT_DIR)$(STYLECHECK) $(STYLECHECKFLAGS) $* > $*.stylecheck; \ 228 | if [ -s $*.stylecheck ]; then \ 229 | cat $*.stylecheck; \ 230 | else \ 231 | rm -f $*.stylecheck; \ 232 | fi; 233 | 234 | %.styleclean: 235 | $(Q)rm -f $*.stylecheck; 236 | 237 | 238 | %.stlink-flash: %.bin 239 | @printf " FLASH $<\n" 240 | $(STFLASH) write $(*).bin 0x8000000 241 | 242 | ifeq ($(BMP_PORT),) 243 | ifeq ($(OOCD_FILE),) 244 | %.flash: %.elf 245 | @printf " FLASH $<\n" 246 | (echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \ 247 | $(OOCD) -f interface/$(OOCD_INTERFACE).cfg \ 248 | -f target/$(OOCD_TARGET).cfg \ 249 | -c "program $(*).elf verify reset exit" \ 250 | $(NULL) 251 | else 252 | %.flash: %.elf 253 | @printf " FLASH $<\n" 254 | (echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \ 255 | $(OOCD) -f $(OOCD_FILE) \ 256 | -c "program $(*).elf verify reset exit" \ 257 | $(NULL) 258 | endif 259 | else 260 | %.flash: %.elf 261 | @printf " GDB $(*).elf (flash)\n" 262 | $(GDB) --batch \ 263 | -ex 'target extended-remote $(BMP_PORT)' \ 264 | -x $(EXAMPLES_SCRIPT_DIR)/black_magic_probe_flash.scr \ 265 | $(*).elf 266 | endif 267 | 268 | .PHONY: images clean stylecheck styleclean elf bin hex srec list 269 | 270 | -include $(OBJS:.o=.d) 271 | -------------------------------------------------------------------------------- /images/include_paths.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/images/include_paths.png -------------------------------------------------------------------------------- /images/source_locations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/images/source_locations.png -------------------------------------------------------------------------------- /images/tim3_config1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/images/tim3_config1.png -------------------------------------------------------------------------------- /images/tim3_dma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/images/tim3_dma.png -------------------------------------------------------------------------------- /images/tim3_gpio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/images/tim3_gpio.png -------------------------------------------------------------------------------- /images/tim3_params.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/stm32-ws2812/b1f229844b87c779031d168880b2104c0c3ab2ca/images/tim3_params.png -------------------------------------------------------------------------------- /src/color_values.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : color_values.h 4 | * @brief : Ws2812b library color values 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | * Copyright (c) 2024 Lars Boegild Thomsen . 9 | * All rights reserved 10 | * 11 | * This software is licensed under terms that can be found in the LICENSE file 12 | * in the root directory of this software component. 13 | * If no LICENSE file comes with this software, it is provided AS-IS. 14 | * 15 | ****************************************************************************** 16 | */ 17 | 18 | #ifndef COLOR_VALUES_H_ 19 | #define COLOR_VALUES_H_ 20 | 21 | extern const uint16_t color_value[256][8]; 22 | 23 | #endif /* COLOR_VALUES_H_ */ 24 | -------------------------------------------------------------------------------- /src/ws2812.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : ws2812.c 4 | * @brief : Ws2812 library source 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | * Copyright (c) 2022 - 2025 Lars Boegild Thomsen 9 | * All rights reserved 10 | * 11 | * This software is licensed under terms that can be found in the LICENSE file 12 | * in the root directory of this software component. 13 | * If no LICENSE file comes with this software, it is provided AS-IS. 14 | * 15 | ****************************************************************************** 16 | */ 17 | 18 | /** 19 | * Notice, a timer with a DMA driven PWM output will need to be configured 20 | * before this library is initialized. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "main.h" 28 | 29 | #include "ws2812.h" 30 | #include "color_values.h" 31 | 32 | /* 33 | * Update next 24 bits in the dma buffer - assume dma_buffer_pointer is pointing 34 | * to the buffer that is safe to update. The dma_buffer_pointer and the call to 35 | * this function is handled by the dma callbacks. 36 | */ 37 | inline void ws2812_update_buffer(ws2812_handleTypeDef *ws2812, uint16_t *dma_buffer_pointer) { 38 | 39 | #ifdef BUFF_GPIO_Port 40 | HAL_GPIO_WritePin(BUFF_GPIO_Port, BUFF_Pin, GPIO_PIN_SET); 41 | #endif 42 | 43 | // A simple state machine - we're either resetting (two buffers worth of zeros), 44 | // idle (just winging out zero buffers) or 45 | // we are transmitting data for the "current" led. 46 | 47 | ++ws2812->dma_cbs; 48 | 49 | if (ws2812->led_state == LED_RES) { // Latch state - 10 or more full buffers of zeros 50 | 51 | // This one is simple - we got a bunch of zeros of the right size - just throw 52 | // that into the buffer. Twice will do (two half buffers). 53 | if (ws2812->zero_halves < 2) { 54 | memset(dma_buffer_pointer, 0, 2 * BUFFER_SIZE); // Fill the buffer with zeros 55 | ws2812->zero_halves++; // We only need to update two half buffers 56 | } 57 | 58 | ws2812->res_cnt++; 59 | 60 | if (ws2812->res_cnt >= LED_RESET_CYCLES) { // done enough reset cycles - move to next state 61 | ws2812->led_cnt = 0; // prepare to send data 62 | if (ws2812->is_dirty) { 63 | ws2812->is_dirty = false; 64 | ws2812->led_state = LED_DAT; 65 | } else { 66 | ws2812->led_state = LED_IDL; 67 | } 68 | } 69 | 70 | } else if (ws2812->led_state == LED_IDL) { // idle state 71 | 72 | if (ws2812->is_dirty) { // we do nothing here except waiting for a dirty flag 73 | ws2812->is_dirty = false; 74 | ws2812->led_state = LED_DAT; // when dirty - start processing data 75 | } 76 | 77 | } else { // LED_DAT 78 | 79 | ++ws2812->dat_cbs; 80 | 81 | // First let's deal with the current LED 82 | uint8_t *led = (uint8_t*) &ws2812->led[3 * ws2812->led_cnt]; 83 | 84 | for (uint8_t c = 0; c < 3; c++) { // Deal with the 3 color leds in one led package 85 | 86 | // Copy values from the pre-filled color_value buffer 87 | memcpy(dma_buffer_pointer, color_value[led[c]], 16); // Lookup the actual buffer data 88 | dma_buffer_pointer += 8; // next 8 bytes 89 | 90 | } 91 | 92 | // Now move to next LED switching to reset state when all leds have been updated 93 | ws2812->led_cnt++; // Next led 94 | if (ws2812->led_cnt >= ws2812->leds) { // reached top 95 | ws2812->led_cnt = 0; // back to first 96 | ws2812->zero_halves = 0; 97 | ws2812->res_cnt = 0; 98 | ws2812->led_state = LED_RES; 99 | } 100 | 101 | } 102 | 103 | #ifdef BUFF_GPIO_Port 104 | HAL_GPIO_WritePin(BUFF_GPIO_Port, BUFF_Pin, GPIO_PIN_RESET); 105 | #endif 106 | 107 | } 108 | 109 | ws2812_resultTypeDef zeroLedValues(ws2812_handleTypeDef *ws2812) { 110 | ws2812_resultTypeDef res = WS2812_Ok; 111 | memset(ws2812->led, 0, ws2812->leds * 3); // Zero it all 112 | ws2812->is_dirty = true; // Mark buffer dirty 113 | return res; 114 | } 115 | 116 | ws2812_resultTypeDef setLedValue(ws2812_handleTypeDef *ws2812, uint16_t led, uint8_t col, uint8_t value) { 117 | ws2812_resultTypeDef res = WS2812_Ok; 118 | if (led < ws2812->leds) { 119 | ws2812->led[3 * led + col] = value; 120 | ws2812->is_dirty = true; // Mark buffer dirty 121 | } else { 122 | res = WS2812_Err; 123 | } 124 | return res; 125 | } 126 | 127 | // Just throw values into led_value array - the dma interrupt will 128 | // handle updating the dma buffer when needed 129 | ws2812_resultTypeDef setLedValues(ws2812_handleTypeDef *ws2812, uint16_t led, uint8_t r, uint8_t g, uint8_t b) { 130 | ws2812_resultTypeDef res = WS2812_Ok; 131 | if (led < ws2812->leds) { 132 | ws2812->led[3 * led + RL] = r; 133 | ws2812->led[3 * led + GL] = g; 134 | ws2812->led[3 * led + BL] = b; 135 | ws2812->is_dirty = true; // Mark buffer dirty 136 | } else { 137 | res = WS2812_Err; 138 | } 139 | return res; 140 | } 141 | 142 | ws2812_resultTypeDef ws2812_init(ws2812_handleTypeDef *ws2812, TIM_HandleTypeDef *timer, uint32_t channel, uint16_t leds) { 143 | 144 | ws2812_resultTypeDef res = WS2812_Ok; 145 | 146 | // Store timer handle for later 147 | ws2812->timer = timer; 148 | 149 | // Store channel 150 | ws2812->channel = channel; 151 | 152 | ws2812->leds = leds; 153 | 154 | ws2812->led_state = LED_RES; 155 | ws2812->is_dirty = 0; 156 | ws2812->zero_halves = 2; 157 | 158 | ws2812->led = malloc(leds * 3); 159 | if (ws2812->led != NULL) { // Memory for led values 160 | 161 | memset(ws2812->led, 0, leds * 3); // Zero it all 162 | 163 | // Start DMA to feed the PWM with values 164 | // At this point the buffer should be empty - all zeros 165 | HAL_TIM_PWM_Start_DMA(timer, channel, (uint32_t*) ws2812->dma_buffer, BUFFER_SIZE * 2); 166 | 167 | } else { 168 | res = WS2812_Mem; 169 | } 170 | 171 | return res; 172 | 173 | } 174 | 175 | /* 176 | * vim: ts=4 nowrap 177 | */ 178 | -------------------------------------------------------------------------------- /src/ws2812.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : ws2812.h 4 | * @brief : Ws2812 library header 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | * Copyright (c) 2022 - 2025 Lars Boegild Thomsen 9 | * All rights reserved. 10 | * 11 | * This software is licensed under terms that can be found in the LICENSE file 12 | * in the root directory of this software component. 13 | * If no LICENSE file comes with this software, it is provided AS-IS. 14 | * 15 | ****************************************************************************** 16 | */ 17 | 18 | #ifndef __WS2812_H 19 | #define __WS2812_H 20 | 21 | #include "main.h" 22 | 23 | // Buffer allocated will be twice this 24 | #define BUFFER_SIZE 24 25 | 26 | // LED on/off counts. PWM timer is running 125 counts. LED_CNT need to be set to the total counts in the PWM. 27 | #define LED_OFF 1 * LED_CNT / 3 - 1 // A bit less than 1/3 28 | #define LED_ON 2 * LED_CNT / 3 + 2 // A bit more than 2/3 29 | #define LED_RESET_CYCLES 10 // Full 24-bit cycles 30 | 31 | #define GL 0 // Green LED 32 | #define RL 1 // Red LED 33 | #define BL 2 // Blue LED 34 | 35 | typedef enum { 36 | WS2812_Ok, 37 | WS2812_Err, 38 | WS2812_Mem 39 | } ws2812_resultTypeDef; 40 | 41 | // Statemachine states 42 | typedef enum { 43 | LED_RES = 0, // Reset latch cycle 44 | LED_IDL = 1, // Idle doing nothing except waiting for is_dirty 45 | LED_DAT = 2 // Transferring led data - one led at the time 46 | } ws2812_stateTypeDef; 47 | 48 | typedef struct { 49 | TIM_HandleTypeDef *timer; // Timer running the PWM - MUST run at 800 kHz 50 | uint32_t channel; // Timer channel 51 | uint16_t dma_buffer[BUFFER_SIZE * 2]; // Fixed size DMA buffer 52 | uint16_t leds; // Number of LEDs on the string 53 | uint8_t *led; // Dynamically allocated array of LED RGB values 54 | ws2812_stateTypeDef led_state; // LED Transfer state machine 55 | uint8_t led_cnt; // Counts through the leds starting from zero up to "leds" 56 | uint8_t res_cnt; // Counts reset cycles when in reset state 57 | uint8_t is_dirty; // Indicates to the call back that the led color values have been updated 58 | uint8_t zero_halves; // Counts halves send during reset 59 | uint32_t dma_cbs; // Just used for statistics 60 | uint32_t dat_cbs; // Also used for statistics 61 | } ws2812_handleTypeDef; 62 | 63 | ws2812_resultTypeDef ws2812_init(ws2812_handleTypeDef *ws2812, TIM_HandleTypeDef *timer, uint32_t channel, uint16_t leds); 64 | 65 | void ws2812_update_buffer(ws2812_handleTypeDef *ws2812, uint16_t *dma_buffer_pointer); 66 | 67 | // Set all led values to zero 68 | ws2812_resultTypeDef zeroLedValues(ws2812_handleTypeDef *ws2812); 69 | 70 | // Set a single led value 71 | ws2812_resultTypeDef setLedValue(ws2812_handleTypeDef *ws2812, uint16_t led, uint8_t color, uint8_t value); 72 | 73 | // Set values of all 3 leds 74 | ws2812_resultTypeDef setLedValues(ws2812_handleTypeDef *ws2812, uint16_t led, uint8_t r, uint8_t g, uint8_t b); 75 | 76 | #endif // _WS2812_H 77 | /* 78 | * vim: ts=4 nowrap 79 | */ 80 | -------------------------------------------------------------------------------- /src/ws2812_demos.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : ws2812_demos.h 4 | * @brief : Ws2812b demos source 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | * Copyright (c) 2024 Lars Boegild Thomsen . 9 | * All rights reserved. 10 | * 11 | * This software is licensed under terms that can be found in the LICENSE file 12 | * in the root directory of this software component. 13 | * If no LICENSE file comes with this software, it is provided AS-IS. 14 | * 15 | ****************************************************************************** 16 | */ 17 | 18 | #include "main.h" 19 | 20 | #include "ws2812.h" 21 | #include "ws2812_demos.h" 22 | 23 | 24 | uint8_t active_demo = 0; 25 | 26 | const uint8_t led_line_colors[][3] = { 27 | { 10, 0, 0 }, 28 | { 0, 10, 0 }, 29 | { 0, 0, 10 }, 30 | { 10, 10, 0 }, 31 | { 0, 10, 10 }, 32 | { 10, 0, 10 }, 33 | { 10, 10, 10 } 34 | }; 35 | 36 | void ws2812_demos_set(ws2812_handleTypeDef *ws2812, uint8_t demo) { 37 | active_demo = demo; 38 | } 39 | 40 | void ws2812_demos_tick(ws2812_handleTypeDef *ws2812) { 41 | 42 | static const uint32_t led_interval = 20; 43 | 44 | static uint16_t line_led = 0; 45 | static uint32_t line_count = 0; 46 | static uint8_t line_color = 0; 47 | static uint32_t next_led = led_interval; 48 | 49 | uint32_t now = uwTick; 50 | 51 | switch (active_demo) { 52 | case WS2812_DEMO_LINE: 53 | if (now >= next_led) { 54 | //zeroLedValues(ws2812); 55 | setLedValues(ws2812, line_led, led_line_colors[line_color][0], led_line_colors[line_color][1], led_line_colors[line_color][2]); 56 | ++line_led; 57 | ++line_count; 58 | if (line_count % 64 == 0) 59 | ++line_color; 60 | if (line_color >= sizeof(led_line_colors) / sizeof(led_line_colors[0])) 61 | line_color = 0; 62 | if (line_led >= LEDS) 63 | line_led = 0; 64 | 65 | next_led = now + led_interval; 66 | } 67 | break; 68 | default: 69 | // De nothing really 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/ws2812_demos.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : ws2812_demos.h 4 | * @brief : Ws2812b demos header 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | * Copyright (c) 2024 Lars Boegild Thomsen . 9 | * All rights reserved. 10 | * 11 | * This software is licensed under terms that can be found in the LICENSE file 12 | * in the root directory of this software component. 13 | * If no LICENSE file comes with this software, it is provided AS-IS. 14 | * 15 | ****************************************************************************** 16 | */ 17 | 18 | #ifndef WS2812_DEMOS_H_ 19 | #define WS2812_DEMOS_H_ 20 | 21 | #define WS2812_DEMO_NONE 0 22 | #define WS2812_DEMO_LINE 1 23 | 24 | #include "main.h" 25 | #include "ws2812.h" 26 | 27 | void ws2812_demos_set(ws2812_handleTypeDef *ws2812, uint8_t demo); 28 | void ws2812_demos_tick(ws2812_handleTypeDef *ws2812); 29 | 30 | #endif /* WS2812_DEMOS_H_ */ 31 | --------------------------------------------------------------------------------