RPI Zero - Чистый металл - ШИМ - PullRequest
1 голос
/ 10 июля 2020

Я пытаюсь создать PWM на нулевом RPI выводе .. это голый металл c код

Я пытаюсь чтобы иметь импульс на вывод 13 , я пробовал много разных кодов, ни один из них не работает

, хотя я могу использовать GPIO, SPI и UART без проблем , поэтому загрузчик работает

Еще пробовал ставить карту прямо на sd карту

Пробовал sd карту в другом SPI zero, такая же проблема

#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);
}

извините, мне больше нечего добавить к этому вопросу, но это основной (и единственный) код, который должен быть запущен на pi

Любой гуру по голому железу, который может мне помочь в этом?

спасибо за помощь

Фил

...