turtius Posted November 26, 2019 Posted November 26, 2019 (edited) Hello, I'm new here and do not quite understand the sub-forums here but hopefully this is the right one. I got an Orange pi ONE running 4.19 RT kernel with Armbian buster. I was testing out the GPIO capabilities of the H3 SoC without any libraries and got only 1.67 Mhz at best(which is ironically the same as WiringPIOP) with some task interrupt issues. #define INP_GPIO(g) *(unsigned int *)(gpio+0x04) &= ~(7 << (((g) % 10) * 3)) //I did not thoroughly check if the mapping is okay #define OUT_GPIO(g){\ *(unsigned int *)(gpio+0x04) &= ~(6 << (((g) % 8) * 4));\ *(unsigned int *)(gpio+0x04) |= (1 << (((g) % 8) * 4));\ } #define GET_GPIO(g) (*(unsigned int *)(gpio+0x10) & (1<<g))// 0 if LOW, (1<<g) if HIGH #define GPIO_SET(g) if(!GET_GPIO(g)){*(unsigned int *)(gpio+0x10) |= (1 << g);} #define GPIO_CLR(g) if(GET_GPIO(g)){*(unsigned int *)(gpio+0x10) &= ~(1<< g);} //after accessing /dev/mem OUT_GPIO(12); for(;;) { GPIO_SET(12); GPIO_CLR(12); } The result is pretty inconsistent but at least works (any suggestions?). One could say remove the if statement(got 2Mhz) but that makes the output even more bizarre. At this point i am quite stuck and not sure how to get a faster result with correct timing when rising and falling. Any suggestions for this would be helpful. Thank you! test.cpp Edited November 26, 2019 by fourtyseven Forgot to attach the actual code
turtius Posted November 27, 2019 Author Posted November 27, 2019 (edited) Okay so after some fiddling around with registers;it seems like 1.6Mhz is the best for stability and the results seems quite consistent when the pin is checked if it actually changed the register or not. #define GET_GPIO(g) (*(unsigned int *)(gpio+0x10) & (1<<g))// 0 if LOW, (1<<g) if HIGH #define GPIO_SET(g) if(!GET_GPIO(g)){*(unsigned int *)(gpio+0x10) |= (1 << g);} #define GPIO_CLR(g) if(GET_GPIO(g)){*(unsigned int *)(gpio+0x10) &= ~(1<< g);} This is still disappointing but i guess its a 'one up' from the previous results. Edited November 28, 2019 by fourtyseven syntax cleanup
AnonymousPi Posted September 17, 2020 Posted September 17, 2020 Refer to this C library: https://github.com/luoyi/h3-gpio which seems quite fast, and read this comment. It appears 10Mhz should be doable, but only if you do not read the value of the GPIO. So cache the latest value of the GPIOs locally in your code as a local variable if say, you need to do bit manipulation. 1
Recommended Posts