Beispiel #1
0
// Activate the bootloader without BOOT* pins.
STATIC NORETURN mp_obj_t machine_bootloader(void) {
    pyb_usb_dev_deinit();
    storage_flush();

    HAL_RCC_DeInit();
    HAL_DeInit();

#if defined(MCU_SERIES_F7)
    // arm-none-eabi-gcc 4.9.0 does not correctly inline this
    // MSP function, so we write it out explicitly here.
    //__set_MSP(*((uint32_t*) 0x1FF00000));
    __ASM volatile ("movw r3, #0x0000\nmovt r3, #0x1FF0\nldr r3, [r3, #0]\nMSR msp, r3\n" : : : "r3", "sp");

    ((void (*)(void)) *((uint32_t*) 0x1FF00004))();
#else
    __HAL_REMAPMEMORY_SYSTEMFLASH();

    // arm-none-eabi-gcc 4.9.0 does not correctly inline this
    // MSP function, so we write it out explicitly here.
    //__set_MSP(*((uint32_t*) 0x00000000));
    __ASM volatile ("movs r3, #0\nldr r3, [r3, #0]\nMSR msp, r3\n" : : : "r3", "sp");

    ((void (*)(void)) *((uint32_t*) 0x00000004))();
#endif

    while (1);
}
Beispiel #2
0
void pwmout_init_ex(pwmout_t* obj, PinName pin, uint32_t freq)
{
    HAL_RCC_DeInit();
    if (!HSE_SystemClock_Config_72Mhz()) {
        error("PWM error: switch to 72Mhz failed.");;
    }
    
    // Update the SystemCoreClock variable
    SystemCoreClockUpdate();

    if (freq > SystemCoreClock) {
        error("PWM error: clock is too high.");
    }
    
    if ( (SystemCoreClock / 2) % freq) {
        error("PWM error: unsupported clock.");
    }
    
    // Get the peripheral name from the pin and assign it to the object
    obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);

    if (obj->pwm == (PWMName)NC) {
        error("PWM error: pinout mapping failed.");
    }

    // Enable TIM clock
    if (obj->pwm == PWM_1) __TIM1_CLK_ENABLE();
    if (obj->pwm == PWM_2) __TIM2_CLK_ENABLE();
    if (obj->pwm == PWM_3) __TIM3_CLK_ENABLE();

    // Configure GPIO
    pinmap_pinout(pin, PinMap_PWM);

    obj->pin = pin;
    obj->period = 0;
    obj->pulse = 0;

    pwmout_period_ns(obj, (SystemCoreClock / 2) / freq); // 20 ms per default
}
Beispiel #3
0
/**
 * This RCC initial for system.
 * use HSE clock source
 * HSE = 20MHZ; sysclk = 20MHZ
 * sysclk source is HSE
 * AHB prescaler is 1, HCLK = SYSCKL = SystemCoreClock = 20MHZ
 */
static void RCC_Configuration(void)
{
    RCC_ClkInitTypeDef ClkInit = {0};
    RCC_OscInitTypeDef OscInit = {0};
	
	HAL_RCC_DeInit();
	
    /* Enable HSI Oscillator and Activate PLL with HSI as source */
    OscInit.OscillatorType = RCC_OSCILLATORTYPE_HSI;
    OscInit.HSIState = RCC_HSI_ON;
	OscInit.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    OscInit.PLL.PLLState = RCC_PLL_ON;
    OscInit.PLL.PLLDIV = RCC_PLLDIV_2;
    OscInit.PLL.PLLMUL = RCC_PLLMUL_4;
    OscInit.PLL.PLLSource = RCC_PLLSOURCE_HSI;
    if (HAL_RCC_OscConfig(&OscInit) != HAL_OK)
    {
        RT_ASSERT(RT_NULL);
    }

    /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
    clocks dividers */
    ClkInit.ClockType = RCC_CLOCKTYPE_SYSCLK |
                        RCC_CLOCKTYPE_HCLK |
                        RCC_CLOCKTYPE_PCLK1 |
                        RCC_CLOCKTYPE_PCLK2;

    ClkInit.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    ClkInit.AHBCLKDivider = RCC_SYSCLK_DIV1;
    ClkInit.APB1CLKDivider = RCC_HCLK_DIV1;
    ClkInit.APB2CLKDivider = RCC_HCLK_DIV1;
    if (HAL_RCC_ClockConfig(&ClkInit, FLASH_LATENCY_1) != HAL_OK)
    {
        RT_ASSERT(RT_NULL);
    }
}