Skip to content

Commit af5d43c

Browse files
author
Microchip Technology
committed
Deploy 1.0.0 to pic-avr-solutions github
0 parents  commit af5d43c

File tree

103 files changed

+11399
-0
lines changed

Some content is hidden

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

103 files changed

+11399
-0
lines changed

.main-meta/main.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"metaDataVersion": "1.0.0",
3+
"category": "com.microchip.ide.project",
4+
"content": {
5+
"metaDataVersion": "1.3.0",
6+
"name": "com.microchip.mcu8.mplabx.project.pic16f18446-cnano-8bit-mdfu-solution-mplab-mcc",
7+
"version": "1.0.0",
8+
"displayName": "8-Bit Microchip Device Firmware Update (MDFU) Solution for the PIC16F18446 Curiosity Nano Evaluation Kit",
9+
"projectName": "pic16f18446-cnano-8bit-mdfu-solution-mplab-mcc",
10+
"shortDescription": "This repository contains two MPLAB® X projects designed to showcase the 8-Bit MDFU Client library and the ecosystem it creates.",
11+
"ide": {
12+
"name": "MPLAB X",
13+
"semverRange": "^6.20.0"
14+
},
15+
"compiler": [
16+
{
17+
"name": "XC8",
18+
"semverRange": "^3.00.0"
19+
}
20+
],
21+
"dfp": {
22+
"name": "PIC16F1xxxx_DFP",
23+
"semverRange": "^1.25.389"
24+
},
25+
"configurator": {
26+
"name": "MCC",
27+
"semverRange": "^5.7.1"
28+
},
29+
"device": {
30+
"metaDataVersion": "1.0.0",
31+
"category": "com.microchip.portal.contentRef",
32+
"content": {
33+
"metaDataVersion": "1.0.0",
34+
"category": "com.microchip.device",
35+
"name": "PIC16F18446",
36+
"versionRange": "*"
37+
}
38+
},
39+
"author": "Microchip",
40+
"peripherals": [
41+
"Interrupt",
42+
"UART",
43+
"NVM",
44+
"Timer"
45+
],
46+
"keywords": [
47+
"Melody",
48+
"MCC Melody",
49+
"Curiosity",
50+
"Curiosity Nano",
51+
"Bootloader",
52+
"Memory",
53+
"Serial Communication",
54+
"8-Bit MDFU Client",
55+
"Microchip Device Firmware Update",
56+
"MDFU",
57+
"Virtual COM Port",
58+
"File Transfer Protocol"
59+
],
60+
"additionalData": {
61+
"longDescription": {
62+
"metaDataVersion": "1.0.0",
63+
"category": "com.microchip.portal.fileRef",
64+
"content": {
65+
"metaDataVersion": "1.0.0",
66+
"fileName": "./README.md",
67+
"mimeType": "text/markdown"
68+
}
69+
}
70+
}
71+
}
72+
}
3.47 KB
Binary file not shown.

