Revision fc7151bb

View differences:

Target/Modules/DiWheelDrive_1-1/Boot/blt_conf.h
49 49
 * de-initialize application specific parts, for example to stop blinking an LED, etc.
50 50
 */
51 51
/** \brief Frequency of the external crystal oscillator. */
52
#define BOOT_CPU_XTAL_SPEED_KHZ         (8000)
52
#define BOOT_CPU_XTAL_SPEED_KHZ           (8000)
53 53
/** \brief Desired system speed. */
54
#define BOOT_CPU_SYSTEM_SPEED_KHZ       (72000)
54
#define BOOT_CPU_SYSTEM_SPEED_KHZ         (72000)
55 55
/** \brief Motorola or Intel style byte ordering. */
56
#define BOOT_CPU_BYTE_ORDER_MOTOROLA    (0)
56
#define BOOT_CPU_BYTE_ORDER_MOTOROLA      (0)
57 57
/** \brief Enable/disable hook function call right before user program start. */
58
#define BOOT_CPU_USER_PROGRAM_START_HOOK (1)
58
#define BOOT_CPU_USER_PROGRAM_START_HOOK  (1)
59 59

  
60 60

  
61 61
/****************************************************************************************
......
186 186
 * also be implemented in a way that disables the backdoor entry altogether.
187 187
 */
188 188
/** \brief Enable/disable the backdoor override hook functions. */
189
#define BOOT_BACKDOOR_HOOKS_ENABLE       (1)
189
#define BOOT_BACKDOOR_HOOKS_ENABLE      (1)
190 190

  
191 191

  
192 192
/****************************************************************************************
Target/Modules/DiWheelDrive_1-1/Boot/hooks.c
103 103
        boot_state = BOOT_OS_SYNC;
104 104
        return BLT_FALSE;
105 105
      }
106
      break;
106 107
    }
107 108
    default:
108 109
      return BLT_FALSE;
109 110
      break;
110 111
  }
111 112
  return BLT_FALSE;
112
} /*** end of BackDoorEntryHook ***/
113

  
113
} /*** end of BackDoorEntryCheck ***/
114 114

  
115 115
/************************************************************************************//**
116 116
** \brief     Checks if a backdoor entry is requested.
......
157 157
    case BOOT_OS_SYNC:
158 158
    {
159 159
      /* wait for the SYS_SYNC_N signal to go down */
160

  
161 160
      if (GPIO_ReadInputDataBit(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN) == Bit_RESET) {
162 161
        boot_state = BOOT_OS_START;
163 162
      }
......
176 175
      break;
177 176
  }
178 177
  return BLT_FALSE;
179

  
180 178
} /*** end of CpuUserProgramStartHook ***/
181 179
#endif /* BOOT_CPU_USER_PROGRAM_START_HOOK > 0 */
182 180

  
Target/Modules/DiWheelDrive_1-1/Boot/main.c
47 47
#define RESET_TIMEOUT_MS    100
48 48

  
49 49
/****************************************************************************************
50
* Function prototypes
50
* Function prototypes and static variables
51 51
****************************************************************************************/
52 52
static void Init(void);
53 53

  
......
78 78

  
79 79
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = {
80 80
  .magicNumber = BL_MAGIC_NUMBER,
81
  .vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 0},
81
  .vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 3},
82 82
  .vSSSP = {BL_VERSION_ID_SSSP, BL_SSSP_VERSION_MAJOR, BL_SSSP_VERSION_MINOR, 0},
83 83
  .vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__},  // currently only GCC is supported
84 84
  .cbShutdownHibernate = blCallbackShutdownHibernate,
......
306 306
  /* CNF2[1:0] = %01 and MODE2[1:0] = %00 */
307 307
  GPIOA->CRH |= (blt_int32u)((blt_int32u)0x4 << 8);
308 308
#endif
309

  
310 309
} /*** end of Init ***/
311 310

  
312 311
/*
......
458 457
  /* wait for all boards to be ready for shutdown */
459 458
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
460 459
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
461
    // this must skipped if the pullup voltage (VIO3.3) is not active
460
    // this must be skipped if the pullup voltage (VIO3.3) is not active
462 461
    setLed(BLT_TRUE);
463 462
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
464 463
    setLed(BLT_FALSE);
......
502 501
  /* wait for all boards to be ready for shutdown */
503 502
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
504 503
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
505
    // this must skipped if the pullup voltage (VIO3.3) is not active
504
    // this must be skipped if the pullup voltage (VIO3.3) is not active
506 505
    setLed(BLT_TRUE);
507 506
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
508 507
    setLed(BLT_FALSE);
......
546 545
  /* wait for all boards to be ready for shutdown */
547 546
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
548 547
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
549
    // this must skipped if the pullup voltage (VIO3.3) is not active
548
    // this must be skipped if the pullup voltage (VIO3.3) is not active
550 549
    setLed(BLT_TRUE);
551 550
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
552 551
    setLed(BLT_FALSE);
......
567 566
  PWR_EnterSTANDBYMode();
568 567

  
569 568
  return;
570
} /* end of shutdownToHibernate ***/
569
} /*** end of shutdownToHibernate ***/
571 570

  
572 571
/*
573 572
 * Final shutdown of the system and restart.
......
589 588
  /* wait for all boards to be ready for shutdown */
590 589
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
591 590
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
592
    // this must skipped if the pullup voltage (VIO3.3) is not active
591
    // this must be skipped if the pullup voltage (VIO3.3) is not active
593 592
    setLed(BLT_TRUE);
594 593
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
595 594
    setLed(BLT_FALSE);
......
614 613
   */
615 614

  
616 615
  return;
617
} /*** end of shutdownAndRestart***/
616
} /*** end of shutdownAndRestart ***/
618 617

  
619 618
/*
620 619
 * Configures some GPIO pins as inputs for safety reasons.
......
824 823
 * In transportation low-power mode the system can only be woken up by pulling down the NRST signal.
825 824
 * Furthermore, the system can not be charged when in transportation mode.
826 825
 */
