You are on page 1of 32

By Informa Markets

STM32MP1 Primer
DAY 2 : Swinging Around in the STM32MP1 Device Tree

Sponsored by
Sponsored By

Webinar Logistics

• Turn on your system sound to hear the streaming presentation.


• If you have technical problems, click “Help” or submit a question
asking for assistance.
• Participate in ‘Attendee Chat’ by maximizing the chat widget in your
dock.

2
Sponsored By

Fred Eady
Visit ‘Lecturer Profile’ in your console for more details.

3
STM32MP1 Primer

Sponsored By

AGENDA
 STM32MP157x Raspberry Pi 4B Interface
 Linux-Based STM32MP157D Accel 6 click Project
 STM32MP157x click Arduino Expansion
 Linux-Based STM32MP157F Accel 6 click Project

4
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Sponsored By

STM32MP157x Raspberry Pi 4B Interface

5
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Sponsored By

STM32MP157x Raspberry Pi 4B Interface

6
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Sponsored By

STM32MP157x Raspberry Pi 4B Interface

7
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Sponsored By

Linux-Based STM32MP157D Accel 6 click Project

8
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

Assign I2C5 to the Cortex-A7 and Configure the I2C5 GPIO

9
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

Assign I2C5 to the Cortex-A7 and Configure the I2C5 GPIO

10
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

Assign I2C5 to the Cortex-A7 and Configure the I2C5 GPIO

11
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

I2C5 Device Tree Generation

Copy Device Tree source file to dts directory

12
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

I2C5 Device Tree Generation

Add this entry

13
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

I2C5 Device Tree Generation

