Forum: Mikrocontroller und Digitale Elektronik STM32 BSRRH und BSRRL macht das gleiche


von Harald B. (haraldino)


Lesenswert?

Hallo,

nach dem Reset des Controllers will ich 10 Pins High schalten. Dazu 
benutze ich den Befehl

int main(){
....//init

GPIOE -> BSRRH ... GPIO_PIN0 | GPIO_PIN1 ... GPIO_PIN9

...
}

das klappt.

wenn ich jetzt aber aus dem BSRRH ein BSRRL mache dann passiert aber 
nach dem Reset genau das gleiche. Die Pins haben wieder den Zustand High 
statt erwartet low. Woran kann das liegen?
Klar, nach dem Reset sind die Pins undefiniert (kein Pullup oder 
pulldown)... aber sollte BSRRH nicht die Pins High schalten und BSRRL 
die Pins auf LOW ?  Oder ist das nicht richtig?

Viele Grüße
Harald

von Leo B. (luigi)


Lesenswert?

Probiers mal mit dne Registern BSRR und BRR.
Wenns nicht klappt dann musst du mal nachgucken wo und wie deine BSRRH 
und BSRRL definiert sind, die kenne ich so jetzt gar nicht. Könnte mir 
aber vorstellen, dass du damit das high- und low-byte versuchst 
anzusprechen.

von (prx) A. K. (prx)


Lesenswert?

Harald B. schrieb:
> GPIOE -> BSRRH ... GPIO_PIN0 | GPIO_PIN1 ... GPIO_PIN9
> wenn ich jetzt aber aus dem BSRRH ein BSRRL mache

Kannst du das mal etwas verständlicher ausformulieren?

Übrigens sind nicht alle STM32 identisch. Nicht an dieser Stelle.

von AVerr (Gast)


Lesenswert?

Harald B. schrieb:
> Klar, nach dem Reset sind die Pins undefiniert (kein Pullup oder
> pulldown)... aber sollte BSRRH nicht die Pins High schalten und BSRRL
> die Pins auf LOW ?  Oder ist das nicht richtig?

Das ist nicht richtig ... alles zu finden im GPIO-Teil des Reference 
Manual.
BSRRH/BSRRL verändern den Pegel nur im General Purpose Output Modus ( 
oder Input with pull-up/down ).
Nach dem Reset ist der Pin aber im Input Floating Modus.

von Stm32 (Gast)


Lesenswert?

Wie erwähnt gibt es unterschiede zwischen STM32F1x und STM32Fx
Welchen hast du?

von Harald (Gast)


Lesenswert?

F427vi

von Gerald G. (gerald_g)


Lesenswert?

Die Pins sollten high gesetzt sein bei einem bit im bsrrl und gelöscht 
bei einem bit im bsrrh. Nicht gerade intuitiv, weshalb du es 
wahrscheinlich falsch machst.
Zumindest beim f429
Zeig mal die Initialisierung der ports.

von Harald B. (haraldino)


Lesenswert?

Ok neue Infos.

wenn ich mit BSSRH starte bleibt der Pin low.  Am pin hängt ein relais 
das beim anschalten kurz aktiv wird aber nach dem reset behält es den 
default zustand "low". das des relais kurz anzappelt, liegt daran das es 
kein pull down hat und wenn man den prozessor stromlos macht und wieder 
ansteckt, ist er ja floating. ... ok klar.

Jedenfalls war das Problem einfach das BSSRH = Pin low setzt und L = pin 
High setzt.
Gibts eigentlich keine bessere schnellere Methode den Pin direkt zu 
steuern?


hier mein Code:
1
/**
2
  ******************************************************************************
3
  * File Name          : main.c
4
  * Date               : 08/04/2014 22:36:47
5
  * Description        : Main program body
6
  ******************************************************************************
7
  *
8
  * COPYRIGHT(c) 2014 STMicroelectronics
9
  *
10
  * Redistribution and use in source and binary forms, with or without modification,
11
  * are permitted provided that the following conditions are met:
12
  *   1. Redistributions of source code must retain the above copyright notice,
13
  *      this list of conditions and the following disclaimer.
14
  *   2. Redistributions in binary form must reproduce the above copyright notice,
15
  *      this list of conditions and the following disclaimer in the documentation
16
  *      and/or other materials provided with the distribution.
17
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
18
  *      may be used to endorse or promote products derived from this software
19
  *      without specific prior written permission.
20
  *
21
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
  *
32
  ******************************************************************************
33
  */