827
void blCallbackShutdownTransportation(void) {
826
void blCallbackShutdownTransportation() {
828 827
  /* make sure that the required clocks are activated */
829 828
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
830 829
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
......
833 832
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
834 833
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
835 834

  
836
  setLed(BLT_TRUE);
835
  /* initialized the standalone timer */
837 836
  saTimerInit();
838 837

  
838
  setLed(BLT_TRUE);
839

  
839 840
  shutdownToTransportation(BLT_TRUE);
840 841

  
841 842
  return;
......
855 856
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
856 857
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
857 858

  
859
  /* initialized the standalone timer */
858 860
  saTimerInit();
859 861

  
862
  setLed(BLT_TRUE);
863

  
860 864
  shutdownToDeepsleep(BLT_TRUE);
861 865

  
862 866
  return;
......
875 879
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
876 880
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
877 881

  
882
  /* initialized the standalone timer */
878 883
  saTimerInit();
879 884

  
885
  setLed(BLT_TRUE);
886

  
880 887
  shutdownToHibernate(BLT_TRUE);
881 888

  
882 889
  return;
......
891 898
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
892 899
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
893 900

  
894
  /* set/keep the SYS_SYNC and SYS_PD signal active */
901
  /* set/keep the SYS_SYNC and SYS_PD signals active */
895 902
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
896 903
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
897 904

  
898
  /* ensure that all modules had a chance to detect the pulse on SYS_PD_N */
905
  /* initialized the standalone timer */
899 906
  saTimerInit();
907

  
908
  setLed(BLT_TRUE);
909

  
910
  /* deactivate SYS_PD_N and ensure that all modules had a chance to detect the falling edge */
900 911
  msleep(1);
901 912
  GPIO_SetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
902 913
  msleep(1);
......
916 927
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
917 928
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
918 929

  
919
  /* set/keep the SYS_SYNC and SYS_PD signal active */
930
  /* set/keep the SYS_SYNC and SYS_PD signals active */
920 931
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
921 932
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
922 933

  
......
933 944
  /* wait for all boards to be ready for shutdown */
934 945
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
935 946
  if (GPIO_ReadOutputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
936
    // this must skipped if the pullup voltage (VIO3.3) is not active
947
    // this must be skipped if the pullup voltage (VIO3.3) is not active
937 948
    setLed(BLT_TRUE);
938 949
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
939 950
    setLed(BLT_FALSE);
Target/Modules/DiWheelDrive_1-2/Boot/blt_conf.h
49 49
 * de-initialize application specific parts, for example to stop blinking an LED, etc.
50 50
 */
51 51
/** \brief Frequency of the external crystal oscillator. */
52
#define BOOT_CPU_XTAL_SPEED_KHZ         (8000)
52
#define BOOT_CPU_XTAL_SPEED_KHZ           (8000)
53 53
/** \brief Desired system speed. */
54
#define BOOT_CPU_SYSTEM_SPEED_KHZ       (72000)
54
#define BOOT_CPU_SYSTEM_SPEED_KHZ         (72000)
55 55
/** \brief Motorola or Intel style byte ordering. */
56
#define BOOT_CPU_BYTE_ORDER_MOTOROLA    (0)
56
#define BOOT_CPU_BYTE_ORDER_MOTOROLA      (0)
57 57
/** \brief Enable/disable hook function call right before user program start. */
58
#define BOOT_CPU_USER_PROGRAM_START_HOOK (1)
58
#define BOOT_CPU_USER_PROGRAM_START_HOOK  (1)
59 59

  
60 60

  
61 61
/****************************************************************************************
......
184 184
 * also be implemented in a way that disables the backdoor entry altogether.
185 185
 */
186 186
/** \brief Enable/disable the backdoor override hook functions. */
187
#define BOOT_BACKDOOR_HOOKS_ENABLE       (1)
187
#define BOOT_BACKDOOR_HOOKS_ENABLE      (1)
188 188

  
189 189

  
190 190
/****************************************************************************************
Target/Modules/DiWheelDrive_1-2/Boot/hooks.c
103 103
        boot_state = BOOT_OS_SYNC;
104 104
        return BLT_FALSE;
105 105
      }
106
      break;
106 107
    }
107 108
    default:
108 109
      return BLT_FALSE;
109 110
      break;
110 111
  }
111 112
  return BLT_FALSE;
112
} /*** end of BackDoorEntryHook ***/
113

  
113
} /*** end of BackDoorEntryCheck ***/
114 114

  
115 115
/************************************************************************************//**
116 116
** \brief     Checks if a backdoor entry is requested.
......
157 157
    case BOOT_OS_SYNC:
158 158
    {
159 159
      /* wait for the SYS_SYNC_N signal to go down */
160

  
161 160
      if (GPIO_ReadInputDataBit(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN) == Bit_RESET) {
162 161
        boot_state = BOOT_OS_START;
163 162
      }
......
176 175
      break;
177 176
  }
178 177
  return BLT_FALSE;
179

  
180 178
} /*** end of CpuUserProgramStartHook ***/
181 179
#endif /* BOOT_CPU_USER_PROGRAM_START_HOOK > 0 */
182 180

  
Target/Modules/DiWheelDrive_1-2/Boot/main.c
47 47
#define RESET_TIMEOUT_MS    100
48 48

  
49 49
/****************************************************************************************
50
* Function prototypes
50
* Function prototypes and static variables
51 51
****************************************************************************************/
52 52
static void Init(void);
53 53

  
......
78 78

  
79 79
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = {
80 80
  .magicNumber = BL_MAGIC_NUMBER,
81
  .vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 0},
81
  .vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 3},
82 82
  .vSSSP = {BL_VERSION_ID_SSSP, BL_SSSP_VERSION_MAJOR, BL_SSSP_VERSION_MINOR, 0},
83 83
  .vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__},  // currently only GCC is supported
84 84
  .cbShutdownHibernate = blCallbackShutdownHibernate,
......
306 306
  /* CNF2[1:0] = %01 and MODE2[1:0] = %00 */
307 307
  GPIOA->CRH |= (blt_int32u)((blt_int32u)0x4 << 8);
308 308
#endif
309

  
310 309
} /*** end of Init ***/
311 310

  
312 311
/*
......
456 455
  /* wait for all boards to be ready for shutdown */
457 456
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
458 457
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
459
    // this must skipped if the pullup voltage (VIO3.3) is not active
458
    // this must be skipped if the pullup voltage (VIO3.3) is not active
460 459
    setLed(BLT_TRUE);
461 460
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
462 461
    setLed(BLT_FALSE);
......
500 499
  /* wait for all boards to be ready for shutdown */
501 500
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
502 501
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
503
    // this must skipped if the pullup voltage (VIO3.3) is not active
502
    // this must be skipped if the pullup voltage (VIO3.3) is not active
504 503
    setLed(BLT_TRUE);
505 504
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
506 505
    setLed(BLT_FALSE);
......
544 543
  /* wait for all boards to be ready for shutdown */
545 544
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
546 545
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
547
    // this must skipped if the pullup voltage (VIO3.3) is not active
546
    // this must be skipped if the pullup voltage (VIO3.3) is not active
548 547
    setLed(BLT_TRUE);
549 548
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
550 549
    setLed(BLT_FALSE);
......
565 564
  PWR_EnterSTANDBYMode();
566 565

  
567 566
  return;
568
} /* end of shutdownToHibernate ***/
567
} /*** end of shutdownToHibernate ***/
569 568

  
570 569
/*
571 570
 * Final shutdown of the system and restart.
......
587 586
  /* wait for all boards to be ready for shutdown */
588 587
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
589 588
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
590
    // this must skipped if the pullup voltage (VIO3.3) is not active
589
    // this must be skipped if the pullup voltage (VIO3.3) is not active
591 590
    setLed(BLT_TRUE);
592 591
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
593 592
    setLed(BLT_FALSE);
......
612 611
   */
613 612

  
614 613
  return;
615
} /*** end of shutdownAndRestart***/
614
} /*** end of shutdownAndRestart ***/
616 615

  
617 616
/*
618 617
 * Configures some GPIO pins as inputs for safety reasons.
......
802 801
  GPIO_SetBits(SYS_UART_UP_GPIO, SYS_UART_UP_PIN);
803 802

  
804 803
  return handleColdReset();
805
} /*** end of handleImuWakeu ***/
804
} /*** end of handleImuWakeup ***/
806 805

  
807 806
/*
808 807
 * Callback function that handles the system shutdown and enters transportation mode.
......
810 809
 * In transportation low-power mode the system can only be woken up by pulling down the NRST signal.
811 810
 * Furthermore, the system can not be charged when in transportation mode.
812 811
 */
