svd2rust icon indicating copy to clipboard operation
svd2rust copied to clipboard

Handle SVD files which don't define register reset values

Open ecstatic-morse opened this issue 7 years ago • 11 comments

Atmel's ARM chips omit the <resetValue> element for register descriptions. <resetValue> is used to generate a write function which doesn't have to read the initial value from a register in order to preserve it while modifying individual fields.

ecstatic-morse avatar Feb 07 '18 19:02 ecstatic-morse

You can access the bits via modify

Emilgardis avatar Feb 07 '18 20:02 Emilgardis

I have used @ecstatic-morse's branch to generate the code for an ATtiny2313. The generated code compiles, but doesn't contain .write() and .modify() at all.

kunerd avatar Feb 08 '18 20:02 kunerd

@kunerd, I was wrongly using "ocd-rw" to determine whether registers were read only, when really this field tells the on chip debugger not to read or write to this register because of side effects.

ecstatic-morse avatar Feb 08 '18 21:02 ecstatic-morse

@kunerd @ecstatic-morse is this an issue with the ATDF to SVD parser, or with svd2rust?

I'd like to close this if there is nothing to be done at the svd2rust level.

jamesmunns avatar Mar 13 '18 11:03 jamesmunns

@jamesmunns: Yes this an issue with ATDF to SVD parser, but closing depends on the questions:

Do we want to have a separate atdf2rust executable, or should .atdf support be added to svd2rust directly. And if we choose the separate executable way, should it be part of svd2rust or should it life in it's own repo?

I prefer the former one (for the first question), but I think the questions have not really been answered, yet. See #184

kunerd avatar Mar 13 '18 12:03 kunerd

@kunerd is there anything that #184 doesn't cover that this one does? AFAICT, svd2rust does handle registers without reset values (without <resetValue> elements), as long as they are marked as writable.

I will definitely follow #184 though (no opinions yet :) )

jamesmunns avatar Mar 13 '18 12:03 jamesmunns

@jamesmunns Ahh, I missed the part with the ocd-rw above. So, I would say, this can be closed, but maybe you want to wait until @ecstatic-morse confirmed that, because he has done the implementation and I only tried to test it.

kunerd avatar Mar 13 '18 12:03 kunerd

@ecstatic-morse any feedback?

jamesmunns avatar Mar 24 '18 23:03 jamesmunns

This should be supported. The SVD spec allows <resetValue> to be missing. In the case that resetValue is missing we should not generate the reset method and we should modify the write method somehow because that makes use of resetValue.

japaric avatar Mar 27 '18 19:03 japaric

I've come across this recently as I'm trying to use an Atmel provided SVD file which doesn't have <resetValue> for all registers.

I believe that with no reset value the reset and reset_value methods should be omitted and the write method should instead initialise w to 0 as in:

let mut w = W { bits: 0 };

See https://github.com/sjroe/svd2rust/tree/resetvalue for an example implementation.

sjroe avatar Sep 26 '18 21:09 sjroe

I've pushed pull request #258 with a rebased version of #175 that also addresses the comments from @sjroe.

lambda avatar Nov 19 '18 16:11 lambda

Closing due to write_with_zero. Reopen if you have better solution.

burrbull avatar Nov 07 '22 19:11 burrbull