Library compatibility with Compute Module 3

118 views
Skip to first unread message

Marco Sartore

unread,
Mar 2, 2017, 1:00:32 AM3/2/17
to bcm2835
Hello Mike,
first of all let me thank you for having realized and let freely accessible your very nice bcm2835 Library, that I constantly utilize when writing around the RaspberryPi.

Up to now I have worked with RPi boards but possibly I will also move to the Compute Module 3 (CM3), which has many more available pins and hence functionalities.
I wish to ask you if the latest available version of the Library is fully compatible with the CM3 or not.
In case yes, how can I address all the available signals which are not listed in the .h file and how can I switch among the "alternate functions" that the GPIO pins offer ?
In case not, do you predict to upgrade the library for CM3 compatibility ?

Many thanks in advance,
best greetings,
Marco

Mike McCauley

unread,
Mar 2, 2017, 1:10:33 AM3/2/17
to bcm...@googlegroups.com
Hello,

On Wednesday, 1 March 2017 10:00:31 PM AEST Marco Sartore wrote:
> Hello Mike,
> first of all let me thank you for having realized and let freely accessible
> your very nice bcm2835 Library, that I constantly utilize when writing
> around the RaspberryPi.

Thanks.

>
> Up to now I have worked with RPi boards but possibly I will also move to
> the Compute Module 3 (CM3), which has many more available pins and hence
> functionalities.
> I wish to ask you if the latest available version of the Library is fully
> compatible with the CM3 or not.

I have no idea. I dont have any CM3s and have not tested with it.

> In case yes, how can I address all the available signals which are not
> listed in the .h file and how can I switch among the "alternate functions"
> that the GPIO pins offer ?
> In case not, do you predict to upgrade the library for CM3 compatibility ?

Not in the very short term.
Perhaps if someone sent me a CM3 I may investigate.

Cheers.

>
> Many thanks in advance,
> best greetings,
> Marco


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

Seismic Industries

unread,
Sep 15, 2019, 4:24:15 AM9/15/19
to bcm2835
Hi

i'm working on a thingy where i need to run the spi2 on the computmodule to communicate with a ili9225 2.0" color display.
spi0 is already occupied by an MCP3208 ADC, and i don't wan't to share it with CSx. and the pins where the spi1 resides are used for pcm I/O.

i tried to rewrite the necessary functions like
bcm2835_begin_aux_spi();
bcm2835_aux_spi_write();
bcm2835_aux_spi_transfer();
...

thing compiles, but the MOSI pin doesn't spit out anything. i tried to spit out a byte with a modified spi.c from the examples folder. but the MOSI pin (GPIO41) stays silent..

so far i feel a little stuck - i am a very dilletant programmer... sry.

i can't send a computemodule to australia, but i'd gladly (privately) share the login credentials to give you remote access to it. i can connect a loopback so things could be tested out, if anyone would be interested to have a look / help out.

best regards from switzerland
Raffael

Mike McCauley

unread,
Sep 15, 2019, 4:35:57 AM9/15/19
to bcm...@googlegroups.com
Hi,

Sorry, I cant write your code for you.

Cheers.
http://www.airspayce.com 5R3MRFM2+X6
Phone +61 7 5598-7474



Seismic Industries

unread,
Sep 15, 2019, 4:45:27 AM9/15/19
to bcm2835
Hi

thanks for the reply!
i know it was stupid to ask - but i tought i'd be worth a try. since i am stuck a.t.m. anyway.

nontheless! i appreciate your work very much, the library is super handy!!! and veeery fast.

would it be possible to buy that "engineering service/adaption" from you? i'd be happy to do, if i'd knew what your charges would be like

best
raffi

Arjan van Vught

unread,
Sep 15, 2019, 9:21:24 AM9/15/19
to bcm...@googlegroups.com
Hi Raffael,

Are you able to give it a test on a Raspberry Pi board model <=3 ? 

I am just curious to know if the SPI code works at all for you.

- Arjan

--
You received this message because you are subscribed to the Google Groups "bcm2835" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bcm2835+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bcm2835/3e610ea1-4203-47e7-be8c-11c846a5ed62%40googlegroups.com.

Seismic Industries

