| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

UART_Dma_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : UART_Dma_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the UART functionality with DMA
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
167 /* Includes ------------------------------------------------------------------*/
168 #include "BlueNRG1.h"
169 #include "BlueNRG1_it.h"
170 #include "BlueNRG1_conf.h"
171 #include "SDK_EVAL_Config.h"
172
185 /* Private typedef -----------------------------------------------------------*/
186 /* Private define ------------------------------------------------------------*/
187 #define USART_DR_ADDRESS (UART_BASE)
188 #define SYST_CLOCK 16000000 /*< System clock frequency */
189
190 /* Private macro -------------------------------------------------------------*/
191 /* Private variables ---------------------------------------------------------*/
192 uint8_t buffer_uart[UART_BUFFER_SIZE];
193 uint8_t buffer_uart_tail = 0;
194 volatile uint8_t buffer_uart_used = 0;
195 FlagStatus uart_tx_dma_eot = SET;
196
197 /* Private function prototypes -----------------------------------------------*/
198 void DMA_Configuration(void);
199 void DMAUart_Sending(uint8_t size);
200
201 /* Private functions ---------------------------------------------------------*/
202
203
209 int main(void)
210 {
211 /* System initialization function */
212 SystemInit();
213
214 /* Identify BlueNRG1 platform */
215 SdkEvalIdentification();
216
217 /* UART initialization */
218 SdkEvalComUartInit(UART_BAUDRATE);
219
220 /* DMA initialization */
221 DMA_Configuration();
222
223 /* Configure SysTick to generate interrupt with 25ms period */
224 SysTick_Config(SYST_CLOCK/40);
225
226 while(1) {
227
228 if(buffer_uart_used>0) {
229 DMAUart_Sending(buffer_uart_used);
230 buffer_uart_used = 0;
231 }
232
233 }
234
235 }
236
237
243 void DMA_Configuration(void)
244 {
245 DMA_InitType DMA_InitStructure;
246 NVIC_InitType NVIC_InitStructure;
247
248 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_DMA, ENABLE);
249
250 /* DMA_CH_UART_TX Initialization */
251 DMA_InitStructure.DMA_PeripheralBaseAddr = USART_DR_ADDRESS;
252 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)buffer_uart;
253 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
254 DMA_InitStructure.DMA_BufferSize = (uint32_t)UART_BUFFER_SIZE;
255 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
256 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
257 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
258 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
259 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
260 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
261 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
262 DMA_Init(DMA_CH_UART_TX, &DMA_InitStructure);
263
264 /* Enable DMA_CH_UART_TX Transfer Complete interrupt */
265 DMA_FlagConfig(DMA_CH_UART_TX, DMA_FLAG_TC, ENABLE);
266
267 /* DMA_CH_UART_RX Initialization */
268 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)buffer_uart;
269 DMA_InitStructure.DMA_BufferSize = (uint32_t)UART_BUFFER_SIZE;
270 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
271 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
272 DMA_Init(DMA_CH_UART_RX, &DMA_InitStructure);
273 DMA_Cmd(DMA_CH_UART_RX, ENABLE);
274
275 /* Enable USART_DMAReq_Tx */
276 UART_DMACmd(UART_DMAReq_Tx | UART_DMAReq_Rx, ENABLE);
277
278 /* Enable the DMA Interrupt request */
279 NVIC_InitStructure.NVIC_IRQChannel = DMA_IRQn;
280 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = HIGH_PRIORITY;
281 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
282 NVIC_Init(&NVIC_InitStructure);
283
284 }
285
286 void DMAUart_Sending(uint8_t size)
287 {
288 while(uart_tx_dma_eot==RESET);
289
290 uart_tx_dma_eot = RESET;
291
292 DMA_CH_UART_TX->CMAR = (uint32_t)&buffer_uart[buffer_uart_tail];
293
294 DMA_CH_UART_TX->CNDTR = size;
295 buffer_uart_tail = (buffer_uart_tail+buffer_uart_used)%UART_BUFFER_SIZE;
296
297 /* DMA_CH_UART_TX enable */
298 DMA_CH_UART_TX->CCR_b.EN = SET;
299
300 }
301
302 #ifdef USE_FULL_ASSERT
303
310 void assert_failed(uint8_t* file, uint32_t line)
311 {
312 /* User can add his own implementation to report the file name and line number,
313 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
314 /* Infinite loop */
315 while (1)
316 {
317 }
318 }
319
320 #endif
321
322
335 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
SYST_CLOCK
#define SYST_CLOCK
Definition: UART_Dma_main.c:188
DMA_Configuration
void DMA_Configuration(void)
DMA_Configuration.
Definition: UART_Dma_main.c:243
buffer_uart
uint8_t buffer_uart[UART_BUFFER_SIZE]
Definition: UART_Dma_main.c:192
buffer_uart_used
volatile uint8_t buffer_uart_used
Definition: UART_Dma_main.c:194
DMAUart_Sending
void DMAUart_Sending(uint8_t size)
Definition: UART_Dma_main.c:286
buffer_uart_tail
uint8_t buffer_uart_tail
Definition: UART_Dma_main.c:193
uart_tx_dma_eot
FlagStatus uart_tx_dma_eot
Definition: UART_Dma_main.c:195
main
int main(void)
Main program.
Definition: UART_Dma_main.c:209
USART_DR_ADDRESS
#define USART_DR_ADDRESS
Definition: UART_Dma_main.c:187
UART_BAUDRATE
#define UART_BAUDRATE
Definition: ADC_PDM_main.c:225