Re: Counter configuration STM32


Dmitriy Korovkin
 

With my two cents, it looks like something is missing in the dts file.

Dmitriy Korovkin

On 2022-06-28 15:08, Ordóñez, Tomás wrote:
**[Please note: This e-mail is from an EXTERNAL e-mail address]
Hi im trying to use the counter API with stm32 min_dev_blue board.
This is my app.overlay:
`&timers2 {
status = "okay";
counter {
compatible = "st,stm32-counter";
status = "okay";
label = "COUNTER_2";
};
};`
And this is the zephyr.dts file after the build
`timers2: timers@40000000 {
compatible = "st,stm32-timers";
reg = < 0x40000000 0x400 >;
clocks = < &rcc 0x1c 0x1 >;
interrupts = < 0x1c 0x0 >;
interrupt-names = "global";
st,prescaler = < 0x0 >;
status = "okay";
label = "TIMERS_2";
pwm {
compatible = "st,stm32-pwm";
status = "disabled";
label = "PWM_2";
#pwm-cells = < 0x3 >;
};
counter {
compatible = "st,stm32-counter";
status = "okay";
label = "COUNTER_2";
};
};`
This is my prj.conf
`CONFIG_SERIAL=y
CONFIG_GPIO=y
CONFIG_PRINTK=y
CONFIG_PWM=y
CONFIG_COUNTER=y
CONFIG_COUNTER_INIT_PRIORITY=50
CONFIG_COUNTER_TIMER_STM32=y
CONFIG_COUNTER_RTC_STM32=n`
This is my code
`#include <zephyr.h>
#include <zephyr/drivers/counter.h>
/* Counter */
struct counter_alarm_cfg alarm_cfg;
#define TIMER DT_NODELABEL(timers2)
const struct device *counter_dev = DEVICE_DT_GET(TIMER);
#if !DT_NODE_EXISTS(TIMER)
#error "whoops"
#endif`
If i build this everything is fine.
Then if i add this code the build fails with the following output
`/* Threads */
#define GEN_STACK_SIZE   500
#define GEN_PRIORITY     5
void gen_thread(void *, void *, void *);
K_THREAD_DEFINE(gen_tid, GEN_STACK_SIZE,
                gen_thread, NULL, NULL, NULL,
                GEN_PRIORITY, 0, 0);
void gen_thread(void *arg1, void *arg2, void *arg3){
    ARG_UNUSED(arg1);
    ARG_UNUSED(arg2);
    ARG_UNUSED(arg3);
    if (!device_is_ready(counter_dev)) {
    printk("Error: Counter device %s is not ready\n",
          counter_dev->name);
      return;
    }
    while (1) {
printk("Thread gen loopeando\n");
k_sleep(K_MSEC(50));
}
}`
`c:/users/tomaso/zephyr-sdk-0.14.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: app/libapp.a(gen.c.obj):C:/Users/tomaso/zephyrproject/proyectos/pruebaaa/src/gen.c:19: undefined reference to ´__device_dts_ord_63'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'C:\Program Files\CMake\bin\cmake.EXE' --build 'C:\Users\tomaso\zephyrproject\build'`
What is the correct way to include a counter to a stm32 timer?

Join devel@lists.zephyrproject.org to automatically receive all group messages.