813
void blCallbackShutdownTransportation(void) {
812
void blCallbackShutdownTransportation() {
814 813
  /* make sure that the required clocks are activated */
815 814
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
816 815
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
......
819 818
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
820 819
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
821 820

  
822
  setLed(BLT_TRUE);
821
  /* initialized the standalone timer */
823 822
  saTimerInit();
824 823

  
824
  setLed(BLT_TRUE);
825

  
825 826
  shutdownToTransportation(BLT_TRUE);
826 827

  
827 828
  return;
......
841 842
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
842 843
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
843 844

  
845
  /* initialized the standalone timer */
844 846
  saTimerInit();
845 847

  
848
  setLed(BLT_TRUE);
849

  
846 850
  shutdownToDeepsleep(BLT_TRUE);
847 851

  
848 852
  return;
......
861 865
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
862 866
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
863 867

  
868
  /* initialized the standalone timer */
864 869
  saTimerInit();
865 870

  
871
  setLed(BLT_TRUE);
872

  
866 873
  shutdownToHibernate(BLT_TRUE);
867 874

  
868 875
  return;
......
877 884
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
878 885
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
879 886

  
880
  /* set/keep the SYS_SYNC and SYS_PD signal active */
887
  /* set/keep the SYS_SYNC and SYS_PD signals active */
881 888
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
882 889
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
883 890

  
884
  /* ensure that all modules had a chance to detect the pulse on SYS_PD_N */
891
  /* initialized the standalone timer */
885 892
  saTimerInit();
893

  
894
  setLed(BLT_TRUE);
895

  
896
  /* deactivate SYS_PD_N and ensure that all modules had a chance to detect the falling edge */
886 897
  msleep(1);
887 898
  GPIO_SetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
888 899
  msleep(1);
......
902 913
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
903 914
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
904 915

  
905
  /* set/keep the SYS_SYNC and SYS_PD signal active */
916
  /* set/keep the SYS_SYNC and SYS_PD signals active */
906 917
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
907 918
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
908 919

  
......
919 930
  /* wait for all boards to be ready for shutdown */
920 931
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
921 932
  if (GPIO_ReadOutputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
922
    // this must skipped if the pullup voltage (VIO3.3) is not active
933
    // this must be skipped if the pullup voltage (VIO3.3) is not active
923 934
    setLed(BLT_TRUE);
924 935
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
925 936
    setLed(BLT_FALSE);
Target/Modules/LightRing_1-0/Boot/blt_conf.h
49 49
 * de-initialize application specific parts, for example to stop blinking an LED, etc.
50 50
 */
51 51
/** \brief Frequency of the external crystal oscillator. */
52
#define BOOT_CPU_XTAL_SPEED_KHZ         (8000)
52
#define BOOT_CPU_XTAL_SPEED_KHZ           (8000)
53 53
/** \brief Desired system speed. */
54
#define BOOT_CPU_SYSTEM_SPEED_KHZ       (72000)
54
#define BOOT_CPU_SYSTEM_SPEED_KHZ         (72000)
55 55
/** \brief Motorola or Intel style byte ordering. */
56
#define BOOT_CPU_BYTE_ORDER_MOTOROLA    (0)
56
#define BOOT_CPU_BYTE_ORDER_MOTOROLA      (0)
57 57
/** \brief Enable/disable hook function call right before user program start. */
58
#define BOOT_CPU_USER_PROGRAM_START_HOOK (1)
58
#define BOOT_CPU_USER_PROGRAM_START_HOOK  (1)
59 59

  
60 60

  
61 61
/****************************************************************************************
Target/Modules/LightRing_1-0/Boot/hooks.c
40 40
#include "stm32f10x_conf.h"                      /* STM32 peripheral drivers           */
41 41
#endif
42 42

  
43
/****************************************************************************************
44
*   B A C K D O O R   E N T R Y   H O O K   F U N C T I O N S
45
****************************************************************************************/
46

  
47
#if (BOOT_BACKDOOR_HOOKS_ENABLE > 0)
48

  
43 49
enum BOOT_STATE {BOOT_FLASH_WAIT,
44 50
                 BOOT_OS_SYNC,
45 51
                 BOOT_OS_START
......
50 56
#define SYS_SYNC_N_PIN    GPIO_Pin_2
51 57
#define SYS_SYNC_N_GPIO   GPIOD
52 58

  
53
/****************************************************************************************
54
*   B A C K D O O R   E N T R Y   H O O K   F U N C T I O N S
55
****************************************************************************************/
56

  
57
#if (BOOT_BACKDOOR_HOOKS_ENABLE > 0)
58

  
59 59
/************************************************************************************//**
60 60
** \brief     Initializes the backdoor entry option.
61 61
** \return    none.
......
72 72
** \return    BLT_TRUE if the backdoor entry is requested, BLT_FALSE otherwise.
73 73
**
74 74
****************************************************************************************/
75
blt_bool BackDoorEntryCheck(void) {
75
blt_bool BackDoorEntryCheck(void)
76
{
76 77
  /* evaluate the fsm state */
77 78
  switch (boot_state) {
78 79
    case BOOT_FLASH_WAIT:
......
88 89
      break;
89 90
    }
90 91
    default:
91
      BLT_FALSE;
92
      return BLT_FALSE;
92 93
      break;
93 94
  }
94 95
  return BLT_FALSE;
95
}
96
} /*** end of BackDoorEntryCheck ***/
96 97

  
97 98
/************************************************************************************//**
98 99
** \brief     Checks if a backdoor entry is requested.
Target/Modules/LightRing_1-0/Boot/iodef.h
69 69
#define SYS_SYNC_N_PIN      GPIO_Pin_2
70 70

  
71 71
#endif /* IODEF_H */
72

  
73

  
74

  
Target/Modules/LightRing_1-0/Boot/main.c
46 46
****************************************************************************************/
47 47

  
48 48
/****************************************************************************************
49
* Function prototypes
49
* Function prototypes and static variables
50 50
****************************************************************************************/
51 51
static void Init(void);
52 52

  
......
75 75

  
76 76
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = {
77 77
  .magicNumber = BL_MAGIC_NUMBER,
78
  .vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 0},
78
  .vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 3},
79 79
  .vSSSP = {BL_VERSION_ID_SSSP, BL_SSSP_VERSION_MAJOR, BL_SSSP_VERSION_MINOR, 0},
80 80
  .vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__},  // currently only GCC is supported
81 81
  .cbShutdownHibernate = blCallbackShutdownHibernate,
......
257 257
  /* enable clocks for CAN controller peripheral */
258 258
  RCC->APB1ENR |= (blt_int32u)0x02000000;
259 259
#endif
260

  
260 261
#if (BOOT_COM_UART_ENABLE > 0 || BOOT_GATE_UART_ENABLE > 0)
261 262
  /* enable clocks for USART1 peripheral, transmitter and receiver pins (GPIOA and AFIO) */
262 263
  RCC->APB2ENR |= (blt_int32u)(0x00004000 | 0x00000004 | 0x00000001);
......
344 345
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
345 346
  GPIO_Init(SYS_SYNC_N_GPIO, &gpio_init);
346 347

  
348
  /* initialize SYS_UART_DN and let it go (inactive) */
349
  GPIO_SetBits(SYS_UART_DN_GPIO, SYS_UART_DN_PIN);
350
  gpio_init.GPIO_Pin    = SYS_UART_DN_PIN;
351
  gpio_init.GPIO_Mode   = GPIO_Mode_Out_OD;
352
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
353
  GPIO_Init(SYS_UART_DN_GPIO, &gpio_init);
354

  
347 355
  /*
348 356
   * INPUTS
349 357
   */
......
416 424

  
417 425
  /* wait for all boards to be ready for shutdown */
418 426
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
419
  // this must no be skipped, since the pull-up voltage for SYS_SYNC_N (VIO3.3) must be configured at this point by definition.
427
  // this must not be skipped, since the pull-up voltage for SYS_SYNC_N (VIO3.3) must be configured at this point by definition.
420 428
  setLed(BLT_TRUE);
421 429
  waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
422 430
  setLed(BLT_FALSE);
......
448 456

  
449 457
  /* wait for all boards to be ready for shutdown */
450 458
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
451
  // this must no be skipped, since the pull-up voltage for SYS_SYNC_N (VIO3.3) must be configured at this point by definition.
459
  // this must not be skipped, since the pull-up voltage for SYS_SYNC_N (VIO3.3) must be configured at this point by definition.
452 460
  setLed(BLT_TRUE);
453 461
  waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
454 462
  setLed(BLT_FALSE);
......
480 488

  
481 489
  /* wait for all boards to be ready for shutdown */
482 490
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
483
  // this must no be skipped, since the pull-up voltage for SYS_SYNC_N (VIO3.3) must be configured at this point by definition.
491
  // this must not be skipped, since the pull-up voltage for SYS_SYNC_N (VIO3.3) must be configured at this point by definition.
484 492
  setLed(BLT_TRUE);
485 493
  waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
486 494
  setLed(BLT_FALSE);
......
502 510
  return;
503 511
} /*** end of shutdownToHibernate ***/
504 512

  
513
/*
514
 * Final shutdown of the system and restart.
515
 */
