Skip to content

Commit d3b1f69

Browse files
chrissnowadbridge
authored andcommitted
Resolve warning
1 parent 606f205 commit d3b1f69

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

targets/TARGET_NXP/TARGET_LPC176X/device/flash_api.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
16+
#if DEVICE_FLASH
1717
#include "mbed_critical.h"
1818

1919
#include "flash_api.h"
@@ -106,20 +106,10 @@ typedef void (*IAP_Entry) (unsigned long *cmd, unsigned long *stat);
106106
#define IAP_Call ((IAP_Entry) 0x1FFF1FF1)
107107

108108
int32_t flash_program_page(flash_t *obj, uint32_t address,
109-
const uint8_t *datain, uint32_t size)
109+
const uint8_t *data, uint32_t size)
110110
{
111-
uint8_t *data;
112111
unsigned long n;
113-
114-
if ((unsigned long)datain%4==0)//word boundary
115-
{
116-
data = datain;
117-
}
118-
else
119-
{
120-
data = malloc(size);
121-
memcpy(data,datain,size);
122-
}
112+
uint8_t *alignedData = 0;
123113

124114
n = GetSecNum(address);// Get Sector Number
125115

@@ -131,15 +121,27 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
131121

132122
IAP.cmd = 51;// Copy RAM to Flash
133123
IAP.par[0] = address;// Destination Flash Address
134-
IAP.par[1] = (unsigned long)data;// Source RAM Address
124+
125+
if ((unsigned long)data%4==0)// Word boundary
126+
{
127+
IAP.par[1] = (unsigned long)data;// Source RAM Address
128+
}
129+
else
130+
{
131+
alignedData = malloc(size);
132+
memcpy(alignedData,data,size);
133+
IAP.par[1] = (unsigned long)alignedData;// Source RAM Address
134+
}
135135

136136
IAP.par[2] = 1024;// Fixed Page Size
137137
IAP.par[3] = CCLK;// CCLK in kHz
138138
IAP_Call (&IAP.cmd, &IAP.stat);// Call IAP Command
139-
if(data !=datain)//We allocated our own memory
139+
140+
if(alignedData !=0)//We allocated our own memory
140141
{
141-
free(data);
142+
free(alignedData);
142143
}
144+
143145
if (IAP.stat) return (1);// Command Failed
144146

145147
return (0);// Finished without Errors

0 commit comments

Comments
 (0)