コード例 #1
0
void cmd_testhp(char *line) {
  gpio_set_mode (PIN_MAP[12].gpio_device,PIN_MAP[12].gpio_bit, GPIO_OUTPUT_PP);  // HP_COMBINED
  for(int n=0;n<100000;n++) {
    gpio_write_bit(PIN_MAP[12].gpio_device,PIN_MAP[12].gpio_bit,1);
    delay_us(100);
    gpio_write_bit(PIN_MAP[12].gpio_device,PIN_MAP[12].gpio_bit,0);
    delay_us(100);
  }
}
コード例 #2
0
ファイル: ppm_arch.c プロジェクト: evanov100/paparazzi
void ppm_arch_init ( void ) {

  /* timer clock enable */
  rcc_peripheral_enable_clock(PPM_RCC, PPM_PERIPHERAL);

  /* GPIOA clock enable */
  rcc_peripheral_enable_clock(&RCC_APB2ENR, PPM_GPIO_PERIPHERAL);

  /* timer gpio configuration */
  gpio_set_mode(PPM_GPIO_PORT, GPIO_MODE_INPUT,
		GPIO_CNF_INPUT_FLOAT, PPM_GPIO_PIN);

  /* Time Base configuration */
  timer_reset(PPM_TIMER);
  timer_set_mode(PPM_TIMER, TIM_CR1_CKD_CK_INT,
		 TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
  timer_set_period(PPM_TIMER, 0xFFFF);
  timer_set_prescaler(PPM_TIMER, 0x8);

 /* TIM2 configuration: Input Capture mode ---------------------
     The external signal is connected to TIM2 CH2 pin (PA.01)
     The Rising edge is used as active edge,
  ------------------------------------------------------------ */
#if defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_POSITIVE
  timer_ic_set_polarity(PPM_TIMER, PPM_CHANNEL, TIM_IC_RISING);
#elif defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_NEGATIVE
  timer_ic_set_polarity(PPM_TIMER, PPM_CHANNEL, TIM_IC_FALLING);
#else
#error "ppm_arch.c: Unknown PM_PULSE_TYPE"
#endif
  timer_ic_set_input(PPM_TIMER, PPM_CHANNEL, PPM_TIMER_INPUT);
  timer_ic_set_prescaler(PPM_TIMER, PPM_CHANNEL, TIM_IC_PSC_OFF);
  timer_ic_set_filter(PPM_TIMER, PPM_CHANNEL, TIM_IC_OFF);

  /* Enable timer Interrupt(s). */
  nvic_set_priority(PPM_IRQ, 2);
  nvic_enable_irq(PPM_IRQ);

#ifdef PPM_IRQ2
  nvic_set_priority(PPM_IRQ2, 2);
  nvic_enable_irq(PPM_IRQ2);
#endif

  /* Enable the CC2 and Update interrupt requests. */
  timer_enable_irq(PPM_TIMER, PPM_IRQ_FLAGS);

  /* Enable capture channel. */
  timer_ic_enable(PPM_TIMER, PPM_CHANNEL);

  /* TIM2 enable counter */
  timer_enable_counter(PPM_TIMER);

  ppm_last_pulse_time = 0;
  ppm_cur_pulse = RADIO_CONTROL_NB_CHANNEL;
  timer_rollover_cnt = 0;

}
コード例 #3
0
ファイル: button.c プロジェクト: BuFran/libopencm3-examples
static void gpio_setup(void)
{
	/* Enable GPIOC clock. */
	rcc_periph_clock_enable(RCC_GPIOC);

	/* Set GPIO9 (in GPIO port C) to 'output push-pull'. */
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
		      GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);
}
コード例 #4
0
// setup() and loop():
void setup(void) {

    storage_start();
    storage_add(16, "SOME LOCATION");
    storage_add(16, "ANOTHER LOCATION");


    //bluetooth_start();
    communication_start();

    gpio_set_mode(GPIOB, 8, GPIO_INPUT_PD);
    exti_attach_interrupt(AFIO_EXTI_8, AFIO_EXTI_PB, transmit_interrupt, EXTI_RISING);

    //Onboard LED
    gpio_set_mode(GPIOB, 1, GPIO_OUTPUT_PP);
    gpio_write_bit(GPIOB, 1, 1);

}
コード例 #5
0
void gpio_setup(void)
{
/* Enable GPIO clocks. */
    rcc_peripheral_enable_clock(&RCC_APB2ENR,
                RCC_APB2ENR_IOPBEN);
/* PB8-15 outputs digital for LEDs */
    gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
			    GPIO8 | GPIO9 | GPIO10 | GPIO11 | GPIO12 | GPIO13 | GPIO14 | GPIO15);
}
コード例 #6
0
ファイル: button.c プロジェクト: gxliu/libopenstm32
void button_setup(void)
{
	/* Enable GPIOA clock. */
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);

	/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
	gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
		      GPIO_CNF_INPUT_FLOAT, GPIO0);
}
コード例 #7
0
/*--------------------------------------------------------------------*/
void gpio_setup(void)
{
    rcc_periph_clock_enable(RCC_GPIOA);
    rcc_periph_clock_enable(RCC_GPIOC);
    rcc_periph_clock_enable(RCC_AFIO);
/* Digital Test outputs PC0 and PC1 */
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
		      GPIO_CNF_OUTPUT_PUSHPULL, GPIO0 | GPIO1);
}
コード例 #8
0
static void gpio_setup(void)
{
	/* Enable GPIOC clock. */
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);

	/* Set GPIO9 (in GPIO port C) to 'output push-pull'. */
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
		      GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);
}
コード例 #9
0
ファイル: Dynamixel.cpp プロジェクト: tician/ROBOTIS-OpenCM
void Dynamixel::begin(int baud){

	uint32 Baudrate = 0;
	if(mDxlUsart == USART1)
		afio_remap(AFIO_REMAP_USART1);

#ifdef BOARD_CM900  //Engineering version case
	 gpio_set_mode(PORT_ENABLE_TXD, PIN_ENABLE_TXD, GPIO_OUTPUT_PP);
	 gpio_set_mode(PORT_ENABLE_RXD, PIN_ENABLE_RXD, GPIO_OUTPUT_PP);
	 gpio_write_bit(PORT_ENABLE_TXD, PIN_ENABLE_TXD, 0 );// TX Disable
	 gpio_write_bit(PORT_ENABLE_RXD, PIN_ENABLE_RXD, 1 );// RX Enable
#else
	 gpio_set_mode(mDirPort, mDirPin, GPIO_OUTPUT_PP);
	 gpio_write_bit(mDirPort, mDirPin, 0 );// RX Enable
	 //gpio_set_mode(GPIOB, 5, GPIO_OUTPUT_PP);
	// gpio_write_bit(GPIOB, 5, 0 );// RX Enable
#endif
	// initialize GPIO D20(PB6), D21(PB7) as DXL TX, RX respectively
	gpio_set_mode(mTxPort, mTxPin, GPIO_AF_OUTPUT_PP);
	gpio_set_mode(mRxPort, mRxPin, GPIO_INPUT_FLOATING);
	//Initialize USART 1 device
	 usart_init(mDxlUsart);

	 //Calculate baudrate, refer to ROBOTIS support page.
	 Baudrate = 2000000 / (baud + 1);

	 if(mDxlUsart == USART1)
		 usart_set_baud_rate(mDxlUsart, STM32_PCLK2, Baudrate);
	 else
		 usart_set_baud_rate(mDxlUsart, STM32_PCLK1, Baudrate);
	nvic_irq_set_priority(mDxlUsart->irq_num, 0);//[ROBOTIS][ADD] 2013-04-10 set to priority 0
	usart_attach_interrupt(mDxlUsart, mDxlDevice->handlers);
	usart_enable(mDxlUsart);
	delay(80);
	mDXLtxrxStatus = 0;
	mBusUsed = 0;// only 1 when tx/rx is operated
	//gbIsDynmixelUsed = 1;  //[ROBOTIS]2012-12-13 to notify end of using dynamixel SDK to uart.c
	this->clearBuffer();

	this->setLibStatusReturnLevel(2);
	this->setLibNumberTxRxAttempts(1);


}
コード例 #10
0
ファイル: baro.c プロジェクト: cuspaceflight/DorMouse
void baro_init()
{
    gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14);
    gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
            GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO13 | GPIO15);
    gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
            GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
    deselect_slave();

    spi_init_master(SPI2, SPI_CR1_BAUDRATE_FPCLK_DIV_8, SPI_CR1_CPOL,
            SPI_CR1_CPHA, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
    spi_enable_ss_output(SPI2);
    spi_enable(SPI2);

    dma_set_peripheral_address(DMA1, DMA_CHANNEL3, SPI2_DR);
    dma_set_read_from_memory(DMA1, DMA_CHANNEL3);
    dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL3);
    dma_set_peripheral_size(DMA1, DMA_CHANNEL3, DMA_CCR_PSIZE_8BIT);
    dma_set_memory_size(DMA1, DMA_CHANNEL3, DMA_CCR_MSIZE_8BIT);
    dma_set_priority(DMA1, DMA_CHANNEL3, DMA_CCR_PL_HIGH);

    dma_set_peripheral_address(DMA1, DMA_CHANNEL4, SPI2_DR);
    dma_set_read_from_peripheral(DMA1, DMA_CHANNEL4);
    dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL4);
    dma_set_peripheral_size(DMA1, DMA_CHANNEL4, DMA_CCR_PSIZE_8BIT);
    dma_set_memory_size(DMA1, DMA_CHANNEL4, DMA_CCR_MSIZE_8BIT);
    dma_set_priority(DMA1, DMA_CHANNEL4, DMA_CCR_PL_VERY_HIGH);
    dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL4);

    timer_reset(TIM4);
    timer_enable_irq(TIM4, TIM_DIER_UIE);
    timer_set_mode(TIM4, TIM_CR1_CKD_CK_INT,
            TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
    /* 3200 / 16 = 200 Hz */
    timer_set_prescaler(TIM4, 32);
    timer_set_period(TIM4, 5625);

    nvic_set_priority(NVIC_TIM4_IRQ, 16 * 2);
    nvic_set_priority(NVIC_DMA1_CHANNEL4_IRQ, 16 * 2);
    nvic_enable_irq(NVIC_TIM4_IRQ);
    nvic_enable_irq(NVIC_DMA1_CHANNEL4_IRQ);

    read_calibration_data();
}
コード例 #11
0
ファイル: uart_arch.c プロジェクト: pdanneels/paparazzi
void uart1_init( void ) {

  uart_periph_init(&uart1);
  uart1.reg_addr = (void *)USART1;

  /* init RCC and GPIOs */
#if defined(STM32F4)
  rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
  set_uart_pin(UART1_GPIO_PORT_RX, UART1_GPIO_RX, UART1_GPIO_AF);
  set_uart_pin(UART1_GPIO_PORT_TX, UART1_GPIO_TX, UART1_GPIO_AF);

#elif defined(STM32F1)
  rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
  rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);

  gpio_set_mode(GPIO_BANK_USART1_TX, GPIO_MODE_OUTPUT_50_MHZ,
                GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
  gpio_set_mode(GPIO_BANK_USART1_RX, GPIO_MODE_INPUT,
                GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX);
#endif

  /* Enable USART interrupts in the interrupt controller */
  usart_enable_irq(NVIC_USART1_IRQ);

#if UART1_HW_FLOW_CONTROL
#warning "USING UART1 FLOW CONTROL. Make sure to pull down CTS if you are not connecting any flow-control-capable hardware."
  /* setup CTS and RTS gpios */
#if defined(STM32F4)
  set_uart_pin(UART1_GPIO_PORT_CTS, UART1_GPIO_CTS, UART1_GPIO_AF);
  set_uart_pin(UART1_GPIO_PORT_RTS, UART1_GPIO_RTS, UART1_GPIO_AF);
#elif defined(STM32F1)
  gpio_set_mode(GPIO_BANK_USART1_RTS, GPIO_MODE_OUTPUT_50_MHZ,
                GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RTS);
  gpio_set_mode(GPIO_BANK_USART1_CTS, GPIO_MODE_INPUT,
                GPIO_CNF_INPUT_FLOAT, GPIO_USART1_CTS);
#endif
#endif

  /* Configure USART1, enable hardware flow control*/
  uart_periph_set_mode(&uart1, USE_UART1_TX, USE_UART1_RX, UART1_HW_FLOW_CONTROL);

  /* Set USART1 baudrate and enable interrupt */
  uart_periph_set_baudrate(&uart1, UART1_BAUD);
}
コード例 #12
0
ファイル: i2c_arch.c プロジェクト: maevalopez/paparazzi
void i2c2_hw_init(void) {

  i2c2.reg_addr = (void *)I2C2;
  i2c2.init_struct = NULL;
  i2c2.errors = &i2c2_errors;
  i2c2_watchdog_counter = 0;

  /* zeros error counter */
  ZEROS_ERR_COUNTER(i2c2_errors);

  /* reset peripheral to default state ( sometimes not achieved on reset :(  ) */
  //i2c_reset(I2C2);

  /* Configure and enable I2C2 event interrupt --------------------------------*/
  nvic_set_priority(NVIC_I2C2_EV_IRQ, NVIC_I2C2_IRQ_PRIO);
  nvic_enable_irq(NVIC_I2C2_EV_IRQ);

  /* Configure and enable I2C2 err interrupt ----------------------------------*/
  nvic_set_priority(NVIC_I2C2_ER_IRQ, NVIC_I2C2_IRQ_PRIO+1);
  nvic_enable_irq(NVIC_I2C2_ER_IRQ);

  /* Enable peripheral clocks -------------------------------------------------*/
  /* Enable I2C2 clock */
  rcc_periph_clock_enable(RCC_I2C2);
  /* Enable GPIO clock */
  gpio_enable_clock(I2C2_GPIO_PORT);
#if defined(STM32F1)
  gpio_set_mode(I2C2_GPIO_PORT, GPIO_MODE_OUTPUT_2_MHZ,
                GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN,
                I2C2_GPIO_SCL | I2C2_GPIO_SDA);
#elif defined(STM32F4)
  gpio_mode_setup(I2C2_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE,
                  I2C2_GPIO_SCL | I2C2_GPIO_SDA);
  gpio_set_output_options(I2C2_GPIO_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_25MHZ,
                          I2C2_GPIO_SCL | I2C2_GPIO_SDA);
  gpio_set_af(I2C2_GPIO_PORT, GPIO_AF4,
              I2C2_GPIO_SCL | I2C2_GPIO_SDA);
#endif

  i2c_reset(I2C2);

  // enable peripheral
  i2c_peripheral_enable(I2C2);

  /*
   * XXX: there is a function to do that already in libopencm3 but I am not
   * sure if it is correct, using direct register instead (esden)
   */
  //i2c_set_own_7bit_slave_address(I2C2, 0);
  I2C_OAR1(I2C2) = 0 | 0x4000;

  // enable error interrupts
  I2C_CR2(I2C1) |= I2C_CR2_ITERREN;

  i2c_setbitrate(&i2c2, I2C2_CLOCK_SPEED);
}
コード例 #13
0
ファイル: speaker.c プロジェクト: heorohuy/laser_tag_reloaded
void speaker_start(void) {

    gpio_set_mode(SPEAKER_PORT, SPEAKER_PIN, GPIO_OUTPUT_PP);

    timer_init(SPEAKER_TIMER);
    speaker_pause();
    speaker_setMode(SPEAKER_CHANNEL, TIMER_OUTPUT_COMPARE);
    speaker_setCompare(SPEAKER_CHANNEL, SPEAKER_COMPARE);
    speaker_refresh();
}
コード例 #14
0
ファイル: ad8307.c プロジェクト: avian2/vesna-spectrum-sensor
int vss_ad8307_init(void)
{
	/* GPIO pin for AD8307 ENB */
#ifdef AD8307_PIN_ENB
	gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
			GPIO_CNF_OUTPUT_PUSHPULL, AD8307_PIN_ENB);