PIC16F18446_Application.X/Makefile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# There exist several targets which are by default empty and which can be
3+
# used for execution of your targets. These targets are usually executed
4+
# before and after some main targets. They are:
5+
#
6+
# .build-pre: called before 'build' target
7+
# .build-post: called after 'build' target
8+
# .clean-pre: called before 'clean' target
9+
# .clean-post: called after 'clean' target
10+
# .clobber-pre: called before 'clobber' target
11+
# .clobber-post: called after 'clobber' target
12+
# .all-pre: called before 'all' target
13+
# .all-post: called after 'all' target
14+
# .help-pre: called before 'help' target
15+
# .help-post: called after 'help' target
16+
#
17+
# Targets beginning with '.' are not intended to be called on their own.
18+
#
19+
# Main targets can be executed directly, and they are:
20+
#
21+
# build build a specific configuration
22+
# clean remove built files from a configuration
23+
# clobber remove all built files
24+
# all build all configurations
25+
# help print help mesage
26+
#
27+
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
28+
# .help-impl are implemented in nbproject/makefile-impl.mk.
29+
#
30+
# Available make variables:
31+
#
32+
# CND_BASEDIR base directory for relative paths
33+
# CND_DISTDIR default top distribution directory (build artifacts)
34+
# CND_BUILDDIR default top build directory (object files, ...)
35+
# CONF name of current configuration
36+
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
37+
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
38+
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
39+
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
40+
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
41+
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
42+
#
43+
# NOCDDL
44+
45+
46+
# Environment
47+
MKDIR=mkdir
48+
CP=cp
49+
CCADMIN=CCadmin
50+
RANLIB=ranlib
51+
52+
53+
# build
54+
build: .build-post
55+
56+
.build-pre:
57+
# Add your pre 'build' code here...
58+
59+
.build-post: .build-impl
60+
# Add your post 'build' code here...
61+
62+
63+
# clean
64+
clean: .clean-post
65+
66+
.clean-pre:
67+
# Add your pre 'clean' code here...
68+
# WARNING: the IDE does not call this target since it takes a long time to
69+
# simply run make. Instead, the IDE removes the configuration directories
70+
# under build and dist directly without calling make.
71+
# This target is left here so people can do a clean when running a clean
72+
# outside the IDE.
73+
74+
.clean-post: .clean-impl
75+
# Add your post 'clean' code here...
76+
77+
78+
# clobber
79+
clobber: .clobber-post
80+
81+
.clobber-pre:
82+
# Add your pre 'clobber' code here...
83+
84+
.clobber-post: .clobber-impl
85+
# Add your post 'clobber' code here...
86+
87+
88+
# all
89+
all: .all-post
90+
91+
.all-pre:
92+
# Add your pre 'all' code here...
93+
94+
.all-post: .all-impl
95+
# Add your post 'all' code here...
96+
97+
98+
# help
99+
help: .help-post
100+
101+
.help-pre:
102+
# Add your pre 'help' code here...
103+
104+
.help-post: .help-impl
105+
# Add your post 'help' code here...
106+
107+
108+
109+
# include project implementation makefile
110+
include nbproject/Makefile-impl.mk
111+
112+
# include project make variables
113+
include nbproject/Makefile-variables.mk

PIC16F18446_Application.X/PIC16F18446_Application.mc3

