diff --git a/bootloaders/zero/board_driver_i2c.c b/bootloaders/zero/board_driver_i2c.c index d9181211e4a11e301bd1119ffa4bc31f7cae255b..a83fccf03fbd59653c6e94259f84370e016a8926 100644 --- a/bootloaders/zero/board_driver_i2c.c +++ b/bootloaders/zero/board_driver_i2c.c @@ -71,12 +71,6 @@ static inline void pin_set_peripheral_function(uint32_t pinmux) //----------------------------------------------------------------------------- void i2c_init(int freq) { - int baud = ((float)F_CPU / freq - (float)F_CPU * T_RISE - 10.0) / 2.0; - - if (baud < 0) - baud = 0; - else if (baud > 255) - baud = 255; PM->APBCMASK.reg |= I2C_SERCOM_APBCMASK; @@ -89,7 +83,7 @@ void i2c_init(int freq) I2C_SERCOM->I2CM.CTRLB.reg = SERCOM_I2CM_CTRLB_SMEN; while (I2C_SERCOM->I2CM.SYNCBUSY.reg); - I2C_SERCOM->I2CM.BAUD.reg = SERCOM_I2CM_BAUD_BAUD(baud); + I2C_SERCOM->I2CM.BAUD.reg = SERCOM_I2CM_BAUD_BAUD(48); while (I2C_SERCOM->I2CM.SYNCBUSY.reg); I2C_SERCOM->I2CM.CTRLA.reg = SERCOM_I2CM_CTRLA_ENABLE | diff --git a/bootloaders/zero/board_driver_i2c.h b/bootloaders/zero/board_driver_i2c.h index 2870a814c7f63760c3cf5121f0332c6815d7e1d8..b18698cbd2028bf9b500735a3d33882277c17333 100644 --- a/bootloaders/zero/board_driver_i2c.h +++ b/bootloaders/zero/board_driver_i2c.h @@ -17,8 +17,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _BOARD_DRIVER_LED_ -#define _BOARD_DRIVER_LED_ +#ifndef _BOARD_DRIVER_I2C_ +#define _BOARD_DRIVER_I2C_ #include <sam.h> #include <stdbool.h> @@ -40,4 +40,6 @@ #define FAULT_REGISTER 0x09 #define PMIC_VERSION_REGISTER 0x0A +void configure_pmic(); + #endif // _BOARD_DRIVER_LED_ diff --git a/bootloaders/zero/main.c b/bootloaders/zero/main.c index 0974c9db0f6303c76f0ab1501546f682849adf0d..af004cc689a932502900f97d1dae74054cf5013f 100644 --- a/bootloaders/zero/main.c +++ b/bootloaders/zero/main.c @@ -23,18 +23,33 @@ #include "sam_ba_serial.h" #include "board_definitions.h" #include "board_driver_led.h" +#include "board_driver_i2c.h" #include "sam_ba_usb.h" #include "sam_ba_cdc.h" extern uint32_t __sketch_vectors_ptr; // Exported value from linker script extern void board_init(void); -#if (defined DEBUG) && (DEBUG == 1) volatile uint32_t* pulSketch_Start_Address; -#endif + +static void jump_to_application(void) { + + /* Rebase the Stack Pointer */ + __set_MSP( (uint32_t)(__sketch_vectors_ptr) ); + + /* Rebase the vector table base address */ + SCB->VTOR = ((uint32_t)(&__sketch_vectors_ptr) & SCB_VTOR_TBLOFF_Msk); + + /* Jump to application Reset Handler in the application */ + asm("bx %0"::"r"(*pulSketch_Start_Address)); +} static volatile bool main_b_cdc_enable = false; +#ifdef CONFIGURE_PMIC +static volatile bool jump_to_app = false; +#endif + /** * \brief Check the application startup condition * @@ -44,10 +59,6 @@ static void check_start_application(void) // LED_init(); // LED_off(); -#if (!defined DEBUG) || ((defined DEBUG) && (DEBUG == 0)) -uint32_t* pulSketch_Start_Address; -#endif - /* * Test sketch stack pointer @ &__sketch_vectors_ptr * Stay in SAM-BA if value @ (&__sketch_vectors_ptr) == 0xFFFFFFFF (Erased flash cell value) @@ -130,15 +141,12 @@ uint32_t* pulSketch_Start_Address; */ // LED_on(); +#ifdef CONFIGURE_PMIC + jump_to_app = true; +#else + jump_to_application(); +#endif - /* Rebase the Stack Pointer */ - __set_MSP( (uint32_t)(__sketch_vectors_ptr) ); - - /* Rebase the vector table base address */ - SCB->VTOR = ((uint32_t)(&__sketch_vectors_ptr) & SCB_VTOR_TBLOFF_Msk); - - /* Jump to application Reset Handler in the application */ - asm("bx %0"::"r"(*pulSketch_Start_Address)); } #if DEBUG_ENABLE @@ -160,10 +168,8 @@ int main(void) #endif DEBUG_PIN_HIGH; -#ifndef CONFIGURE_PMIC /* Jump in application if condition is satisfied */ check_start_application(); -#endif /* We have determined we should stay in the monitor. */ /* System initialization */ @@ -172,7 +178,9 @@ int main(void) #ifdef CONFIGURE_PMIC configure_pmic(); - check_start_application(); + if (jump_to_app == true) { + jump_to_application(); + } #endif #if SAM_BA_INTERFACE == SAM_BA_UART_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES