How to use SPI1 from port PB instead of PA in Socket #1

Hi Gents :slight_smile:

I have Cerbuino Bee, and I am working fine with SPI1 on Socket #1.

I am about writing code to program a device using the same Microcontroller (STM32F405), and I found out that, this device is interfacing SPI1 with a sensor BUT not to the same pins that I’ve been working with!!

The device interfacing SPI1 using:

BUT the interface that cerbuino bee used for SPI1 via Socket #1 is as following

So how to communicate with SPI1 from the port PB instead of the port PA?
Do I have to modify the code? because I was trying to do loop-back with the same code but with port PB and it didn’t work!!


I am using Gadgeteer App and not Console!!

Here is my piece of code for SPI1:

          // SPI Initialization
          static GT.Socket _socket;
          static GTI.SPI.Configuration _config;
          static GTI.SPI _spi;

            // SPI Config
            _socket = GT.Socket.GetSocket(1, true, null, null);
            _config = new GTI.SPI.Configuration(false, 0, 0, false, true, 1000);
            _spi = new GTI.SPI(_socket, _config, GTI.SPI.Sharing.Exclusive, _socket, GT.Socket.Pin.Five, null);

You should not use gadgeteer on any device is it is not “gadgeteer”. Use plain NETMF please.

Thnx Gus,

I turned to Console application but I still can’t get SPI1 working from PB port!!

Using console, I did loop-back successfully BUT only between the MOSI/MISO in socket#1 which use PA pins!!

And I couldn’t get PB to work although it’s mentioned that it has SPI1 in:

BTW: here is my code:

using System.Threading;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
using System;

