bcm2835_st_read returns zero - confused

141 views
Skip to first unread message

mick bell

unread,
Jul 26, 2022, 11:59:22 AM7/26/22
to bcm2835
bcm2835 init works fine, as does all the GPIO & bcm2835_delay and the like.

RPi4 & Pi400, Raspbian "Bullseye", bcm2835 1.71, Libcap installed, added the program name etc

And I've compiled with Geany 
gcc -Wall -o "%e" "%f" -pthread $(pkg-config gtk+-3.0 --cflags --libs) -export-dynamic -l bcm2835 -l png -DBCM2835_HAVE_LIBCAP

Here's code:
// bcm_timer.c
//
// Example program for bcm2835 library system time

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>

#include <bcm2835.h>

uint64_t now = 0;
uint64_t then = 0;
uint rescode = 0;

int main(int argc, char **argv)
{
 
    // Init GPIO

    if ( ! bcm2835_init() )
    {
    printf("Fail 0x%X ", errno);
    return -1;
    }
   
    then = bcm2835_st_read();
   
    bcm2835_delay(500);
   
    now = bcm2835_st_read();    

    printf("Then = 0x%lluX, Now = 0x%lluX \n", then, now) ;
   
    bcm2835_close();
    return 0;
}



Here's output:

xxx@raspberrypi:~/Develop/c/test $ ./bcm_timer
Then = 0x0X, Now = 0x0X 

mick bell

unread,
Jul 28, 2022, 3:02:15 AM7/28/22
to bcm2835
By "added program name" I mean ... sudo setcap cap_sys_rawio+ep *progname*

And I've added user to kmem group

mick bell

unread,
Aug 11, 2022, 4:26:02 PM8/11/22
to bcm2835
Nobody ? :/

Scott Poteet

unread,
Dec 8, 2022, 4:20:33 PM12/8/22
to bcm2835
I am also using the RPI4 w/ Raspbian Bullseye and experiencing the same issue that  bcm2835_st_read() returns zero value.  Did you ever determine this cause?

Scott Poteet

unread,
Dec 8, 2022, 4:48:33 PM12/8/22
to bcm2835
The issue was that I was not running as 'root'.  Non-root (users) will only be able to access gpio functions. 
Per documentation: 
If the library runs with any other effective UID (ie not root), then
  bcm2835_init() will attempt to open /dev/gpiomem, and, if
  successful, will only permit GPIO operations. In particular,
  bcm2835_spi_begin() and bcm2835_i2c_begin() will return false and all
  other non-gpio operations may fail silently or crash.
Reply all
Reply to author
Forward
0 new messages