标签: stm32

CMSIS & STM32,如何开始?

我想在 STM32 上使用 CMSIS 启动项目。网上一搜,没找到具体的教程。有些使用 SPL 开始项目(ST 已停止使用)。我想要一个在 stm32cube 上学习 CMSIS 的资源。

如果有人帮助我,我会很高兴。

问候

microcontroller stm32 cmsis

0
推荐指数
1
解决办法
2235
查看次数

stm32写入rw寄存器没有效果

尝试将新值(0x00008000,设置 TSVREFE 位)写入 ADC 控制寄存器 2 (ADC_CR2)。没有效果。我在内存(地址 0x40012408)中看到未更改的值(重置后为 0x00000000)。我应该配置一些东西才能写入该寄存器吗?

为了测试我尝试了这个实验例程:

__main      PROC
    EXPORT  __main
    LDR     R0, =ADC1_ADDR
    ADD     R0, #ADC_CR2_OFFSET
    MOV     R1, #0x00008000
    STR     R1, [R0]
    B   .
        
    ENDP

ADC1_ADDR               EQU 0x40012400
ADC_CR2_OFFSET          EQU 0x08

    END
Run Code Online (Sandbox Code Playgroud)

执行后内存窗口如下所示(断点在 B . 行)

0x40012400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x40012410 ...
Run Code Online (Sandbox Code Playgroud)

embedded assembly stm32

0
推荐指数
1
解决办法
337
查看次数

为什么中断在 STM32 上没有按预期工作?

我正在尝试编写一个简单的程序,该程序利用外部中断来控制 2 个 LED 中的哪一个闪烁。在没有中断例程的情况下,两个 LED 都会闪烁,因此 LED 引脚(PB 和 PC13)的配置是正确的。每当我尝试使用 ISR 时就会出现该程序。我正在为 STM32F103C8 MCU 使用仅带有 CMSIS 内核的 Keil uVision 5。

在下面的代码中,两个 LED 都没有闪烁。我试图将引脚 PB5 设置为输入上拉,并在将 PB5 与 GND 连接时检测下降沿作为中断。

#include "stm32f10x.h"                  // Device header

void delay(int rep);
void EXTI9_5_IRQHandler();

// global variable
int signal = 0; // this will change upon each interrupt