Lines changed: 214 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
REM - @file: build_image.bat
2+
REM - @description: Batch script that can be executed in the MPLAB X post build
3+
REM - step or ran as a standalone script to build the
4+
REM - application binary image.
5+
REM -
6+
REM - @requirements: pyfwimagebuilder, python
7+
REM - @arguments:
8+
REM - %1 - the IS_DEBUG argument is passed by the MPLAB post build step to identify if the application is being built to a hex file (for production) or an elf file (for debugging).
9+
REM - %2 - the INPUT_IMAGE_PATH argument is passed by the MPLAB post build step and it holds the output image path. (.hex or .elf normally)
10+
REM ----------------------------------------------------------------------------
11+
REM - if the script was not called with arguments; setup the arguments manually
12+
if "%1"=="" (set IS_DEBUG=false) else (set IS_DEBUG=%1)
13+
if "%2"=="" (set INPUT_IMAGE_PATH=".\dist\Standalone\production\PIC16F18446_Application.X.production.hex") else (set INPUT_IMAGE_PATH=%2)
14+
REM - relative path to client config file
15+
set CONFIG_FILE_PATH="..\PIC16F18446_Client.X\mcc_generated_files\bootloader\configurations\bootloader_configuration.toml"
16+
set OUTPUT_IMAGE_PATH=".\Application_Binary.img"
17+
18+
REM - Ensure pyfwimagebuilder is installed
19+
WHERE pyfwimagebuilder >nul 2>nul
20+
21+
if %ERRORLEVEL% NEQ 0 (
22+
ECHO "pyfwimagebuilder not found, installing..."
23+
pip install pyfwimagebuilder
24+
)
25+
26+
if %IS_DEBUG% == false (
27+
REM - Build the application binary
28+
pyfwimagebuilder build -i %INPUT_IMAGE_PATH% -c %CONFIG_FILE_PATH% -o %OUTPUT_IMAGE_PATH%
29+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
# - File: build_image.sh
3+
# - Description: Shell script that can be executed in the MPLAB X post build
4+
# - step or ran as a standalone script to build the
5+
# - application binary image.
6+
# -
7+
# - Requirements: pyfwimagebuilder, python
8+
# - Arguments:
9+
# - $1 - the IS_DEBUG argument is passed by the MPLAB post build step to identify if the application is being built to a hex file (for production) or an elf file (for debugging).
10+
# - $2 - the INPUT_IMAGE_PATH argument is passed by the MPLAB post build step and it holds the output image path. (.hex or .elf normally)
11+
# ----------------------------------------------------------------------------
12+
# - if the script was not called with arguments; setup the arguments manually
13+
14+
if [ "$1" = "" ]; then
15+
IS_DEBUG=false
16+
else
17+
IS_DEBUG="$1"
18+
fi
19+
if [ "$2" = "" ]; then
20+
INPUT_IMAGE_PATH="./dist/Standalone/production/PIC16F18446_Application.X.production.hex"
21+
else
22+
INPUT_IMAGE_PATH="$2"
23+
fi
24+
# - relative path to client config file
25+
CONFIG_FILE_PATH="../PIC16F18446_Client.X/mcc_generated_files/bootloader/configurations/bootloader_configuration.toml"
26+
OUTPUT_IMAGE_PATH="./Application_Binary.img"
27+
28+
# - Ensure pyfwimagebuilder is installed
29+
if ! python -c "import pyfwimagebuilder" &> /dev/null; then
30+
echo "pyfwimagebuilder not found, installing..."
31+
pip install pyfwimagebuilder
32+
fi
33+
34+
# - Build the application binary
35+
if [ "$IS_DEBUG" = false ]; then
36+
pyfwimagebuilder build -i $INPUT_IMAGE_PATH -c $CONFIG_FILE_PATH -o $OUTPUT_IMAGE_PATH
37+
fi

PIC16F18446_Application.X/main.c

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
37+
/*
38+
Main application
39+
*/
40+
#include <stdint.h>
41+
#ifdef __XC8__
42+
#include <xc.h>
43+
#endif
44+
volatile const uint32_t
45+
#ifdef __XC8__
46+
__at(0x3FFC)
47+
#endif
48+
applicationFooter __attribute__((used, section("application_footer"))) = 0xFFFFFFFF;
49+
50+
static flash_address_t footerSignatureLocation = 0x3FFC;
51+
52+
void BlinkLED(void)
53+
{
54+
LED_Toggle();
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+
// delay for some time to give the user some time to connect to a terminal
65+
__delay_ms(3000);
66+
67+
Timer0_OverflowCallbackRegister(&BlinkLED);
68+
69+
// Enable the Global Interrupts
70+
INTERRUPT_GlobalInterruptEnable();
71+
72+
// Disable the Global Interrupts
73+
//INTERRUPT_GlobalInterruptDisable();
74+
75+
// Enable the Peripheral Interrupts
76+
INTERRUPT_PeripheralInterruptEnable();
77+
78+
// Disable the Peripheral Interrupts
79+
//INTERRUPT_PeripheralInterruptDisable();
80+
printf("===================================================\r\n");
81+
printf("Hello and thank you for downloading and trying out the 8-Bit MDFU Client solution for the PIC16F18446 Curiosity Nano Development Board.\r\n");
82+
__delay_ms(150);
83+
printf("===================================================\r\n");
84+
printf("You should be able to see that the on-board LED is blinking at a continuous rate.\r\nThis blinking LED is being controlled by a timer interrupt.\r\n");
85+
__delay_ms(250);
86+
printf("\r\nTo pass control to the bootloader code, send the value 'r' over the Data Visualizer Terminal or press and hold the on-board switch.\r\n");
87+
88+
while (1)
89+
{
90+
if (EUSART1_IsRxReady())
91+
{
92+
if (EUSART1_Read() == 'r')
93+
{
94+
flash_address_t erasePageAddress = FLASH_PageAddressGet(footerSignatureLocation);
95+
96+
NVM_UnlockKeySet(UNLOCK_KEY);
97+
nvm_status_t result = FLASH_PageErase(erasePageAddress);
98+
99+
NVM_UnlockKeyClear();
100+
101+
if (result == NVM_OK)
102+
{
103+
// In this example, we are erasing the footer data to force the bootloader to take control but this process can be customized to fit your needs.
104+
printf("Erasing the footer hash... \r\nResetting...\r\n");
105+
RESET();
106+
}
107+
else
108+
{
109+
printf("Error: Could not erase the footer data.\r\n");
110+
}
111+
}
112+
}
113+
else if (BTN_GetValue() == 0U)
114+
{
115+
printf("Resetting...\r\n");
116+
__delay_ms(50);
117+
RESET();
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)