-
Notifications
You must be signed in to change notification settings - Fork 95
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
Added basic support for CH32V003. #153
base: master
Are you sure you want to change the base?
Conversation
…b of ADC pointed to "Vrefint" channel. (Physical entropy source is thermal noise of charge carriers at sample capacitor.) To make use of these changes, of course, one needs a proper CH32V003 project with the corresponding application support. Particularly, one needs to define “CH32V0XX” at the global level as well as implement the RNG_GetCondensedEntropy() function call.
Currently working on minimal PoC project for official CH32V003 IDE, "MounRiver Studio - Community." Should be ready by the end of this weekend. (Will make what I have now available upon request, however.) |
Just kidding! (... Apparently) https://github.com/CharlesScoville/CH32V003F4P6-libhydrogen-PoC/tree/main |
Thanks! But if Couldn't an implemented of |
...Perhaps... I'd have to really think about exactly how without it becoming a big frail mess. As submitted, it's got the best possible decoupling between libhydrogen and any CH32V003 project code, which was the entire idea behind the minimal changes that you are seeing in this PR. The next smallest step isn't very small I fear... it would be to try and pull the LSb accumulator and Von Neumann extractor in. Which, to do this, would likely require doing all the ADC care and feeding from within libhydrogen's part specific header. That's where the nightmare is going to be. I guess we could also go really deep and add a template / PoC project directly to libhydrogen? This way, moving the Von Neumann extractor code out of the CH32V003 project and into libhydrogen has potential to be less frail, though it would still be very coupled. No matter what, the end user is going to have to observe that libhydrogen is using it's resources, and so take care not to mangle them. Re-configuring the ADC to probe some voltage, for example, would probably almost instantly break the system. ... hummmmm ... Anyway, like I said, I'd have to think about precisely how to do it. I'm open to suggestions though! PoC code is linked in post 4. |
…man extractor code has been pulled in from CH32V003 project. A simple check was added to verify that the ADC unit is actually on as well.
OK @jedisct1. Take a look at the new changes and tell me what you think. Basically, I followed paragraph two from my last post above. Other than fighting with the IDE, it wasn't actually that hard. The trick was to separate at the internal voltage reference buffer, rather than having all the extractor and accumulator code in with the ADC. It also turned out to be better system design as a whole since now the ADC code is strictly doing ADC things, and simply handing the data off to the entropy shim via an async buffer. The entropy collecting portion of libhydrogen will block while polling for entropy now, but it doesn't strictly have to. It could easily be changed to doing something useful while waiting if so inclined. That's the good news... The bad news is that I have discovered egregious bias in the resulting collected entropy under very certain power conditions; a situation I was really hoping we avoided by using the internal voltage reference rather than an externally accessible ADC input. Good bypass capacitors right at the power pins, plus cranking the ebits value can work around the problem somewhat. An extra layer could also be added by augmenting the entropy collection process with some XOR mixing/whitening. An interesting alternative that I'm considering is combining the top problem of blocking and waiting around with the bottom problem of dilute entropy by running |
volatile FlagStatus extract_RDY = RESET; | ||
|
||
if ( !((ADC1->CTLR2 & 1) != 0) ) | ||
while(1); /* ADC1 OFF!!! PANIK! */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: dont block your app/system, make usage of errno*
errno = ENOXXX ;
return 0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good ask! +1
I'll see if I can get time to do that this weekend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is done.... Took me long enough!
(Had irl issues I had to clear up.)
Added basic support for CH32V003. Entropy is observed from reading LSb of ADC pointed to "Vrefint" channel. (Physical entropy source is thermal noise of charge carriers at sample capacitor.) To make use of these changes, of course, one needs a proper CH32V003 project with the corresponding application support. Particularly, one needs to define “CH32V0XX” at the global level as well as implement the RNG_GetCondensedEntropy() function call.