From: <zw...@ma...> - 2009-05-07 02:22:25
|
Author: zwelch Date: 2009-05-07 02:21:59 +0200 (Thu, 07 May 2009) New Revision: 1626 Modified: trunk/src/flash/pic32mx.c trunk/src/flash/stm32x.c Log: Fix stm32x and pic32mx flash pointer cast alignment warnings, simplify their last word handling. Modified: trunk/src/flash/pic32mx.c =================================================================== --- trunk/src/flash/pic32mx.c 2009-05-06 23:31:50 UTC (rev 1625) +++ trunk/src/flash/pic32mx.c 2009-05-07 00:21:59 UTC (rev 1626) @@ -463,9 +463,10 @@ while(count > 0) { - u32 status; + u32 value; + memcpy(&value, buffer, sizeof(u32)); - status = pic32mx_write_word(bank, address, *(u32*)buffer); + u32 status = pic32mx_write_word(bank, address, value); if( status & NVMCON_NVMERR ) { LOG_ERROR("Flash write error NVMERR (status=0x%08x)", status); retval = ERROR_FLASH_OPERATION_FAILED; @@ -568,8 +569,10 @@ while (words_remaining > 0) { - status = pic32mx_write_word(bank, address, *(u32*)(buffer + bytes_written)); + u32 value; + memcpy(&value, buffer + bytes_written, sizeof(u32)); + status = pic32mx_write_word(bank, address, value); if( status & NVMCON_NVMERR ) return ERROR_FLASH_OPERATION_FAILED; if( status & NVMCON_LVDERR ) @@ -582,19 +585,10 @@ if (bytes_remaining) { - u8 last_word[4] = {0xff, 0xff, 0xff, 0xff}; - int i = 0; + u32 value = 0xffffffff; + memcpy(&value, buffer + bytes_written, bytes_remaining); - while(bytes_remaining > 0) - { - /* Assumes little endian */ - last_word[i++] = *(buffer + bytes_written); - bytes_remaining--; - bytes_written++; - } - - status = pic32mx_write_word(bank, address, *(u32*)last_word); - + status = pic32mx_write_word(bank, address, value); if( status & NVMCON_NVMERR ) return ERROR_FLASH_OPERATION_FAILED; if( status & NVMCON_LVDERR ) Modified: trunk/src/flash/stm32x.c =================================================================== --- trunk/src/flash/stm32x.c 2009-05-06 23:31:50 UTC (rev 1625) +++ trunk/src/flash/stm32x.c 2009-05-07 00:21:59 UTC (rev 1626) @@ -658,8 +658,11 @@ while (words_remaining > 0) { + u16 value; + memcpy(&value, buffer + bytes_written, sizeof(u16)); + target_write_u32(target, STM32_FLASH_CR, FLASH_PG); - target_write_u16(target, address, *(u16*)(buffer + bytes_written)); + target_write_u16(target, address, value); status = stm32x_wait_status_busy(bank, 5); @@ -681,18 +684,11 @@ if (bytes_remaining) { - u8 last_halfword[2] = {0xff, 0xff}; - int i = 0; - - while(bytes_remaining > 0) - { - last_halfword[i++] = *(buffer + bytes_written); - bytes_remaining--; - bytes_written++; - } - + u16 value = 0xffff; + memcpy(&value, buffer + bytes_written, bytes_remaining); + target_write_u32(target, STM32_FLASH_CR, FLASH_PG); - target_write_u16(target, address, *(u16*)last_halfword); + target_write_u16(target, address, value); status = stm32x_wait_status_busy(bank, 5); |