#endif

	return VSS_OK;
}
コード例 #15
0
ファイル: boxcar.c プロジェクト: karlp/karlnet
void start_rht_read(void)
{
	// First, move the pins up and down to get it going...
	gpio_set_mode(PORT_RHT_IO, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, PIN_RHT_IO);
	gpio_clear(PORT_RHT_IO, PIN_RHT_IO);
	delay_ms(20); // docs say 1-10ms is enough....
	gpio_set(PORT_RHT_IO, PIN_RHT_IO);
	// want to wait for 40us here, but we're ok with letting some code delay us..
	state.bitcount = 0;
	state.seen_startbit = false;
	state.rht_timeout = false;
	nvic_enable_irq(RHT_NVIC);
	// pull up will finish the job here for us.
	gpio_set_mode(PORT_RHT_IO, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, PIN_RHT_IO);
	exti_select_source(RHT_EXTI, PORT_RHT_IO);
	exti_set_trigger(RHT_EXTI, EXTI_TRIGGER_FALLING);
	exti_enable_request(RHT_EXTI);
	setup_tim7();
}
コード例 #16
0
ファイル: haptic.c プロジェクト: Chen-Leon/DeviationX
void VIBRATINGMOTOR_Init()
{
    if (!HAS_VIBRATINGMOTOR)
        return;
    rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPDEN);

    gpio_set_mode(GPIOD, GPIO_MODE_OUTPUT_2_MHZ,
            GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
    gpio_clear(GPIOD, GPIO2);
}
コード例 #17
0
ファイル: stm32utils.c プロジェクト: Saul2588/ousia
/*
 * @brief   stm32 board specific init
 * @param   none
 * @return  none
 * @note    none
 */
