DengQilong
获得 9 次赞
帮助过57人
书上说:C run-time library里面含有初始化代码,还有错误处理代码(例如divide by zero处理)。你写的程序可以没有math库,程序照样运行,只是不能处理复杂的数学运算,不过如果没有了C run-time库,main()就不会被调用,exit()也不能被响应。因为C run-time library包含了C程序运行的最基本和最常用的函数。但是没有给出如何调用main的流程,有达人知道哪里有源码可以学习下吗
有时候程序需要让CPU死等一会,一般用定时器或者systick定时器可以实现精确的微秒级延时,但是那样白白占用了定时器,太浪费资源了,且在有os的系统,systick多用于系统心跳。最近网上看到国外高人使用了这样的延时函数:rt_err_t rt_hw_delay_init(void) { #if !defined(STM32F0xx) uint32_t c; /* Enable TRC */ CoreDebug->DEMCR &= ~0x01000000; CoreDebug->DEMCR |= 0x01000000; /* Enable counter */ DWT->CTRL &= ~0x00000001; DWT->CTRL |= 0x00000001; /* Reset counter */ DWT->CYCCNT = 0; /* Check if DWT has started */ c = DWT->CYCCNT; /* 2 dummys */ __ASM volatile ("NOP"); __ASM volatile ("NOP"); /* if result is zero, DWT has not started */ if (DWT->CYCCNT - c == 0) return RT_ERROR; #else /* Return OK */ return RT_EOK; #endif } void rt_delay_us(__IO uint32_t micros) { #if !defined(STM32F0xx) uint32_t start = DWT->CYCCNT; /* Go to number of cycles for system */ micros *= (HAL_RCC_GetHCLKFreq() / 1000000); /* Delay till end */ while ((DWT->CYCCNT - start) < micros); #else /* Go to clock cycles */ micros *= (SystemCoreClock / 1000000) / 5; /* Wait till done */ while (micros--); #endif } void rt_delay_ms(__IO uint32_t millis) { rt_delay_us(millis*1000); } 有点看不明白,是什么原理,为什么STM32F0就不能用