Docs on GPIO IOF and behavior during sleep mode

Hi all

I am currently implementing the led_demo that was shipped with the HiFive1.
My problem is the PWM generator.
Currently I have this code:

volatile unsigned int* g_output_vals  = (unsigned int *) (GPIO_BASE_ADDR + GPIO_OUTPUT_VAL);
volatile unsigned int* g_input_vals   = (unsigned int *) (GPIO_BASE_ADDR + GPIO_INPUT_VAL);
volatile unsigned int* g_output_en    = (unsigned int *) (GPIO_BASE_ADDR + GPIO_OUTPUT_EN);
volatile unsigned int* g_pullup_en    = (unsigned int *) (GPIO_BASE_ADDR + GPIO_PULLUP_EN);
volatile unsigned int* g_input_en     = (unsigned int *) (GPIO_BASE_ADDR + GPIO_INPUT_EN);


volatile unsigned int * g_pwm1 = (unsigned int *) PWM1_BASE_ADDR;
volatile unsigned int * g_pwm1_s   = (unsigned int *) (PWM1_BASE_ADDR + PWM_S);
volatile unsigned int * g_pwm1_count   = (unsigned int *) (PWM1_BASE_ADDR + PWM_COUNT);
volatile unsigned int * g_pwm_cmp0 = (unsigned int *) (PWM1_BASE_ADDR + PWM_CMP0);
volatile unsigned int * g_pwm_red   = (unsigned int *) (PWM1_BASE_ADDR + PWM_CMP3);
volatile unsigned int * g_pwm_green = (unsigned int *) (PWM1_BASE_ADDR + PWM_CMP1);
volatile unsigned int * g_pwm_blue  = (unsigned int *) (PWM1_BASE_ADDR + PWM_CMP2);


int main() {
  * g_input_en    &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;
  * g_output_en   |= ((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;
  * g_output_vals |= ((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;

  *g_pwm1_count = 0x00;
  *g_pwm1_s = 0x00;
  *g_pwm_cmp0 = 0xff;

  *g_pwm1 = PWM_CFG_ENALWAYS
      | PWM_CFG_ONESHOT
      | PWM_CFG_ZEROCMP
      | PWM_CFG_DEGLITCH
  ;
  
  *g_pwm_red   = 0x80;
  *g_pwm_green = 0xf0;
  *g_pwm_blue  = 0x20;
}

I guess I need to enable IOF and select the PWM generator, but the platform-reference-manual-v1.0.1 has almost no information about it.
Plus the section about sleepmode is missing.

Can you give me any pointers?

Regards
dns2utf8

I was able to resolve the PWM settings, all source code is in this PR: https://github.com/sifive/freedom-e-sdk/pull/41/files

Glad you figured out the PWM module. It does have a lot of knobs to tweak!

During sleep mode, the “sleep” program is executed as described in the PMU section of the doc. By default, this will:

  • Put most of the chip into reset, including the GPIO controller (so all the IO are High-Z)
  • Turn off the 3.3V power rail
  • On the HiFive1, turns off or disables the things connected to the FE310’s 3.3V pins (level shifters, SPI Flash, JTAG).