/*************************************************************************** * Copyright (C) 2020 - 2022 by Silvano Seva IU2KWO * * and Niccolò Izzo IU2KIN * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see * ***************************************************************************/ #include #include /** * Implementation of the delay functions for STM32F405 MCU. */ void delayUs(unsigned int useconds) { // This delay has been calibrated to take x microseconds // It is written in assembler to be independent on compiler optimization asm volatile(" mov r1, #42 \n" " mul r2, %0, r1 \n" " mov r1, #0 \n" "___loop_u: cmp r1, r2 \n" " itt lo \n" " addlo r1, r1, #1 \n" " blo ___loop_u \n"::"r"(useconds):"r1","r2"); } void delayMs(unsigned int mseconds) { register const unsigned int count=42000; for(unsigned int i=0;i