&pinctrl{
~~~~~~~~~~~~
i2c5_pins_mx: i2c5_mx-0 {
.dts
pins {
pinmux = <STM32_PINMUX('A', 11, AF4)>, /* I2C5_SCL */
<STM32_PINMUX('A', 12, AF4)>; /* I2C5_SDA */
bias-disable;
drive-open-drain;
slew-rate = <0>;
Device Tree
};
Compiler
};

i2c5_sleep_pins_mx: i2c5_sleep_mx-0 {
pins {
pinmux = <STM32_PINMUX('A', 11, ANALOG)>, /* I2C5_SCL */
<STM32_PINMUX('A', 12, ANALOG)>; /* I2C5_SDA */
.dtb
};
};
14
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

I2C5 Device Tree Generation


&pinctrl_z{
~~~~~~~~~~
&i2c5{
pinctrl-names = "default", "sleep";
pinctrl-0 = <&i2c5_pins_mx>;
pinctrl-1 = <&i2c5_sleep_pins_mx>;
status = "okay";

/* USER CODE BEGIN i2c5 */


/* USER CODE END i2c5 */
};

15
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

I2C5 Device Tree Generation

Create/modify .dts file (stm32mp157d-accel6_157d-mx.dts)


Copy .dts file to dts directory
Manually enter associated .dtb filename in /dts/Makefile (stm32mp157d-accel6_157d-mx.dtb)

Setup compilation environment (use built-in shell command source)


Compile .dts file (run make dtbs)

Rename and copy resultant .dtb file to STM32MP1 target (/boot/stm32mp157d-dk1.dtb)

16
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

Open I2C5 Peripheral

//*******************************************
//* OPEN I2C PORTAL to ACCEL6 CLICK
//*******************************************
void init(void)
{
sprintf(filename,"/dev/i2c-1");
accel6_click = open(filename,O_RDWR);
if(accel6_click < 0)
{
puts("open accel6_click failed\r\n");
exit(1);
}
puts("accel6_click sensor opened\r\n");
if(ioctl(accel6_click,I2C_SLAVE,0x18) < 0)
{
puts("failed to register slave address\r\n");
exit(1);
}
puts("slave address accepted\r\n");
char buf[1] = {0x00};
if(write(accel6_click,buf,1)!=1)
{
puts("initial addr write failed\r\n");
}
17
}
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157D Accel 6 click Project Sponsored By

Accel 6 click m ain Function

int main (void)


{
int i;
init();

while(1)
{
msleep(1000);
getAccelData();
accelerationX = parseAccelData(ACC_X_MSB, ACC_X_LSB);
accelerationY = parseAccelData(ACC_Y_MSB, ACC_Y_LSB);
accelerationZ = parseAccelData(ACC_Z_MSB, ACC_Z_LSB);
calculatePitchRoll();

for(i=0;i<9;i++)
{
printf("%02X ",i2cRxPkt[i]);
}
printf("\r\n");
temperatureC = (float) (((int8_t)i2cRxPkt[TEMP_RAW]) * 0.5 + 23);
printf("%03.2f C\r\n",temperatureC);
printf("Pitch = %3.2f degrees\r\n",pitch);
printf("Roll = %3.2f degrees\r\n",roll);
}
}

18
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Sponsored By

STM32MP157x click Arduino Expansion

19
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Sponsored By

STM32MP157x click Arduino Expansion

20
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Sponsored By

STM32MP157x click Arduino Expansion

21
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Sponsored By

STM32MP157x click Arduino Expansion

22
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157F Accel 6 click Project Sponsored By

Assign and Configure the I2C5 Peripheral

23
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157F Accel 6 click Project Sponsored By

Configure I2C5 GPIO

24
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157F Accel 6 click Project Sponsored By

Generate Device Tree Source (.dts) File and Copy it to the dts Directory

Copy Device Tree source file to dts directory

25
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157F Accel 6 click Project Sponsored By

Manually Add Device Tree Blob File (.dtb) Entry to Device Tree Blob Makefile

Add this entry

26
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157F Accel 6 click Project Sponsored By

Setup the OpenSTLinux Compilation Environment

27
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157F Accel 6 click Project Sponsored By

Replace Current stm 32m p157f-dk2.dtb File with Newly Compiled stm 32m p157f-accel6-157f-m x .dtb File

28
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157F Accel 6 click Project Sponsored By

GTK Setup

//**************************************
//* GLOBAL GTK WIDGETS
//**************************************
GtkWidget*windowAccel;
GtkWidget*gridAccelFixed1;
GtkWidget*lblAccelPitch;
GtkWidget*lblAccelRoll;
GtkWidget*lblAccelTemp;
GtkWidget*timer;
GtkBuilder*builder;
gboolean accelTimer_handler(GtkWidget *);

gtk_init(&argc, &argv); // init Gtk


//****************************************************************************
//* REFERENCE XML CODE ASSOCIATED WITH WIDGETS
//****************************************************************************
builder = gtk_builder_new_from_file ("accelglade.glade");
windowAccel = GTK_WIDGET(gtk_builder_get_object(builder, "windowAccel"));
g_signal_connect(windowAccel, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_builder_connect_signals(builder, NULL);

gridAccelFixed1 = GTK_WIDGET(gtk_builder_get_object(builder,
"gridAccelFixed1"));
lblAccelPitch = GTK_WIDGET(gtk_builder_get_object(builder, "lblAccelPitch"));
lblAccelRoll = GTK_WIDGET(gtk_builder_get_object(builder, "lblAccelRoll"));
lblAccelTemp = GTK_WIDGET(gtk_builder_get_object(builder, "lblAccelTemp"));
timer = GTK_WIDGET(gtk_builder_get_object(builder, "timer"));

gtk_widget_show(windowAccel);
g_timeout_add_seconds(1,(GSourceFunc)accelTimer_handler, timer);
gtk_main();
close(accel6_click); 29
return EXIT_SUCCESS;
STM32MP1 Primer
Swinging Around in the STM32MP1 Device Tree
Linux-Based STM32MP157F Accel 6 click Project Sponsored By

GTK Timer Handler

gboolean accelTimer_handler(GtkWidget *timer)


{
getAccelData();
accelerationX = parseAccelData(ACC_X_MSB, ACC_X_LSB);
accelerationY = parseAccelData(ACC_Y_MSB, ACC_Y_LSB);
accelerationZ = parseAccelData(ACC_Z_MSB, ACC_Z_LSB);
calculatePitchRoll();

temperatureC = (float) (((int8_t)i2cRxPkt[TEMP_RAW]) * 0.5 + 23);


sprintf(lblmsg,"Temperature C = %03.2fC",temperatureC);
gtk_label_set_text(GTK_LABEL(lblAccelTemp),lblmsg);
sprintf(lblmsg,"Pitch = %3.2f degrees",pitch);
gtk_label_set_text(GTK_LABEL(lblAccelPitch),lblmsg);
sprintf(lblmsg,"Roll = %3.2f degrees",roll);
gtk_label_set_text(GTK_LABEL(lblAccelRoll),lblmsg);
return TRUE;
}

30
Sponsored By

Thank you for attending!!! MORE TO COME…

Please consider the resources below:


• Today’s Project Download Package
• Linux GTK Glade Tutorials
• MikroElektronika Accel 6 click
• STM32MP1 Wiki

To get today’s Project Download Package please send an email request to: therealfredeady@gmail.com 31
Thank You

Sponsored by

You might also like