This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PROCESSOR-SDK-AM335X: McSPI basic example issue

Part Number: PROCESSOR-SDK-AM335X


Hello.

I am looking for help attempting to get the BBB to communicate through the SPI bus to a simple SPI slave. I've already done this as  "proof" using a TIVAC board.

So, in the AM335x world, starting with the example project:
MCSPI_BasicExample_icev2AM335x_armExampleProject
Which does compile and run.  It's not actually talking to the device I'm using... but that's the LEAST of the problems.

(set aside that fact that this example doesn't tell me which pins are being used for MISO or MOSI (SPI0_d0 or SPI0_d1)... Nor can I find anything in and doc to explain that... I can try to decipher that one later...)

So I created a separate test program. I had to drag in a bunch of UART stuff, and GPIO stuff, which is completely unexplained, just to get the linker to resolve everything. 

And my test program is crashing on:

spi = SPI_open(0,&spiParams);

So I am comparing it to 

MCSPI_BasicExample_icev2AM335x_armExampleProject

First...
The documentation says this about the "SPI_init()" call

"The SPI_config structure must exist and be persistent before this
* function can be called."

The example project doesn't have that structure defined ANYWHERE.

I looked through the MAP file, and it appears to be being imported from this:

.rodata.SPI_config
     0x800121a0 0x54 C:\ti\pdk_am335x_1_0_7\packages\ti\drv\spi\lib\am335x\a8\release\ti.drv.spi.aa8fg(SPI_soc.oa8fg)
     0x800121a0 SPI_config

What purpose does this identifier serve anyway?

The documentation simply provides the completely useless statement:

* The SPI_Config structure contains a set of pointers used to characterize
* the SPI driver implementation.
*
* This structure needs to be defined before calling SPI_init() and it must
* not be changed thereafter.

Not much value there. Actually pretty close to NULL...

Next step... Since the structure is in the MAP file of the example program, this identifier is being generated by SOMETHING... Maybe the CFG?
The demo project has this in the CFG file

/* Load the spi package */
var Spi = xdc.loadPackage('ti.drv.spi');
Spi.Settings.socType = socType;

And so does my test project.   And there is no other reference to that JAVA object "Spi"  anywhere in the example CFG file. 

And yet my test project DOESN'T have that identifier in it.

Given two IDENTICAL pieces of CFG code, and one project has a SPI_config identifier, while the other doesn't, should mean that the CFG is NOT be the source of the identifier.

So what IS the source of this identifier ??

On the other hand... maybe the identifier isn't even the reason my test program is crashing. The complete lack of documentation, support, or useful examples leaves me totally lost.

Then other questions I haven't even been able to get to: How are SPIx_d0 and SPIx_D1 mapped to MISO amd MOSI? Where is that controlled?
What is the behavior and timing of SPIx_CS0? Can the active level be set (active_hi or active_low)?

Where is ANY of this actually documented?  I must say, the TIVAC dos was a breeze!

If anyone would be willing to assist, it would be appreciated.  My "test" project is attached.

BiosHWI.zip

  • Hi Christopher,

    The purpose of SPI_config is briefly touched on here:

    The SPI_config[] array definition is contained in the file <PDK>\packages\ti\drv\spi\soc\am335x\SPI_soc.c. The object file for SPI_soc.c should be included in the SPI library build, e.g. 

    • <PDK>\packages\ti\drv\spi\lib\am335x\a8\release\ti.drv.spi.aa8fg
    • <PDK>\packages\ti\drv\spi\lib\am335x\a8\release\ti.drv.spi.dma.aa8fg

    Concerning your questions concerning SPI configuration (SPIx_D0/D1 as MOSI/MISO, SPIx_CS0 timing, CS polarity, etc.):

    • Please use the SPI_socGetInitCfg()/SPI_socSetInitCfg() API functions for SPI configuration.
    • The default configuration for each SPI is contained SPI_soc.c, spiInitCfg[] (where spiInitCfg[] is the hwAttrs member of a SPI_Config structure). Essentially these functions allow the application to change the SPI configuration by updating the entries in the spiInitCfg[] associated with a particular SPI.
    • The SPI examples/tests contain calls to SPI_socGetInitCfg()/SPI_socSetInitCfg() to configure the SPI (e.g. see MCSPI slavemode example application).

    I agree this isn't very well documented.

    Regards,
    Frank

  • Frank,

    I've got two, concurrent projects. 

    1. MCSPI_BasicExample_icev2AM335x_armExampleProject  from my examples in the PDK, which I've managed to modify the code to talk to a simple SPI chip.
    2. My project I attached in my original post. Which does set the params using SPI_Params_init(...) EXACTLY THE SAME as project #1

    Project #1 runs and talks to the chip I wired it to.

    Project #2 runs up until it gets to SPI_transfer(spi,&trans); then crashes.  It has nothing to do with setting the params as far as I can tell.  Especially since what it does up to that point is IDENTICAL to project #1 that doesn't crash.

    (There is no simple SPI example for the AM335x (or BeagleBone) in any examples I can find.)

    I tried to add SPI_socGetInitCfg(...);   But it's "implict" so I have no idea what header it's declared in.  And don't get me started on "Doxygen".  It does link, so at least I know it's in some library that is being imported.

    There is no "SPI_soc.c" file anywhere in either project.  I would imagine it's contents are similar to the blink project (GPIO_v1_Config).  Which isn't documented anywhere I can find... So why does the first one even work?

    So I continue to spin and get annoyed at this eco-system...

  • Chris,

    >> (There is no simple SPI example for the AM335x (or BeagleBone) in any examples I can find.)

    You're correct, I also don't see any simple SPI examples for BBB.

    >> I tried to add SPI_socGetInitCfg(...);   But it's "implict" so I have no idea what header it's declared in.

    The information is defined in <PDK>\packages\ti\drv\spi\soc\SPI_v1.h. I found this as follows in Git bash on Windows:

    $ cd <PDK>/packages/ti/drv/spi
    $ grep -rI -n -i --regexp="SPI_v1_HWAttrs" --include "*.h"
    soc/SPI_v1.h:210:} SPI_v1_HWAttrs;

    >> And don't get me started on "Doxygen".

    I couldn't find this information in Doxygen.

    >> So I continue to spin and get annoyed at this eco-system...

    Thanks much for your feedback.

    I don't have an additional information to provide concerning this topic.

    Regards,
    Frank

  • Frank,

    Thanks...

    On my other thread, I provided my own answer.  As to why my project on this thread was crashing, it was likely because the module/clocks were not enabled.  But I'm not sure, as I just pulled in SOURCE from the libraries, reverse engineered them, and used the raw function calls.

    https://e2e.ti.com/support/processors/f/791/p/872224/3228079#3228079

    What really annoys me is how these examples not portable, and these libraries are incestuous. 

    1.  Everyone says start with an example, and build on it....  But if you have an example of SPI, and an example of I2C....  Just try to combine them.  No clue 

    2.  In the SPI example, you HAVE to incorporate the board and GPIO package.  Which them means you HAVE to incorporate the UART stuff...  Which then means you HAVE to incorporate the other libs...

    I wrote once, over a year ago, that the NDK documentation is excellent.  These days, no such quality documentation and explanations exist.  Maybe, someone at TI will hear these, realize it, and do something about it.

    Thanks again.

    https://e2e.ti.com/support/processors/f/791/p/872224/3228079#3228079