Skip to content

Commit d677bb9

Browse files
M8BTL-4158: Adding github examples for MDFU Client I2C support
1 parent aba4b7d commit d677bb9

File tree

591 files changed

+21697
-12948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

591 files changed

+21697
-12948
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ The following project setup steps will demonstrate the basic configuration of th
6868
**8-Bit MDFU Client**
6969

7070
This section will guide you through the setup process for UART communication. For more details on configuring and operating other communication protocols, refer to the pages listed below.
71-
- [SPI Communication](pic16f18446-spi/Readme.md)
71+
- [SPI Communication](spi/README.md)
72+
- [I<sup>2</sup>C Communication](i2c/README.md)
7273

7374
**8-Bit MDFU Client with UART Communication**
7475

@@ -226,7 +227,8 @@ applicationFooter __attribute__((used, section("application_footer"))) = 0xFFFF;
226227

227228
## Operation
228229
In this section, we will walkthrough how to run the examples in this repository. This example shows how to execute the Checksum verification example and update the device Flash memory with the checksum application image to demonstrate a successful Device Firmware Update (DFU) using UART communication. For additional communication protocol operation information, refer to the pages listed below:
229-
- [SPI Example Operation](pic16f18446-spi/Readme.md#operation)
230+
- [SPI Example Operation](spi/README.md#operation)
231+
- [I<sup>2</sup>C Example Operation](i2c/README.md#operation)
230232

231233
**8-Bit MDFU Client Operation**
232234

i2c/README.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
[![MCHP](../images/microchip.png)](https://www.microchip.com)
2+
3+
# 8-Bit MDFU Client Setup for I<sup>2</sup>C Communication
4+
5+
[Go Back](../README.md)
6+
7+
## Required Hardware
8+
- [Curiosity Nano Base for Click boards™](https://www.microchip.com/en-us/development-tool/AC164162)
9+
- [MCP2221A Breakout Module](https://www.microchip.com/en-us/development-tool/ADM00559)
10+
- Three female-to-male jumper wires
11+
12+
## Hardware Configuration
13+
[![MDFU_I2C_HW](../images/i2c/HardwareSetup_I2C.png)](../images/i2c/HardwareSetup_I2C.png)
14+
15+
## 8-Bit MDFU Client I<sup>2</sup>C Communication
16+
17+
- Communication Protocol: I2C
18+
- Application Start Address: 0x2000
19+
- Device ID: 0x30D4 (automatically added)
20+
- I/O Pin Indicator: Enabled
21+
- I/O Pin Entry: Enabled
22+
- Memory Verification: CRC32
23+
24+
[![MDFU](../images/i2c/MDFUClientSetup.png)](../images/i2c/MDFUClientSetup.png)
25+
26+
**I2C**
27+
- Custom Name: SERCOM
28+
- Client Address: 0x20
29+
- Client Mask: 0x7F
30+
- I2C Client PLIB Selector: MSSP2
31+
32+
[![I2C](../images/i2c/I2CDriverSetup.png)](../images/i2c/I2CDriverSetup.png)
33+
34+
**MSSP2 PLIB**
35+
- Serial Protocol: I2C
36+
- Interrupt Driven: Enabled
37+
38+
[![I2C_PLIB](../images/i2c/I2CPLIBSetup.png)](../images/i2c/I2CPLIBSetup.png)
39+
40+
**I2C Pins**
41+
- MSSP SCL: RB7
42+
- MSSP SDA: RB5
43+
44+
[![I2C_Pins](../images/i2c/I2CPortsSetup.png)](../images/i2c/I2CPortsSetup.png)
45+
46+
**8-Bit MDFU Client I/O**
47+
- BOOT INDICATE: RA2
48+
- BOOT ENTRY: RC2
49+
50+
[![IO-Pins](../images/i2c/IOPortSetup.png)](../images/i2c/IOPortSetup.png)
51+
52+
- BOOT INDICATE: Start High
53+
- BOOT ENTRY: Weak Pull-up
54+
55+
[![IO-Settings](../images/IOPinsSetup.PNG)](../images/IOPinsSetup.PNG)
56+
57+
**8-Bit MDFU Client Project Properties**
58+
- ROM Ranges: This option is configured based on the application's start address. For example, if the application starts at 0x2000 then this value will reflect as 00-7FF,800-FFF,1000-17FF,1800-1FFF.
59+
60+
[![IO-Settings](../images/i2c/ProjectProperties.png)](../images/i2c/ProjectProperties.png)
61+
62+
### Application Setup
63+
Refer to the [Application Setup](../README.md#application-setup) section in the main Readme file.
64+
65+
## Operation
66+
This example shows how to execute the CRC32 verification example and update the device Flash memory with the CRC32 application image to demonstrate a successful device firmware update (DFU) over the I<sup>2</sup>C communication protocol.
67+
68+
**8-Bit MDFU Client Operation**
69+
70+
1. Open the MDFU client project.
71+
72+
[![OpenMDFU](../images/openBtnMDFU.png)](../images/openBtnMDFU.png)
73+
74+
[![OpenMDFUProject](../images/i2c/openProjectMDFU.png)](../images/i2c/openProjectMDFU.png)
75+
76+
2. Set MDFU client project as Main Project.
77+
78+
[![SetAsMainMDFUProject](../images/setAsMainProject_SPI.PNG)](../images/setAsMainProject_SPI.PNG)
79+
80+
3. Right click, then select Clean and Build.
81+
82+
[![CleanBuild](../images/i2c/CleanAndBuildMDFU.png)](../images/i2c/CleanAndBuildMDFU.png)
83+
84+
4. Program the MDFU client project.
85+
86+
[![ProgramMDFU](../images/i2c/ProgramMDFU.png)](../images/i2c/ProgramMDFU.png)
87+
88+
**Bootloader Operation after initial programming**
89+
90+
After initial programming, the LED must be on.
91+
92+
[![MDFU_BootMode](../images/i2c/PIC16F18446_BootMode.png)](../images/i2c/PIC16F18446_BootMode.png)
93+
94+
**Application Operation**
95+
1. Open the application project configured for the selected verification scheme.
96+
97+
[![OpenApp](../images/openBtnApp_SPI.PNG)](../images/openBtnApp_SPI.PNG)
98+
99+
[![OpenAppProject](../images/i2c/openProjectApp.png)](../images/i2c/openProjectApp.png)
100+
101+
2. Set the application project as the Main Project.
102+
103+
[![MainAppProject](../images/setAppAsMainProject_SPI.PNG)](../images/setAppAsMainProject_SPI.PNG)
104+
105+
3. Build the application project.
106+
107+
Right click, then select Clean and Build.
108+
109+
[![CleanBuild_App](../images/i2c/CleanAndBuildApp.png)](../images/i2c/CleanAndBuildApp.png)
110+
111+
4. Build the Application Image File using [pyfwimagebuilder](https://pypi.org/project/pyfwimagebuilder/).
112+
113+
- Navigate to the Project tab and right click on *Important Files>`build_free_image.bat`* for Windows or *Important Files>`build_free_image.sh`* for Mac and Linux.
114+
- Select Run.
115+
116+
[![Run_BuildScript](../images/RunBuildScript_SPI.PNG)](../images/RunBuildScript_SPI.PNG)
117+
118+
**Example Command:**
119+
120+
Below is an example of the command used in the above step.
121+
122+
`pyfwimagebuilder build -i "application_hex_file.hex" -c "mdfu_config_file.toml" -o output.img`
123+
124+
[![build_img](../images/i2c/BuildTheImage.png)](../images/i2c/BuildTheImage.png)
125+
126+
> **Tip**: The configuration TOML file is generated by the MDFU Client project.
127+
128+
[![FindTheTOML_BL](../images/ConfigPathExample_SPI.PNG)](../images/ConfigPathExample_SPI.PNG)
129+
130+
5. Use the [pymdfu](https://pypi.org/project/pymdfu/) Host tool to transfer the application image file to the bootloader.
131+
132+
- Navigate to the project tab and right click, *Important Files>`pymdfu_update.bat`* for Windows or *Important Files>`pymdfu_update.sh`* for Mac and Linux. Double click to open the file.
133+
- Then right click on the script in the Files tab and select Run.
134+
135+
[![UpdateScript_BL](../images/runUpdateScript_SPI.PNG)](../images/runUpdateScript_SPI.PNG)
136+
137+
**Example Command:**
138+
139+
Below is an example of the command used in the above step.
140+
141+
`pymdfu update --tool mcp2221a --image ./output.img --interface i2c --address 32 --clk-speed 100k`
142+
143+
[![transfer_img](../images/i2c/SendTheImage.png)](../images/i2c/SendTheImage.png)
144+
145+
**Application Has Been Updated Successfully**
146+
147+
[![MDFU_AppMode](../images/i2c/PIC16F18446_AppMode.gif)](../images/i2c/PIC16F18446_AppMode.gif)
148+
149+
[Back to top](#8-bit-mdfu-client-setup-for-i2c-communication)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* MAIN Generated Driver File
3+
*
4+
* @file main.c
5+
*
6+
* @defgroup main MAIN
7+
*
8+
* @brief This is the generated driver implementation file for the MAIN driver.
9+
*
10+
* @version MAIN Driver Version 1.0.2
11+
*
12+
* @version Package Version: 3.1.2
13+
*/
14+
15+
/*
16+
© [2025] Microchip Technology Inc. and its subsidiaries.
17+
18+
Subject to your compliance with these terms, you may use Microchip
19+
software and any derivatives exclusively with Microchip products.
20+
You are responsible for complying with 3rd party license terms
21+
applicable to your use of 3rd party software (including open source
22+
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
23+
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
24+
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
25+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
26+
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
27+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
28+
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
29+
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
30+
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
31+
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
32+
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
33+
THIS SOFTWARE.
34+
*/
35+
#include "mcc_generated_files/system/system.h"
36+
#include <stdint.h>
37+
#ifdef __XC8__
38+
#include <xc.h>
39+
#endif
40+
41+
volatile const uint32_t
42+
#ifdef __XC8__
43+
__at(0x3FFC)
44+
#endif
45+
46+
applicationFooter __attribute__((used, section("application_footer"))) = 0xFFFFFFFF;
47+
48+
void BlinkLED(void)
49+
{
50+
LED_Toggle();
51+
}
52+
53+
/*
54+
Main application
55+
*/
56+
57+
int main(void)
58+
{
59+
SYSTEM_Initialize();
60+
// If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
61+
// If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
62+
// Use the following macros to:
63+
64+
// Enable the Global Interrupts
65+
INTERRUPT_GlobalInterruptEnable();
66+
67+
// Disable the Global Interrupts
68+
//INTERRUPT_GlobalInterruptDisable();
69+
70+
// Enable the Peripheral Interrupts
71+
INTERRUPT_PeripheralInterruptEnable();
72+
73+
// Disable the Peripheral Interrupts
74+
//INTERRUPT_PeripheralInterruptDisable();
75+
76+
TMR0_OverflowCallbackRegister(&BlinkLED);
77+
78+
while (1)
79+
{
80+
if (BTN_GetValue() == 0U)
81+
{
82+
RESET();
83+
}
84+
}
85+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file has been autogenerated by MPLAB Code Configurator. Please do not edit this file.
2+
3+
manifest_file_version: 1.0.0
4+
project: pic16f18446-application-crc32
5+
creation_date: 2025-01-08T15:18:35.927-07:00[America/Phoenix]
6+
operating_system: Windows 10
7+
mcc_mode: IDE
8+
mcc_mode_version: v6.20
9+
device_name: PIC16F18446
10+
compiler: XC8 2.50
11+
mcc_version: 5.5.1
12+
mcc_core_version: 5.7.1
13+
content_manager_version: 5.0.1
14+
is_mcc_offline: false
15+
is_using_prerelease_versions: true
16+
mcc_content_registries: https://registry.npmjs.org/, https://artifacts.microchip.com/artifactory/api/npm/npm
17+
device_library: {library_class: com.microchip.mcc.melody.Library, name: Melody, version: 2.8.0}
18+
packs: {name: PIC16F1xxxx_DFP, version: 1.25.389}
19+
modules:
20+
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
21+
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.28.4}
22+
- {name: '@mchp-mcc/pic16-configuration-bits-v3', type: MELODY, version: 1.0.5}
23+
- {name: '@mchp-mcc/pic16-pin-manager', type: MELODY, version: 3.6.1}
24+
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.9.0}
25+
- {name: '@mchp-mcc/scf-pic8-interrupt-v2', type: MELODY, version: 5.2.12}
26+
- {name: '@mchp-mcc/scf-pic8-osc-v1', type: MELODY, version: 4.3.7}
27+
- {name: '@mchp-mcc/scf-pic8-tmr0-v1', type: MELODY, version: 5.0.0}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file has been autogenerated by MPLAB Code Configurator. Please do not edit this file.
2+
3+
manifest_file_version: 1.0.0
4+
project: pic16f18446-application-crc32
5+
creation_date: 2025-01-08T15:18:35.914-07:00[America/Phoenix]
6+
operating_system: Windows 10
7+
mcc_mode: IDE
8+
mcc_mode_version: v6.20
9+
device_name: PIC16F18446
10+
compiler: XC8 2.50
11+
mcc_version: 5.5.1
12+
mcc_core_version: 5.7.1
13+
content_manager_version: 5.0.1
14+
is_mcc_offline: false
15+
is_using_prerelease_versions: true
16+
mcc_content_registries: https://registry.npmjs.org/, https://artifacts.microchip.com/artifactory/api/npm/npm
17+
device_library: {library_class: com.microchip.mcc.melody.Library, name: Melody, version: 2.8.0}
18+
packs: {name: PIC16F1xxxx_DFP, version: 1.25.389}
19+
modules:
20+
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
21+
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.28.4}
22+
- {name: '@mchp-mcc/pic16-configuration-bits-v3', type: MELODY, version: 1.0.5}
23+
- {name: '@mchp-mcc/pic16-pin-manager', type: MELODY, version: 3.6.1}
24+
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.9.0}
25+
- {name: '@mchp-mcc/scf-pic8-interrupt-v2', type: MELODY, version: 5.2.12}
26+
- {name: '@mchp-mcc/scf-pic8-osc-v1', type: MELODY, version: 4.3.7}
27+
- {name: '@mchp-mcc/scf-pic8-tmr0-v1', type: MELODY, version: 5.0.0}

0 commit comments

Comments
 (0)