Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of drivers referencing non-existant hardware features in svd #340

Open
Hendrik410 opened this issue Apr 14, 2020 · 12 comments
Open
Assignees

Comments

@Hendrik410
Copy link

Hello,

I am currently implementing the STM32F411RE Nucleo board.
I have downloaded the svd files from ST and generated the svd ada files.

I've then copied the device folder from another device and started modifying.
While doing so, I commented all the periphirals out, that the STM32F411 doesn't have (The extra timers, the extra usarts, the dac).

I've also created the necessary entries and runtime projects for the board.

When I open the duplicated example project, the compiler copmlains about the missing references of from the stm drivers. An example is seen here:
image

Now if I understand it correctly, the drivers are common for all STM32 devices.

My question is, how should missing peripherals be handled?

@Fabien-Chouteau
Copy link
Member

Hello @Hendrik410 ,

I've also created the necessary entries and runtime projects for the board.

Did you add the board and device definition in the config scripts?

Now if I understand it correctly, the drivers are common for all STM32 devices.

They are at least common to all the STM32 devices that we support so far. But since we do not know the hundreds of STM32 devices available (and the ones to come),

My question is, how should missing peripherals be handled?

There is no easy answer I am afraid. Adding to discussion @pat-rogers who wrote this package.

@Hendrik410
Copy link
Author

Hi @Fabien-Chouteau ,

yes, I've used the config scripts.

I'm not to firm in Ada, I know that in C, compiler dirictives would be used.
Is there a similar construct in Ada?

@Fabien-Chouteau
Copy link
Member

No, Ada doesn't have the same feature, which is a good thing in most cases :)

@pat-rogers what is your opinion on this?

@pat-rogers
Copy link
Contributor

pat-rogers commented May 28, 2020 via email

@pat-rogers
Copy link
Contributor

pat-rogers commented May 28, 2020 via email

@pat-rogers
Copy link
Contributor

Earlier I said:

One possibility, that would be simple and clean, would be to generate
the declarations for all the timer addresses (eg TIM1_Base) defined by
the manual, located as now in STM32_SVD, but giving the null address
value to those not actually declared in a particular SVD file.

Modifying svd2ada is not the right approach because it is device and vendor independent and, as such, is driven purely by the svd input file. I think the right thing to do is for you to augment the supplied svd file to include the otherwise non-existent timers, assigning them null base addresses. Then the base address decls will be generated and the problematic functions (the timer classifiers) will compile (and function correctly). For example, let's say that TIM20 was a real timer not implemented on a given device, and therefore was not in the svd file. If we add the following to the svd file:

<peripheral derivedFrom="TIM3">
  <name>TIM20</name>
  <description>Nonexistent</description>
  <groupName>TIM</groupName>
  <baseAddress>0x0</baseAddress>
</peripheral>

we will get a declaration for TIM20_Base, which is what the classifier functions need:

TIM20_Base : constant System.Address := System'To_Address (16#0#);

We'll also get a corresponding device declaration:

-- Nonexistent
TIM20_Periph : aliased TIM3_Peripheral
with Import, Address => TIM20_Base;

The Import aspect ensures no initialization code accesses address zero, and no other code will reference the fake device (only the base address is referenced in the classifier function comparisons).

By having the svd input say that TIM20 is derived from some other timer that is truly present, we will get a usable type for the fake object declaration (TIM3_Peripheral above). The actual type doesn't matter.

Now, all that said, I would prefer a better solution so I will keep thinking about how to address it at the device driver level, rather than the svd generator.

@pat-rogers
Copy link
Contributor

I'm still thinking about this, in the background.

@kevlar700
Copy link

kevlar700 commented Feb 21, 2022

I have found that svd editing is required anyway, so keeping patches may be a good idea?
"https://community.st.com/s/feed/0D53W00001JWpMGSA1"

I am currently wondering whilst looking at STM32L4R9 if Timer record types showing the register differences (Basic, Advanced, 15, 16_17, Low_Power) and using Generics or overrides to enable common functionality would make this package easier to digest and port to other STM devices by making it clearer which Timers have which registers?

@pat-rogers
Copy link
Contributor

pat-rogers commented Feb 22, 2022 via email

@kevlar700
Copy link

kevlar700 commented Feb 24, 2022

A better approach would be very welcome.

Better is easy, until you notice the regressions!

I looked into various approaches somewhat, initially, but I didn't spend a great amount of time trying to arrange them into something simpler. I looked into an inheritance hierarchy but don't recall the problems(s) encountered. I got the impression from the online support groups that the STM32 timers were unusual in their complexity as a collection, in that it is difficult to understand them individually without understanding the entirety.

Okay, Thank You. I like the info that the contracts provide in the ads file. In a couple of places, it seems like a counter size and Channel mode selection enforced by 5-7 Timer types instead of throwing exceptions on pre conditions, would be nice. I am not fluent on ST hw yet. Therefore, I will try it out piecemeal and make considerations as I require the functionality in real world use cases instead of trying to understand everything now. Then review it further at a later date.

Regards, Kc

@FredPraca
Copy link

On 21-Feb-22 8:28 AM, Kevin Chadwick wrote: I am currently wondering whilst looking at STM32L4R9 if Timer record types showing the register differences (Basic, Advanced, 15, 16_17) and using Generics or overrides to enable common functionality would make this package easier to digest and port to other STM devices by making it clearer which Timers have which functionality?
I looked into various approaches somewhat, initially, but I didn't spend a great amount of time trying to arrange them into something simpler. I looked into an inheritance hierarchy but don't recall the problems(s) encountered. I got the impression from the online support groups that the STM32 timers were unusual in their complexity as a collection, in that it is difficult to understand them individually without understanding the entirety. A better approach would be very welcome. Best regards, Pat

That's something we discussed a long time ago in #196 .
There was some circularities problem AFAIR.

@pat-rogers
Copy link
Contributor

pat-rogers commented Feb 24, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants