Skip to content
Snippets Groups Projects
Commit d36587e4 authored by Martino Facchin's avatar Martino Facchin Committed by Cristian Maglie
Browse files

Fix exploded binary size

parent 5ce5e43c
No related branches found
No related tags found
No related merge requests found
...@@ -71,12 +71,6 @@ static inline void pin_set_peripheral_function(uint32_t pinmux) ...@@ -71,12 +71,6 @@ static inline void pin_set_peripheral_function(uint32_t pinmux)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void i2c_init(int freq) 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; PM->APBCMASK.reg |= I2C_SERCOM_APBCMASK;
...@@ -89,7 +83,7 @@ void i2c_init(int freq) ...@@ -89,7 +83,7 @@ void i2c_init(int freq)
I2C_SERCOM->I2CM.CTRLB.reg = SERCOM_I2CM_CTRLB_SMEN; I2C_SERCOM->I2CM.CTRLB.reg = SERCOM_I2CM_CTRLB_SMEN;
while (I2C_SERCOM->I2CM.SYNCBUSY.reg); 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); while (I2C_SERCOM->I2CM.SYNCBUSY.reg);
I2C_SERCOM->I2CM.CTRLA.reg = SERCOM_I2CM_CTRLA_ENABLE | I2C_SERCOM->I2CM.CTRLA.reg = SERCOM_I2CM_CTRLA_ENABLE |
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef _BOARD_DRIVER_LED_ #ifndef _BOARD_DRIVER_I2C_
#define _BOARD_DRIVER_LED_ #define _BOARD_DRIVER_I2C_
#include <sam.h> #include <sam.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -40,4 +40,6 @@ ...@@ -40,4 +40,6 @@
#define FAULT_REGISTER 0x09 #define FAULT_REGISTER 0x09
#define PMIC_VERSION_REGISTER 0x0A #define PMIC_VERSION_REGISTER 0x0A
void configure_pmic();
#endif // _BOARD_DRIVER_LED_ #endif // _BOARD_DRIVER_LED_
...@@ -23,18 +23,33 @@ ...@@ -23,18 +23,33 @@
#include "sam_ba_serial.h" #include "sam_ba_serial.h"
#include "board_definitions.h" #include "board_definitions.h"
#include "board_driver_led.h" #include "board_driver_led.h"
#include "board_driver_i2c.h"
#include "sam_ba_usb.h" #include "sam_ba_usb.h"
#include "sam_ba_cdc.h" #include "sam_ba_cdc.h"
extern uint32_t __sketch_vectors_ptr; // Exported value from linker script extern uint32_t __sketch_vectors_ptr; // Exported value from linker script
extern void board_init(void); extern void board_init(void);
#if (defined DEBUG) && (DEBUG == 1)
volatile uint32_t* pulSketch_Start_Address; 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; 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 * \brief Check the application startup condition
* *
...@@ -44,10 +59,6 @@ static void check_start_application(void) ...@@ -44,10 +59,6 @@ static void check_start_application(void)
// LED_init(); // LED_init();
// LED_off(); // LED_off();
#if (!defined DEBUG) || ((defined DEBUG) && (DEBUG == 0))
uint32_t* pulSketch_Start_Address;
#endif
/* /*
* Test sketch stack pointer @ &__sketch_vectors_ptr * Test sketch stack pointer @ &__sketch_vectors_ptr
* Stay in SAM-BA if value @ (&__sketch_vectors_ptr) == 0xFFFFFFFF (Erased flash cell value) * Stay in SAM-BA if value @ (&__sketch_vectors_ptr) == 0xFFFFFFFF (Erased flash cell value)
...@@ -130,15 +141,12 @@ uint32_t* pulSketch_Start_Address; ...@@ -130,15 +141,12 @@ uint32_t* pulSketch_Start_Address;
*/ */
// LED_on(); // 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 #if DEBUG_ENABLE
...@@ -160,10 +168,8 @@ int main(void) ...@@ -160,10 +168,8 @@ int main(void)
#endif #endif
DEBUG_PIN_HIGH; DEBUG_PIN_HIGH;
#ifndef CONFIGURE_PMIC
/* Jump in application if condition is satisfied */ /* Jump in application if condition is satisfied */
check_start_application(); check_start_application();
#endif
/* We have determined we should stay in the monitor. */ /* We have determined we should stay in the monitor. */
/* System initialization */ /* System initialization */
...@@ -172,7 +178,9 @@ int main(void) ...@@ -172,7 +178,9 @@ int main(void)
#ifdef CONFIGURE_PMIC #ifdef CONFIGURE_PMIC
configure_pmic(); configure_pmic();
check_start_application(); if (jump_to_app == true) {
jump_to_application();
}
#endif #endif
#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES #if SAM_BA_INTERFACE == SAM_BA_UART_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment