void spiTest() { int i, j; csInit (); // Initialize chip select PC03 spiInit (SPI1); for (i = 0; i < 8; i++) { for (j = 0; j < 4; j++) txbuf [j] = i*4 + j; GPIO_WriteBit (GPIOE , GPIO_Pin_3 , 0); spiReadWrite (SPI1 , rxbuf , txbuf , 4, SPI_SLOW ); GPIO_WriteBit (GPIOE , GPIO_Pin_3 , 1); for (j = 0; j < 4; j++) if (rxbuf [j] != txbuf [j]) assert_failed (__FILE__ , __LINE__ ); } for (i = 0; i < 8; i++) { for (j = 0; j < 4; j++) txbuf16 [j] = i*4 + j + (i << 8); GPIO_WriteBit (GPIOE , GPIO_Pin_3 , 0); spiReadWrite16 (SPI1 , rxbuf16 , txbuf16 , 4, SPI_SLOW ); GPIO_WriteBit (GPIOE , GPIO_Pin_3 , 1); for (j = 0; j < 4; j++) if ( rxbuf16 [j] != txbuf16 [j]) assert_failed (__FILE__ , __LINE__ ); } }
void Reset_Handler(void) { extern int main(void); extern int __libc_init_array(void); extern unsigned __data_start; /* start of .data in the linker script */ extern unsigned __data_end__; /* end of .data in the linker script */ extern unsigned const __data_load; /* initialization values for .data */ extern unsigned __bss_start__; /* start of .bss in the linker script */ extern unsigned __bss_end__; /* end of .bss in the linker script */ unsigned const *src; unsigned *dst; /* copy the data segment initializers from flash to RAM... */ src = &__data_load; for (dst = &__data_start; dst < &__data_end__; ++dst, ++src) { *dst = *src; } /* zero fill the .bss segment... */ for (dst = &__bss_start__; dst < &__bss_end__; ++dst) { *dst = 0; } /* call all static construcors in C++ (harmless in C programs) */ __libc_init_array(); /* call the application's entry point */ main(); /* in a bare-metal system main() has nothing to return to and it should * never return. Just in case main() returns, the assert_failed() gives * the last opportunity to catch this problem. */ assert_failed("startup_stm32f10x_cl", __LINE__); }
void Spurious_Handler(void) { assert_failed("startup_stm32f10x_cl", __LINE__); /* assert_failed() should not return, but just in case the following * enless loop will tie up the CPU. */ for (;;) { } }
/** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * HSE PREDIV = 1 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ static void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; #ifdef USE_FULL_ASSERT uint32_t ret = HAL_OK; #endif /* USE_FULL_ASSERT */ /* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; #ifdef USE_FULL_ASSERT ret = HAL_RCC_OscConfig(&RCC_OscInitStruct); if(ret != HAL_OK) { assert_failed((uint8_t *)__FILE__, __LINE__); } #else HAL_RCC_OscConfig(&RCC_OscInitStruct); #endif /* USE_FULL_ASSERT */ /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; #ifdef USE_FULL_ASSERT ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); if(ret != HAL_OK) { assert_failed((uint8_t *)__FILE__, __LINE__); } #else HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); #endif /* USE_FULL_ASSERT */ }
void BL_crc_deinit(void) { hcrc.Instance = CRC; // TODO: Check if next statement wil be used in future. Semaphore needed? if (!HAL_CRC_DeInit(&hcrc)) { assert_failed((uint8_t *)__FILE__, __LINE__); } }
void debug_raise_assert(const char* filename, size_t lineno, const char* what) { std::stringstream message; message << "Assertion failed in '" << filename << "', line " << lineno << ": " << what; #ifdef AR_TEST_BUILD throw assert_failed(message.str()); #else std::cerr << "\nFATAL ERROR:\n" << message.str() << "\n\n" << "This should not happen! Please file a bug-report at\n " << "https://github.com/MikkelSchubert/adapterremoval/issues/new" << std::endl; std::abort(); #endif }
/************************************************************************* * 野火嵌入式开发工作室 * * 函数名称:lptmr_counter_init * 功能说明:LPT累加捕捉 * 参数说明:LPT0_ALTn 输入管脚号 ,只能是 LPT0_ALT1、LPT0_ALT2 * count 产生中断的累加计数值 * PrescaleValue 延时滤波 * LPT_CFG 触发方式 * 函数返回:无 * 修改时间:2012-3-14 * 备 注: *************************************************************************/ void lptmr_counter_init(LPT0_ALTn altn,u16 count,u8 PrescaleValue,LPT_CFG cfg) { if(PrescaleValue > 0x0f)PrescaleValue=0x0f; //设置输入管脚 if(altn==LPT0_ALT1) { SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; //打开 PORTA 时钟 PORTA_PCR19=PORT_PCR_MUX(0x6); //在PTA19上使用 ALT6 } else if(altn==LPT0_ALT2) { SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; //使能 PORTC 时钟 PORTC_PCR5=PORT_PCR_MUX(0x4); //在PTC5上使用 ALT4 } else //不可能发生事件 { assert_failed(__FILE__, __LINE__); //设置管脚有误? } /* 开启模块时钟 */ SIM_SCGC5|=SIM_SCGC5_LPTIMER_MASK; //使能LPT模块时钟 /* 清状态寄存器 */ LPTMR0_CSR=0x00; //先关了LPT,这样才能设置时钟分频等 /* 设置累加计数值 */ LPTMR_CMR_REG(LPTMR0_BASE_PTR) = LPTMR_CMR_COMPARE(count); //设置比较值 /* 时钟选择 */ LPTMR_PSR_REG(LPTMR0_BASE_PTR) = LPTMR_PSR_PCS(0x1) | LPTMR_PSR_PBYP_MASK | LPTMR_PSR_PRESCALE(PrescaleValue); //使用 LPO clock 且 bypass glitch filter // 开启和配置脉冲滤波器:2^n个时钟上升沿才识别 /* 管脚设置、使能中断 */ LPTMR_CSR_REG(LPTMR0_BASE_PTR) = LPTMR_CSR_TPS(altn)| LPTMR_CSR_TMS_MASK | ( cfg ==LPT_Falling ? LPTMR_CSR_TPP_MASK : 0 ) | LPTMR_CSR_TEN_MASK | LPTMR_CSR_TIE_MASK ; // 选择输入管脚 选择脉冲计数 下降沿 上升沿 使能LPT // TFC = 0,即计数值等于比较值时,计数值复位 enable_irq(LPTMR_irq); //开引脚的IRQ中断 }
void* _sbrk (int incr) { #ifdef DATA_IN_ExtSRAM static char *heap_end = (char*)0x68000000; #else static char *heap_end=&end; /* Defined by the linker */ #endif char *prev_heap_end; prev_heap_end = heap_end; #ifdef DATA_IN_ExtSRAM if ( incr >= (EXTERNAL_RAM_SIZE*1024)) #else if (heap_end + incr > __get_MSP()) #endif { assert_failed(__FILE__,__LINE__); } heap_end += incr; return (void *) prev_heap_end; }
void assertion_failed(const char* file, unsigned line) { assert_failed((uint8_t*)file, line); }
/*..........................................................................*/ void Q_onAssert(char const Q_ROM * const file, int line) { assert_failed(file, line); }
void assert_failed(uint8_t* location, uint32_t line){ assert_failed("Assertion Failed", (const char*)location, line); }
/* Described at the top of this file. */ void BluetoothModemTask( void *pvParameters ) { char cChar; /* Just to avoid compiler warnings. */ ( void ) pvParameters; /* Initialise COM0, which is USART1 according to the STM32 libraries. */ lCOMPortInit( comBTM, mainBAUD_RATE ); /* Reset BTM */ #if 0 GPIO_ResetBits(BTM_Reset_Port, BTM_Reset_Pin); vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS ); GPIO_SetBits(BTM_Reset_Port, BTM_Reset_Pin); #endif // do { } while (1); // const char *atEscape = "^^^"; const char *atEscapeChar = "^"; const char *atEOL = "\r"; const char *atTest = "AT\r"; // after-reset condition: give the BT module some time to init itself. vTaskDelay( ( TickType_t ) 1000 / portTICK_PERIOD_MS ); do { #if 1 // Before the escape sequence there must be silence for 1s vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); // After the escape sequence there must be silence for 1s vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS ); #endif LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_100, LED_INTENS_0); // Send end of line lSerialPutString( comBTM, atEOL, strlen(atEOL) ); // wait a little bit vTaskDelay( ( TickType_t ) 100 / portTICK_PERIOD_MS ); // empty input buffer usartDrainInput(comBTM); /* this drains possible 'ERROR 05' status */ // vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS ); // Send plain AT lSerialPutString( comBTM, atTest, strlen(atTest) ); // vTaskDelay( ( TickType_t ) 20 / portTICK_PERIOD_MS ); // expect "OK\r\n" } while (btmExpectOK()); LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_0, LED_INTENS_100); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 /*| GPIO_Pin_1*/; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init( GPIOA, &GPIO_InitStruct ); do { } while (1); // disable local echo const char *atDisableEcho = "ATE0\r"; lSerialPutString( comBTM, atDisableEcho, strlen(atDisableEcho) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atSetDeviceName = "AT*agln=\"PIP-Watch\",0\r\n"; lSerialPutString( comBTM, atSetDeviceName, strlen(atSetDeviceName) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atSetPin = "AT*agfp=\"1234\",0\r"; lSerialPutString( comBTM, atSetPin, strlen(atSetPin) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atToDataMode = "AT*addm\r"; lSerialPutString( comBTM, atToDataMode, strlen(atToDataMode) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } /* Try sending out a string all in one go, as a very basic test of the lSerialPutString() function. */ // lSerialPutString( comBTM, pcLongishString, strlen( pcLongishString ) ); int k = 0; char *buf = NULL; for( ;; ) { /* Block to wait for a character to be received on COM0. */ xSerialGetChar( comBTM, &cChar, portMAX_DELAY ); /* Write the received character back to COM0. */ xSerialPutChar( comBTM, cChar, 0 ); if (!buf) { buf = pvPortMalloc(sizeof(char) * 32); #if 0 /* start ADC conversion by software */ // ADC_ClearFlag(ADC1, ADC_FLAG_EOC); ADC_ClearFlag(ADC1, ADC_FLAG_STRT); ADC_Cmd(ADC1, ENABLE); #if 0 ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* wait till the conversion starts */ while (ADC_GetSoftwareStartConvStatus(ADC1) != RESET) { } #endif /* wait till the conversion ends */ while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != SET) { } #endif k = 0; // k = itostr(buf, 32, RTC_GetCounter()); // k = itostr(buf, 32, ADC_GetConversionValue(ADC1)); // k = itostr(buf, 32, vbat_measured); // k = itostr(buf, 32, vbat_percent); // ADC_ClearFlag(ADC1, ADC_FLAG_EOC); } buf[k++] = cChar; if (cChar == '\r' || k >= 30) { buf[k] = '\0'; for (int i = 0; i < k-4; ++i) { if (buf[i] == '*') { /* set time: *<hours><minutes> */ int hours = (buf[i+1]-'0')*10 + (buf[i+2]-'0'); int minutes = (buf[i+3]-'0')*10 + (buf[i+4]-'0'); hours %= 24; minutes %= 60; current_rtime.sec = 0; current_rtime.hour = hours; current_rtime.min = minutes; break; } } if (xQueueSend(toDisplayStrQueue, &buf, 0) == pdTRUE) { // ok; will alloc new buffer buf = NULL; } else { // fail; ignore, keep buffer } // motor demo GPIO_SetBits(GPIOB, 1 << 13); vTaskDelay( ( TickType_t ) 300 / portTICK_PERIOD_MS ); GPIO_ResetBits(GPIOB, 1 << 13); k = 0; xSerialPutChar( comBTM, '\n', 0 ); } } }