void stm32utils_system_init(void)
{
    setupFlash();
    setupClocks();
    setupNVIC();
    systick_init(SYSTICK_RELOAD_VAL);
    gpio_init_all();
    afio_init();
    setupADC();
    setupTimers();
    setupUSART(USARTx, SERIAL_BAUDRATE);

    gpio_set_mode(GPIOA, 0, GPIO_OUTPUT_PP);
    gpio_write_bit(GPIOA, 0, 0);
    gpio_set_mode(GPIOA, 1, GPIO_OUTPUT_PP);
    gpio_write_bit(GPIOA, 1, 0);
    gpio_set_mode(GPIOA, 12, GPIO_OUTPUT_PP);
    gpio_write_bit(GPIOA, 12, 0);
}
コード例 #18
0
ファイル: platform.c プロジェクト: DanielO/blackmagic
void disconnect_usb(void)
{
	/* Disconnect USB cable by resetting USB Device and pulling USB_DP low*/
	rcc_periph_reset_pulse(RST_USB);
	rcc_periph_clock_enable(RCC_USB);
	rcc_periph_clock_enable(RCC_GPIOA);
	gpio_clear(GPIOA, GPIO12);
	gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
		GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12);
}
コード例 #19
0
ファイル: usart.c プロジェクト: ericwahahaha/nucleo_tests
int main(void)
{
    int32_t i;

    rcc_periph_clock_enable(RCC_GPIOA);
    gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);

    flash_set_ws(FLASH_ACR_LATENCY_2WS);
	rcc_set_adcpre(RCC_CFGR_ADCPRE_PCLK2_DIV4); /* 14MHz */
	rcc_set_hpre(RCC_CFGR_HPRE_SYSCLK_NODIV); /* 56MHz */
	rcc_set_ppre1(RCC_CFGR_PPRE1_HCLK_DIV2); /* 28MHz */
	rcc_set_ppre2(RCC_CFGR_PPRE2_HCLK_NODIV); /* 56MHz */
    rcc_set_pll_multiplication_factor(RCC_CFGR_PLLMUL_PLL_CLK_MUL14); /* 8MHz/2 x14 = 56MHz */
	rcc_set_pll_source(RCC_CFGR_PLLSRC_HSI_CLK_DIV2);
	rcc_osc_on(PLL);
	rcc_wait_for_osc_ready(PLL);
	rcc_set_sysclk_source(RCC_CFGR_SW_SYSCLKSEL_PLLCLK);

    rcc_periph_clock_enable(RCC_USART2);
    gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
    gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX);

    uint32_t baud = 57600;
    uint32_t clock = 28000000;
	USART2_BRR = ((2 * clock) + baud) / (2 * baud);
    
	usart_set_databits(USART2, 8);
	usart_set_stopbits(USART2, USART_STOPBITS_1);
	usart_set_mode(USART2, USART_MODE_TX_RX);
	usart_set_parity(USART2, USART_PARITY_NONE);
	usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
	usart_enable(USART2);

    usart_puts(USART2, "ready to receive.\r\n");
    gpio_set(GPIOA, GPIO5);
    while(1)
    {
        uint16_t c;
        c = usart_recv_blocking(USART2);
        usart_send_blocking(USART2, toupper(c));
        gpio_toggle(GPIOA, GPIO5);
    }
}
コード例 #20
0
static void gpio_setup(void)
{
	/*
	 * Set GPIO6 and 7 (in GPIO port A) to
	 * 'output alternate function push-pull'.
	 */
	gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
		      GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
		      GPIO_TIM3_CH1 | GPIO_TIM3_CH2);

	/*
	 * Set GPIO0 and 1 (in GPIO port B) to
	 * 'output alternate function push-pull'.
	 */
	gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
		      GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
		      GPIO_TIM3_CH3 | GPIO_TIM3_CH4);

}
コード例 #21
0
ファイル: swdptap.c プロジェクト: mbolivar/blackmagic
static void swdptap_turnaround(uint8_t dir)
{
	static uint8_t olddir = 0;

	DEBUG("%s", dir ? "\n-> ":"\n<- ");

	/* Don't turnaround if direction not changing */
	if(dir == olddir) return;
	olddir = dir;

	if(dir) 
		gpio_set_mode(SWDP_PORT, GPIO_MODE_INPUT, 
				GPIO_CNF_INPUT_FLOAT, SWDIO_PIN);
	gpio_set(SWDP_PORT, SWCLK_PIN);
	gpio_clear(SWDP_PORT, SWCLK_PIN);
	if(!dir) 
		gpio_set_mode(SWDP_PORT, GPIO_MODE_OUTPUT_50_MHZ, 
				GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN);
}
コード例 #22
0
void uart_init_gpio_usart1(void)
{
	/* Enable clocks for USART1 (and the gpios it's connected to) */
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
	rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART1EN);
	gpio_set_mode(GPIOA,
		GPIO_MODE_OUTPUT_50_MHZ,
		GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
		GPIO9);

	gpio_set_mode(GPIOA,
		GPIO_MODE_INPUT,
		GPIO_CNF_INPUT_FLOAT,
		GPIO10);

	/* USART lines should idle high */
	gpio_set(GPIOA, GPIO9);
	gpio_set(GPIOA, GPIO10);
}
コード例 #23
0
ファイル: usb.c プロジェクト: iperry/libmaple
void setupUSB (void) {
  gpio_set_mode(USB_DISC_DEV, USB_DISC_PIN, GPIO_OUTPUT_PP);

  /* setup the apb1 clock for USB */
  pRCC->APB1ENR |= 0x00800000;

  /* initialize the usb application */
  gpio_write_bit(USB_DISC_DEV, USB_DISC_PIN, 0); // presents us to the host
  USB_Init();  // low level init routine provided by the ST library
}
コード例 #24
0
ファイル: spi.c プロジェクト: BuFran/libopencm3-examples
static void usart_setup(void)
{
	/* Setup GPIO pin GPIO_USART2_TX and GPIO_USART2_RX. */
	gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
		      GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
	gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
		      GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX);

	/* Setup UART parameters. */
	usart_set_baudrate(USART2, 9600);
	usart_set_databits(USART2, 8);
	usart_set_stopbits(USART2, USART_STOPBITS_1);
	usart_set_mode(USART2, USART_MODE_TX_RX);
	usart_set_parity(USART2, USART_PARITY_NONE);
	usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);

	/* Finally enable the USART. */
	usart_enable(USART2);
}
コード例 #25
0
ファイル: main.c プロジェクト: 9DSmart/stm32-pwm-servo-sample
/**
 * Initialize the GPIO port for the LED at pin 12 on port C.
 */
