Memory to Memory DMA demo from CMSIS example. This demo execute 1000 times of 32 word memory to memory DMA (copy), and also measures number of dummy loop execution during DMA cylcles. Line 56 of "DMA_M2M.c" can change DMA source. where; 1)static : source is SRAM 2)const : source is Flash ROM

Dependencies:   mbed

Committer:
todotani
Date:
Sun Nov 14 03:26:04 2010 +0000
Revision:
0:692bf16d1455
2010/11/14

Who changed what in which revision?

UserRevisionLine numberNew contents of line
todotani 0:692bf16d1455 1 /***********************************************************************//**
todotani 0:692bf16d1455 2 * @file flash_2_ram.c
todotani 0:692bf16d1455 3 * @purpose This example used to test GPDMA function by transferring
todotani 0:692bf16d1455 4 * data from flash to ram memory
todotani 0:692bf16d1455 5 * @version 2.0
todotani 0:692bf16d1455 6 * @date 21. May. 2010
todotani 0:692bf16d1455 7 * @author NXP MCU SW Application Team
todotani 0:692bf16d1455 8 *
todotani 0:692bf16d1455 9 * Adupted for mebed
todotani 0:692bf16d1455 10 * and modified for insturction execution test during DMA
todotani 0:692bf16d1455 11 * by Todotani 14 Nov. 2010
todotani 0:692bf16d1455 12 *---------------------------------------------------------------------
todotani 0:692bf16d1455 13 * Software that is described herein is for illustrative purposes only
todotani 0:692bf16d1455 14 * which provides customers with programming information regarding the
todotani 0:692bf16d1455 15 * products. This software is supplied "AS IS" without any warranties.
todotani 0:692bf16d1455 16 * NXP Semiconductors assumes no responsibility or liability for the
todotani 0:692bf16d1455 17 * use of the software, conveys no license or title under any patent,
todotani 0:692bf16d1455 18 * copyright, or mask work right to the product. NXP Semiconductors
todotani 0:692bf16d1455 19 * reserves the right to make changes in the software without
todotani 0:692bf16d1455 20 * notification. NXP Semiconductors also make no representation or
todotani 0:692bf16d1455 21 * warranty that such application will be suitable for the specified
todotani 0:692bf16d1455 22 * use without further testing or modification.
todotani 0:692bf16d1455 23 **********************************************************************/
todotani 0:692bf16d1455 24
todotani 0:692bf16d1455 25 #include "lpc17xx_gpdma.h"
todotani 0:692bf16d1455 26 #include "lpc17xx_libcfg.h"
todotani 0:692bf16d1455 27 #include "mbed.h"
todotani 0:692bf16d1455 28 #include "GetTickCount.h"
todotani 0:692bf16d1455 29
todotani 0:692bf16d1455 30 /* Example group ----------------------------------------------------------- */
todotani 0:692bf16d1455 31 /** @defgroup GPDMA_Flash_2_Ram_Test Flash_2_Ram_Test
todotani 0:692bf16d1455 32 * @ingroup GPDMA_Examples
todotani 0:692bf16d1455 33 * @{
todotani 0:692bf16d1455 34 */
todotani 0:692bf16d1455 35
todotani 0:692bf16d1455 36 /************************** PRIVATE DEFINTIONS*************************/
todotani 0:692bf16d1455 37 #define DMA_SIZE 32 /** DMA transfer size */
todotani 0:692bf16d1455 38 #define DMA_CYCLES 1000
todotani 0:692bf16d1455 39
todotani 0:692bf16d1455 40 /************************** PRIVATE VARIABLES *************************/
todotani 0:692bf16d1455 41 uint8_t menu[]=
todotani 0:692bf16d1455 42 "********************************************************************************\n\r"
todotani 0:692bf16d1455 43 "Hello NXP Semiconductors \n\r"
todotani 0:692bf16d1455 44 "GPDMA demo \n\r"
todotani 0:692bf16d1455 45 "\t - MCU: LPC1768(mbed) \n\r"
todotani 0:692bf16d1455 46 "\t - Core: ARM CORTEX-M3 \n\r"
todotani 0:692bf16d1455 47 "\t - Communicate via: UART0 - 9600 bps \n\r"
todotani 0:692bf16d1455 48 "This example used to test GPDMA function by transfer data from Flash \n\r"
todotani 0:692bf16d1455 49 "to RAM memory\n\r"
todotani 0:692bf16d1455 50 "********************************************************************************\n\r";
todotani 0:692bf16d1455 51 uint8_t menu2[] = "Demo terminated! \n\r";
todotani 0:692bf16d1455 52 uint8_t err_menu[] = "Buffer Check fail!\n\r";
todotani 0:692bf16d1455 53 uint8_t compl_menu[] = "Buffer Check success!\n\r\n\r";
todotani 0:692bf16d1455 54
todotani 0:692bf16d1455 55 //DMAScr_Buffer will be burn into flash when compile
todotani 0:692bf16d1455 56 static uint32_t DMASrc_Buffer[DMA_SIZE]=
todotani 0:692bf16d1455 57 {
todotani 0:692bf16d1455 58 0x01020304,0x05060708,0x090A0B0C,0x0D0E0F10,
todotani 0:692bf16d1455 59 0x11121314,0x15161718,0x191A1B1C,0x1D1E1F20,
todotani 0:692bf16d1455 60 0x21222324,0x25262728,0x292A2B2C,0x2D2E2F30,
todotani 0:692bf16d1455 61 0x31323334,0x35363738,0x393A3B3C,0x3D3E3F40,
todotani 0:692bf16d1455 62 0x01020304,0x05060708,0x090A0B0C,0x0D0E0F10,
todotani 0:692bf16d1455 63 0x11121314,0x15161718,0x191A1B1C,0x1D1E1F20,
todotani 0:692bf16d1455 64 0x21222324,0x25262728,0x292A2B2C,0x2D2E2F30,
todotani 0:692bf16d1455 65 0x31323334,0x35363738,0x393A3B3C,0x3D3E3F40
todotani 0:692bf16d1455 66 };
todotani 0:692bf16d1455 67
todotani 0:692bf16d1455 68 uint32_t DMADest_Buffer[DMA_SIZE];
todotani 0:692bf16d1455 69 //uint32_t *DMADest_Buffer = (uint32_t *)0x2007C000; //LPC_AHBRAM0_BASE;
todotani 0:692bf16d1455 70
todotani 0:692bf16d1455 71 volatile uint32_t TC_count = 0;
todotani 0:692bf16d1455 72 uint32_t loop = 0;
todotani 0:692bf16d1455 73 GPDMA_Channel_CFG_Type GPDMACfg;
todotani 0:692bf16d1455 74
todotani 0:692bf16d1455 75 Serial pc(USBTX, USBRX);
todotani 0:692bf16d1455 76
todotani 0:692bf16d1455 77
todotani 0:692bf16d1455 78 /*-------------------------MAIN FUNCTION------------------------------*/
todotani 0:692bf16d1455 79 extern "C" void DMA_IRQHandler (void); // extern "C" required for mbed
todotani 0:692bf16d1455 80
todotani 0:692bf16d1455 81 void Buffer_Init(void);
todotani 0:692bf16d1455 82 void Buffer_Verify(void);
todotani 0:692bf16d1455 83 void SetupDMA(void);
todotani 0:692bf16d1455 84
todotani 0:692bf16d1455 85
todotani 0:692bf16d1455 86 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
todotani 0:692bf16d1455 87 /*********************************************************************//**
todotani 0:692bf16d1455 88 * @brief GPDMA interrupt handler sub-routine
todotani 0:692bf16d1455 89 * @param[in] None
todotani 0:692bf16d1455 90 * @return None
todotani 0:692bf16d1455 91 **********************************************************************/
todotani 0:692bf16d1455 92 void DMA_IRQHandler (void)
todotani 0:692bf16d1455 93 {
todotani 0:692bf16d1455 94 // check GPDMA interrupt on channel 0
todotani 0:692bf16d1455 95 if (GPDMA_IntGetStatus(GPDMA_STAT_INT, 0)) { //check interrupt status on channel 0
todotani 0:692bf16d1455 96 // Check counter terminal status
todotani 0:692bf16d1455 97 if(GPDMA_IntGetStatus(GPDMA_STAT_INTTC, 0)) {
todotani 0:692bf16d1455 98 // Clear terminate counter Interrupt pending
todotani 0:692bf16d1455 99 GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, 0);
todotani 0:692bf16d1455 100
todotani 0:692bf16d1455 101 if (++TC_count < DMA_CYCLES) {
todotani 0:692bf16d1455 102 // Setup channel with given parameter
todotani 0:692bf16d1455 103 GPDMA_Setup(&GPDMACfg);
todotani 0:692bf16d1455 104 // Run DMA again
todotani 0:692bf16d1455 105 GPDMA_ChannelCmd(0, ENABLE);
todotani 0:692bf16d1455 106 return;
todotani 0:692bf16d1455 107 } else {
todotani 0:692bf16d1455 108 /* DMA run predetermined cycles */
todotani 0:692bf16d1455 109 int elapsedTime = GetTickCount();
todotani 0:692bf16d1455 110 Buffer_Verify();
todotani 0:692bf16d1455 111 pc.printf("%s", compl_menu);
todotani 0:692bf16d1455 112 pc.printf("DMA %d cycles, %d loop executions\n\r", TC_count, loop);
todotani 0:692bf16d1455 113 pc.printf("Elapsed time %d ms\n\r\n\r", elapsedTime);
todotani 0:692bf16d1455 114
todotani 0:692bf16d1455 115 while(1); // Halt program
todotani 0:692bf16d1455 116 }
todotani 0:692bf16d1455 117 }
todotani 0:692bf16d1455 118
todotani 0:692bf16d1455 119 if (GPDMA_IntGetStatus(GPDMA_STAT_INTERR, 0)){
todotani 0:692bf16d1455 120 // Clear error counter Interrupt pending
todotani 0:692bf16d1455 121 GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, 0);
todotani 0:692bf16d1455 122 pc.printf("DMA Error detected.\n\r");
todotani 0:692bf16d1455 123 while(1); // Halt program
todotani 0:692bf16d1455 124 }
todotani 0:692bf16d1455 125 }
todotani 0:692bf16d1455 126 }
todotani 0:692bf16d1455 127
todotani 0:692bf16d1455 128
todotani 0:692bf16d1455 129 /*********************************************************************//**
todotani 0:692bf16d1455 130 * @brief Verify buffer
todotani 0:692bf16d1455 131 * @param[in] None
todotani 0:692bf16d1455 132 * @return None
todotani 0:692bf16d1455 133 **********************************************************************/
todotani 0:692bf16d1455 134 void Buffer_Verify(void)
todotani 0:692bf16d1455 135 {
todotani 0:692bf16d1455 136 uint8_t i;
todotani 0:692bf16d1455 137 uint32_t *src_addr = (uint32_t *)DMASrc_Buffer;
todotani 0:692bf16d1455 138 uint32_t *dest_addr = (uint32_t *)DMADest_Buffer;
todotani 0:692bf16d1455 139
todotani 0:692bf16d1455 140 for ( i = 0; i < DMA_SIZE; i++ )
todotani 0:692bf16d1455 141 {
todotani 0:692bf16d1455 142 if ( *src_addr++ != *dest_addr++ )
todotani 0:692bf16d1455 143 {
todotani 0:692bf16d1455 144 pc.printf("Verrify Error!.\n\r");
todotani 0:692bf16d1455 145 }
todotani 0:692bf16d1455 146 }
todotani 0:692bf16d1455 147 }
todotani 0:692bf16d1455 148
todotani 0:692bf16d1455 149
todotani 0:692bf16d1455 150 /*-------------------------MAIN FUNCTION--------------------------------*/
todotani 0:692bf16d1455 151 /*********************************************************************//**
todotani 0:692bf16d1455 152 * @brief c_entry: Main program body
todotani 0:692bf16d1455 153 * @param[in] None
todotani 0:692bf16d1455 154 * @return int
todotani 0:692bf16d1455 155 **********************************************************************/
todotani 0:692bf16d1455 156 int c_entry(void)
todotani 0:692bf16d1455 157 {
todotani 0:692bf16d1455 158 pc.baud(9600);
todotani 0:692bf16d1455 159
todotani 0:692bf16d1455 160 // print welcome screen
todotani 0:692bf16d1455 161 pc.printf("%s", menu);
todotani 0:692bf16d1455 162
todotani 0:692bf16d1455 163 /* Disable GPDMA interrupt */
todotani 0:692bf16d1455 164 NVIC_DisableIRQ(DMA_IRQn);
todotani 0:692bf16d1455 165 /* preemption = 1, sub-priority = 1 */
todotani 0:692bf16d1455 166 NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01));
todotani 0:692bf16d1455 167
todotani 0:692bf16d1455 168 /* Initialize GPDMA controller */
todotani 0:692bf16d1455 169 GPDMA_Init();
todotani 0:692bf16d1455 170
todotani 0:692bf16d1455 171 // Setup GPDMA channel --------------------------------
todotani 0:692bf16d1455 172 // channel 0
todotani 0:692bf16d1455 173 GPDMACfg.ChannelNum = 0;
todotani 0:692bf16d1455 174 // Source memory
todotani 0:692bf16d1455 175 GPDMACfg.SrcMemAddr = (uint32_t)DMASrc_Buffer;
todotani 0:692bf16d1455 176 // Destination memory
todotani 0:692bf16d1455 177 GPDMACfg.DstMemAddr = (uint32_t)DMADest_Buffer;
todotani 0:692bf16d1455 178 // Transfer size
todotani 0:692bf16d1455 179 GPDMACfg.TransferSize = DMA_SIZE;
todotani 0:692bf16d1455 180 // Transfer width
todotani 0:692bf16d1455 181 GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD;
todotani 0:692bf16d1455 182 // Transfer type
todotani 0:692bf16d1455 183 GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M;
todotani 0:692bf16d1455 184 // Source connection - unused
todotani 0:692bf16d1455 185 GPDMACfg.SrcConn = 0;
todotani 0:692bf16d1455 186 // Destination connection - unused
todotani 0:692bf16d1455 187 GPDMACfg.DstConn = 0;
todotani 0:692bf16d1455 188 // Linker List Item - unused
todotani 0:692bf16d1455 189 GPDMACfg.DMALLI = 0;
todotani 0:692bf16d1455 190 // Setup channel with given parameter
todotani 0:692bf16d1455 191 GPDMA_Setup(&GPDMACfg);
todotani 0:692bf16d1455 192
todotani 0:692bf16d1455 193 /* Enable GPDMA interrupt */
todotani 0:692bf16d1455 194 NVIC_EnableIRQ(DMA_IRQn);
todotani 0:692bf16d1455 195
todotani 0:692bf16d1455 196 pc.printf("Start transfer...\n\r");
todotani 0:692bf16d1455 197 GetTickCount_Start();
todotani 0:692bf16d1455 198
todotani 0:692bf16d1455 199 // Enable GPDMA channel 0
todotani 0:692bf16d1455 200 GPDMA_ChannelCmd(0, ENABLE);
todotani 0:692bf16d1455 201
todotani 0:692bf16d1455 202 /* Wait for GPDMA processing complete */
todotani 0:692bf16d1455 203 while (1) {
todotani 0:692bf16d1455 204 loop++;
todotani 0:692bf16d1455 205 }
todotani 0:692bf16d1455 206
todotani 0:692bf16d1455 207 return 1;
todotani 0:692bf16d1455 208 }
todotani 0:692bf16d1455 209
todotani 0:692bf16d1455 210 /* With ARM and GHS toolsets, the entry point is main() - this will
todotani 0:692bf16d1455 211 allow the linker to generate wrapper code to setup stacks, allocate
todotani 0:692bf16d1455 212 heap area, and initialize and copy code and data segments. For GNU
todotani 0:692bf16d1455 213 toolsets, the entry point is through __start() in the crt0_gnu.asm
todotani 0:692bf16d1455 214 file, and that startup code will setup stacks and data */
todotani 0:692bf16d1455 215 int main(void) {
todotani 0:692bf16d1455 216 return c_entry();
todotani 0:692bf16d1455 217 }
todotani 0:692bf16d1455 218
todotani 0:692bf16d1455 219 #ifdef DEBUG
todotani 0:692bf16d1455 220 /*******************************************************************************
todotani 0:692bf16d1455 221 * @brief Reports the name of the source file and the source line number
todotani 0:692bf16d1455 222 * where the CHECK_PARAM error has occurred.
todotani 0:692bf16d1455 223 * @param[in] file Pointer to the source file name
todotani 0:692bf16d1455 224 * @param[in] line assert_param error line source number
todotani 0:692bf16d1455 225 * @return None
todotani 0:692bf16d1455 226 *******************************************************************************/
todotani 0:692bf16d1455 227 void check_failed(uint8_t *file, uint32_t line) {
todotani 0:692bf16d1455 228 /* User can add his own implementation to report the file name and line number,
todotani 0:692bf16d1455 229 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
todotani 0:692bf16d1455 230
todotani 0:692bf16d1455 231 /* Infinite loop */
todotani 0:692bf16d1455 232 while (1)
todotani 0:692bf16d1455 233 ;
todotani 0:692bf16d1455 234 }
todotani 0:692bf16d1455 235 #endif
todotani 0:692bf16d1455 236
todotani 0:692bf16d1455 237 /*
todotani 0:692bf16d1455 238 * @}
todotani 0:692bf16d1455 239 */