34
35
/* Includes ------------------------------------------------------------------*/
36
#include "stm32f4xx_hal.h"
37
#include "ff.h"
38
#include "ff_gen_drv.h"
39
#include "sd_diskio.h" /* defines SD_Driver as external */
40
#include "usb_device.h"
41
42
/*
43
44
PD14  I/O  GPIO_Input  IN0
45
PD15  I/O  GPIO_Input  IN1
46
PE9    I/O  GPIO_Input  IN2
47
PE10  I/O  GPIO_Input  IN3
48
PE11  I/O  GPIO_Input  IN4
49
PE12  I/O  GPIO_Input  IN5
50
PE13  I/O  GPIO_Input  IN6
51
PE14  I/O  GPIO_Input  IN7
52
PE15  I/O  GPIO_Input  IN8
53
PE8  I/O  GPIO_Output  NOTAUS_OUT
54
PE0  I/O  GPIO_Output  OUT0
55
PE1  I/O  GPIO_Output  OUT1
56
PE2  I/O  GPIO_Output  OUT2
57
PE3  I/O  GPIO_Output  OUT3
58
PE4  I/O  GPIO_Output  OUT4
59
PE5  I/O  GPIO_Output  OUT5
60
PE6  I/O  GPIO_Output  OUT6
61
PE7  I/O  GPIO_Output  OUT7
62
63
*/
64
65
/* Private variables ---------------------------------------------------------*/
66
ADC_HandleTypeDef hadc1;
67
ADC_HandleTypeDef hadc2;
68
69
CAN_HandleTypeDef hcan2;
70
71
CRC_HandleTypeDef hcrc;
72
73
I2C_HandleTypeDef hi2c1;
74
I2C_HandleTypeDef hi2c2;
75
76
IWDG_HandleTypeDef hiwdg;
77
78
RTC_HandleTypeDef hrtc;
79
80
SD_HandleTypeDef hsd;
81
HAL_SD_CardInfoTypedef SDCardInfo;
82
83
SPI_HandleTypeDef hspi2;
84
85
UART_HandleTypeDef huart1;
86
UART_HandleTypeDef huart3;
87
UART_HandleTypeDef huart6;
88
89
WWDG_HandleTypeDef hwwdg;
90
91
uint8_t SD_DriverNum;      /* FatFS SD part */
92
char SD_Path[4];           /* SD card logical drive path */
93
94
/* USER CODE BEGIN 0 */
95
96
/* USER CODE END 0 */
97
98
/* Private function prototypes -----------------------------------------------*/
99
static void SystemClock_Config(void);
100
static void MX_GPIO_Init(void);
101
static void MX_ADC1_Init(void);
102
static void MX_ADC2_Init(void);
103
static void MX_CAN2_Init(void);
104
static void MX_CRC_Init(void);
105
static void MX_I2C1_Init(void);
106
static void MX_I2C2_Init(void);
107
static void MX_IWDG_Init(void);
108
static void MX_RTC_Init(void);
109
static void MX_SDIO_SD_Init(void);
110
static void MX_SPI2_Init(void);
111
static void MX_USART1_UART_Init(void);
112
static void MX_USART3_UART_Init(void);
113
static void MX_USART6_UART_Init(void);
114
static void MX_WWDG_Init(void);
115
116
int main(void)
117
{
118
  /* USER CODE BEGIN 1 */
119
120
  /* USER CODE END 1 */
121
122
  /* MCU Configuration----------------------------------------------------------*/
123
124
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
125
  HAL_Init();
126
127
  /* Configure the system clock */
128
  SystemClock_Config();
129
130
  /* Initialize all configured peripherals */
131
  MX_GPIO_Init();
132
  MX_ADC1_Init();
133
  MX_ADC2_Init();
134
  MX_CAN2_Init();
135
  MX_CRC_Init();
136
  MX_I2C1_Init();
137
  MX_I2C2_Init();
138
  MX_IWDG_Init();
139
  MX_RTC_Init();
140
  MX_SDIO_SD_Init();
141
  MX_SPI2_Init();
142
  MX_USART1_UART_Init();
143
  MX_USART3_UART_Init();
144
  MX_USART6_UART_Init();
145
  MX_WWDG_Init();
146
  MX_USB_DEVICE_Init();
147
148
  /* USER CODE BEGIN 2 */
149
150
  /* USER CODE END 2 */
151
152
  /*## FatFS: Link the SD disk I/O driver ###############################*/
153
  SD_DriverNum = FATFS_LinkDriver(&SD_Driver, SD_Path);
154
155
  /* USER CODE BEGIN 3 */
156
  /* Infinite loop */
157
      int i = 0;
158
  while (1)
159
  {
160
161
    HAL_Delay(1000);
162
    
163
    GPIOE->BSRRH = GPIO_PIN_0;
164
    
165
    HAL_Delay(1000);
166
    
167
  //  GPIOE->BSRRL = GPIO_PIN_0;
168
  
169
170
    
171
    
172
    
173
  }
174
  /* USER CODE END 3 */
175
176
}
177
178
/** System Clock Configuration
179
*/
180
static void SystemClock_Config(void)
181
{
182
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
183
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
184
  RCC_OscInitTypeDef RCC_OscInitStruct;
185
186
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
187
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
188
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
189
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
190
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
191
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
192
  RCC_OscInitStruct.PLL.PLLM = 8;
193
  RCC_OscInitStruct.PLL.PLLN = 336;
194
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
195
  RCC_OscInitStruct.PLL.PLLQ = 7;
196
  HAL_RCC_OscConfig(&RCC_OscInitStruct);
197
198
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
199
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
200
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
201
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
202
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
203
204
  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
205
  PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
206
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
207
208
  HAL_RCC_EnableCSS();
209
210
}
211
212
/* ADC1 init function */
213
void MX_ADC1_Init(void)
214
{
215
  ADC_ChannelConfTypeDef sConfig;
216
  ADC_MultiModeTypeDef multimode;
217
218
  /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
219
  */
220
  hadc1.Instance = ADC1;
221
  hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
222
  hadc1.Init.Resolution = ADC_RESOLUTION12b;
223
  hadc1.Init.ScanConvMode = DISABLE;
224
  hadc1.Init.ContinuousConvMode = DISABLE;
225
  hadc1.Init.DiscontinuousConvMode = DISABLE;
226
  hadc1.Init.NbrOfDiscConversion = 1;
227
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
228
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
229
  hadc1.Init.NbrOfConversion = 1;
230
  hadc1.Init.DMAContinuousRequests = DISABLE;
231
  hadc1.Init.EOCSelection = EOC_SINGLE_CONV;
232
  HAL_ADC_Init(&hadc1);
233
234
  /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
235
  */
236
  sConfig.Channel = ADC_CHANNEL_1;
237
  sConfig.Rank = 1;
238
  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
239
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
240
241
  /**Configure the ADC multi-mode 
242
  */
243
  multimode.Mode = ADC_MODE_INDEPENDENT;
244
  multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_5CYCLES;
245
  HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode);
246
247
}
248
249
/* ADC2 init function */
250
void MX_ADC2_Init(void)
251
{
252
  ADC_ChannelConfTypeDef sConfig;
253
  ADC_MultiModeTypeDef multimode;
254
255
  /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
256
  */
257
  hadc2.Instance = ADC2;
258
  hadc2.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
259
  hadc2.Init.Resolution = ADC_RESOLUTION12b;
260
  hadc2.Init.ScanConvMode = DISABLE;
261
  hadc2.Init.ContinuousConvMode = DISABLE;
262
  hadc2.Init.DiscontinuousConvMode = DISABLE;
263
  hadc2.Init.NbrOfDiscConversion = 1;
264
  hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
265
  hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
266
  hadc2.Init.NbrOfConversion = 1;
267
  hadc2.Init.DMAContinuousRequests = DISABLE;
268
  hadc2.Init.EOCSelection = EOC_SINGLE_CONV;
269
  HAL_ADC_Init(&hadc2);
270
271
  /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
272
  */
273
  sConfig.Channel = ADC_CHANNEL_2;
274
  sConfig.Rank = 1;
275
  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
276
  HAL_ADC_ConfigChannel(&hadc2, &sConfig);
277
278
  /**Configure the ADC multi-mode 
279
  */
280
  multimode.Mode = ADC_MODE_INDEPENDENT;
281
  multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_5CYCLES;
282
  HAL_ADCEx_MultiModeConfigChannel(&hadc2, &multimode);
283
284
}
285
286
/* CAN2 init function */
287
void MX_CAN2_Init(void)
288
{
289
290
  hcan2.Instance = CAN2;
291
  hcan2.Init.Prescaler = 16;
292
  hcan2.Init.Mode = CAN_MODE_NORMAL;
293
  hcan2.Init.SJW = CAN_SJW_1TQ;
294
  hcan2.Init.BS1 = CAN_BS1_1TQ;
295
  hcan2.Init.BS2 = CAN_BS2_1TQ;
296
  hcan2.Init.TTCM = DISABLE;
297
  hcan2.Init.ABOM = DISABLE;
298
  hcan2.Init.AWUM = DISABLE;
299
  hcan2.Init.NART = DISABLE;
300
  hcan2.Init.RFLM = DISABLE;
301
  hcan2.Init.TXFP = DISABLE;
302
  HAL_CAN_Init(&hcan2);
303
304
}
305
306
/* CRC init function */
307
void MX_CRC_Init(void)
308
{
309
310
  hcrc.Instance = CRC;
311
  HAL_CRC_Init(&hcrc);
312
313
}
314
315
/* I2C1 init function */
316
void MX_I2C1_Init(void)
317
{
318
319
  hi2c1.Instance = I2C1;
320
  hi2c1.Init.ClockSpeed = 200000;
321
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
322
  hi2c1.Init.OwnAddress1 = 0;
323
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
324
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
325
  hi2c1.Init.OwnAddress2 = 0;
326
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
327
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
328
  HAL_I2C_Init(&hi2c1);
329
330
}
331
332
/* I2C2 init function */
333
void MX_I2C2_Init(void)
334
{
335
336
  hi2c2.Instance = I2C2;
337
  hi2c2.Init.ClockSpeed = 200000;
338
  hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
339
  hi2c2.Init.OwnAddress1 = 0;
340
  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
341
  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
342
  hi2c2.Init.OwnAddress2 = 0;
343
  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
344
  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
345
  HAL_I2C_Init(&hi2c2);
346
347
}
348
349
/* IWDG init function */
350
void MX_IWDG_Init(void)
351
{
352
353
  hiwdg.Instance = IWDG;
354
  hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
355
  hiwdg.Init.Reload = 50;
356
  HAL_IWDG_Init(&hiwdg);
357
358
}
359
360
/* RTC init function */
361
void MX_RTC_Init(void)
362
{
363
  RTC_TimeTypeDef sTime;
364
  RTC_DateTypeDef sDate;
365
  RTC_AlarmTypeDef sAlarm;
366
367
  /**Initialize RTC and set the Time and Date 
368
  */
369
  hrtc.Instance = RTC;
370
  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
371
  hrtc.Init.AsynchPrediv = 127;
372
  hrtc.Init.SynchPrediv = 255;
373
  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
374
  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
375
  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
376
  HAL_RTC_Init(&hrtc);
377
378
  sTime.Hours = 0;
379
  sTime.Minutes = 0;
380
  sTime.Seconds = 0;
381
  sTime.SubSeconds = 0;
382
  sTime.TimeFormat = RTC_HOURFORMAT12_AM;
383
  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_SUB1H;
384
  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
385
  HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BCD);
386
387
  sDate.WeekDay = RTC_WEEKDAY_MONDAY;
388
  sDate.Month = RTC_MONTH_JANUARY;
389
  sDate.Date = 1;
390
  sDate.Year = 0;
391
  HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BCD);
392
393
  /**Enable the Alarm A 
394
  */
395
  sAlarm.AlarmTime.Hours = 0;
396
  sAlarm.AlarmTime.Minutes = 0;
397
  sAlarm.AlarmTime.Seconds = 0;
398
  sAlarm.AlarmTime.SubSeconds = 0;
399
  sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
400
  sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_SUB1H;
401
  sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
402
  sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
403
  sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
404
  sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
405
  sAlarm.AlarmDateWeekDay = 1;
406
  sAlarm.Alarm = RTC_ALARM_A;
407
  HAL_RTC_SetAlarm(&hrtc, &sAlarm, FORMAT_BCD);
408
409
}
410
411
/* SDIO init function */
412
void MX_SDIO_SD_Init(void)
413
{
414
415
  hsd.Instance = SDIO;
416
  hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
417
  hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
418
  hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
419
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
420
  hsd.Init.ClockDiv = 0;
421
  HAL_SD_Init(&hsd, &SDCardInfo);
422
423
}
424
425
/* SPI2 init function */
426
void MX_SPI2_Init(void)
427
{
428
429
  hspi2.Instance = SPI2;
430
  hspi2.Init.Mode = SPI_MODE_MASTER;
431
  hspi2.Init.Direction = SPI_DIRECTION_2LINES;
432
  hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
433
  hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
434
  hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
435
  hspi2.Init.NSS = SPI_NSS_HARD_OUTPUT;
436
  hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
437
  hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
438
  hspi2.Init.TIMode = SPI_TIMODE_DISABLED;
439
  hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
440
  HAL_SPI_Init(&hspi2);
441
442
}
443
444
/* USART1 init function */
445
void MX_USART1_UART_Init(void)
446
{
447
448
  huart1.Instance = USART1;
449
  huart1.Init.BaudRate = 115200;
450
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
451
  huart1.Init.StopBits = UART_STOPBITS_1;
452
  huart1.Init.Parity = UART_PARITY_NONE;
453
  huart1.Init.Mode = UART_MODE_TX_RX;
454
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
455
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
456
  HAL_UART_Init(&huart1);
457
458
}
459
460
/* USART3 init function */
461
void MX_USART3_UART_Init(void)
462
{
463
464
  huart3.Instance = USART3;
465
  huart3.Init.BaudRate = 115200;
466
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
467
  huart3.Init.StopBits = UART_STOPBITS_1;
468
  huart3.Init.Parity = UART_PARITY_NONE;
469
  huart3.Init.Mode = UART_MODE_TX_RX;
470
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
471
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
472
  HAL_UART_Init(&huart3);
473
474
}
475
476
/* USART6 init function */
477
void MX_USART6_UART_Init(void)
478
{
479
480
  huart6.Instance = USART6;
481
  huart6.Init.BaudRate = 115200;
482
  huart6.Init.WordLength = UART_WORDLENGTH_8B;
483
  huart6.Init.StopBits = UART_STOPBITS_1;
484
  huart6.Init.Parity = UART_PARITY_NONE;
485
  huart6.Init.Mode = UART_MODE_TX_RX;
486
  huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
487
  huart6.Init.OverSampling = UART_OVERSAMPLING_16;
488
  HAL_UART_Init(&huart6);
489
490
}
491
492
/* WWDG init function */
493
void MX_WWDG_Init(void)
494
{
495
496
  hwwdg.Instance = WWDG;
497
  hwwdg.Init.Prescaler = WWDG_PRESCALER_1;
498
  hwwdg.Init.Window = 35;
499
  hwwdg.Init.Counter = 64;
500
  HAL_WWDG_Init(&hwwdg);
501
502
}
503
504
/** Configure pins as 
505
        * Analog 
506
        * Input 
507
        * Output
508
        * EVENT_OUT
509
        * EXTI
510
        * Free pins are configured automatically as Analog (this feature is enabled through 
511
        * the Code Generation settings)
512
*/
513
void MX_GPIO_Init(void)
514
{
515
  GPIO_InitTypeDef GPIO_InitStruct;
516
517
  /* GPIO Ports Clock Enable */
518
  __GPIOE_CLK_ENABLE();
519
  __GPIOC_CLK_ENABLE();
520
  __GPIOH_CLK_ENABLE();
521
  __GPIOA_CLK_ENABLE();
522
  __GPIOB_CLK_ENABLE();
523
  __GPIOD_CLK_ENABLE();
524
525
  /*Configure GPIO pins : PE2 PE3 PE4 PE5 
526
                           PE6 PE7 PE8 PE0 
527
                           PE1 */
528
  GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5 
529
                          |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_0 
530
                          |GPIO_PIN_1;
531
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
532
  GPIO_InitStruct.Pull = GPIO_PULLDOWN ;
533
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
534
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
535
536
  /*Configure GPIO pin : PC13 */
537
  GPIO_InitStruct.Pin = GPIO_PIN_13;
538
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
539
  GPIO_InitStruct.Pull = GPIO_NOPULL;
540
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
541
542
  /*Configure GPIO pins : PA0 PA3 PA4 PA5 */
543
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
544
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
545
  GPIO_InitStruct.Pull = GPIO_NOPULL;
546
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
547
548
  /*Configure GPIO pins : PA6 PA7 */
549
  GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
550
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
551
  GPIO_InitStruct.Pull = GPIO_NOPULL;
552
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
553
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
554
555
  /*Configure GPIO pins : PC4 PC5 */
556
  GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
557
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
558
  GPIO_InitStruct.Pull = GPIO_NOPULL;
559
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
560
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
561
562
  /*Configure GPIO pins : PB0 PB1 PB2 PB14 
563
                           PB15 PB5 */
564
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_14 
565
                          |GPIO_PIN_15|GPIO_PIN_5;
566
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
567
  GPIO_InitStruct.Pull = GPIO_NOPULL;
568
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
569
570
  /*Configure GPIO pins : PE9 PE10 PE11 PE12 
571
                           PE13 PE14 PE15 */
572
  GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12 
573
                          |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
574
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
575
  GPIO_InitStruct.Pull = GPIO_NOPULL;
576
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
577
578
  /*Configure GPIO pin : PD10 */
579
  GPIO_InitStruct.Pin = GPIO_PIN_10;
580
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
581
  GPIO_InitStruct.Pull = GPIO_NOPULL;
582
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
583
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
584
585
  /*Configure GPIO pins : PD11 PD12 PD13 PD0 
586
                           PD1 PD4 PD5 PD6 
587
                           PD7 */
588
  GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_0 
589
                          |GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6 
590
                          |GPIO_PIN_7;
591
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
592
  GPIO_InitStruct.Pull = GPIO_NOPULL;
593
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
594
595
  /*Configure GPIO pins : PD14 PD15 */
596
  GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
597
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
598
  GPIO_InitStruct.Pull = GPIO_NOPULL;
599
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
600
601
  /*Configure GPIO pin : PA8 */
602
  GPIO_InitStruct.Pin = GPIO_PIN_8;
603
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
604
  GPIO_InitStruct.Pull = GPIO_NOPULL;
605
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
606
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
607
608
  /*Configure GPIO pins : PB8 PB9 */
609
  GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
610
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
611
  GPIO_InitStruct.Pull = GPIO_NOPULL;
612
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
613
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
614
}
615
616
/* USER CODE BEGIN 4 */
617
618
/* USER CODE END 4 */
619
620
#ifdef USE_FULL_ASSERT
621
622
/**
623
   * @brief Reports the name of the source file and the source line number
624
   * where the assert_param error has occurred.
625
   * @param file: pointer to the source file name
626
   * @param line: assert_param error line source number
627
   * @retval None
628
   */
629
void assert_failed(uint8_t* file, uint32_t line)
630
{
631
  /* User can add his own implementation to report the file name and line number,
632
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
633
634
}
635
636
#endif
637
638
/**
639
  * @}
640
  */ 
641
642
/**
643
  * @}
644
*/ 
645
646
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

von Detlef K. (adenin)


Lesenswert?

> Gibts eigentlich keine bessere schnellere Methode den Pin direkt zu
> steue

Also wenn die die Register BSRRH und BSRRL nicht gefallen, dann kannst 
Du
noch über Bitbanding atomar auf einzelne Pins zugreifen.
Ansonsten über Register ODR mit gleichzeitigem Zugriff auf alle 16 Pins.

von AVerr (Gast)


Lesenswert?

Harald B. schrieb:
> Jedenfalls war das Problem einfach das BSSRH = Pin low setzt und L = pin
> High setzt.

Und das ist genau so richtig, siehe STM32F4 Reference Manual ( vorhin 
war ich noch von den STM32F1 ausgegangen, weil es da noch nicht bekannt 
war, um welche Serie es sich hier handelt ).

> Gibts eigentlich keine bessere schnellere Methode den Pin direkt zu
> steuern?

Das BSRR Register ist dazu da, um die entsprechenden Werte im ODR 
Register
atomar zu setzen oder zu löschen.
Wenn du das nicht brauchst, kannst du natürlich auch direkt auf das ODR 
Register zugreifen, aber scheller wird das im Normalfall auch nicht sein 
( weil man das Bit dann noch maskieren muss etc ).

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.