0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【要調査】CubeIDE v1.19.0でBSPを設定するとI2Cが動かない 対策あり

Posted at

1. はじめに

原因が不明です。わかる方いたらご教授ください。
とりあえず一部のコードをコメントアウトすれば動作する。

2. 状況

Nucleo-G431にF303のコードを移植するために作業していた際に発覚した。
プロジェクト作成時に評価ボードの機能を実装するか否かの選択画面で下図のように選択した(デフォルトの状態である)。
select.PNG
このままプロジェクトを作成し、F303のコードを移植(引数等書き換えて)し、ビルド成功。
デバッグを開始したところでmainループ内でI2Cが正しく動作していないことに気が付いた。

3. 暫定対策

下図の179行目にある関数をコメントアウトするとI2Cが正常に動いた。
この行の実行以前であれば、でHAL_I2C_Mem_ReadやHAL_I2C_Mem_Writeは実行でき、以降では動作がおかしくなった。
commentout.PNG

4. 原因の関数

stm32g4xx_nucleo.c
int32_t BSP_LED_Init(Led_TypeDef Led)
{
  GPIO_InitTypeDef  gpio_init_structure;

  /* Enable the GPIO LED Clock */
  LED2_GPIO_CLK_ENABLE();

  /* Configure the GPIO_LED pin */
  gpio_init_structure.Pin   = LED_PIN[Led];
  gpio_init_structure.Mode  = GPIO_MODE_OUTPUT_PP;
  gpio_init_structure.Pull  = GPIO_NOPULL;
  gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  HAL_GPIO_Init(LED_PORT[Led], &gpio_init_structure);
  HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);

  return BSP_ERROR_NONE;
}

5. 終わりに

全て自力で設定すれば問題はないが、とりあえず動作させたい時に思考停止でBSP設定を通過してしまうと面倒なことになる。
デフォルトでこの動作はライト層が混乱しそうであるという印象(筆者が混乱しているため)。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?