Closed jcassette closed 3 years ago
I was able to flash this project: bluepill_blink.zip It blinks the LED on the BluePill but very slowly My delay is surely inaccurate or maybe the clock is setup incorrectly RTS: zfp-stm32f103.zip
Hello @jcassette, thanks for you contribution.
The delay has to be accurate before we can merge this PR. You can check the values of clock constants and clock setup.
I have made a new busy wait in assembly but it is still too slow I reviewed the clock setup compared to the reference manual but for me it is ok I could use some help, maybe from @morbos ?
@jcassette I have some experience with similar STM32s so I thought I'd take a look in case I can help out. I looked at your clock setup code and noticed some things which might be causing problems:
s-bbmcpa.ads
defines PWR_Initialize
, PWR_Overdrive_Enable
, and Is_PWR_Stabilized
. As far as I can tell these are not relevant for the F1 series. I think these functions could be deleted.arm/stm32f1/i-stm32-pwr.ads
has been generated from the STM32F40x SVD file which is not compatible with the F1. For example, PWR_Initialize
writes to PWR_Periph.CR.VOS
, but the VOS
field does not exist on the F10x series. So your code is actually writing to a reserved field; it's best not to do that :)The clock setup code otherwise looks OK to me. As far as I can tell the registers are being configured correctly to generate a 72 MHz system clock.
I looked at your bluepill_blink example and I can see that you are trying to busy loop for 1 second. But beware that the compiler will generate code that takes multiple cycles per loop iteration! So I would expect each loop to take several seconds to run, which isn't what you want.
You could try using the Ravenscar runtime features to perform a proper timed delay. Try running this example:
with Ada.Real_Time; use Ada.Real_Time;
with Interfaces.STM32.RCC; use Interfaces.STM32.RCC;
with Interfaces.STM32.GPIO; use Interfaces.STM32.GPIO;
procedure Main is
Period : constant Time_Span := Seconds (1);
Next : Time;
begin
-- Enable clock for GPIO C
RCC_Periph.APB2ENR.IOPCEN := 1;
-- Configure PC13
GPIOC_Periph.CRH.Val := 16#00100000#;
-- Blink the LED
Next := Clock;
loop
-- Set PC13 low for 1 second
GPIOC_Periph.BSRR.BR.Val := 16#2000#;
Next := Next + Period;
delay until Next;
-- Set PC13 high for 1 second
GPIOC_Periph.BSRR.BS.Val := 16#2000#;
Next := Next + Period;
delay until Next;
end loop;
end Main;
You will need to build the example with either the ravenscar-sfp or ravenscar-full version of your runtime.
Note: I haven't tried compiling or running this code, but I think I got it right.
Hi @damaki and thank you for helping out :-)
I have pushed some changes to update the SVD and remove unused code, but without luck
I have also removed some startup code which seemed to be for Cortex M4
I am afraid I have no support for Ravenscar at the moment
This is the project with the modified busy wait: bluepill_blink.zip
You can see that the loop is 2 instructions long only with arm-eabi-objdump -d -S main
@Fabien-Chouteau please can you reopen the PR so that we can see the updates ?
@jcassette let us know when the BSP is fully working an we will be able to review it.
Hello @Fabien-Chouteau Are you still interested in this PR and can you review it? The BSP is working, it was only my test program which was incorrect zfp-stm32f103.zip bluepill_blink.zip
Hello @jcassette, Did you see this blog post about our new solution for micro-controller run-times? https://blog.adacore.com/ada-on-any-arm-cortex-m-device-in-just-a-couple-minutes
If you only need a ZFP run-time, this is a better option than doing the BSP here.
Hello This is the BSP from @morbos See https://github.com/morbos/embedded-runtimes/commit/26b9b4378bb2db98459dbdfe23dd5d303e2e6d00 I might test it on a Blue Pill if I have some time