void CPU_InitializeCommunication() { NATIVE_PROFILE_PAL_COM(); // STDIO can be different from the Debug Text port // do these first so we can print out messages if(COM_IsSerial(HalSystemConfig.DebugTextPort)) { USART_Initialize( ConvertCOM_ComPort(HalSystemConfig.DebugTextPort), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); } if(COM_IsSerial(HalSystemConfig.stdio)) { USART_Initialize( ConvertCOM_ComPort(HalSystemConfig.stdio), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); } if(COM_IsUsb(HalSystemConfig.DebugTextPort)) { USB_Configure( ConvertCOM_UsbController(HalSystemConfig.DebugTextPort), NULL ); USB_Initialize( ConvertCOM_UsbController(HalSystemConfig.DebugTextPort) ); USB_OpenStream( ConvertCOM_UsbStream(HalSystemConfig.DebugTextPort), USB_DEBUG_EP_WRITE, USB_DEBUG_EP_READ ); } Network_Initialize(); }
void __section("SectionForFlashOperations") Native_Profiler_WriteToCOM(void *buffer, UINT32 size) { UINT64 time1, time2; time1 = Native_Profiler_TimeInMicroseconds(); USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); // disable watchdog Watchdog_GetSetEnabled( FALSE, TRUE ); // flush existing characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); // write string char *offset = (char *) buffer; do { UINT32 bytes_written = USART_Write(ConvertCOM_ComPort(USART_DEFAULT_PORT), offset, size); offset += bytes_written; size -= bytes_written; } while(size); // flush new characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); Watchdog_GetSetEnabled( TRUE, TRUE ); time2 = Native_Profiler_TimeInMicroseconds(); s_native_profiler.initTime += (time2 - time1); }
void __section("SectionForFlashOperations") Native_Profiler_Dump() { lcd_printf("Buffer is full. Dumping...\r\n"); UINT64 time1, time2; time1 = Native_Profiler_TimeInMicroseconds(); USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); // clear_watchdog // if we do not disable the watchdog, it can be called while we dump data Watchdog_GetSetEnabled( FALSE, TRUE ); // flush existing characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); // write string char *offset = (char *)&ProfilerBufferBegin; UINT32 size = (char *)s_native_profiler.position - (char *)&ProfilerBufferBegin; do { UINT32 bytes_written = USART_Write(ConvertCOM_ComPort(USART_DEFAULT_PORT), offset, size); offset += bytes_written; size -= bytes_written; } while(size); // flush new characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); Watchdog_GetSetEnabled( TRUE, TRUE ); time2 = Native_Profiler_TimeInMicroseconds(); s_native_profiler.initTime += (time2 - time1); s_native_profiler.position = &ProfilerBufferBegin; *s_native_profiler.position++ = NATIVE_PROFILER_START_TAG; *s_native_profiler.position++ = s_native_profiler.engineTimeOffset; s_native_profiler.writtenData = FALSE; }
BOOL DebuggerPort_Initialize( COM_HANDLE ComPortNum ) { NATIVE_PROFILE_PAL_COM(); switch(ExtractTransport(ComPortNum)) { case USART_TRANSPORT: return USART_Initialize( ConvertCOM_ComPort(ComPortNum), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); case USB_TRANSPORT: if(USB_CONFIG_ERR_OK != USB_Configure( ConvertCOM_UsbController(ComPortNum), NULL )) return FALSE; if(!USB_Initialize( ConvertCOM_UsbController(ComPortNum) )) return FALSE; return USB_OpenStream( ConvertCOM_UsbStream(ComPortNum), USB_DEBUG_EP_WRITE, USB_DEBUG_EP_READ ); case SOCKET_TRANSPORT: return SOCKETS_Initialize(ConvertCOM_SockPort(ComPortNum)); } return FALSE; }
void FAULT_HandlerDisplay( UINT32 *registers, UINT32 exception ) { int i; USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), USART_DEFAULT_BAUDRATE, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); if (exception) { monitor_debug_printf("EXCEPTION 0x%02x:\r\n", exception); } else { monitor_debug_printf("ERROR:\r\n"); } monitor_debug_printf(" cpsr=0x%08x\r\n", registers[15]); monitor_debug_printf(" pc =0x%08x\r\n", registers[14]); monitor_debug_printf(" lr =0x%08x\r\n", registers[13]); monitor_debug_printf(" sp =0x%08x\r\n", registers + 16); for(i = 0; i <= 12; i++) { monitor_debug_printf(" r%02d =0x%08x\r\n", i, registers[i]); } }
int main() { pm_enable_osc0_crystal (&AVR32_PM, FOSC0); pm_enable_clk0 (&AVR32_PM, OSC0_STARTUP); pm_switch_to_clock (&AVR32_PM, AVR32_PM_MCSEL_OSC0); USART_Initialize (); usart_write_line (&AVR32_USART0, "USART initialized\n"); usart_write_line (&AVR32_USART0, "DIP204 initialized\n"); Item_Available_Count = xSemaphoreCreateCounting (Item_Buffer_Count, 0); Space_Available_Count = xSemaphoreCreateCounting (Item_Buffer_Count, Item_Buffer_Count - 1); xTaskCreate (Producer_Task_Function, "Producer", 512, NULL, tskIDLE_PRIORITY + 4, &Producer_Task_Handle); xTaskCreate (Consumer_Task_Function, "Consumer", 512, NULL, tskIDLE_PRIORITY + 4, &Consumer_Task_Handle); xTaskCreate (Blinker_Task_Function, "Blinker", 512, NULL, tskIDLE_PRIORITY + 4, NULL); vTaskStartScheduler (); }
/********************************************************************* * Function: void APP_DeviceCDCEmulatorInitialize(void); * * Overview: Initializes the demo code * * PreCondition: None * * Input: None * * Output: None * ********************************************************************/ void APP_DeviceCDCEmulatorInitialize() { CDCInitEP(); line_coding.bCharFormat = 0; line_coding.bDataBits = 8; line_coding.bParityType = 0; line_coding.dwDTERate = 19200; unsigned char i; USART_Initialize(); // Initialize the arrays for (i=0; i<sizeof(USB_Out_Buffer); i++) { USB_Out_Buffer[i] = 0; } NextUSBOut = 0; LastRS232Out = 0; lastTransmission = 0; }
/** * We are using Adafruit Ultimate GPS Breakout that you can find here. * https://www.adafruit.com/products/746 * * We are using USART2 and are connected like this. * Gps - stm32 * 3.3V - Gdd * Gnd - Gnd * RX - PA2 * TX - PA3 * * We use 3.3V instead of 5V. * */ void GPS_Initialise() { USART_Initialize(USART2,9600,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,USART_Mode_Tx | USART_Mode_Rx,USART_HardwareFlowControl_None); }
static int32_t USART1_Initialize (ARM_USART_SignalEvent_t cb_event) { return USART_Initialize (cb_event, &USART1_Resources); }
void ABORT_HandlerDisplay( UINT32 *registers_const, UINT32 sp, UINT32 lr, UINT32 pc_offset, const char *Title, BOOL SerialOutput ) { UINT32 cpsr; UINT32 pc; int i; int j; #if !defined(PLATFORM_ARM_OS_PORT) UINT8* stackbytes; const UINT32* const stackwords = (UINT32 *)sp; #endif int page; UINT32* registers; #if defined(PLATFORM_ARM_MC9328) UINT32 URXDn_X; MC9328MXL_USART& USART = MC9328MXL::USART( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); #else // TODO ??? #endif ++ABORT_recursion_counter; dump_again: page = 0; registers = registers_const; cpsr = *registers++; pc = (*registers++) - pc_offset; if(SerialOutput) { // unprotect the GPIO pins for USART, allowing USART output USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), USART_DEFAULT_BAUDRATE, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); monitor_debug_printf("ERROR: %s\r\n", Title); monitor_debug_printf(" cpsr=0x%08x\r\n", cpsr); monitor_debug_printf(" pc =0x%08x\r\n", pc); monitor_debug_printf(" lr =0x%08x\r\n", lr); for(i = 0; i <= 12; i++) { monitor_debug_printf(" r%d=0x%08x\r\n", i, registers[i]); } monitor_debug_printf(" sp =0x%08x\r\n", sp); RegisterDump(); } // don't let the screen go away if the watchdog was enabled. Watchdog_Disable(); //Flash_ChipReadOnly(TRUE); // first dump stuff to the com port, then go interactive with the buttons and LCD if(SerialOutput) { monitor_debug_printf("ERROR: %s\r\n", Title); monitor_debug_printf(" cpsr=0x%08x\r\n", cpsr); monitor_debug_printf(" pc =0x%08x\r\n", pc); monitor_debug_printf(" lr =0x%08x\r\n", lr); for(i = 0; i <= 12; i++) { monitor_debug_printf(" r%d=0x%08x\r\n", i, registers[i]); } monitor_debug_printf(" sp =0x%08x\r\n", sp); #if !defined(PLATFORM_ARM_OS_PORT) stackbytes = (UINT8 *)sp; for(i = 0; i < 16; i++) { monitor_debug_printf("[0x%08x] :", (UINT32)&stackbytes[i*16]); for(j = 0; j < 16; j++) { // don't cause a data abort here! if((UINT32) &stackbytes[i*16 + j] < (UINT32) &StackTop) { monitor_debug_printf(" %02x", stackbytes[i*16 + j]); } else { monitor_debug_printf(" "); } } monitor_debug_printf(" "); for(j = 0; j < 16; j++) { if((UINT32) &stackbytes[i*16 + j] < (UINT32) &StackTop) { monitor_debug_printf("%c", (stackbytes[i*16 + j] >= ' ') ? stackbytes[i*16 + j] : '.'); } } monitor_debug_printf("\r\n"); } #endif } //--// // make sure USART is ready to go (clock enabled, pins set active) regardless of charger state, idem potent call if it was already on CPU_ProtectCommunicationGPIOs( FALSE ); #if defined(PLATFORM_ARM_MC9328) while(USART.URXDn_X[0] & MC9328MXL_USART::URXDn__CHARRDY); #else // TODO ??? #endif //--// // go interactive with the buttons and LCD while(true) { UINT32 CurrentButtonsState; lcd_printf("\f"); switch(page) { case 0: lcd_printf("%-12s \r\n\r\n", Title); lcd_printf("Build Date:\r\n"); lcd_printf("%-12s \r\n" , __DATE__); lcd_printf("%-12s \r\n" , __TIME__); lcd_printf("\r\n"); lcd_printf("cps=0x%08x\r\n", cpsr); lcd_printf("pc =0x%08x\r\n", pc); lcd_printf("lr =0x%08x\r\n", lr); lcd_printf("sp =0x%08x\r\n", sp); break; case 1: lcd_printf("Registers 1\r\n\r\n"); for(i = 0; i < 10; i++) { lcd_printf("r%1d =0x%08x\r\n", i, registers[i]); } break; case 2: lcd_printf("Registers 2\r\n\r\n"); for(i = 10; i < 13; i++) { lcd_printf("r%2d=0x%08x\r\n", i, registers[i]); } break; case 3: default: { #if !defined(PLATFORM_ARM_OS_PORT) UINT32 index = (page-3)*10; lcd_printf("Stack %08x\r\n\r\n", (UINT32)&stackwords[index]); for(i = 0; i < 10; i++) { stackbytes = (UINT8 *)&stackwords[index+i]; // don't cause a data abort displaying past the end of the stack! if((UINT32) &stackwords[index+i] < (UINT32) &StackTop) { lcd_printf("%08x %c%c%c%c\r\n", stackwords[index+i], (stackbytes[0] >= ' ') ? stackbytes[0] : '.', (stackbytes[1] >= ' ') ? stackbytes[1] : '.', (stackbytes[2] >= ' ') ? stackbytes[2] : '.', (stackbytes[3] >= ' ') ? stackbytes[3] : '.' ); } else { lcd_printf(" \r\n"); } } #endif } break; } // wait for a button press while(0 == (CurrentButtonsState = Buttons_CurrentHWState())) { #if defined(PLATFORM_ARM_MC9328) if(USART.URXDn_X[0] & MC9328MXL_USART::URXDn__CHARRDY) { goto StartMonitorMode; } #else // TODO ??? #endif } // wait for 10 mSec HAL_Time_Sleep_MicroSeconds(10000/64); // wait for it to release while(0 == (CurrentButtonsState ^ Buttons_CurrentHWState())); // wait for 10 mSec HAL_Time_Sleep_MicroSeconds(10000/64); if(CurrentButtonsState & BUTTON_B5) { page = (page + 1); // no limit of stack pages LCD_Clear(); } if(CurrentButtonsState & BUTTON_B2) { page = (page > 0) ? page - 1 : 0; LCD_Clear(); } if((CurrentButtonsState & BUTTON_B4) || (CurrentButtonsState & BUTTON_B0)) { goto dump_again; } continue; #if defined(PLATFORM_ARM_MC9328) StartMonitorMode: #endif { char data[16]; UINT32 pos = 0; LCD_Clear(); lcd_printf("\fMONITOR MODE\r\n"); HAL_Time_Sleep_MicroSeconds(10000); while(1) { #if defined(PLATFORM_ARM_MC9328) URXDn_X = USART.URXDn_X[0]; if(URXDn_X & MC9328MXL_USART::URXDn__CHARRDY) { data[pos++] = (char)(URXDn_X & MC9328MXL_USART::URXDn__DATA_mask); #else if(false) { // TODO ??? #endif switch(data[0]) { case 'L': monitor_debug_printf("rb=0x%08x\r\n", HalSystemConfig.RAM1.Base ); monitor_debug_printf("rs=0x%08x\r\n", HalSystemConfig.RAM1.Size ); monitor_debug_printf("fb=0x%08x\r\n", HalSystemConfig.FLASH.Base); monitor_debug_printf("fs=0x%08x\r\n", HalSystemConfig.FLASH.Size); break; case 'M': if(pos < 12) continue; { UINT8* start = *(UINT8**)&data[4]; UINT8* end = *(UINT8**)&data[8]; lcd_printf( "\f\r\n\r\nREAD:\r\n %08x\r\n %08x", (UINT32)start, (UINT32)end ); if(AbortHandler_CheckMemoryRange( start, end )) { while(start < end) { monitor_debug_printf("[0x%08x]", (UINT32)start); for(j = 0; j < 128; j++) { monitor_debug_printf("%02x", *start++); if(start == end) break; } monitor_debug_printf("\r\n"); } } else { monitor_debug_printf("ERROR: invalid range: %08x-%08x\r\n", (UINT32)start, (UINT32)end ); } } break; case 'R': for(i = 0; i <= 12; i++) { monitor_debug_printf("r%d=%08x\r\n", i, registers[i]); } monitor_debug_printf("sp=%08x\r\n", sp); monitor_debug_printf("lr=%08x\r\n", lr); monitor_debug_printf("pc=%08x\r\n", pc); monitor_debug_printf("cpsr=%08x\r\n", cpsr); #if defined(PLATFORM_ARM_MC9328) monitor_debug_printf("BWA=%08x\r\n", 0); monitor_debug_printf("BWC=%08x\r\n", 0); #else // TODO ??? #endif break; case '\r': case '\n': case ' ': break; default: monitor_debug_printf("ERROR: unknown command %c\r\n", data[0] ); break; } pos = 0; } else if(Buttons_CurrentHWState()) { // wait for it to release while (Buttons_CurrentHWState()); LCD_Clear(); break; } } } } } #endif // !defined(ABORTS_REDUCESIZE) extern "C" { void UNDEF_Handler( UINT32* registers, UINT32 sp, UINT32 lr ) { ASSERT_IRQ_MUST_BE_OFF(); #if !defined(ABORTS_REDUCESIZE) Verify_RAMConstants((void *) FALSE); ABORT_HandlerDisplay(registers, sp, lr, 4, "Undef Instr", TRUE); CPU_Halt(); #else CPU_Reset(); #endif // !defined(ABORTS_REDUCESIZE) }