unread,
Sep 15, 2019, 10:51:30 AM9/15/19
to bcm2835
already tried that as a POC.
i have the development board from waveshare for the computemodule so i could plug the display in everywhere.

i tried the bcm2835 driver on spi0. and it works perfect. super fast.

in the meantime i was able to modify the bcm2835 stuff so i have a working aux_spi_begin function to initialize spi2, and also i can transmit 16bit (modified aux_spi_write) but i also need an according function to transmit 8bit. tried to fiddle with the shift length, but that didn't work out. i'll grab the code and paste it here.

Am Sonntag, 15. September 2019 15:21:24 UTC+2 schrieb Arjan van Vught:
Hi Raffael,

Are you able to give it a test on a Raspberry Pi board model <=3 ? 

I am just curious to know if the SPI code works at all for you.

- Arjan
To unsubscribe from this group and stop receiving emails from it, send an email to bcm...@googlegroups.com.

Seismic Industries

unread,
Sep 15, 2019, 11:08:22 AM9/15/19
to bcm2835
heres the init function:

int bcm2835_aux_spi_begin(void)
{
    volatile uint32_t* enable = bcm2835_aux + BCM2835_AUX_ENABLE/4;
//    volatile uint32_t* cntl0 = bcm2835_spi1 + BCM2835_AUX_SPI_CNTL0/4;
//    volatile uint32_t* cntl1 = bcm2835_spi1 + BCM2835_AUX_SPI_CNTL1/4;
    volatile uint32_t* cntl0 = bcm2835_spi2 + BCM2835_AUX_SPI_CNTL0/4;
    volatile uint32_t* cntl1 = bcm2835_spi2 + BCM2835_AUX_SPI_CNTL1/4;

    if (bcm2835_spi2 == MAP_FAILED) // bcm2835_spi1 auf bcm2835_spi2 - raffimod
      return 0; /* bcm2835_init() failed, or not root */

    /* Set the SPI pins to the Alt 4 function to enable SPI1 access on them */
//  bcm2835_gpio_fsel(RPI_V2_GPIO_P1_36, BCM2835_GPIO_FSEL_ALT4);   /* SPI1_CE2_N */
//  bcm2835_gpio_fsel(RPI_V2_GPIO_P1_35, BCM2835_GPIO_FSEL_ALT4);   /* SPI1_MISO */
//  bcm2835_gpio_fsel(RPI_V2_GPIO_P1_38, BCM2835_GPIO_FSEL_ALT4);   /* SPI1_MOSI */
//  bcm2835_gpio_fsel(RPI_V2_GPIO_P1_40, BCM2835_GPIO_FSEL_ALT4);   /* SPI1_SCLK */
//raffimod mit CM3 pins
  bcm2835_gpio_fsel(CM3_BANK1_GPIO43, BCM2835_GPIO_FSEL_ALT4);  /* SPI2_CE0_N */
  bcm2835_gpio_fsel(CM3_BANK1_GPIO40, BCM2835_GPIO_FSEL_ALT4);  /* SPI2_MISO */
  bcm2835_gpio_fsel(CM3_BANK1_GPIO41, BCM2835_GPIO_FSEL_ALT4);  /* SPI2_MOSI */
  bcm2835_gpio_fsel(CM3_BANK1_GPIO42, BCM2835_GPIO_FSEL_ALT4);  /* SPI2_SCLK */


    //bcm2835_aux_spi_setClockDivider(bcm2835_aux_spi_CalcClockDivider(1000000));   // Default 1MHz SPI
    bcm2835_aux_spi_setClockDivider(bcm2835_aux_spi_CalcClockDivider(10000000));    // 10MHz SPI

//  bcm2835_peri_write(enable, BCM2835_AUX_ENABLE_SPI0);
  bcm2835_peri_write(enable, BCM2835_AUX_ENABLE_SPI1); // aka spi2 - raffimod
    bcm2835_peri_write(cntl1, 0);
    bcm2835_peri_write(cntl0, BCM2835_AUX_SPI_CNTL0_CLEARFIFO);

    return 1; /* OK */
}


the working 16bit write function:

