///////////////////////////////////////////////////////////////////////////// // Customized HardFault Handler which prints out debugging informations ///////////////////////////////////////////////////////////////////////////// void HardFault_Handler_c(unsigned int * hardfault_args) { // from the book: "The definiteve guide to the ARM Cortex-M3" volatile unsigned int stacked_r0; volatile unsigned int stacked_r1; volatile unsigned int stacked_r2; volatile unsigned int stacked_r3; volatile unsigned int stacked_r12; volatile unsigned int stacked_lr; volatile unsigned int stacked_pc; volatile unsigned int stacked_psr; stacked_r0 = ((unsigned long) hardfault_args[0]); stacked_r1 = ((unsigned long) hardfault_args[1]); stacked_r2 = ((unsigned long) hardfault_args[2]); stacked_r3 = ((unsigned long) hardfault_args[3]); stacked_r12 = ((unsigned long) hardfault_args[4]); stacked_lr = ((unsigned long) hardfault_args[5]); stacked_pc = ((unsigned long) hardfault_args[6]); stacked_psr = ((unsigned long) hardfault_args[7]); MIOS32_MIDI_SendDebugMessage("Hard Fault PC = %08x\n", stacked_pc); // ensure that at least the PC will be sent MIOS32_MIDI_SendDebugMessage("==================\n"); MIOS32_MIDI_SendDebugMessage("!!! HARD FAULT !!!\n"); MIOS32_MIDI_SendDebugMessage("==================\n"); MIOS32_MIDI_SendDebugMessage("R0 = %08x\n", stacked_r0); MIOS32_MIDI_SendDebugMessage("R1 = %08x\n", stacked_r1); MIOS32_MIDI_SendDebugMessage("R2 = %08x\n", stacked_r2); MIOS32_MIDI_SendDebugMessage("R3 = %08x\n", stacked_r3); MIOS32_MIDI_SendDebugMessage("R12 = %08x\n", stacked_r12); MIOS32_MIDI_SendDebugMessage("LR = %08x\n", stacked_lr); MIOS32_MIDI_SendDebugMessage("PC = %08x\n", stacked_pc); MIOS32_MIDI_SendDebugMessage("PSR = %08x\n", stacked_psr); MIOS32_MIDI_SendDebugMessage("BFAR = %08x\n", (*((volatile unsigned long *)(0xE000ED38)))); MIOS32_MIDI_SendDebugMessage("CFSR = %08x\n", (*((volatile unsigned long *)(0xE000ED28)))); MIOS32_MIDI_SendDebugMessage("HFSR = %08x\n", (*((volatile unsigned long *)(0xE000ED2C)))); MIOS32_MIDI_SendDebugMessage("DFSR = %08x\n", (*((volatile unsigned long *)(0xE000ED30)))); MIOS32_MIDI_SendDebugMessage("AFSR = %08x\n", (*((volatile unsigned long *)(0xE000ED3C)))); #ifndef MIOS32_DONT_USE_LCD // TODO: here we should select the normal font - but only if available! // MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); MIOS32_LCD_DeviceSet(0); MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("!! HARD FAULT !!"); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintFormattedString("at PC=0x%08x", stacked_pc); #endif _abort(); }
void vApplicationStackOverflowHook(xTaskHandle xTask, signed portCHAR *pcTaskName) { MIOS32_MIDI_SendDebugMessage("======================\n"); MIOS32_MIDI_SendDebugMessage("!!! STACK OVERFLOW !!!\n"); MIOS32_MIDI_SendDebugMessage("======================\n"); MIOS32_MIDI_SendDebugMessage("Function: %s\n", pcTaskName); #ifndef MIOS32_DONT_USE_LCD // TODO: here we should select the normal font - but only if available! // MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); MIOS32_LCD_DeviceSet(0); MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("!! STACK OVERFLOW !!"); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintFormattedString("in Task %s", pcTaskName); #endif _abort(); }
///////////////////////////////////////////////////////////////////////////// // _exit() for newer newlib versions ///////////////////////////////////////////////////////////////////////////// void exit(int par) { #ifndef MIOS32_DONT_USE_LCD // TODO: here we should select the normal font - but only if available! // MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); MIOS32_LCD_DeviceSet(0); MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("Goodbye!"); #endif #ifndef MIOS32_DONT_USE_MIDI // Note: message won't be sent if MIDI task cannot be created! MIOS32_MIDI_SendDebugMessage("Goodbye!\n"); #endif // pro forma: since this is a noreturn function, loop endless and call _abort (which will never exit) while( 1 ) _abort(); }
///////////////////////////////////////////////////////////////////////////// // enabled in FreeRTOSConfig.h ///////////////////////////////////////////////////////////////////////////// void vApplicationMallocFailedHook(void) { #ifndef MIOS32_DONT_USE_LCD // TODO: here we should select the normal font - but only if available! // MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); MIOS32_LCD_DeviceSet(0); MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("FATAL: FreeRTOS "); // 16 chars MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintString("Malloc Error!!! "); // 16 chars #endif #ifndef MIOS32_DONT_USE_MIDI // Note: message won't be sent if MIDI task cannot be created! MIOS32_MIDI_SendDebugMessage("FATAL: FreeRTOS Malloc Error!!!\n"); #endif _abort(); }
///////////////////////////////////////////////////////////////////////////// // Initializes application specific LCD driver // IN: <mode>: optional configuration // OUT: returns < 0 if initialisation failed ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Init(u32 mode) { GPIO_InitTypeDef GPIO_InitStructure; s32 delay; // set LCD type mios32_lcd_parameters.lcd_type = MIOS32_LCD_TYPE_GLCD_CUSTOM; // set initial font and colours MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); // control lines PIN_BL(1); PIN_RS(1); PIN_RD(1); PIN_CS(1); PIN_WR(1); PIN_RST(1); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = APP_LCD_BL_PIN; GPIO_Init(APP_LCD_BL_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_RS_PIN; GPIO_Init(APP_LCD_RS_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_RD_PIN; GPIO_Init(APP_LCD_RD_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_WR_PIN; GPIO_Init(APP_LCD_WR_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_CS_PIN; GPIO_Init(APP_LCD_CS_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_RST_PIN; GPIO_Init(APP_LCD_RST_PORT, &GPIO_InitStructure); // Apply hardware reset PIN_RST(0); for(delay=0; delay<0x500; ++delay); PIN_RST(1); for(delay=0; delay<0x500; ++delay); // configure data pins as outputs GPIO_InitStructure.GPIO_Pin = APP_LCD_D_PINS; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(APP_LCD_D_PORT, &GPIO_InitStructure); //----------- software reset ------------------------------------------------ APP_LCD_Cmd(ST7637_SWRESET); //----------- disable autoread + Manual read once --------------------------- APP_LCD_Cmd( ST7637_AUTOLOADSET ); // Auto Load Set 0xD7 APP_LCD_Data( 0xBF ); // Auto Load Disable APP_LCD_Cmd( ST7637_EPCTIN ); // EE Read/write mode 0xE0 APP_LCD_Data( 0x00 ); // Set read mode APP_LCD_Cmd( ST7637_EPMRD ); // Read active 0xE3 APP_LCD_Cmd( ST7637_EPCTOUT ); // Cancel control 0xE1 //---------------------------------- Sleep OUT ------------------------------ APP_LCD_Cmd( ST7637_DISPOFF ); // display off 0x28 APP_LCD_Cmd( ST7637_SLPOUT ); // Sleep Out 0x11 //--------------------------------Vop setting-------------------------------- APP_LCD_Cmd( ST7637_VOPSET ); // Set Vop by initial Module 0xC0 APP_LCD_Data( 0xFB ); // Vop = 13.64 APP_LCD_Data( 0x00 ); // base on Module //----------------------------Set Register----------------------------------- APP_LCD_Cmd( ST7637_BIASSEL ); // Bias select 0xC3 APP_LCD_Data( 0x00 ); // 1/12 Bias, base on Module APP_LCD_Cmd( ST7637_BSTBMPXSEL ); // Setting Booster times 0xC4 APP_LCD_Data( 0x05 ); // Booster X 8 APP_LCD_Cmd( ST7637_BSTEFFSEL ); // Booster eff 0xC5 APP_LCD_Data( 0x11 ); // BE = 0x01 (Level 2) APP_LCD_Cmd( ST7637_VGSORCSEL ); // Vg with booster x2 control 0xcb APP_LCD_Data( 0x01 ); // Vg from Vdd2 APP_LCD_Cmd( ST7637_ID1SET ); // ID1 = 00 0xcc APP_LCD_Data( 0x00 ); // APP_LCD_Cmd( ST7637_ID3SET ); // ID3 = 00 0xce APP_LCD_Data( 0x00 ); // APP_LCD_Cmd( ST7637_COMSCANDIR ); // Glass direction APP_LCD_Data( 0xC0 ); // APP_LCD_Cmd( ST7637_ANASET ); // Analog circuit setting 0xd0 APP_LCD_Data( 0x1D ); // APP_LCD_Cmd( ST7637_PTLMOD ); // PTL mode set APP_LCD_Data( 0x18 ); // power normal mode APP_LCD_Cmd( ST7637_INVOFF ); // Display Inversion OFF 0x20 APP_LCD_Cmd( ST7637_CASET ); // column range APP_LCD_Data( 0x04 ); // APP_LCD_Data( 0x83 ); // APP_LCD_Cmd( ST7637_RASET ); // raw range APP_LCD_Data( 0x04 ); // APP_LCD_Data( 0x83 ); // APP_LCD_Cmd( ST7637_COLMOD ); // Color mode = 65k 0x3A APP_LCD_Data( 0x05 ); // APP_LCD_Cmd( ST7637_MADCTR ); // Memory Access Control 0x36 APP_LCD_Data( V12_MADCTRVAL ); APP_LCD_Cmd( ST7637_DUTYSET ); // Duty = 132 duty 0xb0 APP_LCD_Data( 0x7F ); APP_LCD_Cmd( ST7637_DISPON ); // Display ON APP_LCD_Cmd( ST7637_FRAMESET ); // Gamma APP_LCD_Data( 0x00 ); // APP_LCD_Data( 0x03 ); // APP_LCD_Data( 0x05 ); // APP_LCD_Data( 0x07 ); // APP_LCD_Data( 0x09 ); // APP_LCD_Data( 0x0B ); // APP_LCD_Data( 0x0D ); // APP_LCD_Data( 0x0F ); // APP_LCD_Data( 0x11 ); // APP_LCD_Data( 0x13 ); // APP_LCD_Data( 0x15 ); // APP_LCD_Data( 0x17 ); // APP_LCD_Data( 0x19 ); // APP_LCD_Data( 0x1B ); // APP_LCD_Data( 0x1D ); // APP_LCD_Data( 0x1F ); // return 0; // no error }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // print static screen MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0x000000); MIOS32_LCD_FColourSet(0xffffff); // clear LCD MIOS32_LCD_Clear(); // print text MIOS32_LCD_CursorSet(3, 3); MIOS32_LCD_PrintString("ST7637 LCD"); MIOS32_LCD_CursorSet(7, 5); MIOS32_LCD_PrintString("powered by"); // endless loop: print animations u8 mios_r = 0; u8 mios_g = 0; u8 mios_b = 0; u8 dir = 1; u8 knob_icon_ctr[4] = {0, 3, 6, 9}; // memo: 12 icons u8 knob_icon_delay_ctr[4] = {0, 2, 4, 6}; const u8 knob_icon_x[4] = {0, 100, 0, 100}; // memo: icon width 28 const u8 knob_icon_y[4] = {0, 0, 104, 104}; // memo: icon height 24 u8 vmeter_icon_ctr[2] = {0, 5}; // memo: 28 icons (14 used) u8 vmeter_icon_dir[2] = {1, 1}; u8 vmeter_icon_delay_ctr[2] = {1, 4}; const u8 vmeter_icon_x[2] = {0, 120}; // memo: icon width 8 const u8 vmeter_icon_y[2] = {48, 48}; // memo: icon height 32 u8 hmeter_icon_ctr[2] = {6, 11}; // memo: 28 icons (14 used) u8 hmeter_icon_dir[2] = {1, 0}; u8 hmeter_icon_delay_ctr[2] = {4, 2}; const u8 hmeter_icon_x[2] = {50, 50}; // memo: icon width 28 const u8 hmeter_icon_y[2] = {0, 120}; // memo: icon height 8 while( 1 ) { s32 i; // toggle the state of all LEDs (allows to measure the execution speed with a scope) MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get()); // colour-cycle "MIOS32" up and down :-) // ST7637 supports 5bit r, 6bit g and 5bit b if( dir ) { if( mios_r < 0x1f ) ++mios_r; else if( mios_g < 0x3f ) ++mios_g; else if( mios_b < 0x1f ) ++mios_b; else dir = 0; } else { if( mios_r > 0x00 ) --mios_r; else if( mios_g > 0x00 ) --mios_g; else if( mios_b > 0x00 ) --mios_b; else dir = 1; } // set new colour MIOS32_LCD_FColourSet((mios_r << 16) | (mios_g << 8) | mios_b); // print "MIOS32" MIOS32_LCD_FontInit((u8 *)GLCD_FONT_BIG); MIOS32_LCD_GCursorSet(16, 52); MIOS32_LCD_PrintString("MIOS32"); // icons with different colour MIOS32_LCD_FColourSet(((dir?mios_r:~mios_r) << 16) | (~mios_g << 8) | (dir?mios_b:~mios_b)); // print turning Knob icons at all edges MIOS32_LCD_FontInit((u8 *)GLCD_FONT_KNOB_ICONS); // memo: 12 icons, icon size: 28x24 for(i=0; i<4; ++i) { if( ++knob_icon_delay_ctr[i] > 10 ) { knob_icon_delay_ctr[i] = 0; if( ++knob_icon_ctr[i] >= 12 ) knob_icon_ctr[i] = 0; } MIOS32_LCD_GCursorSet(knob_icon_x[i], knob_icon_y[i]); MIOS32_LCD_PrintChar(knob_icon_ctr[i]); } // print vmeter icons MIOS32_LCD_FontInit((u8 *)GLCD_FONT_METER_ICONS_V); // memo: 28 icons, 14 used, icon size: 8x32 for(i=0; i<2; ++i) { if( ++vmeter_icon_delay_ctr[i] > 5 ) { vmeter_icon_delay_ctr[i] = 0; if( vmeter_icon_dir[i] ) { if( ++vmeter_icon_ctr[i] >= 13 ) vmeter_icon_dir[i] = 0; } else { if( --vmeter_icon_ctr[i] < 1 ) vmeter_icon_dir[i] = 1; } } MIOS32_LCD_GCursorSet(vmeter_icon_x[i], vmeter_icon_y[i]); MIOS32_LCD_PrintChar(vmeter_icon_ctr[i]); } // print hmeter icons MIOS32_LCD_FontInit((u8 *)GLCD_FONT_METER_ICONS_H); // memo: 28 icons, 14 used, icon size: 28x8 for(i=0; i<2; ++i) { if( ++hmeter_icon_delay_ctr[i] > 7 ) { hmeter_icon_delay_ctr[i] = 0; if( hmeter_icon_dir[i] ) { if( ++hmeter_icon_ctr[i] >= 13 ) hmeter_icon_dir[i] = 0; } else { if( --hmeter_icon_ctr[i] < 1 ) hmeter_icon_dir[i] = 1; } } MIOS32_LCD_GCursorSet(hmeter_icon_x[i], hmeter_icon_y[i]); MIOS32_LCD_PrintChar(hmeter_icon_ctr[i]); } } }