Hot answers tagged

21

The context of this inline no-dependency delay is missing here. But I'm assuming you need a short delay during initialization or other part of the code where it is allowed to be blocking. Your question shouldn't be how to fool GCC. You should tell GCC what you want. #pragma GCC push_options #pragma GCC optimize ("O0") for(uint i=0; i<T; i++){...


12

Use a timer if you have one available. The SysTick is very simple to configure, with documentation in the Cortex M4 User guide (or M0 if you're on the M0 part). Increment a number in its interrupt, and in your delay function you can block until the number has incremented a certain number of steps. Your part contains many timers if the systick is already in ...


10

Not to detract from other answers here, but exactly what length delay do you need? Some datasheets mention nanoseconds; others microseconds; and still others milliseconds. Nanosecond delays are usually best served by adding "time-wasting" instructions. Indeed, sometimes the very speed of the microcontroller means that the delay has been satisfied between ...


4

My answer doesn't answer the actual question but proposes a different solution. I wouldn't try to include the link to the actual ISR into the library. Instead write code which is supposed to be called by the actual ISR and let the people using your library handle the implementation of the ISR. This could also mean, that your library is no longer device ...


3

The best way is to use on-chip timers. Systick, RTC or peripheral timers. These have the advantage that the timing is precise, deterministic and can be easily adapted if CPU clock speed is changed. Optionally, you can even let the CPU sleep and use a wake-up interrupt. Dirty "busy-delay" loops on the other hand, are rarely accurate and come with various ...


1

Your vector table will always be project-specific. The correct approach is to define the ISR inside the .c file of the relevant driver handling the hardware that the ISR belongs to. If you need to expose the ISR name to the file containing the vector table, you should add a function declaration of the ISR in the .h file of the driver. For example, if you ...


1

The first expression shows a common error in embedded programming. Note that the expression PINB&(1<<PB0) has two variables, PINB and PB0. Exxentially the result of this expression will be equal to 1 << PB0 if and only if bit number PB0 in PINB is a 0. Note that the result can be equal to 0x1 only if the value of PB0 is 0, so the entire ...


Only top voted, non community-wiki answers of a minimum length are eligible