header file for CCSv6 & PRU

59 views
Skip to first unread message

Hugh Frater

unread,
Aug 14, 2018, 7:29:12 AM8/14/18
to BeagleBoard
Does anyone know the header file I need to include to get access to the i2c2 control registers from within the PRU subsystem? Having a hard time getting any info and my google-foo is usually pretty decent...

Charles Steinkuehler

unread,
Aug 14, 2018, 10:30:01 PM8/14/18
to beagl...@googlegroups.com
AFAIK, there are no "standard" headers for accessing physical hardware
like the i2c buses from the PRU. Even the Linux kernel generally
mixes this sort of thing between header files (for the bit definitions
and "structure" of the control registers) and the device tree (for
base addresses, IRQ values, etc).

Probably the closest you'll find is something from the TI bare-metal code:

http://processors.wiki.ti.com/index.php/StarterWare

--
Charles Steinkuehler
cha...@steinkuehler.net

Hugh Frater

unread,
Aug 15, 2018, 4:43:00 AM8/15/18
to BeagleBoard
Interesting, thanks Charles...

FWIW, I've been working with the eQEP hardware from within the PRU and that also lacks a header file, however, some example TI code (which I am using in my project) shows:

/* Non-CT register defines */
#define CM_PER_EPWMSS1 (*((volatile unsigned int *)0x44E000CC))

Coupled with:

#include <sys_pwmss.h>

As being good enough to allow subsequent access and control of the PWMSS from within the PRU... I have added a #define for the base address of I2C2 but I now need to find if there is a header file to go with. I'll do some searching.

Hugh Frater

unread,
Aug 17, 2018, 10:41:55 AM8/17/18
to BeagleBoard
An update:

1. Enable the i2c peripheral clock: 

#define CM_PER_I2C2 (*((volatile unsigned int *)0x44E00044))

/* Enable I2C2 clock signal generation */
while (!(CM_PER_I2C2 & 0x2))
     CM_PER_I2C2 |= 0x2;

2. Setup the registers:

    /*
     *  set I2C2_PSC register to 0x0B
     *  set I2C2_SCCL register to 0x0D
     *  set I2C2_SCCH register to 0x0F
     *  set I2C2_CON register to 1000 0110 0000 0000 (0x8600)
     *  set I2C2_SA register to 0x2E (address of MCP4641)
     *  set I2C2_CNT register to 2 (data length)
     */

    I2C2_PSC = 0x000B;
    I2C2_SCLL = 0x000D;
    I2C2_SCLH = 0x000F;
    I2C2_CON = 0x8600;
    I2C2_SA = i2cPotAddress;
    I2C2_CNT = 2;

3. You can now program the device:

/*
*  poll 'busy bit' in I2C2_STATUSRAW register (bit 12) until it is zero
*  set start/stop bits in I2C2_CON register to initiate a transfer
*  poll XRDY bit in I2C2_STATUSRAW register (bit 4) until it is non-zero
*  load 1st byte of data into I2C2_DATA register
*  poll XRDY bit in I2C2_STATUSRAW register (bit 4) until it is non-zero
*  load 2nd byte of data into I2C2_DATA register
*/

while (I2C2_STATUSRAW & 0x1000);
   //poll 'busy bit' in I2C2_STATUSRAW register (bit 12) until it is zero
I2C2_CON = 0x8603;
while (!I2C2_STATUSRAW & 0x0010);
   //poll XRDY bit in I2C2_STATUSRAW register (bit 4) until it is non-zero
I2C2_DATA = torqueWiper;
while (!I2C2_STATUSRAW & 0x0010);
   //poll XRDY bit in I2C2_STATUSRAW register (bit 4) until it is non-zero
I2C2_DATA = 0x55;

4. The kernel mode (and bonescript) i2c drivers will put the device to sleep and disable the clock after every transfer, so to access it from the PRU you need to setup the registers each time you want to access a device on the bus. 

Hope that helps someone...

Hugh Frater

unread,
Aug 17, 2018, 10:43:47 AM8/17/18
to BeagleBoard
I forgot this from my previous post:

/* I2C2 register offsets */

#define I2C2_STATUSRAW (*((volatile unsigned int*)0x4819C024))
#define I2C2_CNT (*((volatile unsigned int*)0x4819C098))
#define I2C2_SA (*((volatile unsigned int*)0x4819C0AC))
#define I2C2_DATA (*((volatile unsigned int*)0x4819C09C))
#define I2C2_CON (*((volatile unsigned int*)0x4819C0A4))
#define I2C2_SCLL (*((volatile unsigned int*)0x4819C0B4))
#define I2C2_SCLH (*((volatile unsigned int*)0x4819C0B8))
#define I2C2_PSC (*((volatile unsigned int*)0x4819C0B0))

I couldn't be bothered to setup a header file for this lot, so just stuffed it in the top of my PRU code... Registers for other I2C modules are in the memory map from the am335X_trm

On Tuesday, 14 August 2018 12:29:12 UTC+1, Hugh Frater wrote:

Gaurav S

unread,
Aug 21, 2018, 7:44:01 AM8/21/18
to BeagleBoard
Hugh,
Thanks for sharing your research.
Any chance you could also include a reference (ie where did you find this info)?

Thanks

Hugh Frater

unread,
Aug 21, 2018, 9:26:31 AM8/21/18
to BeagleBoard
Hi, I found all the required information in the AM335x TRM pdf file. You need to offsets for the I2C module you are using and the base address from the memory map.

The programming sequence is all detailed in there under the I2C section.
Reply all
Reply to author
Forward
0 new messages