drv_ext_io.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-19 zylx first version
  9. */
  10. #include "board.h"
  11. #ifdef BSP_USING_EXT_FMC_IO
  12. //#define DRV_DEBUG
  13. #define LOG_TAG "drv.ext_io"
  14. #include <drv_log.h>
  15. #include "drv_ext_io.h"
  16. #define HC574_PORT *(volatile rt_uint32_t *)0x64001000
  17. volatile rt_uint32_t HC574_state = 0;
  18. void HC574_SetPin(rt_uint32_t _pin, uint8_t _value)
  19. {
  20. if (_value == 0)
  21. {
  22. HC574_state &= (~_pin);
  23. }
  24. else
  25. {
  26. HC574_state |= _pin;
  27. }
  28. HC574_PORT = HC574_state;
  29. }
  30. rt_uint8_t HC574_GetPin(rt_uint32_t _pin)
  31. {
  32. if (HC574_state & _pin)
  33. {
  34. return 1;
  35. }
  36. else
  37. {
  38. return 0;
  39. }
  40. }
  41. static void HC574_Config_FMC(void)
  42. {
  43. FMC_NORSRAM_TimingTypeDef timing = {0};
  44. SRAM_HandleTypeDef sram2 = {0};
  45. /*
  46. For LCD compatibility,select 3-0-6-1-0-0
  47. 3-0-5-1-0-0 : RD high level 75ns,low level 50ns. Read 8 channels of data into memory in 1us.
  48. 1-0-1-1-0-0 : RD high level 75ns,low level 12ns,trailing edge 12ns.
  49. */
  50. /* FMC_Bank1_NORSRAM2 configuration */
  51. timing.AddressSetupTime = 3;
  52. timing.AddressHoldTime = 0;
  53. timing.DataSetupTime = 6;
  54. timing.BusTurnAroundDuration = 1;
  55. timing.CLKDivision = 0;
  56. timing.DataLatency = 0;
  57. timing.AccessMode = FMC_ACCESS_MODE_A;
  58. /*
  59. LCD configured as follow:
  60. - Data/Address MUX = Disable
  61. - Memory Type = SRAM
  62. - Data Width = 32bit
  63. - Write Operation = Enable
  64. - Extended Mode = Enable
  65. - Asynchronous Wait = Disable
  66. */
  67. sram2.Instance = FMC_NORSRAM_DEVICE;
  68. sram2.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
  69. sram2.Init.NSBank = FMC_NORSRAM_BANK2;
  70. sram2.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
  71. sram2.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
  72. sram2.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_32;
  73. sram2.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
  74. sram2.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
  75. sram2.Init.WrapMode = FMC_WRAP_MODE_DISABLE;
  76. sram2.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
  77. sram2.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
  78. sram2.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
  79. sram2.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
  80. sram2.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
  81. sram2.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
  82. sram2.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
  83. sram2.Init.PageSize = FMC_PAGE_SIZE_1024;
  84. if (HAL_SRAM_Init(&sram2, &timing, NULL) != HAL_OK)
  85. {
  86. LOG_E("extend IO init failed!");
  87. }
  88. else
  89. {
  90. LOG_D("extend IO init success");
  91. }
  92. }
  93. static int stm32_ext_io_init(void)
  94. {
  95. HC574_Config_FMC();
  96. /* Set the chip select to high level */
  97. HC574_state = (NRF24L01_CE | VS1053_XDCS | LED1 | LED2 | LED3 | LED4 );
  98. /* Change IO state */
  99. HC574_PORT = HC574_state;
  100. return RT_EOK;
  101. }
  102. INIT_BOARD_EXPORT(stm32_ext_io_init);
  103. #endif /* BSP_USING_EXT_FMC_IO */