![](/media/cache/profiles/827ccb0eea8a706c4c34a16891f84e7b.jpg.50x50_q85.jpg)
Bootload from SD card to sector 0, and jump to sector 24 where new firmware resides
Fork of Panel-Controller-Bootloader by
main.cpp@2:0fa89ba8f6fe, 2015-04-22 (annotated)
- Committer:
- bonchenko
- Date:
- Wed Apr 22 10:18:55 2015 +0000
- Revision:
- 2:0fa89ba8f6fe
- Parent:
- 0:c3a652eff606
Bootloader from SD card works perfectly. Compiled with offset in EmBlocks, ADE cannot print readings - but its happened without bootloader too. The problem is Emblocks compiler settings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bonchenko | 0:c3a652eff606 | 1 | /* Includes */ |
bonchenko | 0:c3a652eff606 | 2 | #include <stddef.h> |
bonchenko | 0:c3a652eff606 | 3 | #include "stm32f10x.h" |
bonchenko | 2:0fa89ba8f6fe | 4 | #include "stm32f10x_usart.h" |
bonchenko | 0:c3a652eff606 | 5 | #include "main.h" |
bonchenko | 0:c3a652eff606 | 6 | |
bonchenko | 2:0fa89ba8f6fe | 7 | extern "C" |
bonchenko | 0:c3a652eff606 | 8 | { |
bonchenko | 0:c3a652eff606 | 9 | #include "flash.h" |
bonchenko | 0:c3a652eff606 | 10 | #include "usart.h" |
bonchenko | 0:c3a652eff606 | 11 | } |
bonchenko | 0:c3a652eff606 | 12 | |
bonchenko | 0:c3a652eff606 | 13 | /* Private define */ |
bonchenko | 0:c3a652eff606 | 14 | /* Private macro */ |
bonchenko | 0:c3a652eff606 | 15 | /* Private variables */ |
bonchenko | 0:c3a652eff606 | 16 | typedef void (*pFunction)(void); |
bonchenko | 0:c3a652eff606 | 17 | uint32_t JumpAddress; |
bonchenko | 0:c3a652eff606 | 18 | pFunction Jump_To_Application; |
bonchenko | 0:c3a652eff606 | 19 | FLASH_RESULT flashResult; |
bonchenko | 0:c3a652eff606 | 20 | |
bonchenko | 0:c3a652eff606 | 21 | /* Private function prototypes */ |
bonchenko | 0:c3a652eff606 | 22 | /* Private functions */ |
bonchenko | 0:c3a652eff606 | 23 | void RCC_Configuration(); |
bonchenko | 0:c3a652eff606 | 24 | void NVIC_Configuration(void); |
bonchenko | 0:c3a652eff606 | 25 | void Timer2_Init(void); |
bonchenko | 0:c3a652eff606 | 26 | void Timer2_DeInit(void); |
bonchenko | 0:c3a652eff606 | 27 | void Timer3_Init(void); |
bonchenko | 0:c3a652eff606 | 28 | void Timer3_DeInit(void); |
bonchenko | 0:c3a652eff606 | 29 | /** |
bonchenko | 0:c3a652eff606 | 30 | **=========================================================================== |
bonchenko | 0:c3a652eff606 | 31 | ** |
bonchenko | 0:c3a652eff606 | 32 | ** Abstract: main program |
bonchenko | 0:c3a652eff606 | 33 | ** |
bonchenko | 0:c3a652eff606 | 34 | **=========================================================================== |
bonchenko | 0:c3a652eff606 | 35 | */ |
bonchenko | 0:c3a652eff606 | 36 | int main(void) |
bonchenko | 0:c3a652eff606 | 37 | { |
bonchenko | 0:c3a652eff606 | 38 | USART_Initialise(); |
bonchenko | 2:0fa89ba8f6fe | 39 | USART_SendString("Bootloader EMMA\r\n"); |
bonchenko | 0:c3a652eff606 | 40 | RCC_Configuration(); |
bonchenko | 0:c3a652eff606 | 41 | NVIC_Configuration(); |
bonchenko | 0:c3a652eff606 | 42 | Timer2_Init(); |
bonchenko | 0:c3a652eff606 | 43 | Timer3_Init(); |
bonchenko | 0:c3a652eff606 | 44 | USART_SendString("Starting\r\n"); |
bonchenko | 2:0fa89ba8f6fe | 45 | |
bonchenko | 0:c3a652eff606 | 46 | //If new firmware present on microSD card -> Flash to MCU |
bonchenko | 0:c3a652eff606 | 47 | flashResult = FlashFirmware(); |
bonchenko | 0:c3a652eff606 | 48 | USART_SendString("OK\r\n"); |
bonchenko | 0:c3a652eff606 | 49 | |
bonchenko | 0:c3a652eff606 | 50 | /* Check if the result of the Flash Firmware function */ |
bonchenko | 0:c3a652eff606 | 51 | if(flashResult == FLASH_OK |
bonchenko | 0:c3a652eff606 | 52 | || flashResult == FLASH_NO_FILE |
bonchenko | 0:c3a652eff606 | 53 | || flashResult == FLASH_NO_SD_CARD) |
bonchenko | 0:c3a652eff606 | 54 | { |
bonchenko | 0:c3a652eff606 | 55 | USART_SendString("FLASH_OK or NO_FILE or NO_SD\r\n"); |
bonchenko | 0:c3a652eff606 | 56 | /* Test if user code is programmed starting from address "ApplicationAddress" */ |
bonchenko | 2:0fa89ba8f6fe | 57 | NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x6000); |
bonchenko | 0:c3a652eff606 | 58 | if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000) |
bonchenko | 0:c3a652eff606 | 59 | { |
bonchenko | 0:c3a652eff606 | 60 | // Disable Timers |
bonchenko | 0:c3a652eff606 | 61 | Timer2_DeInit(); |
bonchenko | 0:c3a652eff606 | 62 | Timer3_DeInit(); |
bonchenko | 0:c3a652eff606 | 63 | |
bonchenko | 0:c3a652eff606 | 64 | /* Jump to user application */ |
bonchenko | 0:c3a652eff606 | 65 | JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4); |
bonchenko | 2:0fa89ba8f6fe | 66 | __disable_irq (); |
bonchenko | 0:c3a652eff606 | 67 | Jump_To_Application = (pFunction) JumpAddress; |
bonchenko | 0:c3a652eff606 | 68 | |
bonchenko | 0:c3a652eff606 | 69 | /* Initialise user application's Stack Pointer */ |
bonchenko | 0:c3a652eff606 | 70 | __set_MSP(*(__IO uint32_t*) ApplicationAddress); |
bonchenko | 0:c3a652eff606 | 71 | Jump_To_Application(); |
bonchenko | 0:c3a652eff606 | 72 | } |
bonchenko | 0:c3a652eff606 | 73 | } |
bonchenko | 0:c3a652eff606 | 74 | |
bonchenko | 0:c3a652eff606 | 75 | while(1) |
bonchenko | 0:c3a652eff606 | 76 | { |
bonchenko | 0:c3a652eff606 | 77 | // Led1Flash(1, 5000); |
bonchenko | 0:c3a652eff606 | 78 | } |
bonchenko | 0:c3a652eff606 | 79 | } |
bonchenko | 0:c3a652eff606 | 80 | |
bonchenko | 0:c3a652eff606 | 81 | void RCC_Configuration() |
bonchenko | 0:c3a652eff606 | 82 | { |
bonchenko | 0:c3a652eff606 | 83 | /* GPIOA */ |
bonchenko | 0:c3a652eff606 | 84 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); |
bonchenko | 0:c3a652eff606 | 85 | |
bonchenko | 0:c3a652eff606 | 86 | /* GPIOB */ |
bonchenko | 0:c3a652eff606 | 87 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); |
bonchenko | 0:c3a652eff606 | 88 | |
bonchenko | 0:c3a652eff606 | 89 | /* GPIOC */ |
bonchenko | 0:c3a652eff606 | 90 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); |
bonchenko | 0:c3a652eff606 | 91 | |
bonchenko | 0:c3a652eff606 | 92 | /* GPIOD */ |
bonchenko | 0:c3a652eff606 | 93 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); |
bonchenko | 0:c3a652eff606 | 94 | |
bonchenko | 0:c3a652eff606 | 95 | /* GPIOE */ |
bonchenko | 0:c3a652eff606 | 96 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); |
bonchenko | 0:c3a652eff606 | 97 | |
bonchenko | 0:c3a652eff606 | 98 | /* AFIO */ |
bonchenko | 0:c3a652eff606 | 99 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); |
bonchenko | 0:c3a652eff606 | 100 | |
bonchenko | 0:c3a652eff606 | 101 | /* TIM2 */ |
bonchenko | 0:c3a652eff606 | 102 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); |
bonchenko | 0:c3a652eff606 | 103 | |
bonchenko | 0:c3a652eff606 | 104 | /* TIM3 */ |
bonchenko | 0:c3a652eff606 | 105 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); |
bonchenko | 0:c3a652eff606 | 106 | } |
bonchenko | 0:c3a652eff606 | 107 | |
bonchenko | 0:c3a652eff606 | 108 | void NVIC_Configuration(void) |
bonchenko | 0:c3a652eff606 | 109 | { |
bonchenko | 0:c3a652eff606 | 110 | #ifdef VECT_TAB_RAM |
bonchenko | 0:c3a652eff606 | 111 | /* Set the Vector Table base location at 0x20000000 */ |
bonchenko | 0:c3a652eff606 | 112 | NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); |
bonchenko | 0:c3a652eff606 | 113 | #else /* VECT_TAB_FLASH */ |
bonchenko | 0:c3a652eff606 | 114 | /* Set the Vector Table base location at 0x08000000 */ |
bonchenko | 0:c3a652eff606 | 115 | NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); |
bonchenko | 0:c3a652eff606 | 116 | #endif |
bonchenko | 0:c3a652eff606 | 117 | |
bonchenko | 0:c3a652eff606 | 118 | NVIC_InitTypeDef NVIC_InitStructure; |
bonchenko | 0:c3a652eff606 | 119 | |
bonchenko | 0:c3a652eff606 | 120 | // Enable the TIM3 Interrupt |
bonchenko | 0:c3a652eff606 | 121 | NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; |
bonchenko | 0:c3a652eff606 | 122 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; |
bonchenko | 0:c3a652eff606 | 123 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; |
bonchenko | 0:c3a652eff606 | 124 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
bonchenko | 0:c3a652eff606 | 125 | NVIC_Init(&NVIC_InitStructure); |
bonchenko | 0:c3a652eff606 | 126 | } |
bonchenko | 0:c3a652eff606 | 127 | |
bonchenko | 0:c3a652eff606 | 128 | void Timer2_Init(void) |
bonchenko | 0:c3a652eff606 | 129 | { |
bonchenko | 0:c3a652eff606 | 130 | // Time base configuration Timer2 clock |
bonchenko | 0:c3a652eff606 | 131 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
bonchenko | 0:c3a652eff606 | 132 | TIM_TimeBaseStructure.TIM_Period = 65535; |
bonchenko | 0:c3a652eff606 | 133 | TIM_TimeBaseStructure.TIM_Prescaler = 7199; |
bonchenko | 0:c3a652eff606 | 134 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV2; |
bonchenko | 0:c3a652eff606 | 135 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
bonchenko | 0:c3a652eff606 | 136 | TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); |
bonchenko | 0:c3a652eff606 | 137 | |
bonchenko | 0:c3a652eff606 | 138 | TIM_ARRPreloadConfig(TIM2, ENABLE); |
bonchenko | 0:c3a652eff606 | 139 | TIM_Cmd(TIM2, ENABLE); |
bonchenko | 0:c3a652eff606 | 140 | } |
bonchenko | 0:c3a652eff606 | 141 | |
bonchenko | 0:c3a652eff606 | 142 | void Timer3_Init(void) |
bonchenko | 2:0fa89ba8f6fe | 143 | { |
bonchenko | 0:c3a652eff606 | 144 | // Time base configuration Timer3 clock |
bonchenko | 0:c3a652eff606 | 145 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
bonchenko | 0:c3a652eff606 | 146 | TIM_TimeBaseStructure.TIM_Period = 10; |
bonchenko | 0:c3a652eff606 | 147 | TIM_TimeBaseStructure.TIM_Prescaler = 7199; |
bonchenko | 0:c3a652eff606 | 148 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV2; |
bonchenko | 0:c3a652eff606 | 149 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
bonchenko | 0:c3a652eff606 | 150 | TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); |
bonchenko | 0:c3a652eff606 | 151 | |
bonchenko | 0:c3a652eff606 | 152 | TIM_ARRPreloadConfig(TIM3, ENABLE); |
bonchenko | 0:c3a652eff606 | 153 | TIM_ClearITPendingBit(TIM3, TIM_IT_Update); |
bonchenko | 0:c3a652eff606 | 154 | TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); |
bonchenko | 0:c3a652eff606 | 155 | TIM_Cmd(TIM3, ENABLE); |
bonchenko | 0:c3a652eff606 | 156 | } |
bonchenko | 0:c3a652eff606 | 157 | |
bonchenko | 0:c3a652eff606 | 158 | void Timer2_DeInit() |
bonchenko | 0:c3a652eff606 | 159 | { |
bonchenko | 0:c3a652eff606 | 160 | TIM_Cmd(TIM2, DISABLE); |
bonchenko | 0:c3a652eff606 | 161 | TIM_DeInit(TIM2); |
bonchenko | 0:c3a652eff606 | 162 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, DISABLE); |
bonchenko | 0:c3a652eff606 | 163 | } |
bonchenko | 0:c3a652eff606 | 164 | |
bonchenko | 0:c3a652eff606 | 165 | void Timer3_DeInit(void) |
bonchenko | 0:c3a652eff606 | 166 | { |
bonchenko | 0:c3a652eff606 | 167 | TIM_Cmd(TIM3, DISABLE); |
bonchenko | 0:c3a652eff606 | 168 | TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE); |
bonchenko | 0:c3a652eff606 | 169 | TIM_ARRPreloadConfig(TIM3, DISABLE); |
bonchenko | 0:c3a652eff606 | 170 | NVIC_DisableIRQ(TIM3_IRQn); |
bonchenko | 0:c3a652eff606 | 171 | TIM_DeInit(TIM3); |
bonchenko | 0:c3a652eff606 | 172 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, DISABLE); |
bonchenko | 0:c3a652eff606 | 173 | } |
bonchenko | 0:c3a652eff606 | 174 | |
bonchenko | 0:c3a652eff606 | 175 | void SD_LowLevel_DeInit(void) |
bonchenko | 0:c3a652eff606 | 176 | { |
bonchenko | 0:c3a652eff606 | 177 | GPIO_InitTypeDef GPIO_InitStructure; |
bonchenko | 0:c3a652eff606 | 178 | |
bonchenko | 0:c3a652eff606 | 179 | SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */ |
bonchenko | 0:c3a652eff606 | 180 | SPI_I2S_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */ |
bonchenko | 0:c3a652eff606 | 181 | |
bonchenko | 0:c3a652eff606 | 182 | /*!< SD_SPI Periph clock disable */ |
bonchenko | 0:c3a652eff606 | 183 | RCC_APB2PeriphClockCmd(SD_SPI_CLK, DISABLE); |
bonchenko | 0:c3a652eff606 | 184 | |
bonchenko | 0:c3a652eff606 | 185 | /*!< Configure SD_SPI pins: SCK */ |
bonchenko | 0:c3a652eff606 | 186 | GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN; |
bonchenko | 0:c3a652eff606 | 187 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; |
bonchenko | 0:c3a652eff606 | 188 | GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 189 | |
bonchenko | 0:c3a652eff606 | 190 | /*!< Configure SD_SPI pins: MISO */ |
bonchenko | 0:c3a652eff606 | 191 | GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN; |
bonchenko | 0:c3a652eff606 | 192 | GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 193 | |
bonchenko | 0:c3a652eff606 | 194 | /*!< Configure SD_SPI pins: MOSI */ |
bonchenko | 0:c3a652eff606 | 195 | GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN; |
bonchenko | 0:c3a652eff606 | 196 | GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 197 | |
bonchenko | 0:c3a652eff606 | 198 | /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */ |
bonchenko | 0:c3a652eff606 | 199 | GPIO_InitStructure.GPIO_Pin = SD_CS_PIN; |
bonchenko | 0:c3a652eff606 | 200 | GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 201 | |
bonchenko | 0:c3a652eff606 | 202 | /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ |
bonchenko | 0:c3a652eff606 | 203 | GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; |
bonchenko | 0:c3a652eff606 | 204 | GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 205 | } |
bonchenko | 0:c3a652eff606 | 206 | |
bonchenko | 0:c3a652eff606 | 207 | |
bonchenko | 0:c3a652eff606 | 208 | void SD_LowLevel_Init(void) |
bonchenko | 0:c3a652eff606 | 209 | { |
bonchenko | 0:c3a652eff606 | 210 | GPIO_InitTypeDef GPIO_InitStructure; |
bonchenko | 0:c3a652eff606 | 211 | SPI_InitTypeDef SPI_InitStructure; |
bonchenko | 0:c3a652eff606 | 212 | |
bonchenko | 0:c3a652eff606 | 213 | /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO |
bonchenko | 0:c3a652eff606 | 214 | and SD_SPI_SCK_GPIO Periph clock enable */ |
bonchenko | 0:c3a652eff606 | 215 | RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK | |
bonchenko | 0:c3a652eff606 | 216 | SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE); |
bonchenko | 0:c3a652eff606 | 217 | |
bonchenko | 0:c3a652eff606 | 218 | /*!< SD_SPI Periph clock enable */ |
bonchenko | 0:c3a652eff606 | 219 | RCC_APB2PeriphClockCmd(SD_SPI_CLK, ENABLE); |
bonchenko | 0:c3a652eff606 | 220 | |
bonchenko | 0:c3a652eff606 | 221 | /*!< Configure SD_SPI pins: SCK */ |
bonchenko | 0:c3a652eff606 | 222 | GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN; |
bonchenko | 0:c3a652eff606 | 223 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
bonchenko | 0:c3a652eff606 | 224 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
bonchenko | 0:c3a652eff606 | 225 | GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 226 | |
bonchenko | 0:c3a652eff606 | 227 | /*!< Configure SD_SPI pins: MOSI */ |
bonchenko | 0:c3a652eff606 | 228 | GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN; |
bonchenko | 0:c3a652eff606 | 229 | GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 230 | |
bonchenko | 0:c3a652eff606 | 231 | /*!< Configure SD_SPI pins: MISO */ |
bonchenko | 0:c3a652eff606 | 232 | GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN; |
bonchenko | 0:c3a652eff606 | 233 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; |
bonchenko | 0:c3a652eff606 | 234 | GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 235 | |
bonchenko | 0:c3a652eff606 | 236 | /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */ |
bonchenko | 0:c3a652eff606 | 237 | GPIO_InitStructure.GPIO_Pin = SD_CS_PIN; |
bonchenko | 0:c3a652eff606 | 238 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
bonchenko | 0:c3a652eff606 | 239 | GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 240 | |
bonchenko | 0:c3a652eff606 | 241 | /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ |
bonchenko | 0:c3a652eff606 | 242 | GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; |
bonchenko | 0:c3a652eff606 | 243 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; |
bonchenko | 0:c3a652eff606 | 244 | GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 245 | |
bonchenko | 0:c3a652eff606 | 246 | /*!< SD_SPI Config */ |
bonchenko | 0:c3a652eff606 | 247 | SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; |
bonchenko | 0:c3a652eff606 | 248 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master; |
bonchenko | 0:c3a652eff606 | 249 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; |
bonchenko | 0:c3a652eff606 | 250 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; |
bonchenko | 0:c3a652eff606 | 251 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; |
bonchenko | 0:c3a652eff606 | 252 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; |
bonchenko | 0:c3a652eff606 | 253 | SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; |
bonchenko | 0:c3a652eff606 | 254 | |
bonchenko | 0:c3a652eff606 | 255 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; |
bonchenko | 0:c3a652eff606 | 256 | SPI_InitStructure.SPI_CRCPolynomial = 7; |
bonchenko | 0:c3a652eff606 | 257 | SPI_Init(SD_SPI, &SPI_InitStructure); |
bonchenko | 0:c3a652eff606 | 258 | |
bonchenko | 0:c3a652eff606 | 259 | SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */ |
bonchenko | 0:c3a652eff606 | 260 | } |
bonchenko | 0:c3a652eff606 | 261 | |
bonchenko | 0:c3a652eff606 | 262 | #ifdef USE_FULL_ASSERT |
bonchenko | 0:c3a652eff606 | 263 | |
bonchenko | 0:c3a652eff606 | 264 | /** |
bonchenko | 0:c3a652eff606 | 265 | * @brief Reports the name of the source file and the source line number |
bonchenko | 0:c3a652eff606 | 266 | * where the assert_param error has occurred. |
bonchenko | 0:c3a652eff606 | 267 | * @param file: pointer to the source file name |
bonchenko | 0:c3a652eff606 | 268 | * @param line: assert_param error line source number |
bonchenko | 0:c3a652eff606 | 269 | * @retval None |
bonchenko | 0:c3a652eff606 | 270 | */ |
bonchenko | 0:c3a652eff606 | 271 | void assert_failed(uint8_t* file, uint32_t line) |
bonchenko | 0:c3a652eff606 | 272 | { |
bonchenko | 0:c3a652eff606 | 273 | /* User can add his own implementation to report the file name and line number, |
bonchenko | 0:c3a652eff606 | 274 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
bonchenko | 0:c3a652eff606 | 275 | |
bonchenko | 0:c3a652eff606 | 276 | /* Infinite loop */ |
bonchenko | 0:c3a652eff606 | 277 | while (1) |
bonchenko | 0:c3a652eff606 | 278 | { |
bonchenko | 0:c3a652eff606 | 279 | } |
bonchenko | 0:c3a652eff606 | 280 | } |
bonchenko | 0:c3a652eff606 | 281 | #endif |
bonchenko | 0:c3a652eff606 | 282 | |
bonchenko | 0:c3a652eff606 | 283 | /* |
bonchenko | 0:c3a652eff606 | 284 | * Minimal __assert_func used by the assert() macro |
bonchenko | 0:c3a652eff606 | 285 | * */ |
bonchenko | 0:c3a652eff606 | 286 | void __assert_func(const char *file, int line, const char *func, const char *failedexpr) |
bonchenko | 0:c3a652eff606 | 287 | { |
bonchenko | 0:c3a652eff606 | 288 | while(1) |
bonchenko | 0:c3a652eff606 | 289 | {} |
bonchenko | 0:c3a652eff606 | 290 | } |
bonchenko | 0:c3a652eff606 | 291 | |
bonchenko | 0:c3a652eff606 | 292 | /* |
bonchenko | 0:c3a652eff606 | 293 | * Minimal __assert() uses __assert__func() |
bonchenko | 0:c3a652eff606 | 294 | * */ |
bonchenko | 0:c3a652eff606 | 295 | void __assert(const char *file, int line, const char *failedexpr) |
bonchenko | 0:c3a652eff606 | 296 | { |
bonchenko | 0:c3a652eff606 | 297 | __assert_func (file, line, NULL, failedexpr); |
bonchenko | 0:c3a652eff606 | 298 | } |
bonchenko | 0:c3a652eff606 | 299 | |
bonchenko | 0:c3a652eff606 | 300 | #ifdef USE_SEE |
bonchenko | 0:c3a652eff606 | 301 | #ifndef USE_DEFAULT_TIMEOUT_CALLBACK |
bonchenko | 0:c3a652eff606 | 302 | /** |
bonchenko | 0:c3a652eff606 | 303 | * @brief Basic management of the timeout situation. |
bonchenko | 0:c3a652eff606 | 304 | * @param None. |
bonchenko | 0:c3a652eff606 | 305 | * @retval sEE_FAIL. |
bonchenko | 0:c3a652eff606 | 306 | */ |
bonchenko | 0:c3a652eff606 | 307 | uint32_t sEE_TIMEOUT_UserCallback(void) |
bonchenko | 0:c3a652eff606 | 308 | { |
bonchenko | 0:c3a652eff606 | 309 | /* Return with error code */ |
bonchenko | 0:c3a652eff606 | 310 | return sEE_FAIL; |
bonchenko | 0:c3a652eff606 | 311 | } |
bonchenko | 0:c3a652eff606 | 312 | #endif |
bonchenko | 0:c3a652eff606 | 313 | #endif /* USE_SEE */ |