namespace ConsoleApplication1
    public class Program
        public static void Main()
            SPI.Configuration MyConfig =
                 new SPI.Configuration(Cpu.Pin.GPIO_Pin1,
                 false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
            SPI MySPI = new SPI(MyConfig);

            byte[] tx_data = new byte[5];
            byte[] rx_data = new byte[5];

            for (int j = 0; j < 5; j++)
                tx_data[j] = (byte)j;

            while (true)

                for (int j = 0; j < 5; j++)

                MySPI.WriteRead(tx_data, rx_data);


What do you mean by “can’t get it working”?
What device are you using?
How is it wired?

@ PetaByte

How are you using the PA5, PA6, and PA7 pins on Socket 1 on Cerbuino Bee? It is only designed with the PB pins. The Cerberus Firmware also is set only for the PB pins.

@ Gus -

Hi Gus, sorry for the confusing “rooody” was the other username on the PC…

  • “can’t get it working”:
    when I connect MOSI(PA7/SPI1_MOSI) to MISO(PA6/SPI1_MISO) the loop back doesn’t work!!

“it works”:
when I connect MOSI(PB5/SPI1_MOSI) to MISO(PB4/SPI1_MISO) the loop back works!!

  • I am using Cerbuino Bee
  • Wiring is by connecting MOSI to MISO by a single wire

@ Aron -

I am only connecting MOSI(PA7/SPI1_MOSI) to MISO(PA6/SPI1_MISO) by a single wire between 2 of these cables:

That means the other SPI ports are not usable!!
Ooops, what to do now since I have a PCB already with a device connected to PA port??

@ PetaByte

The Cerb-Family Firmware only has the PB pins set as the SPI pins. That is the reason why you can get a loop back on PB5 and PB4 and not on PA7 and PA6. The only way for you to get the other pins to serve as SPI pins is to recompile the firmware for a custom firmware. If you need to have the SPI pins not on the socket, the PB SPI pins are exposed on the D rail (pins 11 - PB3 SCK, 12 - PB4 MISO, and 13 - PB5 MOSI).

@ Aron -

I see :frowning:
So that means I have to recompile the firmware for a custom firmware!!
From where should I start and how tough is that?


@ PetaByte

In file C:\MicroFrameworkPK_v4_2\Solutions\FEZCerberus\platform_selector.h:

 #define STM32F4_SPI_SCLK_PINS {19} // PB3
 #define STM32F4_SPI_MISO_PINS {20} // PB4
 #define STM32F4_SPI_MOSI_PINS {21} // PB5

replace with

 #define STM32F4_SPI_SCLK_PINS {5} // PA5
 #define STM32F4_SPI_MISO_PINS {6} // PA6
 #define STM32F4_SPI_MOSI_PINS {7} // PA7

Or you can expose both interfaces:

 #define STM32F4_SPI_SCLK_PINS {5,19} // PA5,PB3
 #define STM32F4_SPI_MISO_PINS {6,20} // PA6,PB4
 #define STM32F4_SPI_MOSI_PINS {7,21} // PA7,PB5


Hi @ slawek,

Wow, it seems that this is exactly what I need, but unfortunately I couldn’t find this file neither in the provided directory nor on the search result :frowning:

I tried also to search for (platform_selector.h, STM32F4_SPI_SCLK_PINS, MicroFrameworkPK_v4_2), but there was no results!!

Do you have installed Porting Kit ?

@ slawek - Porting Kit!! no I didn’t

Even if you have the porting kit installed you will still need to download the firmware files from Codeplex found here:

Tutorial to setup Porting Kit and ARM RVDS compiler.

1st step.

Make sure that msbuiild is properly set. Open command prompt and type msbuild. If you got the message, ‘msbuild’ is not recognized as an internal…, you need to add or change Path for MSBuild in Environment Variables of your system. In my case I added the path:

2nd step.

Download and install Porting Kit 4.2 (RTM QFE2):

Make sure that you dont have installed other versions of Porting Kits.
I would suggest installing Porting Kit into default location as [quote]C:\MicroFrameworkPK_v4_2[/quote]

Just in case if something will go wrong, create backup copies of 2 folders:


Download source code of Cerberus firmware from:
From downloaded zip file copy the folders Solutions to

and DeviceCode to


If some files already existing, just overwrite them.

3rd step

RVDS is pretty expensive software. But you can use for one month full functional trial version.

Go to the and create an account.

After account verification and site authorization, go to the downloads section:
Downloads - Arm Developer → Development Tools → RVDS and download the file RealView Development Suite (RVDS) 4.1 Professional

During installation process, there would be popup message, asking you to select Ethernet interface. Copy somewhere the number of your network interface.

Go to the Downloads - Arm Developer website again, Licensing->Eval Products->Evaluation Products->Development Studio 5 (DS-5)

Provide all information required and select: View license and save license file or text to license.lic file. I don’t know why, but I had the problems when license file with default .dat extension.

4th step.

Just in case, create a copy of setenv_base.cmd file
Go to the, and from attachment download the file
Extract files to C:\MicroFrameworkPK_v4_2\

I know this is not right solution, but that way resolving many problems with PATH variables and files locations.

Create the folders structure:


Copy into C:\MicroFrameworkPK_v4_2\tools\ads_v4_1\license your license.lic file
Copy to C:\MicroFrameworkPK_v4_2\tools\ads_v4_1\BIN all files from C:\Program Files\ARM\RVCT\Programs\4.1\713\win_32-pentium for 32 bits compiler or C:\Program Files\ARM\RVCT\Programs\4.1\713\win_32-x86_64 for 64 bits compiler.

Open in text editor setenv_base.cmd file, and find the line:

On my file its looks: set ARMLMD_LICENSE_FILE=%ARMROOT%\licenses\license.lic

5th step

Open command prompt, change location to C:\MicroFrameworkPK_v4_2 and type: [quote]setenv_base.cmd RVDS4.1[/quote]

Type in command prompt: armcc.exe.

If everything is set right, you should see the message ARM C/C++ compiler… Your license … will expire…

Now you are ready to compile firmware.

Type in command prompt: [quote]msbuild C:\MicroFrameworkPK_v4_2\Solutions\FEZCerberus
dotnetmf.proj /p:flavor=release[/quote]

Make a cup of coffee and wait.

If after compilation you will see warning messages, just ignore them. If you will see errors, redirect msbuild messages to some text file to found out the problems.

In C:\MicroFrameworkPK_v4_2\BuildOutput\THUMB2\RVDS4.1\le\FLASH\release\FEZCerberus\bin\tinyclr.hex folder you will find compiled firmware.

Still I didnt find the way, how to compile the Cerberus firmware with Ethernet support. I hope somebody from the community or GHI will help with that problem.

In C:\MicroFrameworkPK_v4_2\tools\bin\SolutionWizard you can find SolutionWizard.exe application. Not the best software, but you can use it to clone or edit existing solutions. At least to see what is going on inside the project.

Also you can download NETMF source code from and in the folder client_v4_2_comm\tools\bin\PKStudio you will find PKStudio software to manage firmware solutions. Only the problem, I couldnt make to compile under PKStudio. But still worth to look.

Helpful links:'Horizon.pdf?t=1339779332

Great tutorials about debugging NETMF boards on native code level.

Hope my information helps and good luck with compiling :slight_smile:


@ slawek - Good summary!

Excellent explanation, wow !!

But I couldn’t download download and install Porting Kit 4.2 (RTM QFE2):

I will try to fix it as soon as I possible