stm32

stm32系统时钟初始化过程剖析

隐身守侯 提交于 2019-12-24 04:42:02
STM32有以下4个时钟源: 高速外部时钟(HSE):以外部晶振作时钟源,晶振频率可取范围为4~16MHz,我们一般采用8MHz的晶振。 高速内部时钟(HSI) : 由内部RC振荡器产生,频率为8MHz,但不稳定。 低速外部时钟(LSE):以外部晶振作时钟源,主要提供给实时时钟模块,所以一般采用32.768KHz。 低速内部时钟(LSI) :由内部RC振荡器产生,也主要提供给实时时钟模块,频率大约为40KHz。 然而我们在main函数中并没有调用什么函数来选择systemclock啊,那么这个系统时钟源的选择是在那里初始化的了。。。 其实我们都忽略了STM32的启动文件。 一般而言,系统上电后第一个执行的是由汇编所编写的启动文件,其主要工作为一下五部分: (1)、初始化堆栈指针SP=_initial_sp (2)、初始化PC指针,令其=Reset_Handler (3)、初始化中断向量表 (4)、配置系统时钟 (5)、调用C库函数_main初始化用户堆栈,从而最终调用main函数进入C的世界 这上述的五个功能一般都由STM32官方在它们提供的官方库里的ASM文件(汇编启动文件)startup_stm32f10x_hd.s实现,因此在实际中只需要根据所用编译软件的不同选择对应的ASM文件,然后将之加入编译的工程中,再编写自己的main文件便可

stm32启动文件分析

一个人想着一个人 提交于 2019-12-24 02:02:39
这篇文章主要是分析stm32启动文件,启动文件是由汇编编写的,文件名为startup_stm32f40_41xxx.s。 启动文件做的工作: 启动文件最主要的功能就是初始化堆栈指针sp,执行复位程序进入C语言main函数 1.初始化堆栈空间大小,定义栈顶位置、堆起始位置等等 2.定义中断向量表,初始化sp指针 3.Reset_Handler复位函数定义 4.配置系统时钟,进入main函数 具体代码分析 Stack_Size EQU 0x00000400 AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size __initial_sp 在MDK帮助文档中可以查到EQU是宏定义的伪指令,它的作用就相当于C语言中的define,首先定义栈大小为1KB(0x00000400)。 栈的作用主要保存函数中的局部变量,函数调用过程中的形参,返回地址,因此在函数中如果有较多的局部变量,大型数组最好不要放在函数中定义,在这种情况下就要考虑栈大小是否充足,如果栈溢出了,那程序会出现跑飞,找不到返回地址。 AREA是告诉编译器汇编一个代码段或者数据段,STACK 表示段名,这个可以任意命名; NOINIT 表示不初始化; READWRITE 表示可读可写, ALIGN=3,表示按照 2^3对齐,即 8 字节对齐。

stm32 how to make pulse count up/down with timer

主宰稳场 提交于 2019-12-24 00:22:52
问题 I need for my personal project counting pulse and direction with timer. With this code I can count only one direction. Any suggestion are welcome for correct code (this code is pretesting) pulse count to PA_9 and direction input to PA_8 #include "mbed.h" #include "stm32f4xx.h" #include "stm32f4xx_hal_tim_ex.h" TIM_HandleTypeDef timer; TIM_Base_InitTypeDef inizializza; TIM_IC_InitTypeDef startclock; TIM_ClockConfigTypeDef ClockConfig; TIM_SlaveConfigTypeDef sSlaveConfigure; TIM

How to use formatting strings in user-defined functions?

独自空忆成欢 提交于 2019-12-23 03:56:08
问题 I want to write a function to print characters on an LCD in a similar way that printf/sprintf does using formatting strings. 回答1: You may use sprintf function to format the strings and print to LCD. char buffer[50]; int a = 10, b = 20, c; c = a + b; sprintf(buffer, "Sum of %d and %d is %d", a, b, c); Now the buffer will have the formatted strings 回答2: You could write a variadic function and pass the parameters on to vsnprintf() : #include <stdarg.h> #include <stdio.h> #include <stdlib.h> void

STM32F1 - Using master SPI on bare metal

我的未来我决定 提交于 2019-12-22 15:00:39
问题 I've been trying to port some of my AVR code to drive a simple SPI LCD to ARM as a learning exercise (I'm very new to ARM in general). For this I just need to use SPI in master mode. I looked in the datasheet for my device (STM32F103C8) and found that the SPI1 pins I need, SCK and MOSI are mapped as alternative functions of PA5 and PA7, respectively, along with other peripherals (pg.29). My understanding is that in order to use the SPI function on these pins, I need to make sure that anything

STM32F1 - Using master SPI on bare metal

末鹿安然 提交于 2019-12-22 15:00:11
问题 I've been trying to port some of my AVR code to drive a simple SPI LCD to ARM as a learning exercise (I'm very new to ARM in general). For this I just need to use SPI in master mode. I looked in the datasheet for my device (STM32F103C8) and found that the SPI1 pins I need, SCK and MOSI are mapped as alternative functions of PA5 and PA7, respectively, along with other peripherals (pg.29). My understanding is that in order to use the SPI function on these pins, I need to make sure that anything

Error in Final Launch Sequence - Eclipse System Workbench Debugging for STM32L476

我是研究僧i 提交于 2019-12-22 13:06:14
问题 I'm trying to debug and run simple assembly code for STM32L476. I've set up Eclipse Oxygen, installed the latest version of System Workbench plugin in Eclipse and installed ST-Link drivers. The IDE successfully builds the program without throwing any errors, however when I connect my STM Discovery Board and try to debug, the program throws the following error: Error in Final Launch Sequence - Reset Command not defined for device 'Generic TCP/IP'. , I'm getting this error on both Ubuntu 17.10

Error in Final Launch Sequence - Eclipse System Workbench Debugging for STM32L476

谁说胖子不能爱 提交于 2019-12-22 13:06:08
问题 I'm trying to debug and run simple assembly code for STM32L476. I've set up Eclipse Oxygen, installed the latest version of System Workbench plugin in Eclipse and installed ST-Link drivers. The IDE successfully builds the program without throwing any errors, however when I connect my STM Discovery Board and try to debug, the program throws the following error: Error in Final Launch Sequence - Reset Command not defined for device 'Generic TCP/IP'. , I'm getting this error on both Ubuntu 17.10

Error in Final Launch Sequence - Eclipse System Workbench Debugging for STM32L476

南笙酒味 提交于 2019-12-22 13:06:01
问题 I'm trying to debug and run simple assembly code for STM32L476. I've set up Eclipse Oxygen, installed the latest version of System Workbench plugin in Eclipse and installed ST-Link drivers. The IDE successfully builds the program without throwing any errors, however when I connect my STM Discovery Board and try to debug, the program throws the following error: Error in Final Launch Sequence - Reset Command not defined for device 'Generic TCP/IP'. , I'm getting this error on both Ubuntu 17.10

Bootloader on STM32F303: built in from factory or externally programmed?

孤街浪徒 提交于 2019-12-22 10:54:50
问题 I have some background on ATMEL and ATMEL bootloaders and we are moving to ARM for a new project. In particular we will be using the STM32F303RET6. This essentially is a a Cortex M4 with a higher number of Analog input pins. I have been going through the documentation regarding the bootloader and I am extremely confused: On page 19 of the Getting Started Document it says the following: "The embedded boot loader is located in the System memory, programmed by ST during production " Furthermore