EFM32 Leopard Gecko Software Documentation  efm32lg-doc-4.2.1
bsp_stk.c
Go to the documentation of this file.
1 /***************************************************************************/
18 #include <string.h>
19 #include "em_device.h"
20 #include "em_cmu.h"
21 #include "em_gpio.h"
22 #include "bsp.h"
23 #if defined( BSP_STK_USE_EBI )
24 #include "em_ebi.h"
25 #endif
26 
27 #if defined( BSP_STK )
28 
29 
30 /***************************************************************************/
35 /***************************************************************************/
41 /**************************************************************************/
47 int BSP_Disable(void)
48 {
49  BSP_BccDeInit();
50  BSP_EbiDeInit();
51 
52  return BSP_STATUS_OK;
53 }
56 /**************************************************************************/
64 int BSP_EbiInit(void)
65 {
66 #if defined( BSP_STK_USE_EBI )
67  /* ------------------------------------------ */
68  /* NAND Flash, Bank0, Base Address 0x80000000 */
69  /* Micron flash NAND256W3A */
70  /* ------------------------------------------ */
71 
72  EBI_Init_TypeDef ebiConfig =
73  { ebiModeD8A8, /* 8 bit address, 8 bit data */
74  ebiActiveLow, /* ARDY polarity */
75  ebiActiveLow, /* ALE polarity */
76  ebiActiveLow, /* WE polarity */
77  ebiActiveLow, /* RE polarity */
78  ebiActiveLow, /* CS polarity */
79  ebiActiveLow, /* BL polarity */
80  false, /* disble BL */
81  true, /* enable NOIDLE */
82  false, /* disable ARDY */
83  true, /* disable ARDY timeout */
84  EBI_BANK0, /* enable bank 0 */
85  0, /* no chip select */
86  0, /* addr setup cycles */
87  0, /* addr hold cycles */
88  false, /* disable half cycle ALE strobe */
89  0, /* read setup cycles */
90  2, /* read strobe cycles */
91  1, /* read hold cycles */
92  false, /* disable page mode */
93  false, /* disable prefetch */
94  false, /* disable half cycle REn strobe */
95  0, /* write setup cycles */
96  2, /* write strobe cycles */
97  1, /* write hold cycles */
98  false, /* enable the write buffer */
99  false, /* disable half cycle WEn strobe */
100  ebiALowA24, /* ALB - Low bound, address lines */
101  ebiAHighA26, /* APEN - High bound, address lines */
102  ebiLocation1, /* Use Location 1 */
103  true, /* enable EBI */
104  };
105 
106  /* Enable clocks */
110 
111  /* Enable GPIO's */
112  /* ALE and CLE */
113  GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 0);
114  GPIO_PinModeSet(gpioPortC, 2, gpioModePushPull, 0);
115 
116  /* WP, CE and R/B */
117  GPIO_PinModeSet(gpioPortD, 13, gpioModePushPull, 0); /* active low write-protect */
118  GPIO_PinModeSet(gpioPortD, 14, gpioModePushPull, 1); /* active low chip-enable */
119  GPIO_PinModeSet(gpioPortD, 15, gpioModeInput, 0); /* ready/busy */
120 
121  /* IO pins */
122  GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
123  GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
124  GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
125  GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
126  GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
127  GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
128  GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
129  GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
130 
131  /* WE and RE */
132  GPIO_PinModeSet(gpioPortF, 8, gpioModePushPull, 1);
133  GPIO_PinModeSet(gpioPortF, 9, gpioModePushPull, 1);
134 
135  /* NAND Power Enable */
136  GPIO_PinModeSet(gpioPortB, 15, gpioModePushPull, 1);
137 
138  EBI_Init(&ebiConfig);
140 
141  return BSP_STATUS_OK;
142 #else
144 #endif
145 }
146 
147 /**************************************************************************/
157 int BSP_EbiDeInit( void )
158 {
159 #if defined( BSP_STK_USE_EBI )
160  return BSP_STATUS_OK;
161 #else
163 #endif
164 }
165 
167 /**************************************************************************/
175 int BSP_Init( uint32_t flags )
176 {
177  if ( flags & BSP_INIT_BCC )
178  {
179  BSP_BccInit();
180  }
181 
182  return BSP_STATUS_OK;
183 }
186 /**************************************************************************/
196 float BSP_CurrentGet( void )
197 {
198  BCP_Packet pkt;
199  float *pcurrent;
200 
202  pkt.payloadLength = 0;
203 
204  /* Send Request/Get reply */
205  BSP_BccPacketSend( &pkt );
206  BSP_BccPacketReceive( &pkt );
207 
208  /* Process reply */
209  pcurrent = (float *)pkt.data;
210  if ( pkt.type != BSP_BCP_CURRENT_REPLY )
211  {
212  *pcurrent = 0.0f;
213  }
214 
215  return *pcurrent;
216 }
217 
218 /**************************************************************************/
228 float BSP_VoltageGet( void )
229 {
230  BCP_Packet pkt;
231  float *pvoltage;
232 
234  pkt.payloadLength = 0;
235 
236  /* Send Request/Get reply */
237  BSP_BccPacketSend( &pkt );
238  BSP_BccPacketReceive( &pkt );
239 
240  /* Process reply */
241  pvoltage = (float *)pkt.data;
242  if ( pkt.type != BSP_BCP_VOLTAGE_REPLY )
243  {
244  *pvoltage = 0.0f;
245  }
246 
247  return *pvoltage;
248 }
249 
253 #endif /* BSP_STK */
Clock management unit (CMU) API.
Board support package API definitions.
float BSP_CurrentGet(void)
Request AEM (Advanced Energy Monitoring) current from board controller.
Definition: bsp_stk.c:196
BCP Packet Structure - Board controller communication protocol version 2.
Definition: bsp_bcp.h:95
#define BSP_BCP_VOLTAGE_REQ
Definition: bsp_bcp.h:47
uint8_t payloadLength
Definition: bsp_bcp.h:99
#define BSP_BCP_CURRENT_REQ
Definition: bsp_bcp.h:45
#define BSP_INIT_BCC
Definition: bsp.h:48
#define EBI_NANDCTRL_BANKSEL_BANK0
Definition: efm32lg_ebi.h:967
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define BSP_BCP_CURRENT_REPLY
Definition: bsp_bcp.h:46
#define EBI_NANDCTRL_EN
Definition: efm32lg_ebi.h:954
#define BSP_STATUS_OK
Definition: bsp.h:40
External Bus Iterface (EBI) peripheral API.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
Definition: em_gpio.c:226
#define BSP_STATUS_NOT_IMPLEMENTED
Definition: bsp.h:42
General Purpose IO (GPIO) peripheral API.
int BSP_BccInit(void)
Initialize board controller communication support (BCC) functionality.
Definition: bsp_bcc.c:89
#define EBI_BANK0
Definition: em_ebi.h:75
void EBI_Init(const EBI_Init_TypeDef *ebiInit)
Configure and enable External Bus Interface.
Definition: em_ebi.c:60
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
Definition: em_cmu.c:1369
uint8_t data[BSP_BCP_PACKET_SIZE]
Definition: bsp_bcp.h:101
#define BSP_BCP_VOLTAGE_REPLY
Definition: bsp_bcp.h:48
int BSP_BccPacketSend(BCP_Packet *pkt)
Send a packet to the board controller.
Definition: bsp_bcc.c:195
float BSP_VoltageGet(void)
Request AEM (Advanced Energy Monitoring) voltage from board controller.
Definition: bsp_stk.c:228
int BSP_EbiDeInit(void)
Deinitialize the EBI interface for accessing the onboard nandflash.
Definition: bsp_stk.c:157
uint8_t type
Definition: bsp_bcp.h:98
int BSP_EbiInit(void)
Initialize the EBI interface for accessing the onboard nandflash.
Definition: bsp_stk.c:64
bool BSP_BccPacketReceive(BCP_Packet *pkt)
Get a packet from the board controller.
Definition: bsp_bcc.c:137
#define EBI
int BSP_BccDeInit(void)
Deinitialize board controller communication support (BCC) functionality. Reverse actions performed by...
Definition: bsp_bcc.c:61