| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dfuutil_programming_any_algorithm.c
Go to the documentation of this file.
1 /*
2 * @brief DFU Utility program for IRAM/peripheral addresses
3 * This programming algortihm allows reading or writing
4 * any address in the device.
5 *
6 * @note
7 * Copyright(C) NXP Semiconductors, 2012
8 * All rights reserved.
9 *
10 * @par
11 * Software that is described herein is for illustrative purposes only
12 * which provides customers with programming information regarding the
13 * LPC products. This software is supplied "AS IS" without any warranties of
14 * any kind, and NXP Semiconductors and its licensor disclaim any and
15 * all warranties, express or implied, including all implied warranties of
16 * merchantability, fitness for a particular purpose and non-infringement of
17 * intellectual property rights. NXP Semiconductors assumes no responsibility
18 * or liability for the use of the software, conveys no license or rights under any
19 * patent, copyright, mask work right, or any other intellectual property rights in
20 * or to any products. NXP Semiconductors reserves the right to make changes
21 * in the software without notification. NXP Semiconductors also makes no
22 * representation or warranty that such application will be suitable for the
23 * specified use without further testing or modification.
24 *
25 * @par
26 * Permission to use, copy, modify, and distribute this software and its
27 * documentation is hereby granted, under NXP Semiconductors' and its
28 * licensor's relevant copyrights in the software, without fee, provided that it
29 * is used in conjunction with NXP Semiconductors microcontrollers. This
30 * copyright, permission, and disclaimer notice must appear in all copies of
31 * this code.
32 */
33
34 #include "board.h"
35 #include "dfuutil_programming_api.h"
36 #include "stdio.h"
37 #include "string.h"
38
65 /*****************************************************************************
66 * Private types/enumerations/variables
67 ****************************************************************************/
68
69 /* Number of program regions */
70 #define PROGRAM_REGIONS 1
71
72 /* Size of DFU USB buffer in bytes, do not exceed 4K */
73 #define DFU_BUFF_PROG_SIZE 2048
74
75 /* Forward references */
76 int32_t progalgo_emiram_erase(uint32_t start, uint32_t size);
77
78 int32_t progalgo_emiram_erase_all(void);
79
80 int32_t progalgo_emiram_write(void *buff, uint32_t start, uint32_t size);
81
82 int32_t progalgo_emiram_read(void *buff, uint32_t start, uint32_t size);
83
84 /* Function table for exposed API functions */
85 static const PROGALGOS_T palgos = {
86 progalgo_emiram_erase,
87 progalgo_emiram_erase_all,
88 progalgo_emiram_write,
89 progalgo_emiram_read
90 };
91
92 /* 1 huge region with 4GB range, so we can stream large files */
93 static const DFUPROG_REGZONE_T pregions[PROGRAM_REGIONS] = {
94 {0x00000000, 0xFFFFFFFC}
95 };
96
97 /* DFU programming region/API structure
98 This structure puts them all together and is used by the DFU streamer */
99 static DFUPROG_REGION_T dfuregion = {
100 PROGRAM_REGIONS, /* Regions per device */
101 DFU_BUFF_PROG_SIZE, /* Size of buffer provided to DFU streamer */
102 &palgos, /* Pointer to programming algorithm function table */
103 pregions, /* Array of region addresses and sizes */
104 DFUPROG_VALIDVAL,
105 "iramregs_access"
106 };
107
108 /* Temporary work string for formatting */
109 static char tempSTR[64];
110
111 /*****************************************************************************
112 * Public types/enumerations/variables
113 ****************************************************************************/
114
115 /*****************************************************************************
116 * Private functions
117 ****************************************************************************/
118
119 /* Erases a specific area of a device. This function can be optionally
120 supported (by an empty function) if only the erase all function is used. */
121 static int32_t progalgo_emiram_erase(uint32_t start, uint32_t size)
122 {
123 sprintf(tempSTR, "Erasing memory region: %p, size %d\n", (void *) start, size);
124 usbDebug(tempSTR);
125 memset((void *) start, 0, size);
126
127 /* This function should block until the operation is complete. If the
128 operation fails, use the usbDebug() function to specify the error. */
129
130 return size;
131 }
132
133 /* Erases all regions of all devices. This function can be optionally
134 supported (with an empty function) in only the region erase is used. */
135 static int32_t progalgo_emiram_erase_all(void)
136 {
137 usbDebug("Full device erase not supported for this algorithm, ignoring erase command\n");
138
139 /* This function should block until the operation is complete. If the
140 operation fails, use the usbDebug() function to specify the error. */
141
142 /* It's not supported, but don't generate an error */
143 return 1;
144 }
145
146 /* Write the buffer to the device. Returns 0 if the region cannot
147 be written (programming failure or region overlap) or the write
148 size>0 if it passed. */
149 static int32_t progalgo_emiram_write(void *buff, uint32_t start, uint32_t size)
150 {
151 sprintf(tempSTR, "WRITE @ 0x%p, %p bytes\n", (void *) start, (void *) size);
152 usbDebug(tempSTR);
153 memmove((void *) start, buff, size);
154
155 /* This function should block until the operation is complete. If the
156 operation fails, use the usbDebug() function to specify the error. */
157
158 return size;
159 }
160
161 /* Read data from the device. Returns 0 if the region cannot
162 be read. */
163 static int32_t progalgo_emiram_read(void *buff, uint32_t start, uint32_t size)
164 {
165 sprintf(tempSTR, "READ @ 0x%p, %p bytes\n", (void *) start, (void *) size);
166 usbDebug(tempSTR);
167 memmove(buff, (void *) start, size);
168
169 return size;
170 }
171
172 /*****************************************************************************
173 * Public functions
174 ****************************************************************************/
175
183 DFUPROG_REGION_T *algo_flash_init(void)
184 {
185 usbDebug("Memory mapped programming algorithm\n");
186
187 /* Nothing to realliy initialize for this algorithm */
188 return &dfuregion;
189 }
190