|
在網(wǎng)上爬行了很久才找到一個(gè)介紹USBMEM_BOOTLOADER的且有源代碼的論壇,用KEIL 編譯后結(jié)果不能運(yùn)行,后來才找到問題的根源:
//usbhw.c
void USB_Init (void) {
PINSEL1 &= ~0xC000C000;
//PINSEL1 |= 0x40004000; //這是原來的程序
PINSEL1 |= 0x80004000; /* Select USB Link, VBUS */
原來得改一下才能用到我的板子上面。
另外,原來的程序是在復(fù)位時(shí)檢測P0.15是否為低來判斷是進(jìn)入用戶程序,還是USB IAP程序,我針對我的板子改了一下,我用了兩個(gè)按鈕來控制它,當(dāng)按下P0.21的按鈕時(shí)運(yùn)行用戶程序,當(dāng)按下P0.22的按鈕時(shí)則運(yùn)行USB IAP程序:
首先要在sbl_config.h中做一下修改:
#define USER_START_SECTOR 2 //用戶程序起始扇區(qū)
#define MAX_USER_SECTOR 26 //最大扇區(qū) LPC2146是 14,LPC2148是26
#define ISP_ENTRY_GPIO_REG 0xE0028000 /* Port */
#define ISP_ENTRY_PIN21 21 /* User Code Pin */ //這里原來是 15
#define ISP_ENTRY_PIN22 22 /* USB IAP Pin */ //這個(gè)是增加的
然后把sbl_iap.c里面的相關(guān)內(nèi)容修改一下:
void check_isp_entry_pin(void)
{
while(1)
{
if(!( (*(volatile unsigned *)ISP_ENTRY_GPIO_REG) & (0x1<<isp_entry_pin21)) )[="" size][="" font][="" backcolor][="" color]
{
execute_user_code(); break;
}
if(!( (*(volatile unsigned *)ISP_ENTRY_GPIO_REG) & (0x1<<isp_entry_pin22)) )[="" size][="" font][="" backcolor][="" color]
{
break; // Enter ISP mode
}
}
}
現(xiàn)在就可以來實(shí)驗(yàn)一下了:
ourdev_433852.JPG (56.6 KB, 下載次數(shù): 91)
下載附件
2017-11-11 19:57 上傳
usbmem程序的設(shè)置
boot程序按照這個(gè)設(shè)置編譯程序,要輸出HEX文件,然后試用ISP工具將其下載到LPC2148中。
現(xiàn)在按一下復(fù)位按鈕,按K1(P0.21)沒有反應(yīng),因?yàn)楝F(xiàn)在還沒有用戶程序;按一下K2(P0.22),指示燈亮了,此時(shí)電腦會(huì)顯示發(fā)現(xiàn)了新硬件:
ourdev_433853.JPG (56.53 KB, 下載次數(shù): 98)
下載附件
2017-11-11 19:57 上傳
電腦中出現(xiàn)了一個(gè)可移動(dòng)磁盤
打開這個(gè)磁盤,會(huì)發(fā)現(xiàn)里面有一個(gè)文件是492K,
ourdev_433854.JPG (41.92 KB, 下載次數(shù): 91)
下載附件
2017-11-11 19:57 上傳
得把這個(gè)文件刪除掉才能拷貝入你自己的程序
然后再編譯用戶程序,要把起始位置修改為0x2000;同時(shí)要輸出BIN文件:(在user run 寫入fromelf --bin .FlashBlinky.axf -o .FlashBlinky.bin)把得到的BIN文件拷貝入空白的磁盤:
ourdev_433855.JPG (45.9 KB, 下載次數(shù): 87)
下載附件
2017-11-11 19:57 上傳
拷入用戶程序
按一下復(fù)位鍵,再按一下K1,就開始運(yùn)行流水燈程序了。
單片機(jī)源程序如下:
- /*----------------------------------------------------------------------------
- * U S B - K e r n e l
- *----------------------------------------------------------------------------
- * Name: USBUSER.C
- * Purpose: USB Custom User Module
- * Version: V1.10
- *----------------------------------------------------------------------------
- * This software is supplied "AS IS" without any warranties, express,
- * implied or statutory, including but not limited to the implied
- * warranties of fitness for purpose, satisfactory quality and
- * noninfringement. Keil extends you a royalty-free right to reproduce
- * and distribute executable files created using this software for use
- * on Philips LPC2xxx microcontroller devices only. Nothing else gives
- * you the right to use this software.
- *
- * Copyright (c) 2005-2006 Keil Software.
- *---------------------------------------------------------------------------*/
- #include <LPC214X.H> /* LPC214x definitions */
- #include "type.h"
- #include "usb.h"
- #include "usbcfg.h"
- #include "usbhw.h"
- #include "usbcore.h"
- #include "usbuser.h"
- #include "mscuser.h"
- #include "memory.h"
- /*
- * USB Power Event Callback
- * Called automatically on USB Power Event
- * Parameter: power: On(TRUE)/Off(FALSE)
- */
- #if USB_POWER_EVENT
- void USB_Power_Event (BOOL power) {
- }
- #endif
- /*
- * USB Reset Event Callback
- * Called automatically on USB Reset Event
- */
- #if USB_RESET_EVENT
- void USB_Reset_Event (void) {
- USB_ResetCore();
- IOCLR1 = LED_CFG; /* Turn Off Cfg LED */
- }
- #endif
- /*
- * USB Suspend Event Callback
- * Called automatically on USB Suspend Event
- */
- #if USB_SUSPEND_EVENT
- void USB_Suspend_Event (void) {
- IOSET1 = LED_SUSP; /* Turn On Suspend LED */
- }
- #endif
- /*
- * USB Resume Event Callback
- * Called automatically on USB Resume Event
- */
- #if USB_RESUME_EVENT
- void USB_Resume_Event (void) {
- IOCLR1 = LED_SUSP; /* Turn Off Suspend LED */
- }
- #endif
- /*
- * USB Remote Wakeup Event Callback
- * Called automatically on USB Remote Wakeup Event
- */
- #if USB_WAKEUP_EVENT
- void USB_WakeUp_Event (void) {
- }
- #endif
- /*
- * USB Start of Frame Event Callback
- * Called automatically on USB Start of Frame Event
- */
- #if USB_SOF_EVENT
- void USB_SOF_Event (void) {
- }
- #endif
- /*
- * USB Error Event Callback
- * Called automatically on USB Error Event
- * Parameter: error: Error Code
- */
- #if USB_ERROR_EVENT
- void USB_Error_Event (DWORD error) {
- }
- #endif
- /*
- * USB Set Configuration Event Callback
- * Called automatically on USB Set Configuration Request
- */
- #if USB_CONFIGURE_EVENT
- void USB_Configure_Event (void) {
- if (USB_Configuration) { /* Check if USB is configured */
- IOSET1 = LED_CFG; /* Turn On Cfg LED */
- } else {
- IOCLR1 = LED_CFG; /* Turn Off Cfg LED */
- }
- }
- #endif
- /*
- * USB Set Interface Event Callback
- * Called automatically on USB Set Interface Request
- */
- #if USB_INTERFACE_EVENT
- void USB_Interface_Event (void) {
- }
- #endif
- /*
- * USB Set/Clear Feature Event Callback
- * Called automatically on USB Set/Clear Feature Request
- */
- #if USB_FEATURE_EVENT
- void USB_Feature_Event (void) {
- }
- #endif
- #define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)
- /* USB Endpoint Events Callback Pointers */
- void (* const USB_P_EP[16]) (DWORD event) = {
- P_EP(0),
- P_EP(1),
- P_EP(2),
- P_EP(3),
- P_EP(4),
- P_EP(5),
- P_EP(6),
- P_EP(7),
- P_EP(8),
- P_EP(9),
- P_EP(10),
- P_EP(11),
- P_EP(12),
- P_EP(13),
- P_EP(14),
- P_EP(15),
- };
- /*
- * USB Endpoint 1 Event Callback
- * Called automatically on USB Endpoint 1 Event
- * Parameter: event
- */
- void USB_EndPoint1 (DWORD event) {
- }
- /*
- * USB Endpoint 2 Event Callback
- * Called automatically on USB Endpoint 2 Event
- * Parameter: event
- */
- void USB_EndPoint2 (DWORD event) {
- switch (event) {
- case USB_EVT_OUT:
- MSC_BulkOut();
- break;
- case USB_EVT_IN:
- MSC_BulkIn();
- break;
- }
- }
- /*
- * USB Endpoint 3 Event Callback
- * Called automatically on USB Endpoint 3 Event
- * Parameter: event
- */
- void USB_EndPoint3 (DWORD event) {
- }
- /*
- * USB Endpoint 4 Event Callback
- * Called automatically on USB Endpoint 4 Event
- * Parameter: event
- */
- void USB_EndPoint4 (DWORD event) {
- }
- /*
- * USB Endpoint 5 Event Callback
- * Called automatically on USB Endpoint 5 Event
- * Parameter: event
- */
- void USB_EndPoint5 (DWORD event) {
- }
- /*
- * USB Endpoint 6 Event Callback
- * Called automatically on USB Endpoint 6 Event
- * Parameter: event
- */
- void USB_EndPoint6 (DWORD event) {
- }
- /*
- * USB Endpoint 7 Event Callback
- * Called automatically on USB Endpoint 7 Event
- * Parameter: event
- */
- void USB_EndPoint7 (DWORD event) {
- }
- /*
- * USB Endpoint 8 Event Callback
- * Called automatically on USB Endpoint 8 Event
- * Parameter: event
- */
- void USB_EndPoint8 (DWORD event) {
- }
- /*
- * USB Endpoint 9 Event Callback
- * Called automatically on USB Endpoint 9 Event
- * Parameter: event
- */
- void USB_EndPoint9 (DWORD event) {
- }
- /*
- * USB Endpoint 10 Event Callback
- * Called automatically on USB Endpoint 10 Event
- * Parameter: event
- */
- void USB_EndPoint10 (DWORD event) {
- }
- /*
- * USB Endpoint 11 Event Callback
- * Called automatically on USB Endpoint 11 Event
- * Parameter: event
- */
- void USB_EndPoint11 (DWORD event) {
- }
- /*
- * USB Endpoint 12 Event Callback
- * Called automatically on USB Endpoint 12 Event
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
0.png (13.7 KB, 下載次數(shù): 110)
下載附件
2017-11-11 19:59 上傳
所有資料51hei提供下載:
USB IAP 程序.rar
(427.99 KB, 下載次數(shù): 18)
2017-11-11 17:32 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|