简体   繁体   中英

Reading from register of Allwinner H3 ARM processor

#include <stdint.h>
#include <stddef.h>
#include <stdio.h>


static void foo(void){
    volatile  uint32_t *temp_addr;
    temp_addr = (uint32_t*)(0x01C20C00);
    *temp_addr =0;
}
int main(){
    tinit();

};

It compiles but returns Segmentation fault message as a result. I just want to reset all bits in register 0x01c200c00 .

在此处输入图片说明

Your program does not work because 0x01C20C00 is a physical address, but your program uses virtual addresses. For experimentation, you can access GPIO, timers, or other peripherals without writing a kernel driver. For this, you need to create a memory mapping, like this:

#define ALLWINNER_TIMER_BASE 0x01C20C00

struct allwinner_timer
{
  volatile uint32_t IRQ_EN_REG;
  // add other registers from the datasheet, or find a kernel driver source with these definitions
};

int fd = open("/dev/mem", O_RDWR);
struct allwinner_timer *t = (struct allwinner_timer *)mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ALLWINNER_TIMER_BASE);
// TODO: check for errors
t->IRQ_EN_REG = 0;

Note that:

  • It may not work if kernel restricts access to /dev/mem . This can be found out by looking at kernel options, eg CONFIG_STRICT_DEVMEM and with dmesg ;
  • It has to run under superuser, obviously;
  • Your code may interfere with other parts of the system, eg kernel drivers accessing the same peripheral, leading to unpredictable results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM