On 13/03/17 11:44, Karl Palsson wrote: > Matthew Lai <m...@matthewlai.ca> wrote: >> Oops, looks like I only replied to Chuck. >> >> -------------------------------------------------------------------------- >> >> When compiling with optimizations, I would expect >> rcc_periph_clock_enable() to be inlined even at -Os since >> function body (one instruction after constant propagation) is >> smaller than the code to call the function. > except it probably won't, because it's not static, and not marked > inline. It might get inlined if you use LTO, but I wouldn't rely > on it. > > eg > > ``` > rcc_periph_clock_enable(RCC_TIM6); > 80008bc: f240 4084 movw r0, #1156 ; 0x484 > 80008c0: f001 ffeb bl 800289a <rcc_periph_clock_enable> > rcc_periph_clock_enable(RCC_TIM7); > 80008c4: f240 4085 movw r0, #1157 ; 0x485 > 80008c8: f001 ffe7 bl 800289a <rcc_periph_clock_enable> > ``` For things like fast GPIO toggling, turning on LTO is the easiest way to get the same performance as writing to registers directly, without having to change the code at all. >> Peripherals on APB would also need more cycles. >> >> >> Try to break it. You know the conditions try to create them. >> >> I suspect it's not so easy to reproduce - otherwise we would be >> seeing many more bug reports. >> >> It may only happen for some peripherals when the peripheral and >> the CPU are in specific states. >> >> I don't think trying to break it would really be useful - a >> positive result means we need to fix it, and a negative result >> still doesn't mean we don't have to worry about it. >> > > I would ignore it. There's very few places where it will really matter, and > the people who will need it, will be handling it themselves anyway, not using > high level helper functions. It would mean things like: rcc_periph_clock_enable(RCC_TIM3); timer_set_period(TIM3, 1024);
Would violate this, at high prescalar settings (or low prescalar settings with LTO). That is actually the example given here: https://github.com/libopencm3/libopencm3/blob/master/lib/stm32/common/timer_common_all.c#L70 It would be a potential source of very difficult to find bugs. Since I imagine rcc_periph_clock_enable() to not be performance-critical in most applications, wouldn't adding the wait states be better default behaviour, and people who really need to enable clocks very quickly can go to registers directly? Thanks Matthew ------------------------------------------------------------------------------ Announcing the Oxford Dictionaries API! The API offers world-renowned dictionary content that is easy and intuitive to access. Sign up for an account today to start using our lexical data to power your apps and projects. Get started today and enter our developer competition. http://sdm.link/oxford _______________________________________________ libopencm3-devel mailing list libopencm3-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libopencm3-devel