我已经购买了STM32F411核板,现在我正在尝试了解HAL的各种零碎.从外部中断开始似乎是一个好主意,因为电路板有一个连接到PC13的按钮.所以我设置了一个简单的切换频率闪烁.下面的代码有点简化:
#define LED_PIN GPIO_PIN_5
#define BTN_PIN GPIO_PIN_13
static uint32_t blink_period = 250;
int main(void)
{
HAL_Init();
SystemClock_Config();
__GPIOA_CLK_ENABLE();
GPIO_InitTypeDef pinConfig;
pinConfig.Pin = (LED_PIN);
pinConfig.Pull = GPIO_NOPULL;
pinConfig.Mode = GPIO_MODE_OUTPUT_PP;
pinConfig.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOA, &pinConfig);
__GPIOC_CLK_ENABLE();
pinConfig.Pin = (BTN_PIN);
pinConfig.Pull = GPIO_NOPULL;
pinConfig.Mode = GPIO_MODE_IT_FALLING;
pinConfig.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOC, &pinConfig);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0x0F, 0x00);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
while (1)
{
HAL_GPIO_TogglePin(GPIOA, LED_PIN);
HAL_Delay(blink_period);
}
}
void EXTI15_10_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(BTN_PIN);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == BTN_PIN)
{
if (blink_period == 500)
{
blink_period …Run Code Online (Sandbox Code Playgroud) 我正在尝试开始使用STM32(Cortex-M3),我的计划是从Ubuntu(9.04/AMD64)开始使用它.
首先,我得到了Olimex stm32-h103标题板和Olimex ARM-USB-OCD jtag,并且我可能会使用OpenOCD,gcc和Eclipse.
但是现在我正在研究使用什么版本的gcc以及如何设置它以便能够交叉编译代码.
似乎有一些手臂项目,但我不知道从什么开始,有人可以推动我朝着正确的方向前进吗?
谢谢约翰
更新:似乎几乎是什么,我想从CodeSourcery的,但他们似乎把重点放在IA32和AMD64没有.
但是在支持的设备中,我找到了Cortex-M3
更新:有可能在AMD64上安装IA32,因此标记的答案可能已经过时了.
更新:找到有关Cortex-M3的交叉编译的链接.
我目前在STM32平台上参与嵌入式C++开发.我们的团队正在评估模板的使用,以便为各种低级硬件设备参数化驱动程序.
所有有效的模板特化都是事先已知的,因此我们可以在实现文件中明确地给出所有有效的特化(实现和声明分离).事实上,对我们来说,显式专业化非常有用,因为它有助于记录可行的参数集.
// file i2c_dev.h
template<typename traits>
struct i2c_dev
{
public:
static void init();
static void send();
static bool busy();
...
private:
static i2c_transfer periodic_transfer; // class with used-defined constructor
};
// traits class for configuration A
struct i2c_dev_traitsA
{
enum
{
I2Cx_BASE = I2C1_BASE
, PORTx_BASE = GPIOB_BASE
, PORTx_PIN_TX = PB08
, PORTx_PIN_RX = PB09
};
};
// traits class for configuration B, different I2C peripherial and pinout
struct i2c_dev_traitsB
{
enum
{
I2Cx_BASE = I2C2_BASE
, PORTx_BASE …Run Code Online (Sandbox Code Playgroud) 我有一些I2C2中断的问题,我启用了中断,但处理程序中断从不执行.
这是i2c2的初始化:
void i2c2InitSlave(void)
{
I2C_DeInit(I2C2);
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
/*I2C2 Peripheral clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
/* Enable GPIO clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
// I2C2 SCL and SDA Pin configuration
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOH, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource4, GPIO_AF_I2C2);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource5, GPIO_AF_I2C2);
/* Initialize I2C peripheral */
/* I2C Init */
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = SLAVE_ADDRESS;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_ClockSpeed = 100000; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用arm-none-eabi-gcc和Makefile编译STM32Cube项目.我已经指定:
CFLAGS = -mthumb\
-march=armv6-m\
-mlittle-endian\
-mcpu=cortex-m0\
-ffunction-sections\
-fdata-sections\
-MMD\
-std=c99\
-Wall\
-g\
-D$(PART)\
-c
Run Code Online (Sandbox Code Playgroud)
和:
LDFLAGS = -Wl,--gc-sections\
-Wl,-T$(LDFILE)\
-Wl,-v
Run Code Online (Sandbox Code Playgroud)
FW构建没有问题.但是当我启动MCU时,我陷入了Hard Fault.堆栈跟踪是:
#0 HardFault_Handler () at ./Src/main.c:156
#1 <signal handler called>
#2 0x0800221c in ____libc_init_array_from_thumb ()
#3 0x080021be in LoopFillZerobss () at Src/startup_stm32f030x8.s:103
#4 0x080021be in LoopFillZerobss () at Src/startup_stm32f030x8.s:103
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Run Code Online (Sandbox Code Playgroud)
当我踩到bl __libc_init_array启动文件时,我会直接进入Hard Fault .
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, …Run Code Online (Sandbox Code Playgroud) 我无法获得可靠的调试设置。我在网络上的一些论坛上看到过类似标题的其他主题,但情况似乎不同。
设置:
现在,有一个序列,每次经过一番挣扎后,我都能够与调试器连接,但是单步执行和读取变量的工作并不那么可靠,以至于我暂时相信我所看到的。但是,即使到了调用堆栈不会充满明显的无意义条目并且只有很少的地方的地步,也是很累的。
例子:
OpenOCD 输出:
GNU ARM Eclipse 64 位开放式片上调试器 0.10.0-dev-00287-g85cec24-dirty (2016-01-10-10:31)
根据 GNU GPL v2 许可
有关错误报告,请阅读
http://openocd.org/doc/doxygen/bugs.html
信息:自动选择第一个可用的会话传输“hla_swd”。要覆盖使用“传输选择”。
信息:选定的传输接管了低级目标控制。与普通 JTAG/SWD 相比,结果可能有所不同
适配器速度:500 kHz
适配器_nsrst_delay:100
没有分开
没有分开
信息:无法匹配请求的速度 500 kHz,使用 480 … 有没有办法在STM32F4上上传程序时用计算机信息更新RTC?例如,计算机上的日期和时间信息是:12h40 11/09/2018,当我用IAR/AC6刷新微控制器时,RTC被设置为这些信息?
通过“原子访问防护”或“中断防护”强制对与 ISR 共享的易失性变量进行原子访问的标准技术,特别是在没有操作系统的情况下运行裸机、单线程协作多任务应用程序时,如下所示:
// 1. save interrupt state
// 2. disable only the interrupts necessary
// You get atomic access to volatile variables shared with ISRs here,
// since ISRs are the only other "context" or running "thread" which
// might attempt to modify a shared memory block or variable.
// 3. restore interrupt state
Run Code Online (Sandbox Code Playgroud)
另请参阅我在这里详细描述的地方,包括最佳实践(在短时间内保持中断关闭)以及如何通过我的doAtomicRead()重复读取循环函数进行原子读取而不首先禁用中断:读取 64 位变量,即由 ISR 更新。
我之前已经记录过如何对 AVR 微控制器/Arduino 执行此操作:How do I Forceatomity in Atmel AVR mcus/Arduino? …
操作系统:Ubuntu
rustup update-->成功rutstup target install thumbv7m-none-eabi-->成功cargo install cargo-flasherror: failed to run custom build command for `hidapi v1.4.2`
process didn't exit successfully: `/tmp/cargo-installgobLzf/release/build/hidapi-aad2646622c847a4/build-script-build` (exit status: 101)
error: could not find system library 'libudev' required by the 'hidapi' crate
error: failed to compile `cargo-flash v0.13.0`, intermediate artifacts can be found at `/tmp/cargo-installgobLzf`
Run Code Online (Sandbox Code Playgroud)