505 516
void shutdownAndRestart(const blt_bool exec_disambiguation) {
506 517
  /* configure some criticpal GPIOs as input
507 518
   * This is required, because otherwise some hardware might be powered through these signals */
......
509 520

  
510 521
  /* wait for all boards to be ready for shutdown */
511 522
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
512
  // this must no be skipped, since the pull-up voltage for SYS_SYNC_N (VIO3.3) must be configured at this point by definition.
523
  // this must not be skipped, since the pull-up voltage for SYS_SYNC_N (VIO3.3) must be configured at this point by definition.
513 524
  setLed(BLT_TRUE);
514 525
  waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
515 526
  setLed(BLT_FALSE);
......
533 544
   */
534 545

  
535 546
  return;
536
} /*** end of shutdownAndRestart***/
547
} /*** end of shutdownAndRestart ***/
537 548

  
538 549
/*
539 550
 * Configures some GPIO pins as inputs for safety reasons.
......
602 613
//      setLed(BLT_FALSE);
603 614
//    } else if (currentTime < loopStartTime + 50+100+50) {
604 615
//      setLed(BLT_TRUE);
605
//    } else if ( currentTime < loopStartTime + 50+100+50+300) {
616
//    } else if (currentTime < loopStartTime + 50+100+50+300) {
606 617
//      setLed(BLT_FALSE);
607 618
//    } else {
608 619
//      loopStartTime = currentTime;
......
636 647
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
637 648
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
638 649

  
650
  /* initialized the standalone timer */
639 651
  saTimerInit();
640 652

  
641 653
  setLed(BLT_TRUE);
......
659 671
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
660 672
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
661 673

  
674
  /* initialized the standalone timer */
662 675
  saTimerInit();
663 676

  
664 677
  setLed(BLT_TRUE);
......
681 694
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
682 695
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
683 696

  
697
  /* initialized the standalone timer */
684 698
  saTimerInit();
685 699

  
686 700
  setLed(BLT_TRUE);
......
703 717
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
704 718
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
705 719

  
706
  /* ensure that all modules had a chance to detect the pulse on SYS_PD_N */
720
  /* initialized the standalone timer */
707 721
  saTimerInit();
722

  
723
  setLed(BLT_TRUE);
724

  
725
  /* deactivate SYS_PD_N and ensure that all modules had a chance to detect the falling edge */
708 726
  msleep(1);
709 727
  GPIO_SetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
710 728
  msleep(1);
......
712 730
  shutdownAndRestart(BLT_TRUE);
713 731

  
714 732
  return;
715
} /** end of blCallbackShutdownRestart ***/
733
} /*** end of blCallbackShutdownRestart ***/
716 734

  
717 735
/*
718 736
 * Callback function that handles a system shutdown/restart request from another module.
......
728 746
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
729 747
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
730 748

  
731
  /* ensure that all modules had a chance to detect the pulse on SYS_PD_N */
749
  /* initialized the standalone timer */
732 750
  saTimerInit();
751

  
752
  setLed(BLT_TRUE);
753

  
754
  /* deactivate SYS_PD_N and ensure that all modules had a chance to detect the falling edge */
733 755
  msleep(1);
734 756
  GPIO_SetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
735 757
  msleep(1);
Target/Modules/LightRing_1-0/Boot/makefile
104 104
../../../Source/file.h \
105 105
../../../Source/assert.c \
106 106
../../../Source/assert.h \
107
../../../Source/helper.h \
108 107
../../../Source/plausibility.h \
109 108
../../../Source/ARMCM3_STM32/types.h \
110 109
../../../Source/ARMCM3_STM32/cpu.c \
Target/Modules/LightRing_1-2/Boot/blt_conf.h
1
/************************************************************************************//**
2
* \file         Demo\ARMCM3_STM32_Olimex_STM32P103_GCC\Boot\blt_conf.h
3
* \brief        Bootloader configuration header file.
4
* \ingroup      Boot_ARMCM3_STM32_Olimex_STM32P103_GCC
5
* \internal
6
*----------------------------------------------------------------------------------------
7
*                          C O P Y R I G H T
8
*----------------------------------------------------------------------------------------
9
*   Copyright (c) 2012  by Feaser    http://www.feaser.com    All rights reserved
10
*
11
*----------------------------------------------------------------------------------------
12
*                            L I C E N S E
13
*----------------------------------------------------------------------------------------
14
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
15
* modify it under the terms of the GNU General Public License as published by the Free
16
* Software Foundation, either version 3 of the License, or (at your option) any later
17
* version.
18
*
19
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
20
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21
* PURPOSE. See the GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License along with OpenBLT.
24
* If not, see <http://www.gnu.org/licenses/>.
25
*
26
* A special exception to the GPL is included to allow you to distribute a combined work
27
* that includes OpenBLT without being obliged to provide the source code for any
28
* proprietary components. The exception text is included at the bottom of the license
29
* file <license.html>.
30
*
31
* \endinternal
32
****************************************************************************************/
33
#ifndef BLT_CONF_H
34
#define BLT_CONF_H
35

  
36
/****************************************************************************************
37
*   C P U   D R I V E R   C O N F I G U R A T I O N
38
****************************************************************************************/
39
/* To properly initialize the baudrate clocks of the communication interface, typically
40
 * the speed of the crystal oscillator and/or the speed at which the system runs is
41
 * needed. Set these through configurables BOOT_CPU_XTAL_SPEED_KHZ and
42
 * BOOT_CPU_SYSTEM_SPEED_KHZ, respectively. To enable data exchange with the host that is
43
 * not dependent on the targets architecture, the byte ordering needs to be known.
44
 * Setting BOOT_CPU_BYTE_ORDER_MOTOROLA to 1 selects little endian mode and 0 selects
45
 * big endian mode.
46
 *
47
 * Set BOOT_CPU_USER_PROGRAM_START_HOOK to 1 if you would like a hook function to be
48
 * called the moment the user program is about to be started. This could be used to
49
 * de-initialize application specific parts, for example to stop blinking an LED, etc.
50
 */
