Skip to content

Commit 74bc3ba

Browse files
committed
Adding LP-MSPM0G3519 code examples for I2C.
1 parent 6256974 commit 74bc3ba

12 files changed

+899
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2024, Texas Instruments Incorporated
3+
* All rights reserved.
4+
*
5+
* TODO: Add license
6+
*/
7+
/*!****************************************************************************
8+
* @file Driver_Config_MSP.h
9+
* @brief CMSIS-Drivers board configuration file for Texas Instruments
10+
* MSP MCUs based on Arm Cortex-M CPUs
11+
*
12+
* This configuration file must be tailored for each board port.
13+
*
14+
* <hr>
15+
******************************************************************************
16+
*/
17+
18+
#ifndef DRIVER_CONFIG_MSP_H_
19+
#define DRIVER_CONFIG_MSP_H_
20+
21+
#ifdef __cplusplus
22+
extern "C"
23+
{
24+
#endif
25+
26+
#include <ti/devices/msp/msp.h>
27+
#include <Driver_I2C_MSP.h>
28+
29+
/* I2C Driver Configuration Options */
30+
31+
/* Driver_I2C0 Configuration (Maps to MSP hardware I2C0 peripheral) */
32+
#define DRIVER_CONFIG_HAS_I2C0 (1)
33+
#if (DRIVER_CONFIG_HAS_I2C0==1) && defined(I2C0_BASE)
34+
#define DRIVER_I2C0_SDA_PINCM (IOMUX_PINCM1)
35+
#define DRIVER_I2C0_SDA_PF (IOMUX_PINCM1)
36+
#define DRIVER_I2C0_SCL_PINCM (IOMUX_PINCM2)
37+
#define DRIVER_I2C0_SCL_PF (IOMUX_PINCM2_PF_I2C0_SCL)
38+
#define DRIVER_I2C0_CLOCK_SEL (DRIVER_CLK_MSP_BUSCLK)
39+
#define DRIVER_I2C0_CLOCK_FREQ (32000000U)
40+
#define DRIVER_I2C0_TRANSMIT_DMA_HW (DMA)
41+
#define DRIVER_I2C0_TRANSMIT_DMA_CH (0U)
42+
#define DRIVER_I2C0_TRANSMIT_DMA_TRIG (DMA_I2C0_TX_TRIG)
43+
#define DRIVER_I2C0_RECEIVE_DMA_HW (DMA)
44+
#define DRIVER_I2C0_RECEIVE_DMA_CH (1U)
45+
#define DRIVER_I2C0_RECEIVE_DMA_TRIG (DMA_I2C0_RX_TRIG)
46+
#endif
47+
48+
/* Driver_I2C1 Configuration (Maps to MSP hardware I2C1 peripheral) */
49+
#define DRIVER_CONFIG_HAS_I2C1 (1)
50+
#if (DRIVER_CONFIG_HAS_I2C1==1) && defined(I2C1_BASE)
51+
#define DRIVER_I2C1_SDA_PINCM (IOMUX_PINCM16)
52+
#define DRIVER_I2C1_SDA_PF (IOMUX_PINCM16_PF_I2C1_SDA)
53+
#define DRIVER_I2C1_SCL_PINCM (IOMUX_PINCM15)
54+
#define DRIVER_I2C1_SCL_PF (IOMUX_PINCM15_PF_I2C1_SCL)
55+
#define DRIVER_I2C1_CLOCK_SEL (DRIVER_CLK_MSP_BUSCLK)
56+
#define DRIVER_I2C1_CLOCK_FREQ (32000000U)
57+
#define DRIVER_I2C1_TRANSMIT_DMA_HW (DMA)
58+
#define DRIVER_I2C1_TRANSMIT_DMA_CH (2U)
59+
#define DRIVER_I2C1_TRANSMIT_DMA_TRIG (DMA_I2C1_TX_TRIG)
60+
#define DRIVER_I2C1_RECEIVE_DMA_HW (DMA)
61+
#define DRIVER_I2C1_RECEIVE_DMA_CH (3U)
62+
#define DRIVER_I2C1_RECEIVE_DMA_TRIG (DMA_I2C1_RX_TRIG)
63+
#endif
64+
65+
/* Driver_I2C2 Configuration (Maps to MSP hardware I2C2 peripheral) */
66+
#define DRIVER_CONFIG_HAS_I2C2 (0)
67+
#if (DRIVER_CONFIG_HAS_I2C2==1) && defined(I2C2_BASE)
68+
#define DRIVER_I2C2_SDA_PINCM (IOMUX_PINCM38)
69+
#define DRIVER_I2C2_SDA_PF (IOMUX_PINCM38_PF_I2C2_SDA)
70+
#define DRIVER_I2C2_SCL_PINCM (IOMUX_PINCM37)
71+
#define DRIVER_I2C2_SCL_PF (IOMUX_PINCM37_PF_I2C2_SCL)
72+
#define DRIVER_I2C2_CLOCK_FREQ (32000000U)
73+
#define DRIVER_I2C2_TRANSMIT_DMA_HW (DRIVER_DMA_HW_NONE)
74+
#define DRIVER_I2C2_TRANSMIT_DMA_CH (DRIVER_DMA_CH_NONE)
75+
#define DRIVER_I2C2_TRANSMIT_DMA_TRIG (DRIVER_DMA_TRIG_NONE)
76+
#define DRIVER_I2C2_RECEIVE_DMA_HW (DRIVER_DMA_HW_NONE)
77+
#define DRIVER_I2C2_RECEIVE_DMA_CH (DRIVER_DMA_CH_NONE)
78+
#define DRIVER_I2C2_RECEIVE_DMA_TRIG (DRIVER_DMA_TRIG_NONE)
79+
#endif
80+
81+
#ifdef __cplusplus
82+
}
83+
#endif
84+
85+
#endif /* DRIVER_CONFIG_MSP_H_ */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Example Summary
2+
3+
This is an example project for the CMSIS-Driver I2C module.
4+
The example uses the I2C0 and I2C1 device peripherals for communication, which present as Driver_I2C0 and Driver_I2C1 respectively in the CMSIS-Driver I2C module.
5+
The project uses SysConfig for initialization, but all functionality related to the CMSIS-Driver I2C module is handled by the CMSIS-Driver itself. All transmissions
6+
are done using the DMA. The LP-MSPM0G3519 LaunchPad configuration must be set with J21 and J22 to connect PA10 and PA11 to the boosterpack directly. Connect PA0 and PA10 with a jumper wire. Connected PA1 and P11 with a jumper wire. External resistors are needed and should be connected to PA0 and PA1, or PA10 and PA11. The on-board pull up resistors can be used by populating J16 and J17.
7+
8+
This example uses on-board LEDs to demonstrate succesfully transmission between target and controller. When the controller transmits data to the target, the BLUE led
9+
is turned on. When the target transmit data to the controller, the RED led is turned on.
10+
11+
## Peripherals, Pin Functions, MCU Pins, Launchpad Pins
12+
| Peripheral | Function | Pin | Launchpad Pin |
13+
| --- | --- | --- | --- |
14+
| BOARD | Debug Clock | PA20 | J19_16 |
15+
| BOARD | Debug Data In Out | PA19 | J19_14 |
16+
| I2C0 | I2C0_SDA | PA0 |
17+
| I2C0 | I2C0_SCL | PA1 |
18+
| I2C1 | I2C1_SCL | PA11 |
19+
| I2C1 | I2C1_SDA | PA10 |
20+
| GPIOB | USER_LED_1 | PB22 |
21+
| GPIOB | USER_LED_2 | PB26 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
* Copyright (c) 2021, Texas Instruments Incorporated
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of Texas Instruments Incorporated nor the names of
17+
* its contributors may be used to endorse or promote products derived
18+
* from this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27+
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29+
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
#include "ti_msp_dl_config.h"
34+
#include "Driver_I2C_MSP.h"
35+
36+
/**
37+
* @brief Transaction length size in bytes
38+
*/
39+
#define TRANSACTION_LEN_SZ (4U)
40+
41+
/**
42+
* @brief Master transmit complete flag
43+
*/
44+
static volatile bool mTransmit;
45+
46+
/**
47+
* @brief Master transaction complete flag
48+
*/
49+
static volatile bool mDone;
50+
51+
/**
52+
* @brief Slave transaction complete flag
53+
*/
54+
static volatile bool sDone;
55+
56+
/**
57+
* @brief Master receive buffer
58+
*/
59+
static uint8_t mBuf[TRANSACTION_LEN_SZ];
60+
61+
/**
62+
* @brief Master transmit buffer
63+
*/
64+
static uint8_t sBuf[TRANSACTION_LEN_SZ];
65+
66+
/**
67+
* @brief Callback handler for master I2C instance
68+
*/
69+
static void i2c0_cb(uint32_t event);
70+
71+
/**
72+
* @brief Callback handler for slave I2C instance
73+
*/
74+
static void i2c1_cb(uint32_t event);
75+
76+
/* This results in approximately 1s of delay assuming 32MHz CPU_CLK */
77+
#define DELAY (32000000)
78+
79+
#define TARGET_ADDRESS (0x11)
80+
81+
int main(void)
82+
{
83+
ARM_DRIVER_I2C *i2c0 = &Driver_I2C0;
84+
ARM_DRIVER_I2C *i2c1 = &Driver_I2C1;
85+
86+
/* Execute SysConfig generated initialization routine */
87+
SYSCFG_DL_init();
88+
DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN | GPIO_LEDS_USER_LED_2_PIN);
89+
90+
/* Configure i2c0 */
91+
i2c0->Initialize(&i2c0_cb);
92+
i2c0->PowerControl(ARM_POWER_FULL);
93+
i2c0->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
94+
95+
/* Configure i2c1 */
96+
i2c1->Initialize(&i2c1_cb);
97+
i2c1->PowerControl(ARM_POWER_FULL);
98+
i2c1->Control(ARM_I2C_OWN_ADDRESS, TARGET_ADDRESS);
99+
i2c1->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
100+
101+
/* Fill buffer with data */
102+
for(uint32_t i = 0U; i < TRANSACTION_LEN_SZ; i++)
103+
{
104+
mBuf[i] = i + 1;
105+
}
106+
107+
/* Start the first transaction with a master transmit */
108+
mTransmit = true;
109+
110+
/* Loop and send data in both directions continously */
111+
while (1)
112+
{
113+
mDone = false;
114+
sDone = false;
115+
116+
if(mTransmit)
117+
{
118+
i2c1->SlaveReceive(&sBuf[0], TRANSACTION_LEN_SZ);
119+
i2c0->MasterTransmit(TARGET_ADDRESS, &mBuf[0], TRANSACTION_LEN_SZ, false);
120+
}
121+
else
122+
{
123+
i2c1->SlaveTransmit(&sBuf[0], TRANSACTION_LEN_SZ);
124+
i2c0->MasterReceive(TARGET_ADDRESS, &mBuf[0], TRANSACTION_LEN_SZ, false);
125+
}
126+
127+
while(mDone == false && sDone == false);
128+
129+
if(mTransmit)
130+
{
131+
DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
132+
DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_2_PIN);
133+
}
134+
else
135+
{
136+
DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_2_PIN);
137+
DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
138+
}
139+
/* Alternate which side is transmitting */
140+
mTransmit = !mTransmit;
141+
delay_cycles(DELAY);
142+
}
143+
}
144+
145+
static void i2c0_cb(uint32_t event)
146+
{
147+
148+
if (event & ARM_I2C_EVENT_TRANSFER_DONE)
149+
{
150+
mDone = true;
151+
}
152+
else
153+
{
154+
155+
}
156+
return;
157+
}
158+
159+
static void i2c1_cb(uint32_t event)
160+
{
161+
if (event & ARM_I2C_EVENT_TRANSFER_DONE)
162+
{
163+
sDone = true;
164+
}
165+
else
166+
{
167+
168+
}
169+
return;
170+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* These arguments were used when this file was generated. They will be automatically applied on subsequent loads
3+
* via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
4+
*/
5+
//@cliArgs --device "MSPM0G351X" --package "LQFP-100(PZ)" --part "Default"
6+
//@v2CliArgs --device "MSPM0G3519" --package "LQFP-100(PZ)"
7+
// @cliArgs --board /ti/boards/LP_MSPM0G3519 --rtos nortos
8+
9+
/**
10+
* Import the modules used in this configuration.
11+
*/
12+
const GPIO = scripting.addModule("/ti/driverlib/GPIO", {}, false);
13+
const GPIO1 = GPIO.addInstance();
14+
const SYSCTL = scripting.addModule("/ti/driverlib/SYSCTL");
15+
16+
/**
17+
* Write custom configuration values to the imported modules.
18+
*/
19+
GPIO1.$name = "GPIO_LEDS";
20+
GPIO1.port = "PORTB";
21+
GPIO1.associatedPins.create(2);
22+
GPIO1.associatedPins[0].$name = "USER_LED_1";
23+
GPIO1.associatedPins[0].assignedPin = "22";
24+
GPIO1.associatedPins[1].$name = "USER_LED_2";
25+
GPIO1.associatedPins[1].assignedPin = "26";
26+
27+
const Board = scripting.addModule("/ti/driverlib/Board", {}, false);
28+
29+
SYSCTL.forceDefaultClkConfig = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectSpec>
3+
<applicability>
4+
<when>
5+
<context
6+
deviceFamily="ARM"
7+
deviceId="MSPM0G3519"
8+
/>
9+
</when>
10+
</applicability>
11+
12+
<project
13+
title="cmsis-driver-i2c-transmit-receive-dma"
14+
name="cmsis-driver-i2c-transmit-receive-dma_LP_MSPM0G3519_nortos_ticlang"
15+
configurations="Debug"
16+
toolChain="TICLANG"
17+
connection="TIXDS110_Connection.xml"
18+
device="MSPM0G3519"
19+
ignoreDefaultDeviceSettings="true"
20+
ignoreDefaultCCSSettings="true"
21+
products="MSPM0-SDK;sysconfig"
22+
compilerBuildOptions="
23+
-I${PROJECT_ROOT}
24+
-I${PROJECT_ROOT}/${ConfigName}
25+
-O2
26+
@device.opt
27+
-I${COM_TI_MSPM0_SDK_INSTALL_DIR}/source/third_party/CMSIS/Core/Include
28+
-I${COM_TI_MSPM0_SDK_INSTALL_DIR}/source
29+
-I${PROJECT_ROOT}/msp-cmsis-driver
30+
-I${PROJECT_ROOT}/msp-cmsis-driver/CMSIS/Drivers
31+
-I${PROJECT_ROOT}/msp-cmsis-driver/Drivers/V0
32+
-I${PROJECT_ROOT}/msp-cmsis-driver/Drivers_Interface
33+
-gdwarf-3
34+
-mcpu=cortex-m0plus
35+
-march=thumbv6m
36+
-mfloat-abi=soft
37+
-mthumb
38+
"
39+
linkerBuildOptions="
40+
-ldevice.cmd.genlibs
41+
-L${COM_TI_MSPM0_SDK_INSTALL_DIR}/source
42+
-L${PROJECT_ROOT}
43+
-L${PROJECT_BUILD_DIR}/syscfg
44+
-Wl,--rom_model
45+
-Wl,--warn_sections
46+
-L${CG_TOOL_ROOT}/lib
47+
-llibc.a
48+
"
49+
sysConfigBuildOptions="
50+
--output .
51+
--product ${COM_TI_MSPM0_SDK_INSTALL_DIR}/.metadata/product.json
52+
--compiler ticlang
53+
"
54+
sourceLookupPath="${COM_TI_MSPM0_SDK_INSTALL_DIR}/source/ti/driverlib"
55+
description="I2C transmit and receive with DMA example to demonstrate the CMSIS-Driver I2C module">
56+
57+
<property name="buildProfile" value="release"/>
58+
<property name="isHybrid" value="true"/>
59+
<file path="../cmsis-driver-i2c-transmit-receive-dma.c" openOnCreation="true" excludeFromBuild="false" action="copy"></file>
60+
<file path="../Driver_Config_MSP.h" openOnCreation="false" excludeFromBuild="false" action="copy"></file>
61+
<file path="../../../../../../source/CMSIS" targetDirectory="./msp-cmsis-driver" excludeFromBuild="false" action="copy" />
62+
<file path="../../../../../../source/Drivers" targetDirectory="./msp-cmsis-driver" excludeFromBuild="false" action="copy" />
63+
<file path="../../../../../../source/Drivers_Interface" targetDirectory="./msp-cmsis-driver" excludeFromBuild="false" action="copy" />
64+
<file path="../cmsis-driver-i2c-transmit-receive-dma.syscfg" openOnCreation="false" excludeFromBuild="false" action="copy"></file>
65+
<file path="../README.md" openOnCreation="true" excludeFromBuild="false" action="copy"></file>
66+
</project>
67+
</projectSpec>

0 commit comments

Comments
 (0)