可以用这个,168改成你需要的频率
void udelay(uint32_t time_us){
__attribute__((aligned(16)))
static const uint16_t delay_machine_code[] = {
0x3800 + 3, // SUBS r0, #loop_cycles
0xd8fd, // BHI .-2
0x4770 // BX LR
};
typedef void (* delay_func_t)(uint32_t);
const delay_func_t delay_cycles =
// Set LSB to 1 to execute the code in the Thumb mode.
(delay_func_t)((((uint32_t)delay_machine_code) | 1));
uint32_t cycles = time_us * 168;
delay_cycles(cycles);
}
|