#include "log.h"
#include "time_support.h"
#include <stdlib.h>
+#include <string.h>
/*
* Transaction Mode:
*****************************************************************************/
int mem_ap_write_buf_u32(swjdp_common_t *swjdp, u8 *buffer, int count, u32 address)
{
- u32 outvalue;
int wcount, blocksize, writecount, errorcount = 0, retval = ERROR_OK;
u32 adr = address;
u8* pBuffer = buffer;
for (writecount = 0; writecount < count; writecount++)
{
int i;
- outvalue = *((u32*)pBuffer);
+ u32 outvalue;
+ memcpy(&outvalue, pBuffer, sizeof(u32));
for (i = 0; i < 4; i++ )
{
outvalue >>= 8;
adr++;
}
- pBuffer += 4;
+ pBuffer += sizeof(u32);
}
}
int mem_ap_write_buf_packed_u16(swjdp_common_t *swjdp, u8 *buffer, int count, u32 address)
{
- u32 outvalue;
int retval = ERROR_OK;
int wcount, blocksize, writecount, i;
}
else
{
- outvalue = *((u32*)buffer);
+ u32 outvalue;
+ memcpy(&outvalue, buffer, sizeof(u32));
for (i = 0; i < nbytes; i++ )
{
address++;
}
- outvalue = *((u32*)buffer);
+ memcpy(&outvalue, buffer, sizeof(u32));
dap_ap_write_reg_u32(swjdp, AP_REG_DRW, outvalue);
if (swjdp_transaction_endcheck(swjdp) != ERROR_OK)
{
int mem_ap_write_buf_u16(swjdp_common_t *swjdp, u8 *buffer, int count, u32 address)
{
- u32 outvalue;
int retval = ERROR_OK;
if (count >= 4)
while (count > 0)
{
dap_setup_accessport(swjdp, CSW_16BIT | CSW_ADDRINC_SINGLE, address);
- outvalue = *((u16*)buffer) << 8 * (address & 0x3);
+ u16 svalue;
+ memcpy(&svalue, buffer, sizeof(u16));
+ u32 outvalue = (u32)svalue << 8 * (address & 0x3);
dap_ap_write_reg_u32(swjdp, AP_REG_DRW, outvalue );
retval = swjdp_transaction_endcheck(swjdp);
count -= 2;
int mem_ap_write_buf_packed_u8(swjdp_common_t *swjdp, u8 *buffer, int count, u32 address)
{
- u32 outvalue;
int retval = ERROR_OK;
int wcount, blocksize, writecount, i;
}
else
{
- outvalue = *((u32*)buffer);
+ u32 outvalue;
+ memcpy(&outvalue, buffer, sizeof(u32));
for (i = 0; i < nbytes; i++ )
{
address++;
}
- outvalue = *((u32*)buffer);
+ memcpy(&outvalue, buffer, sizeof(u32));
dap_ap_write_reg_u32(swjdp, AP_REG_DRW, outvalue);
if (swjdp_transaction_endcheck(swjdp) != ERROR_OK)
{
int mem_ap_write_buf_u8(swjdp_common_t *swjdp, u8 *buffer, int count, u32 address)
{
- u32 outvalue;
int retval = ERROR_OK;
if (count >= 4)
while (count > 0)
{
dap_setup_accessport(swjdp, CSW_8BIT | CSW_ADDRINC_SINGLE, address);
- outvalue = *((u8*)buffer) << 8 * (address & 0x3);
+ u32 outvalue = (u32)*buffer << 8 * (address & 0x3);
dap_ap_write_reg_u32(swjdp, AP_REG_DRW, outvalue );
retval = swjdp_transaction_endcheck(swjdp);
count--;
for (readcount = 0; readcount < count; readcount++)
{
int i;
- u32 data = *((u32*)pBuffer);
+ u32 data;
+ memcpy(&data, pBuffer, sizeof(u32));
for (i = 0; i < 4; i++ )
{
}
else
{
- *((u16*)buffer) = (invalue >> 8 * (address & 0x3));
+ u16 svalue = (invalue >> 8 * (address & 0x3));
+ memcpy(buffer, &svalue, sizeof(u16));
address += 2;
buffer += 2;
}