Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C RPI零-裸金属-PWM_C_Raspberry Pi_Pwm_Bare Metal - Fatal编程技术网

C RPI零-裸金属-PWM

C RPI零-裸金属-PWM,c,raspberry-pi,pwm,bare-metal,C,Raspberry Pi,Pwm,Bare Metal,我尝试在RPI零引脚上产生PWM。。这是一个裸露的金属代码 我试着在引脚13上有一个脉冲,我试过许多不同的代码,但都不起作用 虽然我可以毫无问题地使用GPIO、SPI和UART,但引导加载程序可以正常工作 我还试着把卡直接放在sd卡上 我在另一个SPI zero中尝试了sd卡,同样的问题 #define BCM2835_BASE 0x20000000 #define GPIO_BASE ( BCM2835_BASE + 0x200000 ) #define GPIO_CLOCK_BASE (

我尝试在RPI零引脚上产生PWM。。这是一个裸露的金属代码

我试着在引脚13上有一个脉冲,我试过许多不同的代码,但都不起作用

虽然我可以毫无问题地使用GPIO、SPI和UART,但引导加载程序可以正常工作

我还试着把卡直接放在sd卡上

我在另一个SPI zero中尝试了sd卡,同样的问题

#define BCM2835_BASE 0x20000000

#define GPIO_BASE ( BCM2835_BASE + 0x200000 )
#define GPIO_CLOCK_BASE ( BCM2835_BASE + 0x101000 )
#define PWM_BASE ( BCM2835_BASE + 0x20C000 )
#define SYSTIMER_BASE ( BCM2835_BASE + 0x3000 )

#define GPIO_CLOCK_PWM_OFFSET (40 * 4)
#define GPIO_CLOCK_PWD (0x5A << 24)

#define CM_CTL_MASH_1 ( 1 << 9 )
#define CM_CTL_BUSY ( 1 << 7 )
#define CM_CTL_KILL ( 1 << 5 )
#define CM_CTL_ENAB ( 1 << 4 )
#define CM_CTL_SRC_OSCI ( 1 << 0 )

#define CM_DIV_DIVI_SHIFT   12
#define CM_DIV_DIVF_SHIFT   0

#define GPIO_GPFSEL1 4

#define PWM_CTL_SBIT1 ( 1 << 3 )
#define PWM_CTL_PWEN1 ( 1 << 0 )

#define PWM_STA_STA1 ( 1 << 9 )
#define PWM_STA_BERR ( 1 << 8 )
#define PWM_STA_GAPO1 ( 1 << 4 )

#define PWM_BUFFER_SIZE 2048

typedef struct {
     volatile unsigned int ctl;    // 0x00
     volatile unsigned int sta;    // 0x04
     volatile unsigned int dmac;    // 0x08
     volatile unsigned int unused1;  // 0x0c
     volatile unsigned int rng1;    // 0x10
     volatile unsigned int dat1;    // 0x14
     volatile unsigned int fif1;    // 0x18
     volatile unsigned int unused2;  // 0x1c
     volatile unsigned int rng2;    // 0x20
     volatile unsigned int dat2;    // 0x24
} Pwm_registers;

volatile unsigned int* gpio = (unsigned int*)GPIO_BASE;

typedef struct {
     volatile unsigned int control_status;
     volatile unsigned int counter_lo;
     volatile unsigned int counter_hi;
     volatile unsigned int compare0;
     volatile unsigned int compare1;
     volatile unsigned int compare2;
     volatile unsigned int compare3;
} Systimer_t;

Systimer_t* systemTimer = (Systimer_t *)SYSTIMER_BASE;

typedef struct {
     volatile unsigned int ctl;
     volatile unsigned int div;
}Clock_manager;

int notmain ( void )
{
  volatile Pwm_registers* sysPwm = (Pwm_registers *) PWM_BASE;

  volatile Clock_manager* sysClockManager = (Clock_manager *) (GPIO_CLOCK_BASE + GPIO_CLOCK_PWM_OFFSET);

  // ALT0 on pin 13
  gpio[GPIO_GPFSEL1] |= (1 << (9+2));
  gpio[GPIO_GPFSEL1] &= ~(1 << (9+1));
  gpio[GPIO_GPFSEL1] &= ~(1 << (9+0));

  // maximum frequency 37.5K, 256 resolution
  sysClockManager->ctl = GPIO_CLOCK_PWD | CM_CTL_KILL;
  while ( sysClockManager->ctl & CM_CTL_BUSY);
  // clock i = 2 f = 0
  sysClockManager->div = GPIO_CLOCK_PWD | (2 << CM_DIV_DIVI_SHIFT) | (0 << CM_DIV_DIVF_SHIFT);
  sysClockManager->ctl = GPIO_CLOCK_PWD | CM_CTL_MASH_1 | CM_CTL_SRC_OSCI | CM_CTL_ENAB;

  sysPwm->ctl = 0;
  sysPwm->rng1 = 256;
  sysPwm->dat1 = 128;
  sysPwm->ctl |= PWM_CTL_PWEN1;

  while(1)
  {

  };

  return(0);
}
#定义BCM2835_基数0x20000000
#定义GPIO_基(BCM2835_基+0x200000)
#定义GPIO_时钟_基(BCM2835_基+0x101000)
#定义PWM_基准(BCM2835_基准+0x20C000)
#定义SYSTIMER_基地(BCM2835_基地+0x3000)
#定义GPIO_时钟_PWM_偏移(40*4)
#定义GPIO_时钟_PWD(0x5A