AdaCore / Ada_Drivers_Library

Ada source code and complete sample GNAT projects for selected bare-board platforms supported by GNAT.
BSD 3-Clause "New" or "Revised" License
240 stars 141 forks source link

Add BlueNRG-MS driver for the STM32F4 #143

Closed johnleimon closed 7 years ago

johnleimon commented 7 years ago

The BlueNRG-MS is a Bluetooth Low Energy (BLE) Network Processor supporting Bluetooth 4.1 core specification.

johnleimon commented 7 years ago

Fabien,

I used the STM32F4 LED demo template from GPS as a basis for my project. I modified the project files from there.

How would you recommend imposing delays without using Ada.Real_Time?

Thanks, John

On Sun, Feb 12, 2017 at 2:34 PM, Fabien Chouteau notifications@github.com wrote:

@Fabien-Chouteau requested changes on this pull request.

The packages in the Components library have to be hardware agnostic so we they can be reused on any micro-controller. It's not the case with your driver because you have dependency on STM32 packages as well as Ada.Real_Time. As a result, you patches break the builds for other platforms as you can see in the continuous builder: https://travis-ci.org/AdaCore/Ada_Drivers_Library/builds/200763919

(The script always exit with a zero value, so the failure is not detected by travis-ci. I will fix this)

I started to document the design here https://github.com/AdaCore/Ada_Drivers_Library/blob/master/docs/design.md. Please, don't hesitate to ask question or comment on this document.

To make your driver portable, you have to use the interfaces defined in the HAL. You can find an example of a SPI component here https://github.com/AdaCore/Ada_Drivers_Library/blob/master/components/src/screen/ST7735R/st7735r.ads. And how to instantiate it here https://github.com/AdaCore/Ada_Drivers_Library/blob/master/boards/OpenMV2/src/openmv-lcd_shield.adb. By using a the same design you will be able to lift the dependency on STM32 specific packages. Again, don't hesitate to ask questions :)

You can also see in the build logs that there's a good amount of style issues. There are automatically checked by the compiler if you use the right options. Are you using your own projects, or are you relying on the ones we provide in the library?

Thanks,

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AdaCore/Ada_Drivers_Library/pull/143#pullrequestreview-21416912, or mute the thread https://github.com/notifications/unsubscribe-auth/ACvZjPkc9tvjDnD_hyTf7EczygW05efIks5rb2zEgaJpZM4L-Vn4 .

Fabien-Chouteau commented 7 years ago

I used the STM32F4 LED demo template from GPS as a basis for my project. I modified the project files from there.

I would recommend to start from a project of Ada_Drivers_Library, "examples/accelerometer" is a good one. You first copy the directory in your project and then change the path in "accelerometer.gpr" to point to the Ada_Drivers_Library.

How would you recommend imposing delays without using Ada.Real_Time?

The solution we have right now - which is not far from satisfactory but it works - is to use an HAL.Time.Any_Delays interface. You can see an example of that in the ST7735R.

Since you are using Ravenscar, the Delays interface will be provided by the Ravenscar_Time package. Here's how to use it:

with Ravenscar_Time;

package body OpenMV.LCD_Shield is
   [...]
   LCD_Driver : ST7735R_RAM_Framebuffer_Device (Shield_SPI'Access,
                                                LCD_CS'Access,
                                                LCD_RS'Access,
                                                LCD_RST'Access,
                                                Ravenscar_Time.Delays) --  < Using Ravenscar delays here;
johnleimon commented 7 years ago

You first copy the directory in your project...

Should I copy my project's source code files to the examples/accelerometer directory, or should I copy the examples/accelerometer directory outside of the Ada_Drivers_Library directory (e.g. Desktop)?

...then change the path in "accelerometer.gpr" to point to the Ada_Drivers_Library.

Which path in accelerometer.gpr are you referring to? The only paths that look modifiable are:

with "../../boards/stm32f407_discovery.gpr and project Accelerometer extends "../common/common.gpr

Fabien-Chouteau commented 7 years ago

Should I copy my project's source code files to the examples/accelerometer directory, or should I copy the examples/accelerometer directory outside of the Ada_Drivers_Library directory (e.g. Desktop)? Both will work, but I would recommend copying outside of Ada_Drivers_Library so you can control what goes in which project.

...then change the path in "accelerometer.gpr" to point to the Ada_Drivers_Library.

Which path in accelerometer.gpr are you referring to? The only paths that look modifiable are:

with "../../boards/stm32f407_discovery.gpr and project Accelerometer extends "../common/common.gpr

Yes, I'm talking about those two paths. Since you are copying the project, those two relative paths have to be changed.

johnleimon commented 7 years ago

I've copied the accelerometer directory to a path outside of the ada_drivers_library directory and I've modified the two lines to point to the ada_drivers_library:

with "../ada_drivers_library/boards/stm32f407_discovery.gpr";

project Accelerometer extends "../ada_drivers_library/examples/common/common.gpr"

When I try to build the modified accelerometer project with GPS, GPS displays the message:

[2017-02-14 13:43:46] variable"rts" is not a single string variable

When I build it with gprbuild on the command line, I get the following output:

/Desktop/accelerometer $ gprbuild using project file accelerometer.gpr variable"rts" is not a single string variable gprbuild: raised PROGRAM_ERROR : gpr-proc.adb:2403 explicit raise Call stack traceback locations: 0x5873ce 0x587fdc 0x588b7a 0x587ece 0x588b7a 0x587ece 0x58799e 0x5886a5 0x588b7a 0x587ece 0x58799e 0x57cf86 0x411830 0x40c1e5 0x7f6c623c9ec3 0x40c23f

Additionally, after loading the accelerometer.gpr in GPS the Project view does not show any source files (e.g. main.adb).

Software Versions: gprbuild: GPRBUILD GPL 2016 (20160515) (x86_64-pc-linux-gnu) GPS: (20160515) hosted on x86_64-pc-linux-gnu GNAT GPL 2016 (20160515-49)

Fabien-Chouteau commented 7 years ago

This looks like a problem in the paths. There's something shady with the run-time.

Don't get stuck on this issue and forget what I said, start by modifying the example inside the Ada_Drivers_Library if it's easier.

johnleimon commented 7 years ago

Is there a method to compare two Time variables without using Ada.Real_Time? I have a case where I want to continue executing a Read operation until a certain timeout is reached.

Fabien-Chouteau commented 7 years ago

s there a method to compare two Time variables without using Ada.Real_Time? I have a case where I want to continue executing a Read operation until a certain timeout is reached.

I guess you are asking because this code is in the middle-ware and we forbid Ada.Real_Time. Do you get the time values from the BlueNRG or are you also looking for ways to get a time value?

johnleimon commented 7 years ago

I am not receiving time from the BlueNRG device. I was looking for a way to get the time value in order to determine that a time out condition has occurred. If this is not possible I will experiment with counting delay operations.

Fabien-Chouteau commented 7 years ago

OK, we don't have a good solution for this right now but we started to discuss a different things in #118. The problem is that Ada.Real_Time is not available on all platforms.

In the meantime, you can add a function that will return a clock value in the HAL.Time.Delays interface and the implement that function in the Ravenscar_Time package.

Or remove the Ada.Real_Time restriction in your branch so that you can make progress on your driver until we find a better solution.

simonjwright commented 7 years ago

John,

A lot of those style warnings were about trailing blanks. You can set GPS to strip trailing blanks automatically (Preferences > Editor > Strip blanks; not sure what 'Autodetect' means, perhaps it means only do this for Ada source).

johnleimon commented 7 years ago

Closing this request for now. After the code is refactored, I'll try again.