51
/** \brief Frequency of the external crystal oscillator. */
52
#define BOOT_CPU_XTAL_SPEED_KHZ           (8000)
53
/** \brief Desired system speed. */
54
#define BOOT_CPU_SYSTEM_SPEED_KHZ         (72000)
55
/** \brief Motorola or Intel style byte ordering. */
56
#define BOOT_CPU_BYTE_ORDER_MOTOROLA      (0)
57
/** \brief Enable/disable hook function call right before user program start. */
58
#define BOOT_CPU_USER_PROGRAM_START_HOOK  (1)
59

  
60

  
61
/****************************************************************************************
62
*   B O O T L O A D E R   O F   M A I N   D E V I C E
63
****************************************************************************************/
64
/* It is important to initialize if the bootloader is part of the main device. In this
65
 * case some backdoor loops have to stay opened and backdoor loops of other bootloaders
66
 * have to be controlled by this bootloader. Additionally the bootloader should be able
67
 * to send program code of user programs for other devices.
68
 * Make sure that one of the communication interfaces is the gateway!
69
 */
70
/** \brief Bootloader of main device. */
71
#define BOOTLOADER_OF_MAIN_DEVICE       (0)
72

  
73

  
74
/****************************************************************************************
75
*   C O M M U N I C A T I O N   I N T E R F A C E   C O N F I G U R A T I O N
76
****************************************************************************************/
77
/* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE
78
 * configurable to 1. Configurable BOOT_COM_CAN_BAUDRATE selects the communication speed
79
 * in bits/second. Two CAN messages are reserved for communication with the host. The
80
 * message identifier for sending data from the target to the host is configured with
81
 * BOOT_COM_CAN_TXMSG_ID. The one for receiving data from the host is configured with
82
 * BOOT_COM_CAN_RXMSG_ID. The maximum amount of data bytes in a message for data
83
 * transmission and reception is set through BOOT_COM_CAN_TX_MAX_DATA and
84
 * BOOT_COM_CAN_RX_MAX_DATA, respectively. It is common for a microcontroller to have more
85
 * than 1 CAN controller on board. The zero-based BOOT_COM_CAN_CHANNEL_INDEX selects the
86
 * CAN controller channel.
87
 *
88
 */
89
/** \brief Enable/disable CAN transport layer. */
90
#define BOOT_COM_CAN_ENABLE             (1)
91
/** \brief Configure the desired CAN baudrate. */
92
#define BOOT_COM_CAN_BAUDRATE           (1000000)
93
/** \brief Configure CAN message ID target->host. */
94
#define BOOT_COM_CAN_TX_MSG_ID          (0x700)
95
/** \brief Configure number of bytes in the target->host CAN message. */
96
#define BOOT_COM_CAN_TX_MAX_DATA        (255)
97
/** \brief Configure CAN message ID host->target. */
98
#define BOOT_COM_CAN_RX_MSG_ID          (0x600)
99
/** \brief Configure number of bytes in the host->target CAN message. */
100
#define BOOT_COM_CAN_RX_MAX_DATA        (255)
101
/** \brief Select the desired CAN peripheral as a zero based index. */
102
#define BOOT_COM_CAN_CHANNEL_INDEX      (0)
103
/** \brief Configure CAN message acknowledgement ID addition (ORed with original ID). */
104
#define BOOT_COM_CAN_MSG_ACK            (0x001)
105
/** \brief Configure CAN message ID addition for continuous messages (ORed with original ID). */
106
#define BOOT_COM_CAN_MSG_SUBSEQUENT     (0x002)
107

  
108
/**
109
 * \brief Configure device ID for communication (start with 1).
110
 * \details The device ID is a 32 bit integer, which can be interpreted bytewise:
111
 *            <AMiRo_revision>:<moduleID>:<moduleVersion_major>:<moduleVersion_minor>
112
 *          For this module the according values are
113
 *            1:127:1:2 = 0x017F0102
114
 */
115
#define BOOT_COM_DEVICE_ID              (0x017F0102)
116

  
117
/* The UART communication interface is selected by setting the BOOT_COM_UART_ENABLE
118
 * configurable to 1. Configurable BOOT_COM_UART_BAUDRATE selects the communication speed
119
 * in bits/second. The maximum amount of data bytes in a message for data transmission
120
 * and reception is set through BOOT_COM_UART_TX_MAX_DATA and BOOT_COM_UART_RX_MAX_DATA,
121
 * respectively. It is common for a microcontroller to have more than 1 UART interface
122
 * on board. The zero-based BOOT_COM_UART_CHANNEL_INDEX selects the UART interface.
123
 *
124
 */
125
/** \brief Enable/disable UART transport layer. */
126
#define BOOT_COM_UART_ENABLE            (1)
127
/** \brief Configure the desired communication speed. */
128
#define BOOT_COM_UART_BAUDRATE          (115200)
129
/** \brief Configure number of bytes in the target->host data packet. */
130
#define BOOT_COM_UART_TX_MAX_DATA       (255)
131
/** \brief Configure number of bytes in the host->target data packet. */
132
#define BOOT_COM_UART_RX_MAX_DATA       (255)
133
/** \brief Select the desired UART peripheral as a zero based index. */
134
#define BOOT_COM_UART_CHANNEL_INDEX     (0)
135
/* Activate debugging with UART2 */
136
#define BOOT_DEBUGGING_UART2_ENABLE     (0)
137

  
138

  
139
/****************************************************************************************
140
*   F I L E   S Y S T E M   I N T E R F A C E   C O N F I G U R A T I O N
141
****************************************************************************************/
142
/* The file system interface is selected by setting the BOOT_FILE_SYS_ENABLE configurable
143
 * to 1. This enables support for firmware updates from a file stored on a locally
144
 * attached file system such as an SD-card. Note that this interface can be enabled
145
 * together with one of the remote communication interfaces such as UART, CAN or USB.
146
 *
147
 * Set BOOT_FILE_LOGGING_ENABLE to 1 if you would like log messages to be created during
148
 * a firmware update. The hook function FileFirmwareUpdateLogHook() will be called each
149
 * time a new string formatted log entry is available. This could be used during testing
150
 * by outputting the string on UART or to create a log file on the file system itself.
151
 *
152
 * Set BOOT_FILE_ERROR_HOOK_ENABLE to 1 if you would like to be informed in case an error
153
 * occurs during the firmware update. This could for example be used to turn on an error
154
 * LED to inform the user that something went wrong. Inspecting the log messages provides
155
 * additional information on the error cause.
156
 *
157
 * Set BOOT_FILE_STARTED_HOOK_ENABLE to 1 if you would like to be informed when a new
158
 * firmware update is started by the bootloader.
159
 *
160
 * Set BOOT_FILE_COMPLETED_HOOK_ENABLE to 1 if you would like to be informed when a
161
 * firmware update is completed by the bootloader.
162
 */
