Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4961

SDK • repeating_timer doesn't work

$
0
0
So repeating timer callback is not executing not even once, "add_repeating_timer_ms" returns true

Code:

#include "pico/stdlib.h"#include <stdio.h>#include <string.h>void led_blinking_task(void);bool timer_callback(__unused repeating_timer_t *rt) {    led_blinking_task();    printf("Timer callback\r\n");    return true;}/*------------- MAIN -------------*/int main(void){    board_init();    uart_init(uart0, 921600);    uart_puts(uart0, " Hello, UART!\n");    printf("Hello, TinyUSB!\n");    repeating_timer_t timer;    // negative timeout means exact delay (rather than delay between callbacks)    if (!add_repeating_timer_ms(1000, timer_callback, NULL, &timer)) {        printf("Failed to add timer\n");    }    TU_LOG1("Speaker running\r\n");    while (1)    {tight_loop_contents();    }}

Code:

# Generated Cmake Pico project filecmake_minimum_required(VERSION 3.13)set(CMAKE_C_STANDARD 11)set(CMAKE_CXX_STANDARD 17)set(CMAKE_EXPORT_COMPILE_COMMANDS ON)# Initialise pico_sdk from installed location# (note this can come from environment, CMake cache etc)# Pull in Raspberry Pi Pico SDK (must be before project)include(pico_sdk_import.cmake)project(soundcard C CXX ASM)# Initialise the Raspberry Pi Pico SDKpico_sdk_init()# Add executable. Default name is the project name, version 0.1# add_executable(blinker dev_lowlevel.c #   dev_lowlevel.h#   usb_common.h  # )add_executable(soundcard main.c  usb_descriptors.c  quirk_os_guessing.c)pico_set_program_name(soundcard "soundcard")pico_set_program_version(soundcard "0.1")# Modify the below lines to enable/disable output over UART/USBpico_enable_stdio_uart(soundcard 1)pico_enable_stdio_usb(soundcard 0)# Add the standard library to the buildtarget_link_libraries(soundcard        pico_stdlib        hardware_resets         hardware_irq        pico_unique_id         tinyusb_device         tinyusb_board)# Add the standard include files to the buildtarget_include_directories(soundcard PRIVATE  ${CMAKE_CURRENT_LIST_DIR}  ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required)target_compile_definitions(soundcard PUBLIC PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1)pico_add_extra_outputs(soundcard)

Statistics: Posted by hugoballs — Sun Dec 01, 2024 2:06 pm



Viewing all articles
Browse latest Browse all 4961

Trending Articles