CombinedDemo
- Εισέλθετε στο σύστημα ή εγγραφείτε για να υποβάλετε σχόλια
Source code can be downloaded from source:/Examples/CombinedDemo
Description
This examples show allows to test main functions (GPIOs, clock, USB, Ethernet, flash) of LPC4350-DB1 demoboard.
Configure clocks
1 SystemInit();
2
3 // External flash note:
4 // This demo can be larger than 16k (bootloader initializes only A[13..0])
5 // So initialize memory before clock setup
6 MemoryPinInit();
7 EMCFlashInit();
8
9 CGU_Init();
10
11 CGU_SetPLL0();
12 CGU_EnableEntity(CGU_CLKSRC_PLL0, ENABLE);
13 CGU_EntityConnect(CGU_CLKSRC_PLL0, CGU_BASE_USB0);
14
15 CGU_EnableEntity(CGU_CLKSRC_ENET_RX_CLK, ENABLE);
16 CGU_EnableEntity(CGU_CLKSRC_ENET_TX_CLK, ENABLE);
17 CGU_EntityConnect(CGU_CLKSRC_ENET_TX_CLK, CGU_BASE_PHY_TX);
18 CGU_EntityConnect(CGU_CLKSRC_ENET_RX_CLK, CGU_BASE_PHY_RX);
Configure buttons
1 scu_pinmux(S1_SCU_PORT, S1_SCU_PIN, MD_BUK | MD_EZI, FUNC4);
2 scu_pinmux(S2_SCU_PORT, S2_SCU_PIN, MD_BUK | MD_EZI, FUNC4);
3 scu_pinmux(S3_SCU_PORT, S3_SCU_PIN, MD_BUK | MD_EZI, FUNC4);
4 scu_pinmux(S4_SCU_PORT, S4_SCU_PIN, MD_BUK | MD_EZI, FUNC4);
5 GPIO_SetDir(S1_GPIO_PORT, S1_GPIO_MASK, 0);
6 GPIO_SetDir(S2_GPIO_PORT, S2_GPIO_MASK, 0);
7 GPIO_SetDir(S3_GPIO_PORT, S3_GPIO_MASK, 0);
8 GPIO_SetDir(S4_GPIO_PORT, S4_GPIO_MASK, 0);
Configure LEDs
1 scu_pinmux(D2_SCU_PORT, D2_SCU_PIN, MD_BUK, FUNC0);
2 scu_pinmux(D3_SCU_PORT, D3_SCU_PIN, MD_BUK, FUNC4);
3 scu_pinmux(D4_SCU_PORT, D4_SCU_PIN, MD_BUK, FUNC4);
4 scu_pinmux(D5_SCU_PORT, D5_SCU_PIN, MD_BUK, FUNC4);
5 scu_pinmux(D6_SCU_PORT, D6_SCU_PIN, MD_BUK, FUNC4);
6 GPIO_SetDir(D2_GPIO_PORT, D2_GPIO_MASK, 1);
7 GPIO_SetDir(D3_GPIO_PORT, D3_GPIO_MASK, 1);
8 GPIO_SetDir(D4_GPIO_PORT, D4_GPIO_MASK, 1);
9 GPIO_SetDir(D5_GPIO_PORT, D5_GPIO_MASK, 1);
10 GPIO_SetDir(D6_GPIO_PORT, D6_GPIO_MASK, 1);
11 GPIO_ClearValue(D2_GPIO_PORT, D2_GPIO_MASK);
12 GPIO_ClearValue(D3_GPIO_PORT, D3_GPIO_MASK);
13 GPIO_ClearValue(D4_GPIO_PORT, D4_GPIO_MASK);
14 GPIO_ClearValue(D5_GPIO_PORT, D5_GPIO_MASK);
15 GPIO_ClearValue(D6_GPIO_PORT, D6_GPIO_MASK);
Initialize callback structures
1 memset((void*)&usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
2
3 usb_param.usb_reg_base = LPC_USB0_BASE;
4 usb_param.max_num_ep = 6;
5
6 usb_param.mem_base = 0x20004000;
7 usb_param.mem_size = 0x2000;
8 usb_param.USB_Configure_Event = USB_Configure_Event;
For eagle/raptor the local SRAM is not accesable to USB so copy the descriptors to USB accessable memory
1 copy_descriptors(&desc, usb_param.mem_base + usb_param.mem_size);
Turn on the phy
1 LPC_CREG->CREG0 &= ~(1<<5);
Initialize USB
1 ret = USBD_API->hw->Init(&hUsb, &desc, &usb_param);
2 if (ret == LPC_OK)
3 {
4 pIntfDesc = (USB_INTERFACE_DESCRIPTOR*)((uint32_t)desc.high_speed_desc + USB_CONFIGUARTION_DESC_SIZE);
5 ret = usb_hid_init(hUsb, pIntfDesc, &usb_param.mem_base, &usb_param.mem_size);
6 if (ret == LPC_OK)
7 {
8 NVIC_EnableIRQ(USB0_IRQn); // enable interrupt
9 USBD_API->hw->Connect(hUsb, 1); // connect
10 }
11 else
12 {
13 GPIO_SetValue(D4_GPIO_PORT, D4_GPIO_MASK); // for testing
14 while (1); // catch error
15 }
16 }
17 else
18 {
19 GPIO_SetValue(D3_GPIO_PORT, D3_GPIO_MASK); // for testing
20 while (1); // catch error
21 }
Generate interrupt every 10 ms
1 SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / 100);
Configure Ethernet
1 GPIO_SetValue(D6_GPIO_PORT, D6_GPIO_MASK); // for testing
2 TCPLowLevelInit();
3 // clear HTTP-server's flag register
4 HTTPStatus = 0;
5 // set port we want to listen to
6 TCPLocalPort = TCP_PORT_HTTP;
Testing
1 GPIO_ClearValue(D6_GPIO_PORT, D6_GPIO_MASK);
2 blinkOn = 1;
3
4 while (1)
5 {
6 uint8_t b = 0, x = 0, y = 0;
7
8 if ((GPIO_ReadValue(S1_GPIO_PORT) & S1_GPIO_MASK) == 0) x = 1;
9 if ((GPIO_ReadValue(S2_GPIO_PORT) & S2_GPIO_MASK) == 0) x = (uint8_t)-1;
10 if ((GPIO_ReadValue(S3_GPIO_PORT) & S3_GPIO_MASK) == 0) y = 1;
11 if ((GPIO_ReadValue(S4_GPIO_PORT) & S4_GPIO_MASK) == 0) y = (uint8_t)-1;
12
13 HID_MouseReport[0] = b; // buttons
14 HID_MouseReport[1] = x; // x
15 HID_MouseReport[2] = y; // y
16
17 // listen for incoming TCP-connection
18 if (!(SocketStatus & SOCK_ACTIVE)) TCPPassiveOpen();
19 // handle network and easyWEB-stack
20 DoNetworkStuff();
21 // events
22 HTTPServer();
23 }