// raffimodded - aux_spi_write function - works for 16bit
void bcm2835_aux_spi_write(uint16_t data)
{
    volatile uint32_t* cntl0 = bcm2835_spi2 + BCM2835_AUX_SPI_CNTL0/4;        // raffimod - auf _spi2 angepasst
    volatile uint32_t* cntl1 = bcm2835_spi2 + BCM2835_AUX_SPI_CNTL1/4;        // raffimod - auf _spi2 angepasst
    volatile uint32_t* stat = bcm2835_spi2 + BCM2835_AUX_SPI_STAT/4;          // raffimod - auf _spi2 angepasst
    volatile uint32_t* io = bcm2835_spi2 + BCM2835_AUX_SPI_IO/4;              // raffimod - auf _spi2 angepasst

    uint32_t _cntl0 = (spi1_speed << BCM2835_AUX_SPI_CNTL0_SPEED_SHIFT);
    _cntl0 |= BCM2835_AUX_SPI_CNTL0_CS0_N;  // raffimod - von CS2_N auf CS0_N angepasst
    _cntl0 |= BCM2835_AUX_SPI_CNTL0_ENABLE;
    _cntl0 |= BCM2835_AUX_SPI_CNTL0_MSBF_OUT;
    _cntl0 |= 16; // Shift length

    bcm2835_peri_write(cntl0, _cntl0);
    bcm2835_peri_write(cntl1, BCM2835_AUX_SPI_CNTL1_MSBF_IN);
  // room for improvement - disable the simultateous read from the MISO - raffimod to be
    while (bcm2835_peri_read(stat) & BCM2835_AUX_SPI_STAT_TX_FULL)
        ;

    bcm2835_peri_write(io, (uint32_t) data << 16);
}




and the nonworking 8 bit transfer function:

// raffimod - extra transfer function for 8 bit data
void bcm2835_aux_spi_transfer(uint8_t data)
{
    volatile uint32_t* cntl0 = bcm2835_spi2 + BCM2835_AUX_SPI_CNTL0/4;        // raffimod - auf _spi2 angepasst
    volatile uint32_t* cntl1 = bcm2835_spi2 + BCM2835_AUX_SPI_CNTL1/4;        // raffimod - auf _spi2 angepasst
    volatile uint32_t* stat = bcm2835_spi2 + BCM2835_AUX_SPI_STAT/4;          // raffimod - auf _spi2 angepasst
    volatile uint32_t* io = bcm2835_spi2 + BCM2835_AUX_SPI_IO/4;              // raffimod - auf _spi2 angepasst

    uint32_t _cntl0 = (spi1_speed << BCM2835_AUX_SPI_CNTL0_SPEED_SHIFT);
    _cntl0 |= BCM2835_AUX_SPI_CNTL0_CS0_N; // raffimod - von CS2_N auf CS0_N angepasst
    _cntl0 |= BCM2835_AUX_SPI_CNTL0_ENABLE;
    _cntl0 |= BCM2835_AUX_SPI_CNTL0_MSBF_OUT;
    //_cntl0 |= 8; // Shift length
    _cntl0 |= BCM2835_AUX_SPI_CNTL0_VAR_WIDTH;

    bcm2835_peri_write(cntl0, _cntl0);
    bcm2835_peri_write(cntl1, BCM2835_AUX_SPI_CNTL1_MSBF_IN);
    while (bcm2835_peri_read(stat) & BCM2835_AUX_SPI_STAT_TX_FULL)
        ;

    bcm2835_peri_write(io, (uint32_t) data << 8);
}


also here and there were some additional defines needed. and of course the different pins to use. and the baseadress offset (which is already defined in v1.60)

Arjan van Vught

unread,
Sep 15, 2019, 11:49:30 AM9/15/19
to bcm...@googlegroups.com
Ok. You are using SPI2 instead of SPI1. The bcm2835_aux_spi_* functions are initially written for SPI1 which can be found on the 40-pins GPIO header. 

http://www.airspayce.com/mikem/bcm2835/group__spi.html#ga0e572ea5cf830964c4c454774d7eca9f —> "Forces RPi AUX SPI pins P1-36 (MOSI), P1-38 (MISO), P1-40 (CLK) and P1-36 (CE2) to alternate function ALT4, which enables those pins for SPI interface.”

The SPI1 can bound on pin’s 57,59,63,65,69 and 71 with CM-3 -> https://www.raspberrypi.org/documentation/hardware/computemodule/datasheets/rpi_DATA_CM_1p0.pdf

Hence there is compatibility with Compute Module 3.

- Arjan
--
You received this message because you are subscribed to the Google Groups "bcm2835" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bcm2835+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bcm2835/5d77e78c-03c0-44c0-8d03-096d945394b4%40googlegroups.com.

Seismic Industries

unread,
Sep 15, 2019, 2:53:48 PM9/15/19
to bcm2835
i can't use the pins 63,65,69,71 since there's i2s data running for an audiocodec.
and i have only the pins from spi2 available to wire up the display.
the spi2 interface is working, i tested it with the kernel module, the display works fine with it. the dev/devspi2.0 is just no comparison to the bcm2835 library when it comes to speed.

so - i'll fiddle around a little more with the nonworking 8bit transfer function. 

best
raffael


On Sunday, September 15, 2019 at 5:49:30 PM UTC+2, Arjan van Vught wrote:
Ok. You are using SPI2 instead of SPI1. The bcm2835_aux_spi_* functions are initially written for SPI1 which can be found on the 40-pins GPIO header. 

http://www.airspayce.com/mikem/bcm2835/group__spi.html#ga0e572ea5cf830964c4c454774d7eca9f —> "Forces RPi AUX SPI pins P1-36 (MOSI), P1-38 (MISO), P1-40 (CLK) and P1-36 (CE2) to alternate function ALT4, which enables those pins for SPI interface.”

The SPI1 can bound on pin’s 57,59,63,65,69 and 71 with CM-3 -> https://www.raspberrypi.org/documentation/hardware/computemodule/datasheets/rpi_DATA_CM_1p0.pdf

Hence there is compatibility with Compute Module 3.

- Arjan
To unsubscribe from this group and stop receiving emails from it, send an email to bcm...@googlegroups.com.

Arjan van Vught

unread,
Sep 15, 2019, 3:24:01 PM9/15/19
to bcm...@googlegroups.com

Op 15 sep. 2019, om 20:53 heeft Seismic Industries <raffael.s...@gmail.com> het volgende geschreven:

i can't use the pins 63,65,69,71 since there's i2s data running for an audiocodec.
and i have only the pins from spi2 available to wire up the display.
the spi2 interface is working, i tested it with the kernel module, the display works fine with it. the dev/devspi2.0 is just no comparison to the bcm2835 library when it comes to speed.

so - i'll fiddle around a little more with the nonworking 8bit transfer function. 
Just look at bcm2835_aux_spi_writenb with len = 1
Maybe you can just use that call will a constant 1,  and the compiler will generate the optimized code for you.

- Arjan




To unsubscribe from this group and stop receiving emails from it, send an email to bcm2835+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bcm2835/bd42aca7-293b-46bf-b0ad-88f28d4d740d%40googlegroups.com.

Seismic Industries

unread,
Sep 16, 2019, 4:43:57 AM9/16/19
to bcm2835
i managed to get the 8bit function to work. it basically did all the time. but it shifted out only zero's. i tapped the the CS line and saw that the duration changed when i was changing the shift length in the CNTL0 register. and also clock signal was present for the according number of bits to shift.


but somewhere there's still something dodgy in that function. cause the display didn't work with it yesterday evening. but maybe it was just to late and i overlooked something obvious. 
i need to have a closer look at the signals that get sent out and compare them to what the /dev/devspi2.0 sends out, since that one's working. 
on the first look the bytes spit out from them looked identically. but i need to retry. 



On Sunday, September 15, 2019 at 9:24:01 PM UTC+2, Arjan van Vught wrote:

Seismic Industries

unread,
Oct 14, 2019, 9:44:34 AM10/14/19
to bcm2835
Hi all - just wanted to follow up on this. 

i managed to get things running. after finding out i troubled things with bit shifting i also missed to check the BCM2835_AUX_SPI_STAT_BUSY flag in the send functions... so nobody was waiting till stuff got sent out completely and buffers were constantly overwritten... 
a friend of mine wrote things up a little more pretty than i did. and he's also more fond of git. so i told him it would be cool to make (i guess) a pull request in the end, so community can benefit from spi2 in the future easily. 
thanks once again for this VERY nice library!

Raffael
Reply all
Reply to author
Forward
0 new messages