Subversion Repositories testOled

Rev

Rev 8 | Rev 10 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8 Rev 9
Line 58... Line 58...
58
/* USER CODE END PFP */
58
/* USER CODE END PFP */
59
 
59
 
60
/* Private user code ---------------------------------------------------------*/
60
/* Private user code ---------------------------------------------------------*/
61
/* USER CODE BEGIN 0 */
61
/* USER CODE BEGIN 0 */
62
 
62
 
-
 
63
void HAL_GPIO_WRITE_ODR(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
-
 
64
{
-
 
65
  /* Check the parameters */
-
 
66
  assert_param(IS_GPIO_PIN(GPIO_Pin));
-
 
67
 
-
 
68
  GPIOx->ODR |= GPIO_Pin;
-
 
69
}
-
 
70
 
-
 
71
 
-
 
72
/** Errata code from Stack Overflow
-
 
73
1. Disable the I2C peripheral by clearing the PE bit in I2Cx_CR1 register.
-
 
74
2. Configure the SCL and SDA I/Os as General Purpose Output Open-Drain, High level
-
 
75
(Write 1 to GPIOx_ODR).
-
 
76
3. Check SCL and SDA High level in GPIOx_IDR.
-
 
77
4. Configure the SDA I/O as General Purpose Output Open-Drain, Low level (Write 0 to
-
 
78
GPIOx_ODR).
-
 
79
5. Check SDA Low level in GPIOx_IDR.
-
 
80
6. Configure the SCL I/O as General Purpose Output Open-Drain, Low level (Write 0 to
-
 
81
GPIOx_ODR).
-
 
82
7. Check SCL Low level in GPIOx_IDR.
-
 
83
8. Configure the SCL I/O as General Purpose Output Open-Drain, High level (Write 1 to
-
 
84
GPIOx_ODR).
-
 
85
9. Check SCL High level in GPIOx_IDR.
-
 
86
10. Configure the SDA I/O as General Purpose Output Open-Drain , High level (Write 1 to
-
 
87
GPIOx_ODR).
-
 
88
11. Check SDA High level in GPIOx_IDR.
-
 
89
12. Configure the SCL and SDA I/Os as Alternate function Open-Drain.
-
 
90
13. Set SWRST bit in I2Cx_CR1 register.
-
 
91
14. Clear SWRST bit in I2Cx_CR1 register.
-
 
92
15. Enable the I2C peripheral by setting the PE bit in I2Cx_CR1 register.
-
 
93
**/
-
 
94
 
-
 
95
void HAL_I2C_ClearBusyFlagErrata_2_14_7(I2C_HandleTypeDef *hi2c)
-
 
96
{
-
 
97
 
-
 
98
  static uint8_t resetTried = 0;
-
 
99
  if (resetTried == 1)
-
 
100
  {
-
 
101
    return;
-
 
102
  }
-
 
103
  uint32_t const SDA_PIN =  GPIO_PIN_7;
-
 
104
  uint32_t const SCL_PIN = GPIO_PIN_6;
-
 
105
  GPIO_InitTypeDef GPIO_InitStruct;
-
 
106
 
-
 
107
  // 1
-
 
108
  __HAL_I2C_DISABLE(hi2c);
-
 
109
 
-
 
110
  // 2
-
 
111
  GPIO_InitStruct.Pin = SDA_PIN | SCL_PIN;
-
 
112
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
-
 
113
  GPIO_InitStruct.Pull = GPIO_NOPULL;
-
 
114
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-
 
115
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
116
 
-
 
117
  HAL_GPIO_WRITE_ODR(GPIOB, SDA_PIN);
-
 
118
  HAL_GPIO_WRITE_ODR(GPIOB, SCL_PIN);
-
 
119
 
-
 
120
  // 3
-
 
121
  GPIO_PinState pinState;
-
 
122
  if (HAL_GPIO_ReadPin(GPIOB, SDA_PIN) == GPIO_PIN_RESET)
-
 
123
  {
-
 
124
    for (;;)
-
 
125
    {
-
 
126
    }
-
 
127
  }
-
 
128
  if (HAL_GPIO_ReadPin(GPIOB, SCL_PIN) == GPIO_PIN_RESET)
-
 
129
  {
-
 
130
    for (;;)
-
 
131
    {
-
 
132
    }
-
 
133
  }
-
 
134
 
-
 
135
  // 4
-
 
136
  GPIO_InitStruct.Pin = SDA_PIN;
-
 
137
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
138
 
-
 
139
  HAL_GPIO_TogglePin(GPIOB, SDA_PIN);
-
 
140
 
-
 
141
  // 5
-
 
142
  if (HAL_GPIO_ReadPin(GPIOB, SDA_PIN) == GPIO_PIN_SET)
-
 
143
  {
-
 
144
    for (;;)
-
 
145
    {
-
 
146
    }
-
 
147
  }
-
 
148
 
-
 
149
  // 6
-
 
150
  GPIO_InitStruct.Pin = SCL_PIN;
-
 
151
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
152
 
-
 
153
  HAL_GPIO_TogglePin(GPIOB, SCL_PIN);
-
 
154
 
-
 
155
  // 7
-
 
156
  if (HAL_GPIO_ReadPin(GPIOB, SCL_PIN) == GPIO_PIN_SET)
-
 
157
  {
-
 
158
    for (;;)
-
 
159
    {
-
 
160
    }
-
 
161
  }
-
 
162
 
-
 
163
  // 8
-
 
164
  GPIO_InitStruct.Pin = SDA_PIN;
-
 
165
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
166
 
-
 
167
  HAL_GPIO_WRITE_ODR(GPIOB, SDA_PIN);
-
 
168
 
-
 
169
  // 9
-
 
170
  if (HAL_GPIO_ReadPin(GPIOB, SDA_PIN) == GPIO_PIN_RESET)
-
 
171
  {
-
 
172
    for (;;)
-
 
173
    {
-
 
174
    }
-
 
175
  }
-
 
176
 
-
 
177
  // 10
-
 
178
  GPIO_InitStruct.Pin = SCL_PIN;
-
 
179
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
180
 
-
 
181
  HAL_GPIO_WRITE_ODR(GPIOB, SCL_PIN);
-
 
182
 
-
 
183
  // 11
-
 
184
  if (HAL_GPIO_ReadPin(GPIOB, SCL_PIN) == GPIO_PIN_RESET)
-
 
185
  {
-
 
186
    for (;;)
-
 
187
    {
-
 
188
    }
-
 
189
  }
-
 
190
 
-
 
191
  // 12
-
 
192
  GPIO_InitStruct.Pin = SDA_PIN | SCL_PIN;
-
 
193
  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
-
 
194
  GPIO_InitStruct.Pull =   GPIO_PULLUP;
-
 
195
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
 
196
 
-
 
197
  // 13
-
 
198
  hi2c->Instance->CR1 |= I2C_CR1_SWRST;
-
 
199
 
-
 
200
  // 14
-
 
201
  hi2c->Instance->CR1 ^= I2C_CR1_SWRST;
-
 
202
 
-
 
203
  // 15
-
 
204
  __HAL_I2C_ENABLE(hi2c);
-
 
205
 
-
 
206
  resetTried = 1;
-
 
207
}
-
 
208
 
63
/* USER CODE END 0 */
209
/* USER CODE END 0 */
64
 
210
 
65
/**
211
/**
66
  * @brief  The application entry point.
212
  * @brief  The application entry point.
67
  * @retval int
213
  * @retval int
Line 83... Line 229...
83
 
229
 
84
  /* Configure the system clock */
230
  /* Configure the system clock */
85
  SystemClock_Config();
231
  SystemClock_Config();
86
 
232
 
87
  /* USER CODE BEGIN SysInit */
233
  /* USER CODE BEGIN SysInit */
-
 
234
  /* Peripheral clock enable */
88
 
235
 
89
  /* USER CODE END SysInit */
236
  /* USER CODE END SysInit */
90
 
237
 
91
  /* Initialize all configured peripherals */
238
  /* Initialize all configured peripherals */
92
  MX_GPIO_Init();
239
  MX_GPIO_Init();
93
  MX_SPI1_Init();
240
  MX_SPI1_Init();
94
  MX_I2C1_Init();
241
  MX_I2C1_Init();
95
  /* USER CODE BEGIN 2 */
242
  /* USER CODE BEGIN 2 */
96
  cc_init();
243
  cc_init();
97
 
244
 
-
 
245
  HAL_I2C_ClearBusyFlagErrata_2_14_7(&hi2c1);
-
 
246
  MX_I2C1_Init();
98
  init_bmp(&hi2c1);
247
  init_bmp(&hi2c1);
99
  uint32_t lastTick = HAL_GetTick();
248
  uint32_t lastTick = HAL_GetTick();
100
  /* USER CODE END 2 */
249
  /* USER CODE END 2 */
101
 
250
 
102
  /* Infinite loop */
251
  /* Infinite loop */
Line 144... Line 293...
144
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
293
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
145
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
294
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
146
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
295
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
147
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
296
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
148
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
297
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
149
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
298
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
150
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
299
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
151
  {
300
  {
152
    Error_Handler();
301
    Error_Handler();
153
  }
302
  }
154
 
303
 
Line 159... Line 308...
159
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
308
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
160
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
309
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
161
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
310
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
162
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
311
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
163
 
312
 
164
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
313
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
165
  {
314
  {
166
    Error_Handler();
315
    Error_Handler();
167
  }
316
  }
168
}
317
}
169
 
318