163
/** \brief Enable/disable support for firmware updates from a locally attached storage.*/
164
#define BOOT_FILE_SYS_ENABLE            (0)
165
/** \brief Enable/disable logging messages during firmware updates. */
166
#define BOOT_FILE_LOGGING_ENABLE        (1)
167
/** \brief Enable/disable a hook function that is called upon detection of an error. */
168
#define BOOT_FILE_ERROR_HOOK_ENABLE     (1)
169
/** \brief Enable/disable a hook function that is called at the start of the update. */
170
#define BOOT_FILE_STARTED_HOOK_ENABLE   (1)
171
/** \brief Enable/disable a hook function that is called at the end of the update. */
172
#define BOOT_FILE_COMPLETED_HOOK_ENABLE (1)
173

  
174

  
175
/****************************************************************************************
176
*   B A C K D O O R   E N T R Y   C O N F I G U R A T I O N
177
****************************************************************************************/
178
/* It is possible to implement an application specific method to force the bootloader to
179
 * stay active after a reset. Such a backdoor entry into the bootloader is desired in
180
 * situations where the user program does not run properly and therefore cannot
181
 * reactivate the bootloader. By enabling these hook functions, the application can
182
 * implement the backdoor, which overrides the default backdoor entry that is programmed
183
 * into the bootloader. When desired for security purposes, these hook functions can
184
 * also be implemented in a way that disables the backdoor entry altogether.
185
 */
186
/** \brief Enable/disable the backdoor override hook functions. */
187
#define BOOT_BACKDOOR_HOOKS_ENABLE      (1)
188

  
189

  
190
/****************************************************************************************
191
*   N O N - V O L A T I L E   M E M O R Y   D R I V E R   C O N F I G U R A T I O N
192
****************************************************************************************/
193
/* The NVM driver typically supports erase and program operations of the internal memory
194
 * present on the microcontroller. Through these hook functions the NVM driver can be
195
 * extended to support additional memory types such as external flash memory and serial
196
 * eeproms. The size of the internal memory in kilobytes is specified with configurable
197
 * BOOT_NVM_SIZE_KB. If desired the internal checksum writing and verification method can
198
 * be overridden with a application specific method by enabling configuration switch
199
 * BOOT_NVM_CHECKSUM_HOOKS_ENABLE.
200
 */
201
/** \brief Enable/disable the NVM hook function for supporting additional memory devices. */
202
#define BOOT_NVM_HOOKS_ENABLE           (0)
203
/** \brief Configure the size of the default memory device (typically flash EEPROM). */
204
#define BOOT_NVM_SIZE_KB                (512)
205
/** \brief Enable/disable hooks functions to override the user program checksum handling. */
206
#define BOOT_NVM_CHECKSUM_HOOKS_ENABLE  (0)
207

  
208

  
209
/****************************************************************************************
210
*   W A T C H D O G   D R I V E R   C O N F I G U R A T I O N
211
****************************************************************************************/
212
/* The COP driver cannot be configured internally in the bootloader, because its use
213
 * and configuration is application specific. The bootloader does need to service the
214
 * watchdog in case it is used. When the application requires the use of a watchdog,
215
 * set BOOT_COP_HOOKS_ENABLE to be able to initialize and service the watchdog through
216
 * hook functions.
217
 */
218
/** \brief Enable/disable the hook functions for controlling the watchdog. */
219
#define BOOT_COP_HOOKS_ENABLE           (0)
220

  
221

  
222
/****************************************************************************************
223
*   S E E D / K E Y   S E C U R I T Y   C O N F I G U R A T I O N
224
****************************************************************************************/
225
/* A security mechanism can be enabled in the bootloader's XCP module by setting configu-
226
 * rable BOOT_XCP_SEED_KEY_ENABLE to 1. Before any memory erase or programming
227
 * operations can be performed, access to this resource need to be unlocked.
228
 * In the Microboot settings on tab "XCP Protection" you need to specify a DLL that
229
 * implements the unlocking algorithm. The demo programs are configured for the (simple)
230
 * algorithm in "FeaserKey.dll". The source code for this DLL is available so it can be
231
 * customized to your needs.
232
 * During the unlock sequence, Microboot requests a seed from the bootloader, which is in
233
 * the format of a byte array. Using this seed the unlock algorithm in the DLL computes
234
 * a key, which is also a byte array, and sends this back to the bootloader. The
235
 * bootloader then verifies this key to determine if programming and erase operations are
236
 * permitted.
237
 * After enabling this feature the hook functions XcpGetSeedHook() and XcpVerifyKeyHook()
238
 * are called by the bootloader to obtain the seed and to verify the key, respectively.
239
 */
240
#define BOOT_XCP_SEED_KEY_ENABLE        (0)
241

  
242

  
243

  
244

  
245

  
246
#endif /* BLT_CONF_H */
247
/*********************************** end of blt_conf.h *********************************/
Target/Modules/LightRing_1-2/Boot/boot.dox
1
/**
2
\defgroup   Boot_ARMCM3_STM32_Olimex_STM32P103_GCC Bootloader
3
\brief      Bootloader. 
4
\ingroup    ARMCM3_STM32_Olimex_STM32P103_GCC
5
*/
6

  
7

  
Target/Modules/LightRing_1-2/Boot/cmd/build.bat
1
@echo off
2
cs-make --directory=../ all
Target/Modules/LightRing_1-2/Boot/cmd/clean.bat
1
@echo off
2
cs-make --directory=../ clean
Target/Modules/LightRing_1-2/Boot/cmd/debug.bat
1
"C:\Program Files (x86)\OpenOCD\0.4.0\bin\openocd.exe" -f debug.cfg
Target/Modules/LightRing_1-2/Boot/cmd/debug.cfg
1
###
2
# Description: starts the OpenOCD GDB server (localhost:3333)
3
#              once started use arm-elf-insight <program>.elf to start the debug session
4
# Usage: openocd.exe" -f debug.cfg
5
###
6
source [find interface/olimex-arm-usb-tiny-h.cfg]
7
source [find board/olimex_stm32_h103.cfg]
8

  
9
jtag_khz 1000
10
init
11
reset
12
halt
13

  
14

  
15

  
Target/Modules/LightRing_1-2/Boot/cmd/flash.bat
1
"C:\Program Files (x86)\OpenOCD\0.4.0\bin\openocd.exe" -f flash.cfg
Target/Modules/LightRing_1-2/Boot/cmd/flash.cfg
1
###
2
# Description: mass erases and flashes the binary with OpenOCD
3
# Usage: openocd.exe" -f flash.cfg
4
###
5

  
6
source [find interface/olimex-arm-usb-tiny-h.cfg]
7
source [find board/olimex_stm32_h103.cfg]
8

  
9
jtag_khz 1000
10

  
11
init
12
reset
13
sleep 500
14
halt
15
stm32x mass_erase 0
16
flash write_image ..\\bin\\openbtl_olimex_stm32p103.elf
17
#flash write_image erase ..\\bin\\openbtl_olimex_stm32p103.elf
18
reset run
19
shutdown
20

  
21

  
Target/Modules/LightRing_1-2/Boot/hooks.c
1
/************************************************************************************//**
2
* \file         Demo\ARMCM3_STM32_Olimex_STM32P103_GCC\Boot\hooks.c
3
* \brief        Bootloader callback source file.
4
* \ingroup      Boot_ARMCM3_STM32_Olimex_STM32P103_GCC
5
* \internal
6
*----------------------------------------------------------------------------------------
7
*                          C O P Y R I G H T
8
*----------------------------------------------------------------------------------------
9
*   Copyright (c) 2012  by Feaser    http://www.feaser.com    All rights reserved
10
*
11
*----------------------------------------------------------------------------------------
12
*                            L I C E N S E
13
*----------------------------------------------------------------------------------------
14
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
15
* modify it under the terms of the GNU General Public License as published by the Free
16
* Software Foundation, either version 3 of the License, or (at your option) any later
17
* version.
18
*
19
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
20
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21
* PURPOSE. See the GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License along with OpenBLT.
24
* If not, see <http://www.gnu.org/licenses/>.
25
*
26
* A special exception to the GPL is included to allow you to distribute a combined work 
27
* that includes OpenBLT without being obliged to provide the source code for any 
28
* proprietary components. The exception text is included at the bottom of the license
29
* file <license.html>.
30
* 
31
* \endinternal
32
****************************************************************************************/
33

  
34
/****************************************************************************************
35
* Include files
36
****************************************************************************************/
37
#include "boot.h"                                /* bootloader generic header          */
38
#if (BOOT_FILE_LOGGING_ENABLE > 0)
39
#include "stm32f10x.h"                           /* STM32 registers                    */
40
#include "stm32f10x_conf.h"                      /* STM32 peripheral drivers           */
41
#endif
42

  
43
/****************************************************************************************
44
*   B A C K D O O R   E N T R Y   H O O K   F U N C T I O N S
45
****************************************************************************************/
46

  
47
#if (BOOT_BACKDOOR_HOOKS_ENABLE > 0)
48

  
49
enum BOOT_STATE {BOOT_FLASH_WAIT,
50
                 BOOT_OS_SYNC,
51
                 BOOT_OS_START
52
                } boot_state;