void gpio_init(void)
{
     /* enable GPIOC clock */
     rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);

     /*
      * set GPIO12 at PORTC (led) to 'output alternate function push-pull'.
      */
     gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
}
コード例 #26
0
ファイル: systick.c プロジェクト: BuFran/libopencm3-examples
static void gpio_setup(void)
{
	/* Enable alternate function peripheral clock. */
	rcc_periph_clock_enable(RCC_AFIO);

	/* Enable GPIOB clock. */
	rcc_periph_clock_enable(RCC_GPIOB);

	gpio_clear(GPIOB, GPIO4); /* LED green on */
	gpio_set(GPIOB, GPIO5);   /* LED red off */

	/* Set GPIO4/5 (in GPIO port B) to 'output push-pull' for the LEDs. */
	gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
		      GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
	gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
		      GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);

	AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
}
コード例 #27
0
void cdcacm_target_init(void)
{
	rcc_clock_setup_in_hsi_out_48mhz();

	rcc_periph_clock_enable(RCC_GPIOC);

	gpio_set(GPIOC, GPIO11);
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
		      GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
}
コード例 #28
0
void usb_midi_enable(gpio_dev *disc_dev, uint8 disc_bit) {
    /* Present ourselves to the host. Writing 0 to "disc" pin must
     * pull USB_DP pin up while leaving USB_DM pulled down by the
     * transceiver. See USB 2.0 spec, section 7.1.7.3. */
    gpio_set_mode(disc_dev, disc_bit, GPIO_OUTPUT_PP);
    gpio_write_bit(disc_dev, disc_bit, 0);

    /* Initialize the USB peripheral. */
    usb_init_usblib(USBLIB, ep_int_in, ep_int_out);
}
コード例 #29
0
ファイル: example.c プロジェクト: MikrySoft/openfat
void stm32_setup(void)
{
	/* Setup SYSCLK */
	rcc_clock_setup_in_hsi_out_48mhz();

	/* Enable peripheral clocks for GPIOA, GPIOB, SPI2 */
	rcc_peripheral_enable_clock(&RCC_APB2ENR, 
				RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN);

	rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_SPI2EN);

	/* Enable power to SD card */
	gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
			GPIO2);
	gpio_set(GPIOA, GPIO2);

	/* Force to SPI mode.  This should be default after reset! */
	SPI2_I2SCFGR = 0; 

	/* Configure SD card i/f SPI2: PB13(SCK), PB14(MISO), PB15(MOSI) */
	gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_10_MHZ, 
			GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
			GPIO_SPI2_SCK | GPIO_SPI2_MOSI);
	gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
			GPIO_SPI2_MISO);
	/* SD nCS pin is GPIOA 3 */
	gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
			GPIO3);

	/* Enable Systick for benchmark timing */
	/* 48MHz / 8 => 6000000 counts per second */
	systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); 
	/* 6000000/6000 = 1000 overflows per second - every 1ms one interrupt */
	systick_set_reload(6000);
	systick_interrupt_enable();
	/* start counting */
	systick_counter_enable();

	/* Enable LED output */
	gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
			GPIO12);
	gpio_set(GPIOB, GPIO12);
}
コード例 #30
0
ファイル: hbridge.cpp プロジェクト: arpit15/SubjuGator
void hbridge_init() {
  // M- bridge
  // A9 - pin 21 - PWM2A - HIN
  // B0 - pin 15 - PWM2B - \LIN
  
  // M+ bridge
  // A8 - pin 20 - PWM1A - HIN
  // A7 - pin 14 - PWM1B - \LIN
  
  rcc_peripheral_enable_clock(&RCC_APB2ENR,
    RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |
    RCC_APB2ENR_AFIOEN | RCC_APB2ENR_TIM1EN);
  
  AFIO_MAPR |= AFIO_MAPR_TIM1_REMAP_PARTIAL_REMAP;
  gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
                GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO7 | GPIO8 | GPIO9);
  gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
                GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO0);
  
  timer_reset(TIM1);
  timer_set_mode(TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_CENTER_1,
                 TIM_CR1_DIR_UP);
  timer_set_period(TIM1, half_period_ticks);
  timer_set_prescaler(TIM1, 9); // / 10
  
  timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM2);
  timer_set_oc_polarity_high(TIM1, TIM_OC1);
  timer_set_oc_polarity_low(TIM1, TIM_OC1N);
  timer_enable_oc_output(TIM1, TIM_OC1);
  timer_enable_oc_output(TIM1, TIM_OC1N);
  timer_set_oc_value(TIM1, TIM_OC1, half_period_ticks);
  
  timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_PWM2);
  timer_set_oc_polarity_high(TIM1, TIM_OC2);
  timer_set_oc_polarity_low(TIM1, TIM_OC2N);
  timer_enable_oc_output(TIM1, TIM_OC2);
  timer_enable_oc_output(TIM1, TIM_OC2N);
  timer_set_oc_value(TIM1, TIM_OC2, half_period_ticks);
  
  timer_enable_break_main_output(TIM1);
  timer_enable_counter(TIM1);
}