Hello! I’m really hoping to get some help here as I’ve already spent several days trying to figure out what’s going on.
I’m trying to learn low-level development, without using libraries (C or assembler, openosd).
I read a lot of documentation, and there is one thing that has been bothering me for several days now.
I’m trying to understand how input gpi works. Let’s say I take gpio port number 16. I turn on the input bit, I turn on the pull-up resistor. Why, I connect this port through a wire to ground. Then, no matter what I do, the value in the bit at address 0x10012000 does not change at all. No matter what external influence I have, it will always be 1.
Do I understand correctly that this can only be changed through interrupts? Thanks to everyone who decides to help!
#include "types.h"
#include "GPIO.h"
static inline void delay(uint32_t n_cycles) {
for (uint32_t i = 0; i < n_cycles; i++) {
asm volatile("nop");
}
}
static inline void zero_gpio(void){
for(uint32_t * addr = (uint32_t *) GPIO_BASE;
addr <=(uint32_t *) GPIO_PASSTHRU_LOW_IE;
++addr){
*addr = 0;
}
}
void main(void) {
zero_gpio();
uint32_t tmp = 0;
uint32_t socket_mask = 1 << 16;
uint32_t blue_led = 1 << 21;
uint32_t green_led = 1 << 22;
volatile uint32_t *gpio_output_en = (uint32_t *)GPIO_OUTPUT_EN;
volatile uint32_t *gpio_input_en = (uint32_t *)GPIO_INPUT_EN;
volatile uint32_t *gpio_output_val = (uint32_t *)GPIO_OUTPUT_VAL;
volatile uint32_t *gpio_pue = (uint32_t *) GPIO_PUE;
volatile uint32_t *gpio_base = (uint32_t *) GPIO_BASE;
// volatile uint32_t *gpio_xor = (uint32_t *) GPIO_OUTPUT_XOR;
*gpio_input_en |= socket_mask;
*gpio_pue |= socket_mask;
// *gpio_xor |= (socket_mask);
// *gpio_input_en &= ~( blue_led | green_led );
// *gpio_output_en |= ( blue_led | green_led );
while (1) {
int flag = (*gpio_base & socket_mask);
if(flag == socket_mask){
*gpio_output_en = 1 << 21;
*gpio_output_val = 0;
delay(100000);
*gpio_output_en = 0;
*gpio_pue = 0;
delay(100000);
*gpio_base = 0;
}else{
*gpio_output_en = 1 << 19;
delay(100000);
*gpio_output_en = 0;
*gpio_output_val = 0;
*gpio_pue |= socket_mask;
delay(100000);
*gpio_base = 0;
}
}
}