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
241 stars 142 forks source link

Add support for the HiFive1 rev B #335

Closed Fabien-Chouteau closed 4 years ago

Fabien-Chouteau commented 4 years ago

@Irvise can you try this and tell me if it works.

Related to #334.

Irvise commented 4 years ago

I have built and uploaded the example project as described in #334.

It did not have any effect. As in, the program that I had uploaded earlier was not overwritten.

The program that I had was the "hello world" that Freedom Studio includes. In this gist I have written the beginning and the ending of the build process that the IDE uses for the example. Just in case it helps. I have also included the beginning of the disassembly of the elf generated by the IDE here and the one generated by Ada. Both were compiled with the debug option. At the beginning there are some noticeable differences (it is important to point out the IDE's example is using a simple printf which prints to serial, which may be the reason for the extra code added).

I am going to see in more detail how does the IDE upload the binary to the board, just in case I am missing something.

It may be better to mention this in #334 or #335 but since there is the "Metal library" for all the SiFive boards, maybe it is better to create an Ada wrapper around it? If it works, then, theoretically, all boards should be supported by the same "interface".

Fabien-Chouteau commented 4 years ago

I have also included the beginning of the disassembly of the elf generated by the IDE here and the one generated by Ada

Looks like I did a mistake on the flash base address: 0x20100000 instead of 0x20010000.

It may be better to mention this in #334 or #335 but since there is the "Metal library" for all the SiFive boards, maybe it is better to create an Ada wrapper around it? If it works, then, theoretically, all boards should be supported by the same "interface".

The goal of the Ada_Drivers_Library is to provide 100% Ada drivers for various platform. But it's true that this is not necessarily the most efficient way to use Ada on a board. Doing an Ada wrapper is a valid solution.

Fabien-Chouteau commented 4 years ago

@Irvise can you try this new version?

Irvise commented 4 years ago

@Fabien-Chouteau I am sorry I wrote the incorrect address in the issue. I tried the new version.

The generated binary is, as expected, "correct", the "boot" address is the correct one. Upon uploading it, it does nothing.

I have the impression that my changes mentioned in #334 were not correct. I think I tricked myself into thinking my changes worked because the program that was executing was doing a very similar thing to the example in Ada, so it may be more than just fixing the initial address. It seems that the "copy" method explained in the board's documentation may not be working as expected.

I tried to upload a know working .hex binary through this method and it failed. Therefore, I am going to first try to get a reliable upload mechanism I will get back in touch. Trying to trick the IDE by substituting the binaries has already failed, so I will try the freedom e sdk directly.

Irvise commented 4 years ago

Good news @Fabien-Chouteau, I works!

I honestly cannot explain what is happening. To summarize what I have done is:

  1. Built everything with with the Freedom Sdk. The examples work fine
  2. Try to upload Ada's example. It failed, as in, the memory was left untouched (I did a memory dump to confirm this)
  3. Built Ada's example in Production mode in a "desperate" attempt. It worked just fine!! I checked both ways of uploading the sketch (copypasting and with JLink)
  4. Clean everything. Rebuild Ada's example in Debug mode. Expectation: it should fail. Reality, it now works for whatever reason

I don't know what has happened. But now it consistently works with both modes, Production and Debug. I will keep an eye on this and start fiddling with Ada. If I notice something out of the ordinary, I will let you know. However, as things are right now, I think this branch is ready to be merged.

As a side note, you may want to promote/comment/advertise the Ada driver in the official SiFive HiFive1's forum. Some more people could be interested on it.

Regards and thank you,

Fernando Oleo Blanco

Fabien-Chouteau commented 4 years ago

I don't know what has happened. But now it consistently works with both modes, Production and Debug. I will keep an eye on this and start fiddling with Ada. If I notice something out of the ordinary, I will let you know. However, as things are right now, I think this branch is ready to be merged.

Thank you for the update @Irvise.

As a side note, you may want to promote/comment/advertise the Ada driver in the official SiFive HiFive1's forum. Some more people could be interested on it.

Indeed, do you mind doing it for us?