diff --git a/Examples/MAX32690/Bluetooth/Bootloader/README.md b/Examples/MAX32690/Bluetooth/Bootloader/README.md index e988d5bf3ac..06cdf6c11e0 100644 --- a/Examples/MAX32690/Bluetooth/Bootloader/README.md +++ b/Examples/MAX32690/Bluetooth/Bootloader/README.md @@ -9,7 +9,7 @@ the main flash section is erased and replaced with the update image. If no valid is identified, the Bootloader will boot the exiting image in the main flash space. __0x10000000__: Bootloader -__0x10004000__: Main flash space +__0x10008000__: Main flash space __0x10300000__: Update flash space ## Software diff --git a/Examples/MAX32690/Bluetooth/Bootloader/boot_lower.S b/Examples/MAX32690/Bluetooth/Bootloader/boot_lower.S index 6a2646f91c4..1dff366bfd1 100644 --- a/Examples/MAX32690/Bluetooth/Bootloader/boot_lower.S +++ b/Examples/MAX32690/Bluetooth/Bootloader/boot_lower.S @@ -31,7 +31,7 @@ /* Boot from the lower flash array */ Boot_Lower: - ldr r0,=0x10004000 /* Address for main flash image */ + ldr r0,=0x10008000 /* Address for main flash image */ ldr r1,=0xE000ED08 /* Address for SCB_VTOR_REG */ /* First 32-bit word in image is initial stack pointer */ diff --git a/Examples/MAX32690/Bluetooth/Bootloader/bootloader.ld b/Examples/MAX32690/Bluetooth/Bootloader/bootloader.ld index 564c592524c..cb0fdfd4d45 100644 --- a/Examples/MAX32690/Bluetooth/Bootloader/bootloader.ld +++ b/Examples/MAX32690/Bluetooth/Bootloader/bootloader.ld @@ -18,15 +18,17 @@ * ******************************************************************************/ -BOOTLOADER_ORIGIN = 0x10000000; -BOOTLOADER_LEN = 0x4000; -FLASH_SECTION_LEN = 0x40000 - BOOTLOADER_LEN; +/* Note: Flash 0 page size is 16KB (0x4000). Flash 1 page size is 8KB (0x2000) */ +BOOTLOADER_ORIGIN = 0x10000000; /* Bootloader resides in Flash 0 */ +BOOTLOADER_LEN = 0x8000; /* 2 Flash 0 pages length (total 32KB) */ +FLASH0_SECTION_LEN = 0x300000 - BOOTLOADER_LEN; /* 3MB - 2 pages (16KB/page) */ +FLASH1_SECTION_LEN = 0x40000; /* 256KB */ FLASH0_ORIGIN = BOOTLOADER_ORIGIN + BOOTLOADER_LEN; MEMORY { FLASH (rx) : ORIGIN = BOOTLOADER_ORIGIN, LENGTH = BOOTLOADER_LEN - FLASH0 (rx) : ORIGIN = FLASH0_ORIGIN, LENGTH = FLASH_SECTION_LEN - FLASH1 (rx) : ORIGIN = 0x10300000, LENGTH = FLASH_SECTION_LEN + FLASH0 (rx) : ORIGIN = FLASH0_ORIGIN, LENGTH = FLASH0_SECTION_LEN + FLASH1 (rx) : ORIGIN = 0x10300000, LENGTH = FLASH1_SECTION_LEN SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x20000 } @@ -50,14 +52,14 @@ SECTIONS { .flash0 (NOLOAD) : { _flash0 = ALIGN(., 4); - . = . + FLASH_SECTION_LEN; + . = . + FLASH0_SECTION_LEN; _eflash0 = ALIGN(., 4); } > FLASH0 .flash1 (NOLOAD) : { _flash1 = ALIGN(., 4); - . = . + FLASH_SECTION_LEN; + . = . + FLASH1_SECTION_LEN; _eflash1 = ALIGN(., 4); } > FLASH1 diff --git a/Libraries/Boards/MAX32690/APARD/Source/board.c b/Libraries/Boards/MAX32690/APARD/Source/board.c index a239698e495..0889bad3443 100644 --- a/Libraries/Boards/MAX32690/APARD/Source/board.c +++ b/Libraries/Boards/MAX32690/APARD/Source/board.c @@ -146,6 +146,8 @@ int Board_Init(void) return err; } + PB_Set_Polarity(0, PB_POLARITY_HIGH); + if ((err = LED_Init()) != E_NO_ERROR) { MXC_ASSERT_FAIL(); return err; diff --git a/Libraries/MiscDrivers/PushButton/pb.c b/Libraries/MiscDrivers/PushButton/pb.c index 017614621cf..20684c201ff 100644 --- a/Libraries/MiscDrivers/PushButton/pb.c +++ b/Libraries/MiscDrivers/PushButton/pb.c @@ -19,11 +19,15 @@ ******************************************************************************/ #include +#include #include "board.h" #include "mxc_device.h" #include "mxc_assert.h" #include "pb.h" +// State array for holding PB polarity settings +static pb_polarity_t *g_pb_polarity = NULL; + /******************************************************************************/ int PB_Init(void) { @@ -37,9 +41,30 @@ int PB_Init(void) } } + if (g_pb_polarity == NULL) { + g_pb_polarity = malloc(num_pbs * sizeof(pb_polarity_t)); + // Note we have to use malloc here because we decided to make "num_pbs" a + // const variable instead of a compiler definition... + } + + for (unsigned int i = 0; i < num_pbs; i++) { + g_pb_polarity[i] = PB_POLARITY_LOW; + } + return retval; } +/******************************************************************************/ +int PB_Set_Polarity(unsigned int pb, pb_polarity_t polarity) +{ + if (pb >= num_pbs) { + return E_BAD_PARAM; + } + + g_pb_polarity[pb] = polarity; + return E_NO_ERROR; +} + /******************************************************************************/ int PB_RegisterCallback(unsigned int pb, pb_callback callback) { @@ -52,7 +77,11 @@ int PB_RegisterCallback(unsigned int pb, pb_callback callback) MXC_GPIO_RegisterCallback(&pb_pin[pb], callback, (void *)pb); // Configure and enable interrupt - MXC_GPIO_IntConfig(&pb_pin[pb], MXC_GPIO_INT_FALLING); + mxc_gpio_int_pol_t interrupt_polarity = MXC_GPIO_INT_FALLING; + if (g_pb_polarity[pb] == PB_POLARITY_HIGH) { + interrupt_polarity = MXC_GPIO_INT_RISING; + } + MXC_GPIO_IntConfig(&pb_pin[pb], interrupt_polarity); MXC_GPIO_EnableInt(pb_pin[pb].port, pb_pin[pb].mask); NVIC_EnableIRQ((IRQn_Type)MXC_GPIO_GET_IRQ(MXC_GPIO_GET_IDX(pb_pin[pb].port))); } else { @@ -113,7 +142,11 @@ void PB_IntClear(unsigned int pb) int PB_Get(unsigned int pb) { MXC_ASSERT(pb < num_pbs); - return !MXC_GPIO_InGet(pb_pin[pb].port, pb_pin[pb].mask); + uint32_t state = MXC_GPIO_InGet(pb_pin[pb].port, pb_pin[pb].mask); + if (g_pb_polarity[pb] == PB_POLARITY_LOW) { + state = !state; + } + return state; } //****************************************************************************** diff --git a/Libraries/MiscDrivers/PushButton/pb.h b/Libraries/MiscDrivers/PushButton/pb.h index 2a78f41f690..3f172098242 100644 --- a/Libraries/MiscDrivers/PushButton/pb.h +++ b/Libraries/MiscDrivers/PushButton/pb.h @@ -40,6 +40,11 @@ extern "C" { extern const mxc_gpio_cfg_t pb_pin[]; extern const unsigned int num_pbs; +typedef enum pb_polarity { + PB_POLARITY_LOW, ///< Pushing the button sends the signal LOW. When the button is open, the signal is HIGH + PB_POLARITY_HIGH ///< Pushing the button sends the signal HIGH. When the button is open, the signal is LOW. +} pb_polarity_t; + /* **** Function Prototypes **** */ /** @@ -50,6 +55,13 @@ extern const unsigned int num_pbs; */ int PB_Init(void); +/** + * @brief Set the voltage polarity of the pushbutton. + * @param pb Pushbutton to configure + * @param polarity Desired polarity of the push-button (i.e. what voltage level the signal goes to when the button is pushed). + */ +int PB_Set_Polarity(unsigned int pb, pb_polarity_t polarity); + /** * Type alias @c pb_callback for the push button callback. * @details The function is of type: