2010-03-13 01:53 PM
Hard Fault error
2011-05-17 04:43 AM
One of following two accesses is definitely not going to be aligned to short boundary, and ARM doesn't handle this. (Also, they look wrong even if it'd worked?)
2011-05-17 04:43 AM
Oh...?
But then how would you connect two chars (bytes) to a 16-bit usigned integer (u16)? Thomas2011-05-17 04:43 AM
The following methods should be safe, they operate one byte at a time.
unsigned short a; unsigned char b[100]; memcpy(&a,&b[x+ 0],sizeof(unsigned short)); -OR- a = ((unsigned short)b[x + 0] << 0) + ((unsigned short)b[x + 1] << 8); You just can't use casts to arbitrarily change a pointer type and load it. -Clive2011-05-17 04:43 AM
Why do you use memcpy? Wouldn't the ''a ='' be enough?
Thanks anyways. Thomas2011-05-17 04:43 AM
It was an either/or suggestion.
memcpy() works well for structures, and is often optimized to an intrinsic. -Clive2011-05-17 04:43 AM
I can't make it work... Remember, I'm using pointers!
If I try this code, it doesn't get the correct value:
u16 color;
color = ((unsigned short)(&str[ 2 * temp]) << 0) + ((unsigned short)(&str[ 2 * temp+1]) << 8);
And if I use this code, it goes into the Hard Fault routine again:
u16 color;
memcpy(&color,&str[2 * temp],sizeof(unsigned short));
Best Regards
Thomas Jespersen
2011-05-17 04:43 AM
There seems to be a misunderstanding of how to use pointers, you don't need the '&' when you access the content of str[], only when you want the address (ie &str[])
color = ((unsigned short)(str[ 2 * temp]) << 0) + ((unsigned short)(str[ (2 * temp)+1]) << 8); How are you calling the routine? void foo(const unsigned char *str); const unsigned char data[] = { 0x01, 0x02, 0x03, 0x04 }; foo(data); // Or foo(&data[0]);2011-05-17 04:43 AM
void DispPic(u16 x0, u16 y0, const unsigned char *str)
{ typedef union { u16 U16; u8 U8[2]; } ColorTypeDef; u32 temp; u16 i, j; u16 imageWidth; u16 imageHeight; ColorTypeDef color; color.U8[1] = str[0]; color.U8[0] = str[1]; imageWidth = color.U16; color.U8[1] = str[2]; color.U8[0] = str[3]; imageHeight = color.U16; temp = 4; for(j=0; j<imageHeight; j++) { Lcd_SetCursor(x0, y0); LCD_WriteRAM_Prepare(); for(i=0; i<imageWidth; i++) { //Write all pixels to ram, and then update display (fast) color.U8[1] = str[temp++]; color.U8[0] = str[temp++]; LCD_WriteRAM(color.U16); } y0++; } } const unsigned char data[] = { 0x00, 0x03, // 3 Wide 0x00, 0x02, // 2 High 0xAA, 0xAA, 0xBB, 0xBB, 0xCC, 0xCC, 0xDD, 0xDD, 0xEE, 0xEE, 0xFF, 0xFF }; int main(int argc, char **argv) { DispPic(10, 12, data); return(1); }2011-05-17 04:43 AM
After it has shown a couple of lines (I think it's 5 pixel lines) of the image, it goes into the Hard Fault routine.
OBS: The image is 56x56 pixels!
Thomas