Main Site Documentation

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


#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:
(PA5/SPI1_SCK, PA6/SPI1_MISO, PA7/SPI1_MOSI)

BUT the interface that cerbuino bee used for SPI1 via Socket #1 is as following
(PB3/SPI1_SCK, PB4/SPI1_MISO, PB5/SPI1_MOSI)

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!!

Regards…


#2

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);


#3

You should not use gadgeteer on any device is it is not “gadgeteer”. Use plain NETMF please. http://www.ghielectronics.com/docs/14/spi


#4

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!!
(PA6/SPI1_MISO, PA7/SPI1_MOSI)

And I couldn’t get PB to work although it’s mentioned that it has SPI1 in:
(PB4/SPI1_MISO, PB5/SPI1_MOSI)

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++)
                {
                    Debug.Print(rx_data[j].ToString());
                }

                MySPI.WriteRead(tx_data, rx_data);

                Thread.Sleep(1000);
            }        
}
    }
}



#5

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


#6

@ 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.


#7

@ 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

#8

@ Aron -

I am only connecting MOSI(PA7/SPI1_MOSI) to MISO(PA6/SPI1_MISO) by a single wire between 2 of these cables:
https://www.ghielectronics.com/catalog/product/279

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??


#9

@ 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).


#10

@ 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?

Regards…


#11

@ 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

Regards.


#12

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!!


#13

Do you have installed Porting Kit ?


#14

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


#15

Even if you have the porting kit installed you will still need to download the firmware files from Codeplex found here: http://ghiopensource.codeplex.com/


#16

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:

and

Download source code of Cerberus firmware from:
http://ghiopensource.codeplex.com/
From downloaded zip file copy the folders Solutions to

and DeviceCode to

[quote]C:\MicroFrameworkPK_v4_2\DeviceCode[/quote].

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 http://www.arm.com/ and create an account.

After account verification and site authorization, go to the downloads section:
https://silver.arm.com/browse -> 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 https://silver.arm.com/browse 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 http://netmf.codeplex.com/workitem/777, and from attachment download the file RVDS_v4_1.zip
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:

[quote]C:\MicroFrameworkPK_v4_2\tools\ads_v4_1
C:\MicroFrameworkPK_v4_2\tools\ads_v4_1\BIN
C:\MicroFrameworkPK_v4_2\tools\ads_v4_1\licenses[/quote]

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 http://netmf.codeplex.com 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:

http://www.ghielectronics.com/downloads/FEZ/Beginners%20Guide%20to%20Porting%20NETMF.pdf
http://www.netmf.com/working-with-the-net-mf-porting-kit-v41.aspx



Great tutorials about debugging NETMF boards on native code level.

http://www.tinyclr.it/journey-under-the-hood-of-net-micro-framework.aspx
http://www.tinyclr.it/a-new-journey-under-the-hood-of-net-micro-framework-let’s-dig-deep-into-interrupts-management.aspx

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


#17

@ slawek - Good summary!


#18

Excellent explanation, wow !!

But I couldn’t download download and install Porting Kit 4.2 (RTM QFE2):
http://netmf.codeplex.com/downloads/get/470706

I will try to fix it as soon as I possible