Wednesday, July 31, 2013

BLE112 and redirecting debug info to console in IAR

Today I encountered strange behaviour on BLE112 and ST7565R display. The "drawbitmap" function wasn't working as expected, 

source image:


converted to hex with bmp2glcd

static unsigned char stop_glcd_bmp[]={

0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0,
0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 
0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 
0xf8, 0xfc, 0xfe, 0x3f, 0x1f, 0x9f, 0x9f, 0x9f,
0x1f, 0x3f, 0xff, 0x9f, 0x9f, 0x9f, 0x1f, 0x1f, 
0x9f, 0x9f, 0x9f, 0xff, 0x7f, 0x3f, 0x1f, 0x1f,
0x1f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0x1f, 0x1f, 
0x9f, 0x9f, 0x9f, 0x1f, 0x3f, 0x7e, 0xfc, 0xf8, 
0xff, 0xff, 0xff, 0x7c, 0x78, 0xf3, 0xe3, 0xc7,
0x0f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 
0xe7, 0xe7, 0xe7, 0xe3, 0xf0, 0xf8, 0xff, 0xff, 
0x1f, 0x3f, 0x7f, 0xfc, 0xf8, 0xf9, 0xf9, 0xf9,
0xf8, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xf8, 
0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xf1, 0xf1,
0xf1, 0xf8, 0xfc, 0xff, 0xff, 0xff, 0xf0, 0xf0, 
0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x1f, 
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f,
0x1f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x1f, 
0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
};

result on display:



debugging ble112 with IAR works very slow on VMWare Fusion, so i decided just to print some values to console and check if they are correct. Dumping logs to console from compiled code is easy.

Just use standard printf which is in stdio.h, then you need to tell IAR that you want to see these printf's in console. To do this go to the Project options -> Linker -> Output (tab) and in the "Format" section where you have selected "Debug information for C-SPY" you need to have "With I/O emulation modules" checked, then when debugging select View > Terminal I/O.
enable console ouptut

debugging with console printout on right


Long story short - Ive fixed the code to show images properly. The problem was in pmg_read_byte which is not available in IAR. When fixing code Ive found on some website to use macro:

#ifndef pgm_read_byte
#define pgm_read_byte(a) (a)
#endif

But it was not working as expected - returning wrong bytes. After removing this macro and using buffer as array, bitmap is displayed correctly.



No comments: