starfive-tech / JH7100_Docs

59 stars 8 forks source link

Some IO ranges only work with 32-bit access #9

Open BBBSnowball opened 3 years ago

BBBSnowball commented 3 years ago

Byte access to the IO ranges only works for the lowest 8-bit of a 32-bit word. So far, I have only seen this bug on SYSCON_IOPAD and GPIO (because I haven’t used any others). Those will usually be accessed by whole word so the bug isn’t really a problem in practice. I have only noticed this because Python seems to access the memory with memcpy. Nonetheless, I think you should consider fixing it. Depending on which bus interface is used, the fix could be very simple and it may even make the logic slightly smaller. If it isn't fixed, workarounds like this are necessary. This function could be a one-liner without the workaround.

Here is a proof of concept for the bug. The output for my board is here. Usage: make && ./bug-ioaccess-byte. This reconfigures FUNC_SHARE[1:0] so make sure that nothing is connected to GPIO0 and GPIO1 on the pin header - just to be sure.