53

  
54
#define SYS_PD_N_PIN      GPIO_Pin_14
55
#define SYS_PD_N_GPIO     GPIOC
56
#define SYS_SYNC_N_PIN    GPIO_Pin_2
57
#define SYS_SYNC_N_GPIO   GPIOD
58

  
59
/************************************************************************************//**
60
** \brief     Initializes the backdoor entry option.
61
** \return    none.
62
**
63
****************************************************************************************/
64
void BackDoorInitHook(void)
65
{
66
  boot_state = BOOT_FLASH_WAIT;
67
} /*** end of BackDoorInitHook ***/
68

  
69

  
70
/************************************************************************************//**
71
** \brief     Checks if it has to stay in backdoor.
72
** \return    BLT_TRUE if the backdoor entry is requested, BLT_FALSE otherwise.
73
**
74
****************************************************************************************/
75
blt_bool BackDoorEntryCheck(void)
76
{
77
  /* evaluate the fsm state */
78
  switch (boot_state) {
79
    case BOOT_FLASH_WAIT:
80
    {
81
      /* wait for the SYS_SYNC_N signal to go up */
82
      GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
83
      if (GPIO_ReadInputDataBit(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN) == Bit_RESET) {
84
        return BLT_TRUE;
85
      } else {
86
        boot_state = BOOT_OS_SYNC;
87
        return BLT_FALSE;
88
      }
89
      break;
90
    }
91
    default:
92
      return BLT_FALSE;
93
      break;
94
  }
95
  return BLT_FALSE;
96
} /*** end of BackDoorEntryCheck ***/
97

  
98
/************************************************************************************//**
99
** \brief     Checks if a backdoor entry is requested.
100
** \return    BLT_TRUE if the backdoor entry is requested, BLT_FALSE otherwise.
101
**
102
****************************************************************************************/
103
blt_bool BackDoorEntryHook(void)
104
{
105
  /* default implementation always activates the bootloader after a reset */
106
  return BLT_TRUE;
107
} /*** end of BackDoorEntryHook ***/
108
#endif /* BOOT_BACKDOOR_HOOKS_ENABLE > 0 */
109

  
110

  
111
/************************************************************************************//**
112
** \brief     Notice that there is still an open connection over COM 
113
** \return    -
114
**
115
****************************************************************************************/
116
void BackDoorComIsConnected(void)
117
{
118
}
119

  
120

  
121
/****************************************************************************************
122
*   C P U   D R I V E R   H O O K   F U N C T I O N S
123
****************************************************************************************/
124

  
125
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
126
/************************************************************************************//**
127
** \brief     Callback that gets called when the bootloader is about to exit and
128
**            hand over control to the user program. This is the last moment that
129
**            some final checking can be performed and if necessary prevent the
130
**            bootloader from activiting the user program.
131
** \return    BLT_TRUE if it is okay to start the user program, BLT_FALSE to keep
132
**            keep the bootloader active.
133
**
134
****************************************************************************************/
135
blt_bool CpuUserProgramStartHook(void)
136
{
137
  /* evaluate the fsm state */
138
  switch (boot_state) {
139
    case BOOT_OS_SYNC:
140
    {
141
      /* wait for the SYS_SYNC_N signal to go down */
142
      if (GPIO_ReadInputDataBit(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN) == Bit_RESET) {
143
        boot_state = BOOT_OS_START;
144
      }
145
      return BLT_FALSE;
146
      break;
147
    }
148
    case BOOT_OS_START:
149
    {
150
      /* pull down SYS_SYNC_N to indicate that the module is busy
151
       * note: This is optional at this point. The OS however MUST pull down SYS_SYNC_N until it is ready */
152
      GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
153
      return BLT_TRUE;
154
    }
155
    default:
156
      return BLT_FALSE;
157
      break;
158
  }
159
  return BLT_FALSE;
160
} /*** end of CpuUserProgramStartHook ***/
161
#endif /* BOOT_CPU_USER_PROGRAM_START_HOOK > 0 */
162

  
163

  
164
/****************************************************************************************
165
*   N O N - V O L A T I L E   M E M O R Y   D R I V E R   H O O K   F U N C T I O N S
166
****************************************************************************************/
167

  
168
#if (BOOT_NVM_HOOKS_ENABLE > 0)
169
/************************************************************************************//**
170
** \brief     Callback that gets called at the start of the internal NVM driver
171
**            initialization routine. 
172
** \return    none.
173
**
174
****************************************************************************************/
175
void NvmInitHook(void)
176
{
177
} /*** end of NvmInitHook ***/
178

  
179

  
180
/************************************************************************************//**
181
** \brief     Callback that gets called at the start of the NVM driver write 
182
**            routine. It allows additional memory to be operated on. If the address
183
**            is not within the range of the additional memory, then 
184
**            BLT_NVM_NOT_IN_RANGE must be returned to indicate that the data hasn't
185
**            been written yet.
186
** \param     addr Start address.
187
** \param     len  Length in bytes.
188
** \param     data Pointer to the data buffer.
189
** \return    BLT_NVM_OKAY if successful, BLT_NVM_NOT_IN_RANGE if the address is
190
**            not within the supported memory range, or BLT_NVM_ERROR is the write
191
**            operation failed.
192
**
193
****************************************************************************************/
194
blt_int8u NvmWriteHook(blt_addr addr, blt_int32u len, blt_int8u *data)
195
{
196
  return BLT_NVM_NOT_IN_RANGE;
197
} /*** end of NvmWriteHook ***/
198

  
199

  
200
/************************************************************************************//**
201
** \brief     Callback that gets called at the start of the NVM driver erase 
202
**            routine. It allows additional memory to be operated on. If the address
203
**            is not within the range of the additional memory, then
204
**            BLT_NVM_NOT_IN_RANGE must be returned to indicate that the memory
205
**            hasn't been erased yet.
206
** \param     addr Start address.
207
** \param     len  Length in bytes.
208
** \return    BLT_NVM_OKAY if successful, BLT_NVM_NOT_IN_RANGE if the address is
209
**            not within the supported memory range, or BLT_NVM_ERROR is the erase
210
**            operation failed.
211
**
212
****************************************************************************************/
213
blt_int8u NvmEraseHook(blt_addr addr, blt_int32u len)
214
{
215
  return BLT_NVM_NOT_IN_RANGE;
216
} /*** end of NvmEraseHook ***/
217

  
218

  
219
/************************************************************************************//**
220
** \brief     Callback that gets called at the end of the NVM programming session.
221
** \return    BLT_TRUE is successful, BLT_FALSE otherwise.
222
**
223
****************************************************************************************/
224
blt_bool NvmDoneHook(void)
225
{
226
  return BLT_TRUE;
227
} /*** end of NvmDoneHook ***/
228
#endif /* BOOT_NVM_HOOKS_ENABLE > 0 */
229

  
230

  
231
#if (BOOT_NVM_CHECKSUM_HOOKS_ENABLE > 0)
232
/************************************************************************************//**
233
** \brief     Verifies the checksum, which indicates that a valid user program is
234
**            present and can be started.
235
** \return    BLT_TRUE if successful, BLT_FALSE otherwise.
236
**
237
****************************************************************************************/
238
blt_bool NvmVerifyChecksumHook(void)
239
{
240
  return BLT_TRUE;
241
} /*** end of NvmVerifyChecksum ***/
242

  
243

  
244
/************************************************************************************//**
245
** \brief     Writes a checksum of the user program to non-volatile memory. This is
246
**            performed once the entire user program has been programmed. Through
247
**            the checksum, the bootloader can check if a valid user programming is
248
**            present and can be started.
249
** \return    BLT_TRUE if successful, BLT_FALSE otherwise. 
250
**
251
****************************************************************************************/
252
blt_bool NvmWriteChecksumHook(void)
253
{
254
  return BLT_TRUE;
255
}
256
#endif /* BOOT_NVM_CHECKSUM_HOOKS_ENABLE > 0 */
257

  
258

  
259
/****************************************************************************************
260
*   W A T C H D O G   D R I V E R   H O O K   F U N C T I O N S
261
****************************************************************************************/
262

  
263
#if (BOOT_COP_HOOKS_ENABLE > 0)
264
/************************************************************************************//**
265
** \brief     Callback that gets called at the end of the internal COP driver
266
**            initialization routine. It can be used to configure and enable the
267
**            watchdog.
268
** \return    none.
269
**
270
****************************************************************************************/
271
void CopInitHook(void)
272
{
273
} /*** end of CopInitHook ***/
274

  
275

  
276
/************************************************************************************//**
277
** \brief     Callback that gets called at the end of the internal COP driver
278
**            service routine. This gets called upon initialization and during
279
**            potential long lasting loops and routine. It can be used to service
280
**            the watchdog to prevent a watchdog reset.
281
** \return    none.
282
**
283
****************************************************************************************/
284
void CopServiceHook(void)
285
{
286
} /*** end of CopServiceHook ***/
287
#endif /* BOOT_COP_HOOKS_ENABLE > 0 */
288

  
289

  
290
/****************************************************************************************
291
*   F I L E   S Y S T E M   I N T E R F A C E   H O O K   F U N C T I O N S
292
****************************************************************************************/
293

  
294
#if (BOOT_FILE_SYS_ENABLE > 0)
295

  
296
/****************************************************************************************
297
* Constant data declarations
298
****************************************************************************************/
299
/** \brief Firmware filename. */
300
static const blt_char firmwareFilename[] = "/demoprog_olimex_stm32p103.srec";
301

  
302

  
303
/****************************************************************************************
304
* Local data declarations
305
****************************************************************************************/
306
#if (BOOT_FILE_LOGGING_ENABLE > 0)
307
/** \brief Data structure for grouping log-file related information. */
308
static struct 
309
{
310
  FIL      handle;                  /**< FatFS handle to the log-file.                 */
311
  blt_bool canUse;                  /**< Flag to indicate if the log-file can be used. */
312
} logfile;
313
#endif
314

  
315

  
316
/************************************************************************************//**
317
** \brief     Callback that gets called to check whether a firmware update from 
318
**            local file storage should be started. This could for example be when
319
**            a switch is pressed, when a certain file is found on the local file 
320
**            storage, etc.
321
** \return    BLT_TRUE if a firmware update is requested, BLT_FALSE otherwise.
322
**
323
****************************************************************************************/
324
blt_bool FileIsFirmwareUpdateRequestedHook(void)
325
{
326
  FILINFO fileInfoObject = { 0 }; /* needs to be zeroed according to f_stat docs */;
327

  
328
  /* Current example implementation looks for a predetermined firmware file on the 
329
   * SD-card. If the SD-card is accessible and the firmware file was found the firmware
330
   * update is started. When successfully completed, the firmware file is deleted.
331
   * During the firmware update, progress information is written to a file called
332
   * bootlog.txt and additionally outputted on UART @57600 bps for debugging purposes.
333
   */
334
  /* check if firmware file is present and SD-card is accessible */
335
  if (f_stat(firmwareFilename, &fileInfoObject) == FR_OK) 
336
  {
337
    /* check if the filesize is valid and that it is not a directory */
338
    if ( (fileInfoObject.fsize > 0) && (!(fileInfoObject.fattrib & AM_DIR)) )
339
    {
340
      /* all conditions are met to start a firmware update from local file storage */
341
      return BLT_TRUE;
342
    }
343
  }
344
  /* still here so no firmware update request is pending */  
345
  return BLT_FALSE;
346
} /*** end of FileIsFirmwareUpdateRequestedHook ***/
347

  
348

  
349
/************************************************************************************//**
350
** \brief     Callback to obtain the filename of the firmware file that should be
351
**            used during the firmware update from the local file storage. This 
352
**            hook function is called at the beginning of the firmware update from
353
**            local storage sequence. 
354
** \return    valid firmware filename with full path or BLT_NULL.
355
**
356
****************************************************************************************/
357
const blt_char *FileGetFirmwareFilenameHook(void)
358
{
359
  return firmwareFilename;
360
} /*** end of FileGetFirmwareFilenameHook ***/
361

  
362

  
363
#if (BOOT_FILE_STARTED_HOOK_ENABLE > 0)
364
/************************************************************************************//**
365
** \brief     Callback that gets called to inform the application that a firmware
366
**            update from local storage just started. 
367
** \return    none.
368
**
369
****************************************************************************************/
370
void FileFirmwareUpdateStartedHook(void)
371
{
372
  #if (BOOT_FILE_LOGGING_ENABLE > 0)
373
  /* create/overwrite the logfile */
374
  logfile.canUse = BLT_FALSE;
375
  if (f_open(&logfile.handle, "/bootlog.txt", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
376
  {
377
    logfile.canUse = BLT_TRUE;
378
  }
379
  #endif
380
} /*** end of FileFirmwareUpdateStartedHook ***/
381
#endif /* BOOT_FILE_STARTED_HOOK_ENABLE > 0 */
382

  
383

  
384
#if (BOOT_FILE_COMPLETED_HOOK_ENABLE > 0)
385
/************************************************************************************//**
386
** \brief     Callback that gets called to inform the application that a firmware
387
**            update was successfully completed.
388
** \return    none.
389
**
390
****************************************************************************************/
391
void FileFirmwareUpdateCompletedHook(void)
392
{
393
  #if (BOOT_FILE_LOGGING_ENABLE > 0)
394
  /* close the log file */
395
  if (logfile.canUse == BLT_TRUE)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff