Select one of the symbols to view example projects that use it.
 
Outline
#include "stm32412g_discovery.h"
LCD_CONTROLLER_TypeDef
#define __STM32412G_DISCOVERY_BSP_VERSION_MAIN
#define __STM32412G_DISCOVERY_BSP_VERSION_SUB1
#define __STM32412G_DISCOVERY_BSP_VERSION_SUB2
#define __STM32412G_DISCOVERY_BSP_VERSION_RC
#define FMC_BANK1_BASE
#define FMC_BANK3_BASE
#define FMC_BANK1
GPIO_PIN
BUTTON_PORT
BUTTON_PIN
BUTTON_IRQn
JOY_PORT
JOY_PIN
JOY_IRQn
COM_USART
COM_TX_PORT
COM_RX_PORT
COM_TX_PIN
COM_RX_PIN
COM_TX_AF
COM_RX_AF
hI2cAudioHandler
hI2cExtHandler
BSP_GetVersion()
BSP_LED_Init(Led_TypeDef)
BSP_LED_DeInit(Led_TypeDef)
BSP_LED_On(Led_TypeDef)
BSP_LED_Off(Led_TypeDef)
BSP_LED_Toggle(Led_TypeDef)
BSP_PB_Init(Button_TypeDef, ButtonMode_TypeDef)
BSP_PB_DeInit(Button_TypeDef)
BSP_PB_GetState(Button_TypeDef)
BSP_JOY_Init(JOYMode_TypeDef)
BSP_JOY_DeInit()
BSP_JOY_GetState()
BSP_COM_Init(COM_TypeDef, UART_HandleTypeDef *)
BSP_COM_DeInit(COM_TypeDef, UART_HandleTypeDef *)
I2C Routines
I2Cx_MspInit(I2C_HandleTypeDef *)
I2Cx_Init(I2C_HandleTypeDef *)
I2Cx_ReadMultiple(I2C_HandleTypeDef *, uint8_t, uint16_t, uint16_t, uint8_t *, uint16_t)
I2Cx_WriteMultiple(I2C_HandleTypeDef *, uint8_t, uint16_t, uint16_t, uint8_t *, uint16_t)
I2Cx_IsDeviceReady(I2C_HandleTypeDef *, uint16_t, uint32_t)
I2Cx_Error(I2C_HandleTypeDef *, uint8_t)
I2Cx_DeInit(I2C_HandleTypeDef *)
FMC Routines
FMC_BANK1_MspInit()
FMC_BANK1_Init()
FMC_BANK1_WriteData(uint16_t)
FMC_BANK1_WriteReg(uint8_t)
FMC_BANK1_ReadData()
LINK LCD
LCD_IO_Init()
LCD_IO_WriteData(uint16_t)
LCD_IO_WriteMultipleData(uint16_t *, uint32_t)
LCD_IO_WriteReg(uint8_t)
LCD_IO_ReadData()
LCD_IO_Delay(uint32_t)
LINK AUDIO
AUDIO_IO_Init()
AUDIO_IO_DeInit()
AUDIO_IO_Write(uint8_t, uint16_t, uint16_t)
AUDIO_IO_Read(uint8_t, uint16_t)
AUDIO_IO_Delay(uint32_t)
LINK I2C EEPROM
EEPROM_IO_Init()
EEPROM_IO_WriteData(uint16_t, uint16_t, uint8_t *, uint32_t)
EEPROM_IO_ReadData(uint16_t, uint16_t, uint8_t *, uint32_t)
EEPROM_IO_IsDeviceReady(uint16_t, uint32_t)
TS_IO_Init()
TS_IO_Write(uint8_t, uint8_t, uint8_t)
TS_IO_Read(uint8_t, uint8_t)
TS_IO_ReadMultiple(uint8_t, uint8_t, uint8_t *, uint16_t)
TS_IO_WriteMultiple(uint8_t, uint8_t, uint8_t *, uint16_t)
TS_IO_Delay(uint32_t)
Files
loading...
SourceVuSTM32 Libraries and SamplesSTM32412G-Discoverystm32412g_discovery.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file stm32412g_discovery.c * @author MCD Application Team * @brief This file provides a set of firmware functions to manage LEDs, * push-buttons and COM ports available on STM32412G-DISCOVERY board * (MB1209) from STMicroelectronics. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "stm32412g_discovery.h" /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup STM32412G_DISCOVERY * @{ *//* ... */ /** @defgroup STM32412G_DISCOVERY_LOW_LEVEL STM32412G-DISCOVERY LOW LEVEL * @{ *//* ... */ /** @defgroup STM32412G_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32412G Discovery Low Level Private Typedef * @{ *//* ... */ typedef struct { __IO uint16_t REG; __IO uint16_t RAM; ...}LCD_CONTROLLER_TypeDef; /** * @} *//* ... */ /** @defgroup STM32412G_DISCOVERY_LOW_LEVEL_Private_Defines STM32412G Discovery Low Level Private Def * @{ *//* ... */ /** * @brief STM32412G DISCOVERY BSP Driver version number V2.0.3 *//* ... */ #define __STM32412G_DISCOVERY_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */ #define __STM32412G_DISCOVERY_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ #define __STM32412G_DISCOVERY_BSP_VERSION_SUB2 (0x03) /*!< [15:8] sub2 version */ #define __STM32412G_DISCOVERY_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */ #define __STM32412G_DISCOVERY_BSP_VERSION ((__STM32412G_DISCOVERY_BSP_VERSION_MAIN << 24)\ |(__STM32412G_DISCOVERY_BSP_VERSION_SUB1 << 16)\ |(__STM32412G_DISCOVERY_BSP_VERSION_SUB2 << 8 )\ |(__STM32412G_DISCOVERY_BSP_VERSION_RC))... /* We use BANK1 as we use FMC_NE1 signal */ #define FMC_BANK1_BASE ((uint32_t)(0x60000000 | 0x00000000)) #define FMC_BANK3_BASE ((uint32_t)(0x60000000 | 0x08000000)) #define FMC_BANK1 ((LCD_CONTROLLER_TypeDef *) FMC_BANK1_BASE) 8 defines /** * @} *//* ... */ /** @defgroup STM32412G_DISCOVERY_LOW_LEVEL_Private_Variables STM32412G Discovery Low Level Variables * @{ *//* ... */ const uint32_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN, LED4_PIN...}; GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT}; const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN}; const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn}; GPIO_TypeDef* JOY_PORT[JOYn] = {SEL_JOY_GPIO_PORT, DOWN_JOY_GPIO_PORT, LEFT_JOY_GPIO_PORT, RIGHT_JOY_GPIO_PORT, UP_JOY_GPIO_PORT...}; const uint16_t JOY_PIN[JOYn] = {SEL_JOY_PIN, DOWN_JOY_PIN, LEFT_JOY_PIN, RIGHT_JOY_PIN, UP_JOY_PIN...}; const uint8_t JOY_IRQn[JOYn] = {SEL_JOY_EXTI_IRQn, DOWN_JOY_EXTI_IRQn, LEFT_JOY_EXTI_IRQn, RIGHT_JOY_EXTI_IRQn, UP_JOY_EXTI_IRQn...}; USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1}; GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT}; GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT}; const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN}; const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN}; const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF}; const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF}; static I2C_HandleTypeDef hI2cAudioHandler; static I2C_HandleTypeDef hI2cExtHandler; /** * @} *//* ... */ /** @defgroup STM32412G_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32412G Discovery Low Level Private Prototypes * @{ *//* ... */ static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler); static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler); static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length); static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length); static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials); static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr); static void FMC_BANK1_WriteData(uint16_t Data); static void FMC_BANK1_WriteReg(uint8_t Reg); static uint16_t FMC_BANK1_ReadData(void); static void FMC_BANK1_Init(void); static void FMC_BANK1_MspInit(void); /* LCD IO functions */ void LCD_IO_Init(void); void LCD_IO_WriteData(uint16_t RegValue); void LCD_IO_WriteReg(uint8_t Reg); void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size); uint16_t LCD_IO_ReadData(void); void LCD_IO_Delay(uint32_t Delay); /* AUDIO IO functions */ void AUDIO_IO_Init(void); void AUDIO_IO_DeInit(void); void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value); uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg); void AUDIO_IO_Delay(uint32_t Delay); /* I2C EEPROM IO function */ void EEPROM_IO_Init(void); HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize); HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize); HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials); /* TouchScreen (TS) IO functions */ void TS_IO_Init(void); void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value); uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg); uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length); void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length); void TS_IO_Delay(uint32_t Delay); /** * @} *//* ... */ /** @defgroup STM32412G_DISCOVERY_LOW_LEVEL_Private_Functions STM32412G Discovery Low Level Private Functions * @{ *//* ... */ /** * @brief This method returns the STM32412G DISCOVERY BSP Driver revision * @retval version: 0xXYZR (8bits for each decimal, R for RC) *//* ... */ uint32_t BSP_GetVersion(void) { return __STM32412G_DISCOVERY_BSP_VERSION; }{ ... } /** * @brief Configures LEDs. * @param Led: LED to be configured. * This parameter can be one of the following values: * @arg LED1 * @arg LED2 * @arg LED3 * @arg LED4 *//* ... */ void BSP_LED_Init(Led_TypeDef Led) { GPIO_InitTypeDef gpio_init_structure; /* Enable the GPIO_LED clock */ LEDx_GPIO_CLK_ENABLE(); /* Configure the GPIO_LED pin */ gpio_init_structure.Pin = GPIO_PIN[Led]; gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; gpio_init_structure.Pull = GPIO_PULLUP; gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(LEDx_GPIO_PORT, &gpio_init_structure); /* By default, turn off LED */ HAL_GPIO_WritePin(LEDx_GPIO_PORT, GPIO_PIN[Led], GPIO_PIN_SET); }{ ... } /** * @brief DeInit LEDs. * @param Led: LED to be configured. * This parameter can be one of the following values: * @arg LED1 * @arg LED2 * @arg LED3 * @arg LED4 * @note Led DeInit does not disable the GPIO clock nor disable the Mfx *//* ... */ void BSP_LED_DeInit(Led_TypeDef Led) { GPIO_InitTypeDef gpio_init_structure; /* Turn off LED */ HAL_GPIO_WritePin(LEDx_GPIO_PORT, GPIO_PIN[Led], GPIO_PIN_RESET); /* DeInit the GPIO_LED pin */ gpio_init_structure.Pin = GPIO_PIN[Led]; HAL_GPIO_DeInit(LEDx_GPIO_PORT, gpio_init_structure.Pin); }{ ... } /** * @brief Turns selected LED On. * @param Led: LED to be set on * This parameter can be one of the following values: * @arg LED1 * @arg LED2 * @arg LED3 * @arg LED4 *//* ... */ void BSP_LED_On(Led_TypeDef Led) { HAL_GPIO_WritePin(LEDx_GPIO_PORT, GPIO_PIN[Led], GPIO_PIN_RESET); }{ ... } /** * @brief Turns selected LED Off. * @param Led: LED to be set off * This parameter can be one of the following values: * @arg LED1 * @arg LED2 * @arg LED3 * @arg LED4 *//* ... */ void BSP_LED_Off(Led_TypeDef Led) { HAL_GPIO_WritePin(LEDx_GPIO_PORT, GPIO_PIN[Led], GPIO_PIN_SET); }{ ... } /** * @brief Toggles the selected LED. * @param Led: LED to be toggled * This parameter can be one of the following values: * @arg LED1 * @arg LED2 * @arg LED3 * @arg LED4 *//* ... */ void BSP_LED_Toggle(Led_TypeDef Led) { HAL_GPIO_TogglePin(LEDx_GPIO_PORT, GPIO_PIN[Led]); }{ ... } /** * @brief Configures button GPIO and EXTI Line. * @param Button: Button to be configured * This parameter can be one of the following values: * @arg BUTTON_WAKEUP: Wakeup Push Button * @param ButtonMode: Button mode * This parameter can be one of the following values: * @arg BUTTON_MODE_GPIO: Button will be used as simple IO * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line * with interrupt generation capability * @note On STM32412G-DISCOVERY board, the Wakeup button is mapped on * the same push button which is the joystick selection button. *//* ... */ void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode) { GPIO_InitTypeDef gpio_init_structure; /* Enable the BUTTON clock */ WAKEUP_BUTTON_GPIO_CLK_ENABLE(); if(ButtonMode == BUTTON_MODE_GPIO) { /* Configure Button pin as input */ gpio_init_structure.Pin = BUTTON_PIN[Button]; gpio_init_structure.Mode = GPIO_MODE_INPUT; gpio_init_structure.Pull = GPIO_PULLDOWN; gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure); }if (ButtonMode == BUTTON_MODE_GPIO) { ... } if(ButtonMode == BUTTON_MODE_EXTI) { /* Configure Button pin as input with External interrupt */ gpio_init_structure.Pin = BUTTON_PIN[Button]; gpio_init_structure.Pull = GPIO_PULLDOWN; gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; gpio_init_structure.Mode = GPIO_MODE_IT_RISING; HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure); /* Enable and set Button EXTI Interrupt to the lowest priority */ HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00); HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); }if (ButtonMode == BUTTON_MODE_EXTI) { ... } }{ ... } /** * @brief Push Button DeInit. * @param Button: Button to be configured * This parameter can be one of the following values: * @arg BUTTON_WAKEUP: Wakeup Push Button * @note On STM32412G-DISCOVERY board, the Wakeup button is mapped on * the same push button which is the joystick selection button. * @note PB DeInit does not disable the GPIO clock *//* ... */ void BSP_PB_DeInit(Button_TypeDef Button) { GPIO_InitTypeDef gpio_init_structure; gpio_init_structure.Pin = BUTTON_PIN[Button]; HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin); }{ ... } /** * @brief Returns the selected button state. * @param Button: Button to be checked * This parameter can be one of the following values: * @arg BUTTON_WAKEUP: Wakeup Push Button * @note On STM32412G-DISCOVERY board, the Wakeup button is mapped on * the same push button which is the joystick selection button. * @retval The Button GPIO pin value (GPIO_PIN_RESET = button pressed) *//* ... */ uint32_t BSP_PB_GetState(Button_TypeDef Button) { return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]); }{ ... } /** * @brief Configures all joystick's buttons in GPIO or EXTI modes. * @param Joy_Mode: Joystick mode. * This parameter can be one of the following values: * JOY_MODE_GPIO: Joystick pins will be used as simple IOs * JOY_MODE_EXTI: Joystick pins will be connected to EXTI line * with interrupt generation capability * @retval HAL_OK: if all initializations are OK. Other value if error. *//* ... */ uint8_t BSP_JOY_Init(JOYMode_TypeDef Joy_Mode) { JOYState_TypeDef joykey; GPIO_InitTypeDef GPIO_InitStruct; /* Initialized the Joystick. */ for(joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) { /* Enable the JOY clock */ JOYx_GPIO_CLK_ENABLE(joykey); GPIO_InitStruct.Pin = JOY_PIN[joykey]; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; if (Joy_Mode == JOY_MODE_GPIO) { /* Configure Joy pin as input */ GPIO_InitStruct.Mode = GPIO_MODE_INPUT; HAL_GPIO_Init(JOY_PORT[joykey], &GPIO_InitStruct); }if (Joy_Mode == JOY_MODE_GPIO) { ... } else if (Joy_Mode == JOY_MODE_EXTI) { /* Configure Joy pin as input with External interrupt */ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; HAL_GPIO_Init(JOY_PORT[joykey], &GPIO_InitStruct); /* Enable and set Joy EXTI Interrupt to the lowest priority */ HAL_NVIC_SetPriority((IRQn_Type)(JOY_IRQn[joykey]), 0x0F, 0x00); HAL_NVIC_EnableIRQ((IRQn_Type)(JOY_IRQn[joykey])); }else if (Joy_Mode == JOY_MODE_EXTI) { ... } }for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) { ... } return HAL_OK; }{ ... } /** * @brief Unconfigures all GPIOs used as joystick's buttons. *//* ... */ void BSP_JOY_DeInit(void) { JOYState_TypeDef joykey; /* Initialized the Joystick. */ for(joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) { /* Enable the JOY clock */ JOYx_GPIO_CLK_ENABLE(joykey); HAL_GPIO_DeInit(JOY_PORT[joykey], JOY_PIN[joykey]); }for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) { ... } }{ ... } /** * @brief Returns the current joystick status. * @retval Code of the joystick key pressed * This code can be one of the following values: * @arg JOY_NONE * @arg JOY_SEL * @arg JOY_DOWN * @arg JOY_LEFT * @arg JOY_RIGHT * @arg JOY_UP *//* ... */ JOYState_TypeDef BSP_JOY_GetState(void) { JOYState_TypeDef joykey; for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) { if (HAL_GPIO_ReadPin(JOY_PORT[joykey], JOY_PIN[joykey]) != GPIO_PIN_RESET) { /* Return Code Joystick key pressed */ return joykey; }if (HAL_GPIO_ReadPin(JOY_PORT[joykey], JOY_PIN[joykey]) != GPIO_PIN_RESET) { ... } }for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) { ... } /* No Joystick key pressed */ return JOY_NONE; }{ ... } /** * @brief Configures COM port. * @param COM: COM port to be configured. * This parameter can be one of the following values: * @arg COM1 * @param huart: Pointer to a UART_HandleTypeDef structure that contains the * configuration information for the specified USART peripheral. *//* ... */ void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart) { GPIO_InitTypeDef gpio_init_structure; /* Enable GPIO clock */ DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM); DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM); /* Enable USART clock */ DISCOVERY_COMx_CLK_ENABLE(COM); /* Configure USART Tx as alternate function */ gpio_init_structure.Pin = COM_TX_PIN[COM]; gpio_init_structure.Mode = GPIO_MODE_AF_PP; gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; gpio_init_structure.Pull = GPIO_PULLUP; gpio_init_structure.Alternate = COM_TX_AF[COM]; HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure); /* Configure USART Rx as alternate function */ gpio_init_structure.Pin = COM_RX_PIN[COM]; gpio_init_structure.Mode = GPIO_MODE_AF_PP; gpio_init_structure.Alternate = COM_RX_AF[COM]; HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure); /* USART configuration */ huart->Instance = COM_USART[COM]; HAL_UART_Init(huart); }{ ... } /** * @brief DeInit COM port. * @param COM: COM port to be configured. * This parameter can be one of the following values: * @arg COM1 * @param huart: Pointer to a UART_HandleTypeDef structure that contains the * configuration information for the specified USART peripheral. *//* ... */ void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart) { /* USART configuration */ huart->Instance = COM_USART[COM]; HAL_UART_DeInit(huart); /* Enable USART clock */ DISCOVERY_COMx_CLK_DISABLE(COM); /* DeInit GPIO pins can be done in the application (by surcharging this __weak function) *//* ... */ /* GPIO pins clock, FMC clock and DMA clock can be shut down in the application by surcharging this __weak function *//* ... */ }{ ... } /******************************************************************************* BUS OPERATIONS *******************************************************************************//* ... */ /******************************* I2C Routines *********************************/ /** * @brief Initializes I2C MSP. * @param i2c_handler : I2C handler *//* ... */ static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler) { GPIO_InitTypeDef gpio_init_structure; if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler)) { /* AUDIO I2C MSP init */ /*** Configure the GPIOs ***/ /* Enable GPIO clock */ DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_CLK_ENABLE(); /* Configure I2C Tx as alternate function */ gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SCL_PIN; gpio_init_structure.Mode = GPIO_MODE_AF_OD; gpio_init_structure.Pull = GPIO_NOPULL; gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF; HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); /* Configure I2C Rx as alternate function */ gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SDA_PIN; HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); /*** Configure the I2C peripheral ***/ /* Enable I2C clock */ DISCOVERY_AUDIO_I2Cx_CLK_ENABLE(); /* Force the I2C peripheral clock reset */ DISCOVERY_AUDIO_I2Cx_FORCE_RESET(); /* Release the I2C peripheral clock reset */ DISCOVERY_AUDIO_I2Cx_RELEASE_RESET(); /* Enable and set I2Cx Interrupt to a lower priority */ HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_EV_IRQn, 0x0F, 0x00); HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_EV_IRQn); /* Enable and set I2Cx Interrupt to a lower priority */ HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_ER_IRQn, 0x0F, 0x00); HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_ER_IRQn); }if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler)) { ... } else { /* External and Arduino connector I2C MSP init */ /*** Configure the GPIOs ***/ /* Enable GPIO clock */ DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_CLK_ENABLE(); /* Configure I2C Tx as alternate function */ gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SCL_PIN; gpio_init_structure.Mode = GPIO_MODE_AF_OD; gpio_init_structure.Pull = GPIO_NOPULL; gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; gpio_init_structure.Alternate = DISCOVERY_EXT_I2Cx_SCL_AF; HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); /* Configure I2C Rx as alternate function */ gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SDA_PIN; gpio_init_structure.Alternate = DISCOVERY_EXT_I2Cx_SDA_AF; HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); /*** Configure the I2C peripheral ***/ /* Enable I2C clock */ DISCOVERY_EXT_I2Cx_CLK_ENABLE(); /* Force the I2C peripheral clock reset */ DISCOVERY_EXT_I2Cx_FORCE_RESET(); /* Release the I2C peripheral clock reset */ DISCOVERY_EXT_I2Cx_RELEASE_RESET(); /* Enable and set I2Cx Interrupt to a lower priority */ HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_EV_IRQn, 0x0F, 0x00); HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_EV_IRQn); /* Enable and set I2Cx Interrupt to a lower priority */ HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_ER_IRQn, 0x0F, 0x00); HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_ER_IRQn); }else { ... } }{ ... } /** * @brief Initializes I2C HAL. * @param i2c_handler : I2C handler *//* ... */ static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler) { if(HAL_I2C_GetState(i2c_handler) == HAL_I2C_STATE_RESET) { if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler)) { /* Audio and LCD I2C configuration */ i2c_handler->Instance = DISCOVERY_AUDIO_I2Cx; }if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler)) { ... } else { /* External, EEPROM and Arduino connector I2C configuration */ i2c_handler->Instance = DISCOVERY_EXT_I2Cx; }else { ... } i2c_handler->Init.ClockSpeed = DISCOVERY_I2C_SPEED; i2c_handler->Init.DutyCycle = I2C_DUTYCYCLE_2; i2c_handler->Init.OwnAddress1 = 0; i2c_handler->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; i2c_handler->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; i2c_handler->Init.OwnAddress2 = 0; i2c_handler->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; i2c_handler->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; /* Init the I2C */ I2Cx_MspInit(i2c_handler); HAL_I2C_Init(i2c_handler); }if (HAL_I2C_GetState(i2c_handler) == HAL_I2C_STATE_RESET) { ... } }{ ... } /** * @brief Reads multiple data. * @param i2c_handler : I2C handler * @param Addr: I2C address * @param Reg: Reg address * @param MemAddress: Memory address * @param Buffer: Pointer to data buffer * @param Length: Length of the data * @retval HAL status *//* ... */ static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length) { HAL_StatusTypeDef status = HAL_OK; status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000); /* Check the communication status */ if(status != HAL_OK) { /* I2C error occurred */ I2Cx_Error(i2c_handler, Addr); }if (status != HAL_OK) { ... } return status; }{ ... } /** * @brief Writes a value in a register of the device through BUS in using DMA mode. * @param i2c_handler : I2C handler * @param Addr: Device address on BUS Bus. * @param Reg: The target register address to write * @param MemAddress: Memory address * @param Buffer: The target register value to be written * @param Length: buffer size to be written * @retval HAL status *//* ... */ static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length) { HAL_StatusTypeDef status = HAL_OK; status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000); /* Check the communication status */ if(status != HAL_OK) { /* Re-Initialize the I2C Bus */ I2Cx_Error(i2c_handler, Addr); }if (status != HAL_OK) { ... } return status; }{ ... } /** * @brief Checks if target device is ready for communication. * @note This function is used with Memory devices * @param i2c_handler : I2C handler * @param DevAddress: Target device address * @param Trials: Number of trials * @retval HAL status *//* ... */ static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials) { return (HAL_I2C_IsDeviceReady(i2c_handler, DevAddress, Trials, 1000)); }{ ... } /** * @brief Manages error callback by re-initializing I2C. * @param i2c_handler : I2C handler * @param Addr: I2C Address *//* ... */ static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr) { /* De-initialize the I2C communication bus */ HAL_I2C_DeInit(i2c_handler); /* Re-Initialize the I2C communication bus */ I2Cx_Init(i2c_handler); }{ ... } /** * @brief Deinitializes I2C interface * @param i2c_handler : I2C handler *//* ... */ static void I2Cx_DeInit(I2C_HandleTypeDef *i2c_handler) { if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler)) { /* Audio and LCD I2C configuration */ i2c_handler->Instance = DISCOVERY_AUDIO_I2Cx; }if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler)) { ... } else { /* External, EEPROM and Arduino connector I2C configuration */ i2c_handler->Instance = DISCOVERY_EXT_I2Cx; }else { ... } /* Disable I2C block */ __HAL_I2C_DISABLE(i2c_handler); /* DeInit the I2S */ HAL_I2C_DeInit(i2c_handler); }{ ... } I2C Routines /*************************** FMC Routines ************************************/ /** * @brief Initializes FMC_BANK1 MSP. *//* ... */ static void FMC_BANK1_MspInit(void) { GPIO_InitTypeDef gpio_init_structure; /* Enable FSMC clock */ __HAL_RCC_FSMC_CLK_ENABLE(); /* Enable GPIOs clock */ __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); /* Common GPIO configuration */ gpio_init_structure.Mode = GPIO_MODE_AF_PP; gpio_init_structure.Pull = GPIO_PULLUP; gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; gpio_init_structure.Alternate = GPIO_AF12_FSMC; /* GPIOD configuration */ /* GPIO_PIN_7 is FMC_NE1 */ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8 |\ GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_7; HAL_GPIO_Init(GPIOD, &gpio_init_structure); /* GPIOE configuration */ gpio_init_structure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |\ GPIO_PIN_12 |GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; HAL_GPIO_Init(GPIOE, &gpio_init_structure); /* GPIOF configuration */ gpio_init_structure.Pin = GPIO_PIN_0 ; HAL_GPIO_Init(GPIOF, &gpio_init_structure); }{ ... } /** * @brief Initializes LCD IO. *//* ... */ static void FMC_BANK1_Init(void) { SRAM_HandleTypeDef hsram; FMC_NORSRAM_TimingTypeDef sram_timing; FMC_NORSRAM_TimingTypeDef sram_timing_write; /*** Configure the SRAM Bank 1 ***/ /* Configure IPs */ hsram.Instance = FSMC_NORSRAM_DEVICE; hsram.Extended = FSMC_NORSRAM_EXTENDED_DEVICE; /* Timing for READING */ sram_timing.AddressSetupTime = 9; sram_timing.AddressHoldTime = 1; sram_timing.DataSetupTime = 36; sram_timing.BusTurnAroundDuration = 1; sram_timing.CLKDivision = 2; sram_timing.DataLatency = 2; sram_timing.AccessMode = FSMC_ACCESS_MODE_A; /* Timing for WRITING*/ sram_timing_write.AddressSetupTime = 1; sram_timing_write.AddressHoldTime = 1; sram_timing_write.DataSetupTime = 7; sram_timing_write.BusTurnAroundDuration = 0; sram_timing_write.CLKDivision = 2; sram_timing_write.DataLatency = 2; sram_timing_write.AccessMode = FSMC_ACCESS_MODE_A; hsram.Init.NSBank = FSMC_NORSRAM_BANK1; hsram.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE; hsram.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM; hsram.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16; hsram.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE; hsram.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW; hsram.Init.WrapMode = FSMC_WRAP_MODE_DISABLE; hsram.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS; hsram.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE; hsram.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE; hsram.Init.ExtendedMode = FSMC_EXTENDED_MODE_ENABLE; hsram.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE; hsram.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE; hsram.Init.WriteFifo = FSMC_WRITE_FIFO_DISABLE; hsram.Init.PageSize = FSMC_PAGE_SIZE_NONE; hsram.Init.ContinuousClock = FSMC_CONTINUOUS_CLOCK_SYNC_ONLY; /* Initialize the SRAM controller */ FMC_BANK1_MspInit(); HAL_SRAM_Init(&hsram, &sram_timing, &sram_timing_write); }{ ... } /** * @brief Writes register value. * @param Data: Data to be written *//* ... */ static void FMC_BANK1_WriteData(uint16_t Data) { /* Write 16-bit Reg */ FMC_BANK1->RAM = Data; __DSB(); }{ ... } /** * @brief Writes register address. * @param Reg: Register to be written *//* ... */ static void FMC_BANK1_WriteReg(uint8_t Reg) { /* Write 16-bit Index, then write register */ FMC_BANK1->REG = Reg; __DSB(); }{ ... } /** * @brief Reads register value. * @retval Read value *//* ... */ static uint16_t FMC_BANK1_ReadData(void) { return FMC_BANK1->RAM; }{ ... } /******************************************************************************* LINK OPERATIONS *******************************************************************************//* ... */ FMC Routines /********************************* LINK LCD ***********************************/ /** * @brief Initializes LCD low level. *//* ... */ void LCD_IO_Init(void) { FMC_BANK1_Init(); }{ ... } /** * @brief Writes data on LCD data register. * @param RegValue: Data to be written *//* ... */ void LCD_IO_WriteData(uint16_t RegValue) { /* Write 16-bit Reg */ FMC_BANK1_WriteData(RegValue); }{ ... } /** * @brief Writes several data on LCD data register. * @param pData: pointer on data to be written * @param Size: data amount in 16bits short unit *//* ... */ void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size) { uint32_t i; for (i = 0; i < Size; i++) { FMC_BANK1_WriteData(pData[i]); }for (i = 0; i < Size; i++) { ... } }{ ... } /** * @brief Writes register on LCD register. * @param Reg: Register to be written *//* ... */ void LCD_IO_WriteReg(uint8_t Reg) { /* Write 16-bit Index, then Write Reg */ FMC_BANK1_WriteReg(Reg); }{ ... } /** * @brief Reads data from LCD data register. * @retval Read data. *//* ... */ uint16_t LCD_IO_ReadData(void) { return FMC_BANK1_ReadData(); }{ ... } /** * @brief LCD delay * @param Delay: Delay in ms *//* ... */ void LCD_IO_Delay(uint32_t Delay) { HAL_Delay(Delay); }{ ... } LINK LCD /********************************* LINK AUDIO *********************************/ /** * @brief Initializes Audio low level. *//* ... */ void AUDIO_IO_Init(void) { I2Cx_Init(&hI2cAudioHandler); }{ ... } /** * @brief Deinitializes Audio low level. *//* ... */ void AUDIO_IO_DeInit(void) { I2Cx_DeInit(&hI2cAudioHandler); }{ ... } /** * @brief Writes a single data. * @param Addr: I2C address * @param Reg: Reg address * @param Value: Data to be written *//* ... */ void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value) { uint16_t tmp = Value; Value = ((uint16_t)(tmp >> 8) & 0x00FF); Value |= ((uint16_t)(tmp << 8)& 0xFF00); I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 2); }{ ... } /** * @brief Reads a single data. * @param Addr: I2C address * @param Reg: Reg address * @retval Data to be read *//* ... */ uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg) { uint16_t read_value = 0, tmp = 0; I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 2); tmp = ((uint16_t)(read_value >> 8) & 0x00FF); tmp |= ((uint16_t)(read_value << 8)& 0xFF00); read_value = tmp; return read_value; }{ ... } /** * @brief AUDIO Codec delay * @param Delay: Delay in ms *//* ... */ void AUDIO_IO_Delay(uint32_t Delay) { HAL_Delay(Delay); }{ ... } LINK AUDIO /******************************** LINK I2C EEPROM *****************************/ /** * @brief Initializes peripherals used by the I2C EEPROM driver. *//* ... */ void EEPROM_IO_Init(void) { I2Cx_Init(&hI2cExtHandler); }{ ... } /** * @brief Write data to I2C EEPROM driver in using DMA channel. * @param DevAddress: Target device address * @param MemAddress: Internal memory address * @param pBuffer: Pointer to data buffer * @param BufferSize: Amount of data to be sent * @retval HAL status *//* ... */ HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize) { return (I2Cx_WriteMultiple(&hI2cExtHandler, DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize)); }{ ... } /** * @brief Read data from I2C EEPROM driver in using DMA channel. * @param DevAddress: Target device address * @param MemAddress: Internal memory address * @param pBuffer: Pointer to data buffer * @param BufferSize: Amount of data to be read * @retval HAL status *//* ... */ HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize) { return (I2Cx_ReadMultiple(&hI2cExtHandler, DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize)); }{ ... } /** * @brief Checks if target device is ready for communication. * @note This function is used with Memory devices * @param DevAddress: Target device address * @param Trials: Number of trials * @retval HAL status *//* ... */ HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials) { return (I2Cx_IsDeviceReady(&hI2cExtHandler, DevAddress, Trials)); }{ ... } LINK I2C EEPROM /************************** LINK TS (TouchScreen) *****************************/ /** * @brief Initializes Touchscreen low level. *//* ... */ void TS_IO_Init(void) { I2Cx_Init(&hI2cAudioHandler); }{ ... } /** * @brief Writes a single data. * @param Addr: I2C address * @param Reg: Reg address * @param Value: Data to be written *//* ... */ void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value) { I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1); }{ ... } /** * @brief Reads a single data. * @param Addr: I2C address * @param Reg: Reg address * @retval Data to be read *//* ... */ uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg) { uint8_t read_value = 0; I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1); return read_value; }{ ... } /** * @brief Reads multiple data with I2C communication * channel from TouchScreen. * @param Addr: I2C address * @param Reg: Register address * @param Buffer: Pointer to data buffer * @param Length: Length of the data * @retval HAL status *//* ... */ uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length) { return I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length); }{ ... } /** * @brief Writes multiple data with I2C communication * channel from MCU to TouchScreen. * @param Addr: I2C address * @param Reg: Register address * @param Buffer: Pointer to data buffer * @param Length: Length of the data *//* ... */ void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length) { I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length); }{ ... } /** * @brief Delay function used in TouchScreen low level driver. * @param Delay: Delay in ms *//* ... */ void TS_IO_Delay(uint32_t Delay) { HAL_Delay(Delay); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.