bcm2835_init: gpio mmap failed: Cannot allocate memory

762 views
Skip to first unread message

Mr.bombastic

unread,
Aug 1, 2020, 9:17:32 AM8/1/20
to bcm2835
Hi! I have a Raspberry pi with a HAT extention board that uses the bcm2835 library to work. one of the HAT's feachures is a LED that you can program to blink. However, if i run the program it says that it cannot alocate memory. any suggestions as to why?

heres the code:
#include <bcm2835.h>

#define PIN 26
int main(int argc, char **argv)
{
    if (!bcm2835_init())return 1;
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);

    while (1)
    {
        bcm2835_gpio_write(PIN, HIGH);
        bcm2835_delay(500);
        bcm2835_gpio_write(PIN, LOW);
        bcm2835_delay(500);
    }
    bcm2835_close();
    return 0;
}

Mike McCauley

unread,
Aug 2, 2020, 12:41:19 AM8/2/20
to bcm...@googlegroups.com
Hello,


On Saturday, 1 August 2020 23:17:31 AEST Mr.bombastic wrote:
> Hi! I have a Raspberry pi with a HAT extention board that uses the bcm2835
> library to work. one of the HAT's feachures is a LED that you can program
> to blink. However, if i run the program it says that it cannot alocate
> memory. any suggestions as to why?

How exactly does it say 'it cannot alocate memory'. I cant see any message
like that in the library.
There is a message with the phrase "mmap failed".
Perhaps you can send the exact messagem you see?
Also what versionof bcm2835 are you using?
How did you build it?
What version of Linux are you testing on?

Cheers.


>
> heres the code:
> #include <bcm2835.h>
>
> #define PIN 26
> int main(int argc, char **argv)
> {
> if (!bcm2835_init())return 1;
> bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
>
> while (1)
> {
> bcm2835_gpio_write(PIN, HIGH);
> bcm2835_delay(500);
> bcm2835_gpio_write(PIN, LOW);
> bcm2835_delay(500);
> }
> bcm2835_close();
> return 0;
> }


--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com 5R3MRFM2+X6
Phone +61 7 5598-7474



Message has been deleted

Mr.bombastic

unread,
Aug 2, 2020, 2:59:42 AM8/2/20
to bcm2835
Hi! Thanks for the reply.
 
Im using bcm2835 1.68 version and im using Linux Kernel 5.4.51. The code i posted isn't acctually mine. I have a Raspberry pi HAT called  "Pioneer600 extention board" that requires the bcm2835, wiringpi and python libraries to be installed. The code is from the Pioneer600 library that has example code like the blinking LED. 
Heres the link to the Pioneer600 library:https://www.waveshare.com/wiki/File:Pioneer600-Code.tar.gz
If i run the "sudo ./led" command in "/Pioneer600/LED/bcm2835/" folder i get "bcm2835_init:gpio mmap failed: Cannot allocate memory"
I hope this helps....


Mike McCauley

unread,
Aug 2, 2020, 4:33:24 AM8/2/20
to bcm2835, Mr.bombastic
Hi,

What distribution of Linux are you using?

Mr.bombastic

unread,
Aug 2, 2020, 7:36:13 AM8/2/20
to bcm2835
Raspian (Raspberry pi OS)

Mike McCauley

unread,
Aug 2, 2020, 4:56:29 PM8/2/20
to bcm...@googlegroups.com
On Sunday, 2 August 2020 21:36:13 AEST Mr.bombastic wrote:

Which version?
Message has been deleted

Mr.bombastic

unread,
Aug 3, 2020, 7:02:38 AM8/3/20
to bcm2835
I ran lsb_releace -a and it says:
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (duster)
Releace: 10
Codename: buster

Does that help?

Mike McCauley

unread,
Aug 3, 2020, 11:25:30 PM8/3/20
to bcm2835, Mr.bombastic
Hmmm, is it possible your user is not member of the 'gpio' group. The default
user pi is, but perhaps you are not ?

More info here:

https://raspberrypi.stackexchange.com/questions/40105/access-gpio-pins-without-root-no-access-to-dev-mem-try-running-as-root/40106

Cheers.

Mike McCauley

unread,
Aug 3, 2020, 11:30:25 PM8/3/20
to bcm2835, Mr.bombastic, Mike McCauley
Are you able to run it as root?

Mr.bombastic

unread,
Aug 4, 2020, 2:38:08 AM8/4/20
to bcm2835
Yes, i am able to run it as root

Mike McCauley

unread,
Aug 4, 2020, 2:51:32 AM8/4/20
to bcm...@googlegroups.com
I mean, do you see the error message when you run it as root?

Mr.bombastic

unread,
Aug 4, 2020, 11:11:25 AM8/4/20
to bcm2835
Yes

Mike McCauley

unread,
Aug 4, 2020, 10:55:55 PM8/4/20
to bcm2835, Mr.bombastic
Hello,

On Wednesday, 5 August 2020 01:11:25 AEST Mr.bombastic wrote:
> Yes

I suspect that either your non-root user is not a member of the gpio group, or
that you are in fact using a very old version of bcm2835. Other than that I
dont know.

Cheers.

Mr.bombastic

unread,
Aug 5, 2020, 2:51:10 AM8/5/20
to bcm2835
The version im using is the bcm2835 1.68 one. Ill add my user to the gpio group and see if something changes.

Mr.bombastic

unread,
Aug 5, 2020, 2:59:37 AM8/5/20
to bcm2835
Im already in the gpio group and nothing changed. Still getting this message.

Alec Devlin

unread,
Aug 6, 2020, 4:53:26 PM8/6/20
to bcm2835

Hi,

 

I noticed in one of the previous emails that you said the kernel version

was 5.4.51, is this because you are using the pre-released version of the

64 bit version of Raspberry Pi OS?

 

> > > > > > > > > > >> Im using bcm2835 1.68 version and im using Linux Kernel
> > > >
> > > > 5.4.51.

 

I am using the Raspberry Pi OS released 27-May-2020

 

Raspberry Pi OS (32-bit) with desktop and recommended software

Image with desktop and recommended software based on Debian Buster

 

Version:May 2020

Release date:2020-05-27

Kernel version:4.19

 

The Kernel version is :- * Linux kernel 4.19.118

 

Haven’t seen the problem you have described in the previous emails, I haven’t tried the 64 bit version

yet.

 

Not sure if this will help you but might be worth checking.

 

All the best.

 

Alec.

Reply all
Reply to author
Forward
0 new messages