不懂java的programm 发表于 2015-7-7 00:27:28

关于necleo f411RE使用std库和HAL库的问题

necleo f411RE的板子使用std库点灯程序都不正常,把gpio初始化的代码改成HAL的就正常了,f411re用不了std库吗?是necleo板子的原因还是这个芯片的原因?

不懂java的programm 发表于 2015-7-7 08:26:32

求救啊顶顶顶顶顶顶!

creep 发表于 2015-7-7 08:51:06

建议你把用标准库和HAL库写的代码贴出来看看!

lkl0305 发表于 2015-7-7 13:10:14

HAL库封装的比较完整,标准库需要自己配置的比较多,可能是少了某项吧。你在仔细看看:D

不懂java的programm 发表于 2015-7-7 13:24:20

void HAL_GPIO_Init(GPIO_TypeDef*GPIOx, GPIO_InitTypeDef *GPIO_Init)
{
uint32_t position;
uint32_t ioposition = 0x00;
uint32_t iocurrent = 0x00;
uint32_t temp = 0x00;

/* Check the parameters */
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));

/* Configure the port pins */
for(position = 0; position < GPIO_NUMBER; position++)
{
    /* Get the IO position */
    ioposition = ((uint32_t)0x01) << position;
    /* Get the current IO position */
    iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;

    if(iocurrent == ioposition)
    {
      /*--------------------- GPIO Mode Configuration ------------------------*/
      /* In case of Alternate function mode selection */
      if((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
      {
      /* Check the Alternate function parameter */
      assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
      /* Configure Alternate function mapped with the current IO */
      temp = GPIOx->AFR;
      temp &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
      temp |= ((uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & (uint32_t)0x07) * 4));
      GPIOx->AFR = temp;
      }

      /* Configure IO Direction mode (Input, Output, Alternate or Analog) */
      temp = GPIOx->MODER;
      temp &= ~(GPIO_MODER_MODER0 << (position * 2));
      temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2));
      GPIOx->MODER = temp;

      /* In case of Output or Alternate function mode selection */
      if((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) ||
         (GPIO_Init->Mode == GPIO_MODE_OUTPUT_OD) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
      {
      /* Check the Speed parameter */
      assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
      /* Configure the IO Speed */
      temp = GPIOx->OSPEEDR;
      temp &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
      temp |= (GPIO_Init->Speed << (position * 2));
      GPIOx->OSPEEDR = temp;

      /* Configure the IO Output Type */
      temp = GPIOx->OTYPER;
      temp &= ~(GPIO_OTYPER_OT_0 << position) ;
      temp |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position);
      GPIOx->OTYPER = temp;
      }

      /* Activate the Pull-up or Pull down resistor for the current IO */
      temp = GPIOx->PUPDR;
      temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
      temp |= ((GPIO_Init->Pull) << (position * 2));
      GPIOx->PUPDR = temp;

      /*--------------------- EXTI Mode Configuration ------------------------*/
      /* Configure the External Interrupt or event for the current IO */
      if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
      {
      /* Enable SYSCFG Clock */
      __HAL_RCC_SYSCFG_CLK_ENABLE();

      temp = SYSCFG->EXTICR;
      temp &= ~(((uint32_t)0x0F) << (4 * (position & 0x03)));
      temp |= ((uint32_t)(GPIO_GET_INDEX(GPIOx)) << (4 * (position & 0x03)));
      SYSCFG->EXTICR = temp;

      /* Clear EXTI line configuration */
      temp = EXTI->IMR;
      temp &= ~((uint32_t)iocurrent);
      if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
      {
          temp |= iocurrent;
      }
      EXTI->IMR = temp;

      temp = EXTI->EMR;
      temp &= ~((uint32_t)iocurrent);
      if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
      {
          temp |= iocurrent;
      }
      EXTI->EMR = temp;

      /* Clear Rising Falling edge configuration */
      temp = EXTI->RTSR;
      temp &= ~((uint32_t)iocurrent);
      if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
      {
          temp |= iocurrent;
      }
      EXTI->RTSR = temp;

      temp = EXTI->FTSR;
      temp &= ~((uint32_t)iocurrent);
      if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
      {
          temp |= iocurrent;
      }
      EXTI->FTSR = temp;
      }
    }
}
}









////////////////////////////////////////////////////////////////////////////////

void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
{
uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;

/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));

/* ------------------------- Configure the port pins ---------------- */
/*-- GPIO Mode Configuration --*/
for (pinpos = 0x00; pinpos < 0x10; pinpos++)
{
    pos = ((uint32_t)0x01) << pinpos;
    /* Get the port pins position */
    currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;

    if (currentpin == pos)
    {
      GPIOx->MODER&= ~(GPIO_MODER_MODER0 << (pinpos * 2));
      GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));

      if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
      {
      /* Check Speed mode parameters */
      assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));

      /* Speed mode configuration */
      GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
      GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));

      /* Check Output mode parameters */
      assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));

      /* Output mode configuration*/
      GPIOx->OTYPER&= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos)) ;
      GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
      }

      /* Pull-up Pull down resistor configuration*/
      GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
      GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
    }
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
这两个函数的问题,用第一个初始化是正常的,第二个就不行。。。

不懂java的programm 发表于 2015-7-7 13:25:16

这两个函数有什么不同呢???
页: [1]
查看完整版本: 关于necleo f411RE使用std库和HAL库的问题