int main(void)
{
    // set RCC for PortC to enable the clock BUS
    RCC->APB2ENR |= (1<<4);
    // set RCC for portB to enable the clock bus …
Run Code Online (Sandbox Code Playgroud)

c embedded microcontroller arm stm32

0
推荐指数
1
解决办法
665
查看次数

“可能在此函数中未初始化地使用”如何删除此警告?

我将使用 strtok“#”分隔数据,数据类似于“157#178#666#...”-ish。我知道还有另一种方法可以解析它,但我不知道如何。这是我的代码

HAL_UART_Receive_DMA(&huart1, (uint8_t*)dataB,77);

  char *delim="A";
    char *b,*c,*d,*e,*f,*g,*h,*i,*j,*k,*l,*m,*n,*o,*p,*q,*r,*s;
    char *sampah =dataB;
    char *a=strtok(sampah,delim);

    if (a != NULL) {
      b = strtok(NULL, delim);
      if (b != NULL) {
        c = strtok(NULL, delim);
        if (c != NULL) {
          d = strtok(NULL, delim);
          if (d != NULL) {
            e = strtok(NULL, delim);
            if (e != NULL) {
              f = strtok(NULL, delim);
              if (f != NULL) {
                g = strtok(NULL, delim);
                if (g != NULL) {
                  h = strtok(NULL, delim);
                  if (h != NULL) …
Run Code Online (Sandbox Code Playgroud)

c stm32

0
推荐指数
1
解决办法
133
查看次数

cant use sleep() in embedded c for stm32

I try to learn embedded c for a stm32-microcontorller. I try to wirte a easy blink program, where i use the sleep()-function.

code:

/* Includes ------------------------------------------------------------------*/
#include <unistd.h>
#include "main.h"

int main(void)
{
  HAL_Init();

  while (1)
  { 
    HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);
    sleep(1);  // this line throws a error, when compiling
  }
}
Run Code Online (Sandbox Code Playgroud)

the compiler gives me following error:

/usr/lib/gcc/arm-none-eabi/7.4.0/../../../../arm-none-eabi/bin/ld: CMakeFiles/untitled2.elf.dir/Src/main.c.obj: in function `main':
/home/heinrich/CLionProjects/untitled2/Src/main.c:106: undefined reference to `sleep'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/untitled2.elf.dir/build.make:391: untitled2.elf] Fehler 1
make[2]: *** …
Run Code Online (Sandbox Code Playgroud)

c sleep stm32

-1
推荐指数
1
解决办法
158
查看次数

C 语言中 if 或 while 语句中带有宏的 HardFault

我有以下宏用于读取 STM32F091 寄存器中的单个位:

#define GET_BIT(reg, pos)          (((reg)>>(pos))&0x00000001u)
Run Code Online (Sandbox Code Playgroud)

我必须将这个宏与这两个参数一起使用:

#define FLASH_KEYR                 (*((u32_t *)(0x40022004u)))
#define BSY_FLASH_SR_POS           (0u)
Run Code Online (Sandbox Code Playgroud)

使用此宏来评估单个变量时我没有任何问题,例如:

uint32_t value = GET_BIT(FLASH_SR, BSY_FLASH_SR_POS);
Run Code Online (Sandbox Code Playgroud)

但是,在这样的条件语句上使用这个宏:

    while (GET_BIT(FLASH_SR, BSY_FLASH_SR_POS) == 1u);
Run Code Online (Sandbox Code Playgroud)

微型进入硬故障的 ISR。

...为什么?

c crash embedded stm32

-1
推荐指数
1
解决办法
71
查看次数

如何使用加速度计确定八面体和十二面体的边长?

我有三个图形:一个立方体、一个八面体、一个十二面体。

每个人物内部都有一个加速度计。

图形的边编号在 1 到 n 之间。

任务:确定立方体、八面体、十二面体的当前边长。

对于立方体,我推导出公式:

边=圆形((Ax*1/988)+(Ay*2/988)+(Az*3/988));

变量“side”将给出区间 -3 和 3 之间的值(不带 0),这意味着立方体的当前边在 1 到 6 之间。

现在我需要对八面体和十二面体执行相同的操作。求助,我该怎么办?我是否需要额外的传感器或加速度计就足够了?

math physics arduino accelerometer stm32

-2
推荐指数
1
解决办法
193
查看次数

为什么我不能将函数返回的结构分配给结构?

我编写了“轻量级”时间库,并且有如下所示的 struct 和 typedef:

struct tmt {
    uint16_t year;
    uint8_t month;
    uint8_t day;
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
    uint8_t weekday;
    uint8_t is_dst; 
};

typedef struct tmt tm_t;
Run Code Online (Sandbox Code Playgroud)

我有一个返回的函数tm_t

tm_t rtc_get_current_time(void){
    tm_t tm;
    xSemaphoreTake(rtc_mutex, RTC_MUTEX_MAX_WAIT);
    tm = rtc.current_time;
    xSemaphoreGive(rtc_mutex);
    return tm;
}
Run Code Online (Sandbox Code Playgroud)

我想这样使用它:

tm_t s;
s = rtc_get_current_time();    // error is here
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

从类型“int”分配给类型“tm_t”{aka“struct tmt”}时不兼容的类型


我也尝试过像这样更改函数和变量:

struct tmt rtc_get_current_time(void){
    tm_t tm;
    xSemaphoreTake(rtc_mutex, RTC_MUTEX_MAX_WAIT);
    tm = rtc.current_time;
    xSemaphoreGive(rtc_mutex);
    return tm;
}

struct tmt tm = rtc_get_current_time();
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

c stm32 c11 cortex-m arm-none-eabi-gcc

-2
推荐指数
1
解决办法
79
查看次数