1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
27
28
29
30
31
32
35
36
39
40
43
44
47
48
52
55
56
59
60
63
64
65
66
67
71
72
73
74
75
76
77
80
81
84
88
89
93
94
97
98
101
102
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
127
128
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
182
183
186
187
191
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
234
235
236
237
238
239
240
241
242
243
244
248
249
250
251
252
253
254
255
256
257
258
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
310
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
430
434
438
442
446
450
454
455
456
459
460
461
462
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
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
561
562
563
564
565
566
567
568
569
574
575
576
577
578
584
585
586
587
588
589
590
591
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
643
644
645
646
653
657
658
662
663
664
665
666
667
668
669
670
671
672
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
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
764
769
770
774
779
780
784
788
789
792
793
794
795
798
802
803
806
810
811
817
821
822
828
832
833
834
835
836
837
838
839
840
841
845
846
850
854
855
856
857
860
868
869
873
878
879
884
896
897
901
906
907
912
919
920
921
924
928
929
933
937
938
944
948
949
955
959
960
961
962
965
969
970
976
980
981
987
991
992
996
1000
1001
1002
1003
1006
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1036
1037
1038
1039
1040
1041
1042
1043
1044
1048
1049
1052
1053
1056
1057
1060
1061
/* ... */
/* ... */
#include "stm324xg_eval.h"
#include "stm324xg_eval_io.h"
/* ... */
/* ... */
/* ... */
/* ... */
typedef struct
{
__IO uint16_t REG;
__IO uint16_t RAM;
...}LCD_CONTROLLER_TypeDef;
/* ... */
/* ... */
/* ... */
#define __STM324xG_EVAL_BSP_VERSION_MAIN (0x03)
#define __STM324xG_EVAL_BSP_VERSION_SUB1 (0x00)
#define __STM324xG_EVAL_BSP_VERSION_SUB2 (0x04)
#define __STM324xG_EVAL_BSP_VERSION_RC (0x00)
#define __STM324xG_EVAL_BSP_VERSION ((__STM324xG_EVAL_BSP_VERSION_MAIN << 24)\
|(__STM324xG_EVAL_BSP_VERSION_SUB1 << 16)\
|(__STM324xG_EVAL_BSP_VERSION_SUB2 << 8 )\
|(__STM324xG_EVAL_BSP_VERSION_RC))...
#define FMC_BANK3_BASE ((uint32_t)(0x60000000 | 0x08000000))
#define FMC_BANK3 ((LCD_CONTROLLER_TypeDef *) FMC_BANK3_BASE)
#define I2C_TIMEOUT 100
8 defines
/* ... */
/* ... */
GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT,
LED2_GPIO_PORT,
LED3_GPIO_PORT,
LED4_GPIO_PORT...};
const uint16_t GPIO_PIN[LEDn] = {LED1_PIN,
LED2_PIN,
LED3_PIN,
LED4_PIN...};
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT,
TAMPER_BUTTON_GPIO_PORT,
KEY_BUTTON_GPIO_PORT...};
const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN,
TAMPER_BUTTON_PIN,
KEY_BUTTON_PIN...};
const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn,
TAMPER_BUTTON_EXTI_IRQn,
KEY_BUTTON_EXTI_IRQn...};
USART_TypeDef* COM_USART[COMn] = {EVAL_COM1};
GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT};
GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT};
const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN};
const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN};
const uint16_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF};
const uint16_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF};
I2C_HandleTypeDef heval_I2c;
static uint8_t Is_LCD_IO_Initialized = 0;
/* ... */
/* ... */
static void I2Cx_Init(void);
static void I2Cx_ITConfig(void);
static void I2Cx_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
static uint8_t I2Cx_Read(uint8_t Addr, uint8_t Reg);
static HAL_StatusTypeDef I2Cx_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length);
static HAL_StatusTypeDef I2Cx_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length);
static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
static void I2Cx_Error(uint8_t Addr);
static void I2Cx_MspInit(void);
static void FSMC_BANK3_WriteData(uint16_t Data);
static void FSMC_BANK3_WriteReg(uint8_t Reg);
static uint16_t FSMC_BANK3_ReadData(void);
static void FSMC_BANK3_Init(void);
static void FSMC_BANK3_MspInit(void);
void IOE_Init(void);
void IOE_ITConfig(void);
void IOE_Delay(uint32_t Delay);
void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
uint8_t IOE_Read(uint8_t Addr, uint8_t Reg);
uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
void LCD_IO_Init(void);
void LCD_IO_WriteData(uint16_t Data);
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size);
void LCD_IO_WriteReg(uint8_t Reg);
uint16_t LCD_IO_ReadData(uint16_t Reg);
void AUDIO_IO_Init(void);
void AUDIO_IO_DeInit(void);
void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
void CAMERA_IO_Init(void);
void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg);
void CAMERA_Delay(uint32_t Delay);
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);
/* ... */
/* ... */
/* ... */
uint32_t BSP_GetVersion(void)
{
return __STM324xG_EVAL_BSP_VERSION;
}{ ... }
/* ... */
void BSP_LED_Init(Led_TypeDef Led)
{
GPIO_InitTypeDef GPIO_InitStruct;
LEDx_GPIO_CLK_ENABLE(Led);
GPIO_InitStruct.Pin = GPIO_PIN[Led];
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
}{ ... }
/* ... */
void BSP_LED_On(Led_TypeDef Led)
{
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
}{ ... }
/* ... */
void BSP_LED_Off(Led_TypeDef Led)
{
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
}{ ... }
/* ... */
void BSP_LED_Toggle(Led_TypeDef Led)
{
HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
}{ ... }
/* ... */
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
{
GPIO_InitTypeDef GPIO_InitStruct;
BUTTONx_GPIO_CLK_ENABLE(Button);
if(Button_Mode == BUTTON_MODE_GPIO)
{
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
}if (Button_Mode == BUTTON_MODE_GPIO) { ... }
if(Button_Mode == BUTTON_MODE_EXTI)
{
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
if(Button != BUTTON_WAKEUP)
{
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
}if (Button != BUTTON_WAKEUP) { ... }
else
{
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
}else { ... }
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x0);
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
}if (Button_Mode == BUTTON_MODE_EXTI) { ... }
}{ ... }
/* ... */
uint32_t BSP_PB_GetState(Button_TypeDef Button)
{
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}{ ... }
/* ... */
void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef GPIO_InitStruct;
EVAL_COMx_TX_GPIO_CLK_ENABLE(COM);
EVAL_COMx_RX_GPIO_CLK_ENABLE(COM);
EVAL_COMx_CLK_ENABLE(COM);
GPIO_InitStruct.Pin = COM_TX_PIN[COM];
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Alternate = COM_TX_AF[COM];
HAL_GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStruct);
GPIO_InitStruct.Pin = COM_RX_PIN[COM];
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Alternate = COM_RX_AF[COM];
HAL_GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStruct);
huart->Instance = COM_USART[COM];
HAL_UART_Init(huart);
}{ ... }
/* ... */
uint8_t BSP_JOY_Init(JOYMode_TypeDef Joy_Mode)
{
uint8_t ret = 0;
ret = BSP_IO_Init();
if(Joy_Mode == JOY_MODE_EXTI)
{
BSP_IO_ConfigPin(JOY_ALL_PINS, IO_MODE_IT_FALLING_EDGE);
}if (Joy_Mode == JOY_MODE_EXTI) { ... }
return ret;
}{ ... }
/* ... */
JOYState_TypeDef BSP_JOY_GetState(void)
{
uint8_t tmp = 0;
tmp = (uint8_t)BSP_IO_ReadPin(JOY_ALL_PINS);
if((tmp & JOY_NONE_PIN) == JOY_NONE)
{
return(JOYState_TypeDef) JOY_NONE;
}if ((tmp & JOY_NONE_PIN) == JOY_NONE) { ... }
else if(!(tmp & JOY_SEL_PIN))
{
return(JOYState_TypeDef) JOY_SEL;
}else if (!(tmp & JOY_SEL_PIN)) { ... }
else if(!(tmp & JOY_DOWN_PIN))
{
return(JOYState_TypeDef) JOY_DOWN;
}else if (!(tmp & JOY_DOWN_PIN)) { ... }
else if(!(tmp & JOY_LEFT_PIN))
{
return(JOYState_TypeDef) JOY_LEFT;
}else if (!(tmp & JOY_LEFT_PIN)) { ... }
else if(!(tmp & JOY_RIGHT_PIN))
{
return(JOYState_TypeDef) JOY_RIGHT;
}else if (!(tmp & JOY_RIGHT_PIN)) { ... }
else if(!(tmp & JOY_UP_PIN))
{
return(JOYState_TypeDef) JOY_UP;
}else if (!(tmp & JOY_UP_PIN)) { ... }
else
{
return(JOYState_TypeDef) JOY_NONE;
}else { ... }
}{ ... }
/* ... */
/* ... */
static void I2Cx_MspInit(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EVAL_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
GPIO_InitStruct.Pin = EVAL_I2Cx_SCL_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = EVAL_I2Cx_SCL_SDA_AF;
HAL_GPIO_Init(EVAL_I2Cx_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = EVAL_I2Cx_SDA_PIN;
HAL_GPIO_Init(EVAL_I2Cx_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
EVAL_I2Cx_CLK_ENABLE();
EVAL_I2Cx_FORCE_RESET();
EVAL_I2Cx_RELEASE_RESET();
HAL_NVIC_SetPriority(EVAL_I2Cx_EV_IRQn, 0x0F, 0);
HAL_NVIC_EnableIRQ(EVAL_I2Cx_EV_IRQn);
HAL_NVIC_SetPriority(EVAL_I2Cx_ER_IRQn, 0x0F, 0);
HAL_NVIC_EnableIRQ(EVAL_I2Cx_ER_IRQn);
}{ ... }
/* ... */
static void I2Cx_Init(void)
{
if(HAL_I2C_GetState(&heval_I2c) == HAL_I2C_STATE_RESET)
{
heval_I2c.Instance = EVAL_I2Cx;
heval_I2c.Init.ClockSpeed = BSP_I2C_SPEED;
heval_I2c.Init.DutyCycle = I2C_DUTYCYCLE_2;
heval_I2c.Init.OwnAddress1 = 0;
heval_I2c.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
heval_I2c.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
heval_I2c.Init.OwnAddress2 = 0;
heval_I2c.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
heval_I2c.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
I2Cx_MspInit();
HAL_I2C_Init(&heval_I2c);
}if (HAL_I2C_GetState(&heval_I2c) == HAL_I2C_STATE_RESET) { ... }
}{ ... }
/* ... */
static void I2Cx_ITConfig(void)
{
static uint8_t I2C_IT_Enabled = 0;
GPIO_InitTypeDef GPIO_InitStruct;
if(I2C_IT_Enabled == 0)
{
I2C_IT_Enabled = 1;
__GPIOI_CLK_ENABLE();
__SYSCFG_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
HAL_NVIC_SetPriority((IRQn_Type)(EXTI2_IRQn), 0x0F, 0);
HAL_NVIC_EnableIRQ((IRQn_Type)(EXTI2_IRQn));
}if (I2C_IT_Enabled == 0) { ... }
}{ ... }
/* ... */
static uint8_t I2Cx_Read(uint8_t Addr, uint8_t Reg)
{
HAL_StatusTypeDef status = HAL_OK;
uint8_t Value = 0;
status = HAL_I2C_Mem_Read(&heval_I2c, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2C_TIMEOUT);
if(status != HAL_OK)
{
I2Cx_Error(Addr);
}if (status != HAL_OK) { ... }
return Value;
}{ ... }
/* ... */
static void I2Cx_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_I2C_Mem_Write(&heval_I2c, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2C_TIMEOUT);
if(status != HAL_OK)
{
I2Cx_Error(Addr);
}if (status != HAL_OK) { ... }
}{ ... }
/* ... */
static HAL_StatusTypeDef I2Cx_ReadMultiple(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(&heval_I2c, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, I2C_TIMEOUT);
if(status != HAL_OK)
{
I2Cx_Error(Addr);
}if (status != HAL_OK) { ... }
return status;
}{ ... }
/* ... */
static HAL_StatusTypeDef I2Cx_WriteMultiple(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(&heval_I2c, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, I2C_TIMEOUT);
if(status != HAL_OK)
{
I2Cx_Error(Addr);
}if (status != HAL_OK) { ... }
return status;
}{ ... }
/* ... */
static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
{
return (HAL_I2C_IsDeviceReady(&heval_I2c, DevAddress, Trials, I2C_TIMEOUT));
}{ ... }
/* ... */
static void I2Cx_Error(uint8_t Addr)
{
HAL_I2C_DeInit(&heval_I2c);
I2Cx_Init();
}{ ... }
I2C Routines
/* ... */
static void FSMC_BANK3_MspInit(void)
{
GPIO_InitTypeDef GPIO_Init_Structure;
__FSMC_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
__GPIOE_CLK_ENABLE();
__GPIOF_CLK_ENABLE();
__GPIOG_CLK_ENABLE();
GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP;
GPIO_Init_Structure.Pull = GPIO_PULLUP;
GPIO_Init_Structure.Speed = GPIO_SPEED_HIGH;
GPIO_Init_Structure.Alternate = GPIO_AF12_FSMC;
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_11 | GPIO_PIN_12 | GPIO_PIN_13 |\
GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure);
GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3| GPIO_PIN_4 | 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);
GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOF, &GPIO_Init_Structure);
GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_10;
HAL_GPIO_Init(GPIOG, &GPIO_Init_Structure);
}{ ... }
/* ... */
static void FSMC_BANK3_Init(void)
{
SRAM_HandleTypeDef hsram;
FSMC_NORSRAM_TimingTypeDef SRAM_Timing;
hsram.Instance = FMC_NORSRAM_DEVICE;
hsram.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
SRAM_Timing.AddressSetupTime = 5;
SRAM_Timing.AddressHoldTime = 1;
SRAM_Timing.DataSetupTime = 9;
SRAM_Timing.BusTurnAroundDuration = 0;
SRAM_Timing.CLKDivision = 2;
SRAM_Timing.DataLatency = 2;
SRAM_Timing.AccessMode = FSMC_ACCESS_MODE_A;
hsram.Init.NSBank = FSMC_NORSRAM_BANK3;
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_DISABLE;
hsram.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
hsram.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
hsram.Init.PageSize = FSMC_PAGE_SIZE_NONE;
FSMC_BANK3_MspInit();
HAL_SRAM_Init(&hsram, &SRAM_Timing, &SRAM_Timing);
}{ ... }
/* ... */
static void FSMC_BANK3_WriteData(uint16_t Data)
{
FMC_BANK3->RAM = Data;
}{ ... }
/* ... */
static void FSMC_BANK3_WriteReg(uint8_t Reg)
{
FMC_BANK3->REG = Reg;
}{ ... }
/* ... */
static uint16_t FSMC_BANK3_ReadData(void)
{
return FMC_BANK3->RAM;
}{ ... }
/* ... */
FSMC Routines
/* ... */
void IOE_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
void IOE_ITConfig(void)
{
I2Cx_ITConfig();
}{ ... }
/* ... */
void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
I2Cx_Write(Addr, Reg, Value);
}{ ... }
/* ... */
uint8_t IOE_Read(uint8_t Addr, uint8_t Reg)
{
return I2Cx_Read(Addr, Reg);
}{ ... }
/* ... */
uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
{
return I2Cx_ReadMultiple(Addr, Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
}{ ... }
/* ... */
void IOE_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
LINK IOE
/* ... */
void LCD_IO_Init(void)
{
if(Is_LCD_IO_Initialized == 0)
{
Is_LCD_IO_Initialized = 1;
FSMC_BANK3_Init();
}if (Is_LCD_IO_Initialized == 0) { ... }
}{ ... }
/* ... */
void LCD_IO_WriteData(uint16_t Data)
{
FSMC_BANK3_WriteData(Data);
}{ ... }
/* ... */
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size)
{
uint32_t counter;
uint16_t *ptr = (uint16_t *) pData;
for (counter = 0; counter < Size; counter+=2)
{
FSMC_BANK3_WriteData(*ptr);
ptr++;
}for (counter = 0; counter < Size; counter+=2) { ... }
}{ ... }
/* ... */
void LCD_IO_WriteReg(uint8_t Reg)
{
FSMC_BANK3_WriteReg(Reg);
}{ ... }
/* ... */
uint16_t LCD_IO_ReadData(uint16_t Reg)
{
FSMC_BANK3_WriteReg(Reg);
return FSMC_BANK3_ReadData();
}{ ... }
LINK LCD
/* ... */
void AUDIO_IO_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
void AUDIO_IO_DeInit(void)
{
}{ ... }
/* ... */
void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
I2Cx_Write(Addr, Reg, Value);
}{ ... }
/* ... */
uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg)
{
return I2Cx_Read(Addr, Reg);
}{ ... }
LINK AUDIO
/* ... */
void CAMERA_IO_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
I2Cx_Write(Addr, Reg, Value);
}{ ... }
/* ... */
uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg)
{
return I2Cx_Read(Addr, Reg);
}{ ... }
/* ... */
void CAMERA_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
LINK CAMERA
/* ... */
void EEPROM_IO_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
{
return (I2Cx_WriteMultiple(DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
}{ ... }
/* ... */
HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
{
return (I2Cx_ReadMultiple(DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
}{ ... }
/* ... */
HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
{
return (I2Cx_IsDeviceReady(DevAddress, Trials));
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */