void ConfigHWled(void) { GPIO_SetMode(PB, BIT13, GPIO_MODE_OUTPUT); //LED1 GPIO_SetMode(PB, BIT12, GPIO_MODE_OUTPUT); //LED2 }
void Atomizer_Init() { // Select shunt value based on hardware version switch(Dataflash_info.hwVersion) { case 101: case 108: Atomizer_shuntRes = 125; break; case 103: case 104: case 105: case 106: Atomizer_shuntRes = 110; break; case 107: case 109: Atomizer_shuntRes = 120; break; case 110: case 111: Atomizer_shuntRes = 105; break; case 100: case 102: default: Atomizer_shuntRes = 115; break; } // Setup control pins PC1 = 0; GPIO_SetMode(PC, BIT1, GPIO_MODE_OUTPUT); PC3 = 0; GPIO_SetMode(PC, BIT3, GPIO_MODE_OUTPUT); // Both channels powered down Atomizer_ConfigureConverters(0, 0); // Configure 150kHz PWM PWM_ConfigOutputChannel(PWM0, ATOMIZER_PWMCH_BUCK, 150000, 0); PWM_ConfigOutputChannel(PWM0, ATOMIZER_PWMCH_BOOST, 150000, 0); // Start PWM PWM_EnableOutput(PWM0, PWM_CH_0_MASK); PWM_EnableOutput(PWM0, PWM_CH_2_MASK); PWM_Start(PWM0, PWM_CH_0_MASK); PWM_Start(PWM0, PWM_CH_2_MASK); // Set duty cycle to zero PWM_SET_CMR(PWM0, ATOMIZER_PWMCH_BUCK, 0); PWM_SET_CMR(PWM0, ATOMIZER_PWMCH_BOOST, 0); Atomizer_targetVolts = 0; Atomizer_curCmr = 0; Atomizer_curState = POWEROFF; // Setup 5kHz timer for negative feedback cycle // This function should run during system init, so // the user hasn't had time to create timers yet. Timer_CreateTimer(5000, 1, Atomizer_TimerCallback, 0); }
/** * Configures a PWM channel. * This is an internal function. * * @param channel PWM channel to configure. * @param enable True to enable the channel, false to disable it. */ static void Atomizer_ConfigurePWMChannel(uint8_t channel, uint8_t enable) { // If the channel is enabled, we set the MFP register to PWM // If it is disabled, we set it as a GPIO output switch(channel) { case ATOMIZER_PWMCH_BUCK: SYS->GPC_MFPL &= ~SYS_GPC_MFPL_PC0MFP_Msk; if(enable) { SYS->GPC_MFPL |= SYS_GPC_MFPL_PC0MFP_PWM0_CH0; } else { PC0 = 1; GPIO_SetMode(PC, BIT0, GPIO_MODE_OUTPUT); } break; case ATOMIZER_PWMCH_BOOST: SYS->GPC_MFPL &= ~SYS_GPC_MFPL_PC2MFP_Msk; if(enable) { SYS->GPC_MFPL |= SYS_GPC_MFPL_PC2MFP_PWM0_CH2; } else { PC2 = 1; GPIO_SetMode(PC, BIT2, GPIO_MODE_OUTPUT); } break; } }
void Display_SetupSPI() { // Setup output pins PA0 = 0; GPIO_SetMode(PA, BIT0, GPIO_MODE_OUTPUT); PA1 = 0; GPIO_SetMode(PA, BIT1, GPIO_MODE_OUTPUT); PC4 = 0; GPIO_SetMode(PC, BIT4, GPIO_MODE_OUTPUT); PE10 = 0; GPIO_SetMode(PE, BIT10, GPIO_MODE_OUTPUT); PE12 = 0; GPIO_SetMode(PE, BIT12, GPIO_MODE_OUTPUT); // Setup MFP SYS->GPB_MFPL &= ~(SYS_GPE_MFPH_PE11MFP_Msk | SYS_GPE_MFPH_PE12MFP_Msk | SYS_GPE_MFPH_PE13MFP_Msk); SYS->GPE_MFPH |= SYS_GPE_MFPH_PE11MFP_SPI0_MOSI0 | SYS_GPE_MFPH_PE12MFP_SPI0_SS | SYS_GPE_MFPH_PE13MFP_SPI0_CLK; // SPI0 master, MSB first, 8bit transaction, SPI Mode-0 timing, 4MHz clock SPI_Open(SPI0, SPI_MASTER, SPI_MODE_0, 8, 4000000); // Low level active SPI_EnableAutoSS(SPI0, SPI_SS, SPI_SS_ACTIVE_LOW); // Start SPI SPI_ENABLE(SPI0); }
void ConfigHWDoor(void) { GPIO_SetMode(PB, BIT11,GPIO_MODE_INPUT); //¿ª¹Ø GPIO_SetMode(PB, BIT10,GPIO_MODE_INPUT); //ÃÅ´Å GPIO_SetMode(PB, BIT9, GPIO_MODE_INPUT); // GPIO_SetMode(PB, BIT8, GPIO_MODE_OUTPUT); //door }
/** * @brief This function config PC.13 multi-function for PWM to drive Buzzer module, and config PE.6 multi-function for GPIO to control Buzzer power * @return None */ void Initial_PWM_GPIO(void) { GPIO_SetMode(PC, BIT13, GPIO_PMD_OUTPUT); //Buzzer OUT GPIO_SetMode(PE, BIT6, GPIO_PMD_OUTPUT); //Buzzer POWER /* Set PC 13 multi-function pins for PWM0 channel 0*/ SYS->PC_H_MFP = (SYS->PC_H_MFP & ~(SYS_PC_H_MFP_PC13_MFP_Msk )); SYS->PC_H_MFP |= SYS_PC_H_MFP_PC13_MFP_PWM1_CH1; }
void Init_GPIO(void) { /* BLE or WiFi Reset */ GPIO_SetMode(platform_gpio_pins[BLE_WIFI_RESET].port, platform_gpio_pins[BLE_WIFI_RESET].pin_number, GPIO_MODE_OUTPUT); GPIO_SetPinOutHigh(platform_gpio_pins[BLE_WIFI_RESET].port, platform_gpio_pins[BLE_WIFI_RESET].pin_number); /* MPU6050 Interrupt pin */ GPIO_SetMode(platform_gpio_pins[MPU6050_INT].port, platform_gpio_pins[MPU6050_INT].pin_number, GPIO_MODE_QUASI); /* GAS Enable */ GPIO_SetMode(platform_gpio_pins[GAS_EN].port, platform_gpio_pins[GAS_EN].pin_number, GPIO_MODE_OUTPUT); GPIO_SetPinOutHigh(platform_gpio_pins[GAS_EN].port, platform_gpio_pins[GAS_EN].pin_number); /* Main Board Red Green Blue LED */ GPIO_SetMode(platform_gpio_pins[LED_MAINB_R].port, platform_gpio_pins[LED_MAINB_R].pin_number, GPIO_MODE_OUTPUT); GPIO_SetPinOutHigh(platform_gpio_pins[LED_MAINB_R].port, platform_gpio_pins[LED_MAINB_R].pin_number); GPIO_SetMode(platform_gpio_pins[LED_MAINB_G].port, platform_gpio_pins[LED_MAINB_G].pin_number, GPIO_MODE_OUTPUT); GPIO_SetPinOutHigh(platform_gpio_pins[LED_MAINB_G].port, platform_gpio_pins[LED_MAINB_G].pin_number); GPIO_SetMode(platform_gpio_pins[LED_MAINB_B].port, platform_gpio_pins[LED_MAINB_B].pin_number, GPIO_MODE_OUTPUT); GPIO_SetPinOutHigh(platform_gpio_pins[LED_MAINB_B].port, platform_gpio_pins[LED_MAINB_B].pin_number); /* Sensor Board Red Green Blue LED */ GPIO_SetMode(platform_gpio_pins[LED_SENB_R].port, platform_gpio_pins[LED_SENB_R].pin_number, GPIO_MODE_OUTPUT); GPIO_SetPinOutHigh(platform_gpio_pins[LED_SENB_R].port, platform_gpio_pins[LED_SENB_R].pin_number); GPIO_SetMode(platform_gpio_pins[LED_SENB_G].port, platform_gpio_pins[LED_SENB_G].pin_number, GPIO_MODE_OUTPUT); GPIO_SetPinOutHigh(platform_gpio_pins[LED_SENB_G].port, platform_gpio_pins[LED_SENB_G].pin_number); GPIO_SetMode(platform_gpio_pins[LED_SENB_B].port, platform_gpio_pins[LED_SENB_B].pin_number, GPIO_MODE_OUTPUT); GPIO_SetPinOutHigh(platform_gpio_pins[LED_SENB_B].port, platform_gpio_pins[LED_SENB_B].pin_number); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); if(WDT_GET_RESET_FLAG() == 1) { /* Use PA.0 to check time-out period time */ GPIO_SetMode(PA, BIT0, GPIO_PMD_OUTPUT); PA0 = 1; WDT_CLEAR_RESET_FLAG(); printf("\n\n*** WDT time-out reset occurred ***\n"); while(1); } printf("\n\nCPU @ %d Hz\n", SystemCoreClock); printf("+--------------------------------------+\n"); printf("| WDT Time-out Reset Sample Code |\n"); printf("+--------------------------------------+\n\n"); printf("# WDT Settings:\n"); printf(" Clock source is 10 kHz; Enable interrupt; Time-out interval is 2^14 * WDT clock.\n"); printf("# When WDT start counting, system will generate a WDT time-out interrupt after 1.6384 ~ 1.7408 s.\n"); printf(" Measure PA.0 low period to check time-out interval and do not reload WDT counter will cause system reset.\n\n"); /* Use PA.0 to check time-out period time */ GPIO_SetMode(PA, BIT0, GPIO_PMD_OUTPUT); PA0 = 1; PA0 = 0; /* Because of all bits can be written in WDT Control Register are write-protected; To program it needs to disable register protection first. */ SYS_UnlockReg(); /* Enable WDT time-out reset function and select time-out interval to 2^14 * WDT clock then start WDT counting */ g_u8IsWDTTimeoutINT = 0; WDT_Open(WDT_TIMEOUT_2POW14, WDT_RESET_DELAY_1026CLK, TRUE, FALSE); /* Enable WDT interrupt function */ WDT_EnableInt(); /* Enable WDT NVIC */ NVIC_EnableIRQ(WDT_IRQn); while(1); }
void detect_board_version() { //unconnected pins will have their weak pullups going, so they will be at VCC GPIO_SetMode(PA, BIT12, GPIO_PMD_INPUT); GPIO_SetMode(PA, BIT13, GPIO_PMD_INPUT); GPIO_SetMode(PA, BIT14, GPIO_PMD_INPUT); //all grounded if(PA12 == 0 && PA13 == 0 && PA14 == 0) { boardver = 2; } }
void port_dir(port_t *obj, PinDirection dir) { uint32_t i; obj->direction = dir; for (i = 0; i < GPIO_PIN_MAX; i++) { if (obj->mask & (1 << i)) { if (dir == PIN_OUTPUT) { GPIO_SetMode(NU_PORT_BASE(obj->port), 1 << i, GPIO_MODE_OUTPUT); } else { // PIN_INPUT GPIO_SetMode(NU_PORT_BASE(obj->port), 1 << i, GPIO_MODE_INPUT); } } } }
void ConfigHWSpiport(void) { // plese ensure has opened the system clock of SPI1 mode. CLK_EnableModuleClock(SPI1_MODULE); //1st . config pin MFP function /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* SPI1: PC15=MOSI0, PD0=MISO0, PD1=CLK */ //note :there is a qustion that for the Register option must be "OR" bits. //othewith, will occured changed other Hardwave bits. SYS->GPC_MFPH |= (SYS_GPC_MFPH_PC15MFP_SPI1_MOSI0); SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD0MFP_SPI1_MISO0 | SYS_GPD_MFPL_PD1MFP_SPI1_CLK); //2st . config the SPI1 of Hardwave Port /* Configure SPI1 as a master, MSB first, 8-bit transaction, SPI Mode-0 timing, clock is 400KHz */ SPI_Open(SPI1, SPI_MASTER, SPI_MODE_0, 8, 400000); //open SPI1 and config it. SPI_DisableAutoSS(SPI1);//closed the ss by hardwave and give it for softwave ctrl that well used ctrl SS/HSA pin select ADE7878 into the SPI mode. SPI_TRIGGER(SPI1);//start SPI1 transf. //3st . config the SS/HSA pin GPIO_SetMode(PC, BIT12, GPIO_MODE_OUTPUT);// SP1 SS pin by SOFTWAVE ctrl PC12=1;// hold the pin hight.. //2016 01 03 make by wangjunwei in bittel. }
/** * Configure pin pull-up/pull-down */ void pin_mode(PinName pin, PinMode mode) { MBED_ASSERT(pin != (PinName)NC); uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); GPIO_T *gpio_base = NU_PORT_BASE(port_index); uint32_t mode_intern = GPIO_MODE_INPUT; switch (mode) { case PullUp: mode_intern = GPIO_MODE_INPUT; break; case PullDown: case PullNone: // NOTE: Not support return; case PushPull: mode_intern = GPIO_MODE_OUTPUT; break; case OpenDrain: mode_intern = GPIO_MODE_OPEN_DRAIN; break; case Quasi: mode_intern = GPIO_MODE_QUASI; break; } GPIO_SetMode(gpio_base, 1 << pin_index, mode_intern); }
void can_init(can_t *obj, PinName rd, PinName td) { uint32_t can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); uint32_t can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); obj->can = (CANName)pinmap_merge(can_td, can_rd); MBED_ASSERT((int)obj->can != NC); const struct nu_modinit_s *modinit = get_modinit(obj->can, can_modinit_tab); MBED_ASSERT(modinit != NULL); MBED_ASSERT(modinit->modname == obj->can); // Reset this module SYS_ResetModule(modinit->rsetidx); // Enable IP clock CLK_EnableModuleClock(modinit->clkidx); obj->index = 0; pinmap_pinout(td, PinMap_CAN_TD); pinmap_pinout(rd, PinMap_CAN_RD); /* For M453 mbed Board Transmitter Setting (RS Pin) */ GPIO_SetMode(PA, BIT0| BIT1, GPIO_MODE_OUTPUT); PA0 = 0x00; PA1 = 0x00; CAN_Open((CAN_T *)NU_MODBASE(obj->can), 500000, CAN_NORMAL_MODE); can_filter(obj, 0, 0, CANStandard, 0); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %d Hz\n", SystemCoreClock); printf("+-------------------------------------------------------+\n"); printf("| GPIO Power-Down and Wake-up by PB.3 Sample Code |\n"); printf("+-------------------------------------------------------+\n\n"); /* Configure PB.3 as Input mode and enable interrupt by rising edge trigger */ GPIO_SetMode(PB, BIT3, GPIO_PMD_INPUT); GPIO_EnableInt(PB, 3, GPIO_INT_RISING); NVIC_EnableIRQ(GPAB_IRQn); /* Waiting for PB.3 rising-edge interrupt event */ while(1) { printf("Enter to Power-Down ......\n"); PowerDownFunction(); UART_WAIT_TX_EMPTY(UART0); printf("System waken-up done.\n\n"); } }
/** * @brief Main routine. * @param None. * @return None. */ int32_t main(void) { SYS_UnlockReg(); SYS->P5_MFP = (SYS->P5_MFP & 0x00FFFCFC) | 0x03; /* P5.1 -> XTAL2, P5.0 -> XTAL1 */ CLK->PWRCON = CLK_PWRCON_XTL12M | 4 | 8 ; SYS_Init(); /* SPI test */ LCD_Init(); LCD_EnableBackLight(); LCD_ClearScreen(); LCD_Print(0, "Welcome! Nuvoton"); LCD_Print(1, "This is LB board"); LCD_Print(2, "Mini51"); LCD_Print(3, "TEST"); // backlight control pin P5.4 GPIO_SetMode(P5,1<<4,GPIO_PMD_OUTPUT); /* INT button triggers P3.2 */ GPIO_SetMode(P3,(1<<2),GPIO_PMD_OPEN_DRAIN); GPIO_EnableInt(P3, 2, GPIO_INT_FALLING); NVIC_EnableIRQ(EINT0_IRQn); /* Enable interrupt de-bounce function and select de-bounce sampling cycle time */ GPIO_SET_DEBOUNCE_TIME(GPIO_DBNCECON_DBCLKSRC_HCLK,GPIO_DBNCECON_DBCLKSEL_16); GPIO_ENABLE_DEBOUNCE(P3,1<<2); /* Reset and stop TIMER0, TIMER1 counting first */ TIMER1->TCSR = TIMER_TCSR_CRST_Msk; /* Enable TIMER0, TIMER1, NVIC */ NVIC_EnableIRQ(TMR1_IRQn); /* To Configure TCMPR values based on Timer clock source and pre-scale value */ TIMER_SET_PRESCALE_VALUE(TIMER1,0); /* Start TIMER1 counting and setting*/ TIMER_Open(TIMER1,TIMER_PERIODIC_MODE,SystemCoreClock/1000); TIMER_EnableInt(TIMER1); while(1) ; // loop forever }
//============================================================================= __myevic__ void SetADCState( int module, int onoff ) { int pin, mode; mode = onoff ? GPIO_MODE_INPUT : GPIO_MODE_OUTPUT; switch ( module ) { case 1: pin = GPIO_PIN_PIN1_Msk; SYS->GPB_MFPL &= ~SYS_GPB_MFPL_PB1MFP_Msk; if ( onoff ) { SYS->GPB_MFPL |= SYS_GPB_MFPL_PB1MFP_EADC_CH1; } else { PB1 = 0; } break; case 2: pin = GPIO_PIN_PIN2_Msk; SYS->GPB_MFPL &= ~SYS_GPB_MFPL_PB2MFP_Msk; if ( onoff ) { SYS->GPB_MFPL |= SYS_GPB_MFPL_PB2MFP_EADC_CH2; } else { PB2 = 0; } break; case 14: pin = GPIO_PIN_PIN6_Msk; SYS->GPB_MFPL &= ~SYS_GPB_MFPL_PB6MFP_Msk; if ( onoff ) { SYS->GPB_MFPL |= SYS_GPB_MFPL_PB6MFP_EADC_CH14; } else { PB6 = 0; } break; default: return; } GPIO_SetMode( PB, pin, mode ); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { uint32_t u32IntCnts = 0; /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); printf("CPU @ %d Hz\n", SystemCoreClock); printf("+------------------------------------------+\n"); printf("| WDT Time-out Interrupt Sample Code |\n"); printf("+------------------------------------------+\n\n"); printf("# WDT Settings:\n"); printf(" - Clock source is 10 kHz \n"); printf(" - Time-out interval is 2^14 * WDT clock \n"); printf(" (around 1.6384 second) \n"); printf(" - Interrupt enable \n"); printf("# System will generate a WDT time-out interrupt event after around 1.6384 second.\n"); printf(" (Use PA.0 high/low period time to check WDT time-out interval)\n\n"); /* Use PA.0 to check time-out period time */ GPIO_SetMode(PA, BIT0, GPIO_PMD_OUTPUT); PA0 = 1; PA0 = 0; /* Because of all bits can be written in WDT Control Register are write-protected; To program it needs to disable register protection first. */ SYS_UnlockReg(); /* Select WDT time-out interval to 2^14 * WDT clock then start WDT counting */ g_u8IsWDTTimeoutINT = 0; WDT_Open(WDT_TIMEOUT_2POW14, 0, FALSE, FALSE); /* Enable WDT interrupt function */ WDT_EnableInt(); /* Enable WDT NVIC */ NVIC_EnableIRQ(WDT_IRQn); while(1) { /* Check if WDT time-out interrupt occurred or not */ while(g_u8IsWDTTimeoutINT == 0); g_u8IsWDTTimeoutINT = 0; PA0 ^= 1; printf("WDT time-out interrupt occurred. INT counts: %d \r", ++u32IntCnts); } }
void LED_Init(void) { GPIO_SetMode(P5, BIT4, GPIO_MODE_OUTPUT); //P14用于MPU6880 DMP中断 // GPIO_SetMode(P1, BIT4, GPIO_PMD_INPUT); // GPIO_EnableInt(P1, 4, GPIO_INT_HIGH); // NVIC_EnableIRQ(GPIO01_IRQn); }
//========================================================================= //----- (00005CC0) -------------------------------------------------------- __myevic__ void BBC_Configure( uint32_t chan, uint32_t mode ) { if ( chan == BBC_PWMCH_BUCK ) { SYS->GPC_MFPL &= ~SYS_GPC_MFPL_PC0MFP_Msk; if ( mode ) { SYS->GPC_MFPL |= SYS_GPC_MFPL_PC0MFP_PWM0_CH0; } else { GPIO_SetMode( PC, GPIO_PIN_PIN0_Msk, GPIO_MODE_OUTPUT ); } } else if ( chan == BBC_PWMCH_BOOST ) { SYS->GPC_MFPL &= ~SYS_GPC_MFPL_PC2MFP_Msk; if ( mode ) { SYS->GPC_MFPL |= SYS_GPC_MFPL_PC2MFP_PWM0_CH2; } else { GPIO_SetMode( PC, GPIO_PIN_PIN2_Msk, GPIO_MODE_OUTPUT ); } } else if ( chan == BBC_PWMCH_CHARGER ) { SYS->GPD_MFPL &= ~SYS_GPD_MFPL_PD7MFP_Msk; if ( mode ) { SYS->GPD_MFPL |= SYS_GPD_MFPL_PD7MFP_PWM0_CH5; } else { GPIO_SetMode( PD, GPIO_PIN_PIN7_Msk, GPIO_MODE_OUTPUT ); } } }
void HWGPIO_Config(void) { /* Configure P3.2 as EINT0 pin and enable interrupt by falling edge trigger */ GPIO_SetMode(P3, BIT2, GPIO_PMD_INPUT); GPIO_EnableEINT0(P3, 2, GPIO_INT_BOTH_EDGE); NVIC_EnableIRQ(EINT0_IRQn); /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 10 KHz clock */ GPIO_SET_DEBOUNCE_TIME(GPIO_DBCLKSRC_LIRC, GPIO_DBCLKSEL_1); GPIO_ENABLE_DEBOUNCE(P3, BIT2); }
void Config_ADE7878_IRQ(void) { /* Configure PB4-5 as INPUT mode and enable interrupt by falling edge trigger */ GPIO_SetMode(PB, BIT5, GPIO_MODE_INPUT); GPIO_EnableInt(PB, 4, GPIO_INT_FALLING); //IRQ1 GPIO_EnableInt(PB, 5, GPIO_INT_FALLING); //IRQ0 NVIC_SetPriority(GPB_IRQn, 10 ); NVIC_EnableIRQ(GPB_IRQn); }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %d Hz\n", SystemCoreClock); printf("+------------------------------------------------------------+\n"); printf("| GPIO EINT0/EINT1 Interrupt and De-bounce Sample Code |\n"); printf("+------------------------------------------------------------+\n\n"); /*-----------------------------------------------------------------------------------------------------*/ /* GPIO External Interrupt Function Test */ /*-----------------------------------------------------------------------------------------------------*/ printf("EINT0(PB.14) and EINT1(PB.15) are used to test interrupt\n"); /* Configure PB.14 as EINT0 pin and enable interrupt by falling edge trigger */ GPIO_SetMode(PB, BIT14, GPIO_PMD_INPUT); GPIO_EnableEINT0(PB, 14, GPIO_INT_FALLING); NVIC_EnableIRQ(EINT0_IRQn); /* Configure PB.15 as EINT1 pin and enable interrupt by rising and falling edge trigger */ GPIO_SetMode(PB, BIT15, GPIO_PMD_INPUT); GPIO_EnableEINT1(PB, 15, GPIO_INT_BOTH_EDGE); NVIC_EnableIRQ(EINT1_IRQn); /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 * 10 KHz clock */ GPIO_SET_DEBOUNCE_TIME(GPIO_DBCLKSRC_LIRC, GPIO_DBCLKSEL_1024); GPIO_ENABLE_DEBOUNCE(PB, BIT14 | BIT15); /* Waiting for interrupts */ while(1); }
void Usart_Init(void) { /* Enable IP clock */ CLK_EnableModuleClock(UART3_MODULE); /* Select IP clock source */ CLK_SetModuleClock(UART3_MODULE, CLK_CLKSEL1_UARTSEL_HIRC , CLK_CLKDIV0_UART(1)); /* Set GPD multi-function pins for UART3 RXD and TXD */ SYS->GPD_MFPL |= SYS_GPD_MFPL_PD4MFP_UART3_RXD | SYS_GPD_MFPL_PD5MFP_UART3_TXD ; GPIO_SetMode(PD, 5, GPIO_MODE_OUTPUT); GPIO_SetMode(PD, 4, GPIO_MODE_INPUT); UART_Open(UART3, 9600); // UART_DisableFlowCtrl(UART3); //UART_SetLine_Config(UART3, 115200, UART_WORD_LEN_8,UART_PARITY_NONE,UART_STOP_BIT_1); // UART_EnableInt(UART3, UART_INTEN_RDAIEN_Msk ); // NVIC_SetPriority(UART3_IRQn, 2 ); //NVIC_EnableIRQ(UART3_IRQn); //UART_INTEN_THREIEN_Msk NVIC_DisableIRQ(UART3_IRQn); UART_Write(UART3,"Usart3 init done!\r\n", sizeof("Usart3 init done!\r\n")); }
void ABRobotMotorInit() { GPIO_SetMode(IO_MR_CRTL0,GPIO_MODE_OUTPUT); GPIO_SetMode(IO_MR_CRTL1,GPIO_MODE_OUTPUT); GPIO_SetMode(IO_ML_CRTL0,GPIO_MODE_OUTPUT); GPIO_SetMode(IO_ML_CRTL1,GPIO_MODE_OUTPUT); GPIO_SetMode(IO_MC_CRTL0,GPIO_MODE_OUTPUT); GPIO_SetMode(IO_MC_CRTL1,GPIO_MODE_OUTPUT); }
/** * Configure pin pull-up/pull-down */ void pin_mode(PinName pin, PinMode mode) { MBED_ASSERT(pin != (PinName)NC); uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); GPIO_T *gpio_base = NU_PORT_BASE(port_index); uint32_t mode_intern = GPIO_MODE_INPUT; switch (mode) { case InputOnly: mode_intern = GPIO_MODE_INPUT; break; case PushPullOutput: mode_intern = GPIO_MODE_OUTPUT; break; case OpenDrain: mode_intern = GPIO_MODE_OPEN_DRAIN; break; case QuasiBidirectional: mode_intern = GPIO_MODE_QUASI; break; default: /* H/W doesn't support separate configuration for input pull mode/direction. * We expect upper layer would have translated input pull mode/direction * to I/O mode */ return; } GPIO_SetMode(gpio_base, 1 << pin_index, mode_intern); /* Invalid combinations of PinMode/PinDirection * * We assume developer would avoid the following combinations of PinMode/PinDirection * which are invalid: * 1. InputOnly/PIN_OUTPUT * 2. PushPullOutput/PIN_INPUT */ }
/*---------------------------------------------------------------------------------------------------------*/ int main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %d Hz\n", SystemCoreClock); printf("+-------------------------------------------------------+\n"); printf("| GPIO Power-Down and Wake-up by PB.3 Sample Code |\n"); printf("+-------------------------------------------------------+\n\n"); /* Configure PB.3 as Input mode and enable interrupt by rising edge trigger */ GPIO_SetMode(PB, BIT3, GPIO_MODE_INPUT); GPIO_EnableInt(PB, 3, GPIO_INT_RISING); NVIC_EnableIRQ(GPB_IRQn); /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 clocks of LIRC clock */ GPIO_SET_DEBOUNCE_TIME(GPIO_DBCTL_DBCLKSRC_LIRC, GPIO_DBCTL_DBCLKSEL_1024); GPIO_ENABLE_DEBOUNCE(PB, BIT3); /* Unlock protected registers before entering Power-down mode */ SYS_UnlockReg(); /* Waiting for PB.3 rising-edge interrupt event */ while(1) { printf("Enter to Power-Down ......\n"); /* Enter to Power-down mode */ PowerDownFunction(); printf("System waken-up done.\n\n"); } }
void Battery_Init(void) { #ifdef M451 SYS_UnlockReg(); /* Enable EADC module clock */ CLK_EnableModuleClock(EADC_MODULE); /* EADC clock source is 72MHz, set divider to 8, ADC clock is 72/8 MHz */ CLK_SetModuleClock(EADC_MODULE, 0, CLK_CLKDIV0_EADC(8)); SYS_LockReg(); /* Configure the GPB0 - GPB3 ADC analog input pins. */ SYS->GPB_MFPL &= ~SYS_GPB_MFPL_PB2MFP_Msk; SYS->GPB_MFPL |= SYS_GPB_MFPL_PB2MFP_EADC_CH2; GPIO_DISABLE_DIGITAL_PATH(PB, 0x4); /* Set the ADC internal sampling time, input mode as single-end and enable the A/D converter */ EADC_Open(EADC, EADC_CTL_DIFFEN_SINGLE_END); EADC_SetInternalSampleTime(EADC, 6); /* Configure the sample module 0 for analog input channel 2 and software trigger source.*/ EADC_ConfigSampleModule(EADC, 0, EADC_SOFTWARE_TRIGGER, 2); /* Clear the A/D ADINT0 interrupt flag for safe */ EADC_CLR_INT_FLAG(EADC, 0x1); /* Enable the sample module 0 interrupt. */ EADC_ENABLE_INT(EADC, 0x1);//Enable sample module A/D ADINT0 interrupt. EADC_ENABLE_SAMPLE_MODULE_INT(EADC, 0, 0x1);//Enable sample module 0 interrupt. /* Reset the ADC interrupt indicator and trigger sample module 0 to start A/D conversion */ g_u32AdcIntFlag = 0; /* Enable battery detect circuit (PA3=1)*/ GPIO_SetMode(PA, BIT3, GPIO_MODE_OUTPUT); PA3=1; #else /* TBD.. */ #endif }
/*---------------------------------------------------------------------------------------------------------*/ int main() { uint32_t u32Key, i = 0; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init Key and LED GPIO type */ GPIO_SetMode(PD, BIT3, GPIO_MODE_INPUT); Initial_Key_Input(); Initial_LED(); /* Init UART to 115200-8n1 for print message */ UART_Open(UART0, 115200); printf("+-----------------------------------------+\n"); printf("| M451 UART Sample Code |\n"); printf("+-----------------------------------------+\n"); while(1) { /* Detect Key status */ u32Key = Get_Key_Input(); if(PD3 == 0) { LED_On(i); printf("+----------------------------------+\n"); printf("| Standare printf function:%d |\n", i++); printf("+----------------------------------+\n"); } if(u32Key == 0x1) { LED_On(i); printf_UART("+------------------------------+\n"); printf_UART("| Simple printf function:%d |\n", i--); printf_UART("+------------------------------+\n"); } } }
int main(void) { /* Init System, IP clock and multi-function I/O */ SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register. /* Configure UART and set UART Baudrate */ UART_Open(UART, 115200); printf("+---------------------------------+\n"); printf("| Mini58 Toggle LED Sample |\n"); printf("+---------------------------------+\n"); /*set P1.5 to output mode */ GPIO_SetMode(P1, BIT5, GPIO_MODE_OUTPUT); while(1) { P15 = 0; delay_loop(); P15 = 1; delay_loop(); } }
void RC_PWM_Init(void) { SYS->GPB_MFPL &= ~(SYS_GPB_MFPL_PB4MFP_Msk | SYS_GPB_MFPL_PB5MFP_Msk | SYS_GPB_MFPL_PB6MFP_Msk | SYS_GPB_MFPL_PB7MFP_Msk); SYS->GPB_MFPL |= (SYS_GPB_MFPL_PB7MFP_GPIO | SYS_GPB_MFPL_PB6MFP_GPIO | SYS_GPB_MFPL_PB4MFP_GPIO | SYS_GPB_MFPL_PB5MFP_GPIO); SYS->GPD_MFPL &= ~SYS_GPD_MFPL_PD3MFP_Msk; SYS->GPD_MFPL |= SYS_GPD_MFPL_PD3MFP_GPIO; #ifdef M451 GPIO_SetMode(IO_RC_D2, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D4, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D5, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D6, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D7, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D8, GPIO_MODE_QUASI); #else DrvGPIO_Open(IO_RC_D2, E_IO_QUASI); DrvGPIO_Open(IO_RC_D4, E_IO_QUASI); DrvGPIO_Open(IO_RC_D5, E_IO_QUASI); DrvGPIO_Open(IO_RC_D6, E_IO_QUASI); DrvGPIO_Open(IO_RC_D7, E_IO_QUASI); DrvGPIO_Open(IO_RC_D8, E_IO_QUASI); DrvGPIO_SetIntCallback(GPABCallback, GPCDCallback); #endif rcValuePwm = getValue(); }