From 1ced4e1b789ad783bb9bcda0d7ff5aa66153449f Mon Sep 17 00:00:00 2001 From: Boris Honman Date: Tue, 13 Aug 2019 18:18:51 -0400 Subject: [PATCH] moving between PCs - THIS IS HORRIBLY BROKEN AS OF THIS COMMIT --- .../nbproject/configurations.xml | 14 ++-- bootloader/src/VectorRemap.asm | 4 +- bootloader/src/bootloader.c | 6 +- bootloader/src/bootloader.h | 14 ++-- bootloader/src/usb_config.h | 4 +- common_src/memory.h | 2 +- common_src/system.c | 78 +++++++++++++++++++ .../nbproject/configurations.xml | 28 +++++-- firmware/src/dancepad.c | 2 +- firmware/src/main.c | 20 ++--- firmware/src/usb_config.h | 4 +- 11 files changed, 135 insertions(+), 41 deletions(-) diff --git a/bootloader/clubdance_v2_bootloader.X/nbproject/configurations.xml b/bootloader/clubdance_v2_bootloader.X/nbproject/configurations.xml index b5b21b5..c682c61 100644 --- a/bootloader/clubdance_v2_bootloader.X/nbproject/configurations.xml +++ b/bootloader/clubdance_v2_bootloader.X/nbproject/configurations.xml @@ -57,7 +57,7 @@ localhost - PIC18F2550 + PIC18F4550 PICkit3PlatformTool @@ -98,9 +98,9 @@ - + + value="..\src;..\..\common_src\framework\usb\inc;..\..\common_src"/> @@ -109,11 +109,11 @@ - + - + @@ -139,7 +139,7 @@ - + @@ -163,7 +163,7 @@ - + diff --git a/bootloader/src/VectorRemap.asm b/bootloader/src/VectorRemap.asm index ab932ba..245edbf 100644 --- a/bootloader/src/VectorRemap.asm +++ b/bootloader/src/VectorRemap.asm @@ -20,14 +20,14 @@ ;//High priority interrupt vector remapping PSECT HiVector,class=CODE,delta=1,abs org 0x08 - goto 0x1C08 ;Resides at 0x0008 (hardware high priority interrupt vector), and causes PC to jump to 0x1C08 upon a high priority interrupt event + goto 0x2088 ;Resides at 0x0008 (hardware high priority interrupt vector), and causes PC to jump to 0x2008 upon a high priority interrupt event ;//Low priority interrupt vector remapping, as well as bootloader mode absolute ;//entry point (located at 0x001C). PSECT LoVector,class=CODE,delta=1,abs org 0x18 - goto 0x1C18 ;Resides at 0x0018 (hardware low priority interrupt vector), and causes PC to jump to 0x1C18 upon a low priority interrupt event + goto 0x2098 ;Resides at 0x0018 (hardware low priority interrupt vector), and causes PC to jump to 0x2018 upon a low priority interrupt event goto 0x30 ;Resides at 0x001C //Serves as absolute entry point from application program into the bootloader mode diff --git a/bootloader/src/bootloader.c b/bootloader/src/bootloader.c index 74f2125..12fdc7d 100644 --- a/bootloader/src/bootloader.c +++ b/bootloader/src/bootloader.c @@ -3,6 +3,8 @@ #include "usb.h" #include "usb_device_hid.h" +#undef uint24_t +#define uint24_t uint32_t //The bootloader version, which the bootloader PC application can do extended query to get. //Value provided is expected to be in the format of BOOTLOADER_VERSION_MAJOR.BOOTLOADER_VERSION_MINOR @@ -143,8 +145,8 @@ typedef union }; } PacketToFromPC; -PacketToFromPC PacketFromPC __at(0x500); -PacketToFromPC PacketToPC __at(0x550); +PacketToFromPC PacketFromPC __at(0x42C); +PacketToFromPC PacketToPC __at(0x46C); unsigned char ProgrammingBuffer[ERASE_PAGE_SIZE]; unsigned char BootState; unsigned int ErasePageTracker; diff --git a/bootloader/src/bootloader.h b/bootloader/src/bootloader.h index b645b6b..265c46b 100644 --- a/bootloader/src/bootloader.h +++ b/bootloader/src/bootloader.h @@ -27,18 +27,20 @@ #ifndef BOOTLOADER_ #define BOOTLOADER_ +#include "memory.h" + void UserInit(void); void ProcessIO(void); //Vector remapping/absolute address constants -#define REMAPPED_APPLICATION_RESET_VECTOR 0x1C00 -//#define REMAPPED_APPLICATION_HIGH_ISR_VECTOR 0x1C08 //See VectorRemap.asm -//#define REMAPPED_APPLICATION_LOW_ISR_VECTOR 0x1C18 //See VectorRemap.asm -#define BOOTLOADER_ABSOLUTE_ENTRY_ADDRESS 0x001C //Execute a "goto 0x001C" inline assembly instruction, if you want to enter the bootloader mode from the application via software +#define REMAPPED_APPLICATION_RESET_VECTOR APP_FW_MEMORY_OFFSET +//#define REMAPPED_APPLICATION_HIGH_ISR_VECTOR APP_FW_MEMORY_OFFSET + 0x08 //See VectorRemap.asm +//#define REMAPPED_APPLICATION_LOW_ISR_VECTOR APP_FW_MEMORY_OFFSET + 0x18 //See VectorRemap.asm +#define BOOTLOADER_ABSOLUTE_ENTRY_ADDRESS BOOTLOADER_ENTRYPOINT //Execute a "goto 0x001C" inline assembly instruction, if you want to enter the bootloader mode from the application via software -#define APP_SIGNATURE_ADDRESS 0x1C06 //0x1C06 and 0x1C07 contains the "signature" WORD, indicating successful erase/program/verify operation +#define APP_SIGNATURE_ADDRESS APP_FW_MEMORY_OFFSET + 0x06 //0x1C06 and 0x1C07 contains the "signature" WORD, indicating successful erase/program/verify operation #define APP_SIGNATURE_VALUE 0x600D //leet "GOOD", implying that the erase/program was a success and the bootloader intentionally programmed the APP_SIGNATURE_ADDRESS with this value -#define APP_VERSION_ADDRESS 0x1C16 //0x1C16 and 0x1C17 should contain the application image firmware version number +#define APP_VERSION_ADDRESS APP_FW_MEMORY_OFFSET + 0x16 //0x1C16 and 0x1C17 should contain the application image firmware version number #endif /* BOOTLOADER_ */ diff --git a/bootloader/src/usb_config.h b/bootloader/src/usb_config.h index 67b2192..d2611f7 100644 --- a/bootloader/src/usb_config.h +++ b/bootloader/src/usb_config.h @@ -64,8 +64,8 @@ //firmware, can offer better sustained bandwidth, especially for OUT endpoints. //------------------------------------------------------ //#define USB_PING_PONG_MODE USB_PING_PONG__NO_PING_PONG //Not recommended -#define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG //A good all around setting -//#define USB_PING_PONG_MODE USB_PING_PONG__EP0_OUT_ONLY //Another good setting +//#define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG //A good all around setting +#define USB_PING_PONG_MODE USB_PING_PONG__EP0_OUT_ONLY //Another good setting //#define USB_PING_PONG_MODE USB_PING_PONG__ALL_BUT_EP0 //Not recommended //------------------------------------------------------------------------------ diff --git a/common_src/memory.h b/common_src/memory.h index 469c7c2..a1ad1dd 100644 --- a/common_src/memory.h +++ b/common_src/memory.h @@ -27,7 +27,7 @@ #ifndef MEMORY_ #define MEMORY_ -#define APP_FW_MEMORY_OFFSET 0x2000 +#define APP_FW_MEMORY_OFFSET 0x2080 #define BOOTLOADER_ENTRYPOINT 0x001C diff --git a/common_src/system.c b/common_src/system.c index 4d0d9fe..e511ace 100644 --- a/common_src/system.c +++ b/common_src/system.c @@ -24,6 +24,8 @@ */ //#include "usb.h" +#ifdef PIC18F2550 + // PIC18F2550 Configuration Bit Settings // 'C' source line config statements @@ -91,3 +93,79 @@ // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. +#else + +// PIC18F4550 Configuration Bit Settings + +// 'C' source line config statements + +// CONFIG1L +#pragma config PLLDIV = 3 // PLL Prescaler Selection bits (Divide by 3 (12 MHz oscillator input)) +#pragma config CPUDIV = OSC3_PLL4// System Clock Postscaler Selection bits ([Primary Oscillator Src: /3][96 MHz PLL Src: /4]) +#pragma config USBDIV = 2 // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes from the 96 MHz PLL divided by 2) + +// CONFIG1H +#pragma config FOSC = HSPLL_HS // Oscillator Selection bits (HS oscillator, PLL enabled (HSPLL)) +#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled) +#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled) + +// CONFIG2L +#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled) +#pragma config BOR = ON // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled)) +#pragma config BORV = 3 // Brown-out Reset Voltage bits (Minimum setting 2.05V) +#pragma config VREGEN = ON // USB Voltage Regulator Enable bit (USB voltage regulator enabled) + +// CONFIG2H +#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit)) +#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768) + +// CONFIG3H +#pragma config CCP2MX = ON // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1) +#pragma config PBADEN = ON // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset) +#pragma config LPT1OSC = OFF // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation) +#pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled) + +// CONFIG4L +#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset) +#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled) +#pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled) +#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode)) + +// CONFIG5L +#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected) +#pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected) +#pragma config CP2 = OFF // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected) +#pragma config CP3 = OFF // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected) + +// CONFIG5H +#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected) +#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM is not code-protected) + +// CONFIG6L +#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected) +#pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected) +#pragma config WRT2 = OFF // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected) +#pragma config WRT3 = OFF // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected) + +// CONFIG6H +#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected) +#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected) +#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM is not write-protected) + +// CONFIG7L +#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks) +#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks) +#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks) +#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks) + +// CONFIG7H +#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks) + +// #pragma config statements should precede project file includes. +// Use project enums instead of #define for ON and OFF. + +#include + + + +#endif \ No newline at end of file diff --git a/firmware/clubdance_v2.X/nbproject/configurations.xml b/firmware/clubdance_v2.X/nbproject/configurations.xml index 3e2dab7..fe5df09 100644 --- a/firmware/clubdance_v2.X/nbproject/configurations.xml +++ b/firmware/clubdance_v2.X/nbproject/configurations.xml @@ -59,7 +59,7 @@ localhost - PIC18F2550 + PIC18F4550 PICkit3PlatformTool @@ -94,15 +94,27 @@ false false + + + + + + + + + + - + + value="..\src;..\..\common_src\framework\usb\inc;..\..\common_src"/> @@ -115,7 +127,7 @@ - + @@ -126,11 +138,11 @@ - + - + @@ -141,7 +153,7 @@ - + @@ -158,7 +170,7 @@ - + diff --git a/firmware/src/dancepad.c b/firmware/src/dancepad.c index ed41b74..8707d8f 100644 --- a/firmware/src/dancepad.c +++ b/firmware/src/dancepad.c @@ -65,7 +65,7 @@ typedef union _INTPUT_CONTROLS_TYPEDEF } INPUT_CONTROLS; // USB data must exist within the USB RAM memory space -INPUT_CONTROLS joystick_input __at(0x500); +INPUT_CONTROLS joystick_input __at(0x600); // handle to the last data transmission - allows us to check if it completed USB_VOLATILE USB_HANDLE lastTransmission = 0; diff --git a/firmware/src/main.c b/firmware/src/main.c index f450dfa..1a526db 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -22,35 +22,35 @@ * @date 6 Aug 2019 * @brief USB interface to 6-sensor DDR pads. */ -const unsigned int VersionWord __at(0x1C16) = 0x0100; #pragma warning disable 1510 -#include "usb.h" -#include "padhal.h" -#include "dancepad.h" +//#include "usb.h" +//#include "padhal.h" +//#include "dancepad.h" +#include "memory.h" //#ifdef LINK_FOR_BOOTLOADER // only define this if building fw to be used with the bootloader - +const unsigned int VersionWord __at(APP_FW_VERSION_ADDRESS) = 0x0100; //#endif void main(void) { // initialize sensor HAL & the dancepad driver - PADHAL_Initialize(); + /*PADHAL_Initialize(); DANCEPAD_Initialize(); // initialize the USB framework USBDeviceInit(); - USBDeviceAttach(); + USBDeviceAttach();*/ while(1) { // do nothing if: not connected to USB host, or the host put us in suspend state - if((USBGetDeviceState() < CONFIGURED_STATE) | USBIsDeviceSuspended()) - continue; + //if((USBGetDeviceState() < CONFIGURED_STATE) | USBIsDeviceSuspended()) + // continue; // run application specific tasks - DANCEPAD_Tasks(); + //DANCEPAD_Tasks(); } } diff --git a/firmware/src/usb_config.h b/firmware/src/usb_config.h index 1af0ef2..4ea0fb7 100644 --- a/firmware/src/usb_config.h +++ b/firmware/src/usb_config.h @@ -80,8 +80,8 @@ //(ex: USBDeviceTasks()) must be called periodically by the application firmware //at a minimum rate as described in the inline code comments in usb_device.c. //------------------------------------------------------ -//#define USB_POLLING -#define USB_INTERRUPT +#define USB_POLLING +//#define USB_INTERRUPT //------------------------------------------------------------------------------ /* Parameter definitions are defined in usb_device.h */