![](/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@0:c3a652eff606, 2015-04-21 (annotated)
- Committer:
- bonchenko
- Date:
- Tue Apr 21 09:30:11 2015 +0000
- Revision:
- 0:c3a652eff606
- Child:
- 2:0fa89ba8f6fe
Able to remove flash content, write new firmware from sd card, and jump to that new firmware. But its still not running completely
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 | 0:c3a652eff606 | 4 | #include "stm32f10x_usart.h" |
bonchenko | 0:c3a652eff606 | 5 | #include "main.h" |
bonchenko | 0:c3a652eff606 | 6 | |
bonchenko | 0:c3a652eff606 | 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 | 0:c3a652eff606 | 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 | 0:c3a652eff606 | 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 | 0:c3a652eff606 | 57 | if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000) |
bonchenko | 0:c3a652eff606 | 58 | { |
bonchenko | 0:c3a652eff606 | 59 | // Disable Timers |
bonchenko | 0:c3a652eff606 | 60 | Timer2_DeInit(); |
bonchenko | 0:c3a652eff606 | 61 | Timer3_DeInit(); |
bonchenko | 0:c3a652eff606 | 62 | |
bonchenko | 0:c3a652eff606 | 63 | /* Jump to user application */ |
bonchenko | 0:c3a652eff606 | 64 | JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4); |
bonchenko | 0:c3a652eff606 | 65 | Jump_To_Application = (pFunction) JumpAddress; |
bonchenko | 0:c3a652eff606 | 66 | |
bonchenko | 0:c3a652eff606 | 67 | /* Initialise user application's Stack Pointer */ |
bonchenko | 0:c3a652eff606 | 68 | __set_MSP(*(__IO uint32_t*) ApplicationAddress); |
bonchenko | 0:c3a652eff606 | 69 | Jump_To_Application(); |
bonchenko | 0:c3a652eff606 | 70 | } |
bonchenko | 0:c3a652eff606 | 71 | } |
bonchenko | 0:c3a652eff606 | 72 | |
bonchenko | 0:c3a652eff606 | 73 | while(1) |
bonchenko | 0:c3a652eff606 | 74 | { |
bonchenko | 0:c3a652eff606 | 75 | // Led1Flash(1, 5000); |
bonchenko | 0:c3a652eff606 | 76 | } |
bonchenko | 0:c3a652eff606 | 77 | } |
bonchenko | 0:c3a652eff606 | 78 | |
bonchenko | 0:c3a652eff606 | 79 | void RCC_Configuration() |
bonchenko | 0:c3a652eff606 | 80 | { |
bonchenko | 0:c3a652eff606 | 81 | /* GPIOA */ |
bonchenko | 0:c3a652eff606 | 82 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); |
bonchenko | 0:c3a652eff606 | 83 | |
bonchenko | 0:c3a652eff606 | 84 | /* GPIOB */ |
bonchenko | 0:c3a652eff606 | 85 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); |
bonchenko | 0:c3a652eff606 | 86 | |
bonchenko | 0:c3a652eff606 | 87 | /* GPIOC */ |
bonchenko | 0:c3a652eff606 | 88 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); |
bonchenko | 0:c3a652eff606 | 89 | |
bonchenko | 0:c3a652eff606 | 90 | /* GPIOD */ |
bonchenko | 0:c3a652eff606 | 91 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); |
bonchenko | 0:c3a652eff606 | 92 | |
bonchenko | 0:c3a652eff606 | 93 | /* GPIOE */ |
bonchenko | 0:c3a652eff606 | 94 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); |
bonchenko | 0:c3a652eff606 | 95 | |
bonchenko | 0:c3a652eff606 | 96 | /* AFIO */ |
bonchenko | 0:c3a652eff606 | 97 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); |
bonchenko | 0:c3a652eff606 | 98 | |
bonchenko | 0:c3a652eff606 | 99 | /* TIM2 */ |
bonchenko | 0:c3a652eff606 | 100 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); |
bonchenko | 0:c3a652eff606 | 101 | |
bonchenko | 0:c3a652eff606 | 102 | /* TIM3 */ |
bonchenko | 0:c3a652eff606 | 103 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); |
bonchenko | 0:c3a652eff606 | 104 | } |
bonchenko | 0:c3a652eff606 | 105 | |
bonchenko | 0:c3a652eff606 | 106 | void NVIC_Configuration(void) |
bonchenko | 0:c3a652eff606 | 107 | { |
bonchenko | 0:c3a652eff606 | 108 | #ifdef VECT_TAB_RAM |
bonchenko | 0:c3a652eff606 | 109 | /* Set the Vector Table base location at 0x20000000 */ |
bonchenko | 0:c3a652eff606 | 110 | NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); |
bonchenko | 0:c3a652eff606 | 111 | #else /* VECT_TAB_FLASH */ |
bonchenko | 0:c3a652eff606 | 112 | /* Set the Vector Table base location at 0x08000000 */ |
bonchenko | 0:c3a652eff606 | 113 | NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); |
bonchenko | 0:c3a652eff606 | 114 | #endif |
bonchenko | 0:c3a652eff606 | 115 | |
bonchenko | 0:c3a652eff606 | 116 | NVIC_InitTypeDef NVIC_InitStructure; |
bonchenko | 0:c3a652eff606 | 117 | |
bonchenko | 0:c3a652eff606 | 118 | // Enable the TIM3 Interrupt |
bonchenko | 0:c3a652eff606 | 119 | NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; |
bonchenko | 0:c3a652eff606 | 120 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; |
bonchenko | 0:c3a652eff606 | 121 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; |
bonchenko | 0:c3a652eff606 | 122 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
bonchenko | 0:c3a652eff606 | 123 | NVIC_Init(&NVIC_InitStructure); |
bonchenko | 0:c3a652eff606 | 124 | } |
bonchenko | 0:c3a652eff606 | 125 | |
bonchenko | 0:c3a652eff606 | 126 | void Timer2_Init(void) |
bonchenko | 0:c3a652eff606 | 127 | { |
bonchenko | 0:c3a652eff606 | 128 | // Time base configuration Timer2 clock |
bonchenko | 0:c3a652eff606 | 129 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
bonchenko | 0:c3a652eff606 | 130 | TIM_TimeBaseStructure.TIM_Period = 65535; |
bonchenko | 0:c3a652eff606 | 131 | TIM_TimeBaseStructure.TIM_Prescaler = 7199; |
bonchenko | 0:c3a652eff606 | 132 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV2; |
bonchenko | 0:c3a652eff606 | 133 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
bonchenko | 0:c3a652eff606 | 134 | TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); |
bonchenko | 0:c3a652eff606 | 135 | |
bonchenko | 0:c3a652eff606 | 136 | TIM_ARRPreloadConfig(TIM2, ENABLE); |
bonchenko | 0:c3a652eff606 | 137 | TIM_Cmd(TIM2, ENABLE); |
bonchenko | 0:c3a652eff606 | 138 | } |
bonchenko | 0:c3a652eff606 | 139 | |
bonchenko | 0:c3a652eff606 | 140 | void Timer3_Init(void) |
bonchenko | 0:c3a652eff606 | 141 | { |
bonchenko | 0:c3a652eff606 | 142 | // Time base configuration Timer3 clock |
bonchenko | 0:c3a652eff606 | 143 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
bonchenko | 0:c3a652eff606 | 144 | TIM_TimeBaseStructure.TIM_Period = 10; |
bonchenko | 0:c3a652eff606 | 145 | TIM_TimeBaseStructure.TIM_Prescaler = 7199; |
bonchenko | 0:c3a652eff606 | 146 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV2; |
bonchenko | 0:c3a652eff606 | 147 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
bonchenko | 0:c3a652eff606 | 148 | TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); |
bonchenko | 0:c3a652eff606 | 149 | |
bonchenko | 0:c3a652eff606 | 150 | TIM_ARRPreloadConfig(TIM3, ENABLE); |
bonchenko | 0:c3a652eff606 | 151 | TIM_ClearITPendingBit(TIM3, TIM_IT_Update); |
bonchenko | 0:c3a652eff606 | 152 | TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); |
bonchenko | 0:c3a652eff606 | 153 | TIM_Cmd(TIM3, ENABLE); |
bonchenko | 0:c3a652eff606 | 154 | } |
bonchenko | 0:c3a652eff606 | 155 | |
bonchenko | 0:c3a652eff606 | 156 | void Timer2_DeInit() |
bonchenko | 0:c3a652eff606 | 157 | { |
bonchenko | 0:c3a652eff606 | 158 | TIM_Cmd(TIM2, DISABLE); |
bonchenko | 0:c3a652eff606 | 159 | TIM_DeInit(TIM2); |
bonchenko | 0:c3a652eff606 | 160 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, DISABLE); |
bonchenko | 0:c3a652eff606 | 161 | } |
bonchenko | 0:c3a652eff606 | 162 | |
bonchenko | 0:c3a652eff606 | 163 | void Timer3_DeInit(void) |
bonchenko | 0:c3a652eff606 | 164 | { |
bonchenko | 0:c3a652eff606 | 165 | TIM_Cmd(TIM3, DISABLE); |
bonchenko | 0:c3a652eff606 | 166 | TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE); |
bonchenko | 0:c3a652eff606 | 167 | TIM_ARRPreloadConfig(TIM3, DISABLE); |
bonchenko | 0:c3a652eff606 | 168 | NVIC_DisableIRQ(TIM3_IRQn); |
bonchenko | 0:c3a652eff606 | 169 | TIM_DeInit(TIM3); |
bonchenko | 0:c3a652eff606 | 170 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, DISABLE); |
bonchenko | 0:c3a652eff606 | 171 | } |
bonchenko | 0:c3a652eff606 | 172 | |
bonchenko | 0:c3a652eff606 | 173 | void SD_LowLevel_DeInit(void) |
bonchenko | 0:c3a652eff606 | 174 | { |
bonchenko | 0:c3a652eff606 | 175 | GPIO_InitTypeDef GPIO_InitStructure; |
bonchenko | 0:c3a652eff606 | 176 | |
bonchenko | 0:c3a652eff606 | 177 | SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */ |
bonchenko | 0:c3a652eff606 | 178 | SPI_I2S_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */ |
bonchenko | 0:c3a652eff606 | 179 | |
bonchenko | 0:c3a652eff606 | 180 | /*!< SD_SPI Periph clock disable */ |
bonchenko | 0:c3a652eff606 | 181 | RCC_APB2PeriphClockCmd(SD_SPI_CLK, DISABLE); |
bonchenko | 0:c3a652eff606 | 182 | |
bonchenko | 0:c3a652eff606 | 183 | /*!< Configure SD_SPI pins: SCK */ |
bonchenko | 0:c3a652eff606 | 184 | GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN; |
bonchenko | 0:c3a652eff606 | 185 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; |
bonchenko | 0:c3a652eff606 | 186 | GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 187 | |
bonchenko | 0:c3a652eff606 | 188 | /*!< Configure SD_SPI pins: MISO */ |
bonchenko | 0:c3a652eff606 | 189 | GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN; |
bonchenko | 0:c3a652eff606 | 190 | GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 191 | |
bonchenko | 0:c3a652eff606 | 192 | /*!< Configure SD_SPI pins: MOSI */ |
bonchenko | 0:c3a652eff606 | 193 | GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN; |
bonchenko | 0:c3a652eff606 | 194 | GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 195 | |
bonchenko | 0:c3a652eff606 | 196 | /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */ |
bonchenko | 0:c3a652eff606 | 197 | GPIO_InitStructure.GPIO_Pin = SD_CS_PIN; |
bonchenko | 0:c3a652eff606 | 198 | GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 199 | |
bonchenko | 0:c3a652eff606 | 200 | /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ |
bonchenko | 0:c3a652eff606 | 201 | GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; |
bonchenko | 0:c3a652eff606 | 202 | GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 203 | } |
bonchenko | 0:c3a652eff606 | 204 | |
bonchenko | 0:c3a652eff606 | 205 | |
bonchenko | 0:c3a652eff606 | 206 | void SD_LowLevel_Init(void) |
bonchenko | 0:c3a652eff606 | 207 | { |
bonchenko | 0:c3a652eff606 | 208 | GPIO_InitTypeDef GPIO_InitStructure; |
bonchenko | 0:c3a652eff606 | 209 | SPI_InitTypeDef SPI_InitStructure; |
bonchenko | 0:c3a652eff606 | 210 | |
bonchenko | 0:c3a652eff606 | 211 | /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO |
bonchenko | 0:c3a652eff606 | 212 | and SD_SPI_SCK_GPIO Periph clock enable */ |
bonchenko | 0:c3a652eff606 | 213 | RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK | |
bonchenko | 0:c3a652eff606 | 214 | SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE); |
bonchenko | 0:c3a652eff606 | 215 | |
bonchenko | 0:c3a652eff606 | 216 | /*!< SD_SPI Periph clock enable */ |
bonchenko | 0:c3a652eff606 | 217 | RCC_APB2PeriphClockCmd(SD_SPI_CLK, ENABLE); |
bonchenko | 0:c3a652eff606 | 218 | |
bonchenko | 0:c3a652eff606 | 219 | /*!< Configure SD_SPI pins: SCK */ |
bonchenko | 0:c3a652eff606 | 220 | GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN; |
bonchenko | 0:c3a652eff606 | 221 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
bonchenko | 0:c3a652eff606 | 222 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
bonchenko | 0:c3a652eff606 | 223 | GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 224 | |
bonchenko | 0:c3a652eff606 | 225 | /*!< Configure SD_SPI pins: MOSI */ |
bonchenko | 0:c3a652eff606 | 226 | GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN; |
bonchenko | 0:c3a652eff606 | 227 | GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 228 | |
bonchenko | 0:c3a652eff606 | 229 | /*!< Configure SD_SPI pins: MISO */ |
bonchenko | 0:c3a652eff606 | 230 | GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN; |
bonchenko | 0:c3a652eff606 | 231 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; |
bonchenko | 0:c3a652eff606 | 232 | GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 233 | |
bonchenko | 0:c3a652eff606 | 234 | /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */ |
bonchenko | 0:c3a652eff606 | 235 | GPIO_InitStructure.GPIO_Pin = SD_CS_PIN; |
bonchenko | 0:c3a652eff606 | 236 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
bonchenko | 0:c3a652eff606 | 237 | GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 238 | |
bonchenko | 0:c3a652eff606 | 239 | /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ |
bonchenko | 0:c3a652eff606 | 240 | GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; |
bonchenko | 0:c3a652eff606 | 241 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; |
bonchenko | 0:c3a652eff606 | 242 | GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure); |
bonchenko | 0:c3a652eff606 | 243 | |
bonchenko | 0:c3a652eff606 | 244 | /*!< SD_SPI Config */ |
bonchenko | 0:c3a652eff606 | 245 | SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; |
bonchenko | 0:c3a652eff606 | 246 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master; |
bonchenko | 0:c3a652eff606 | 247 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; |
bonchenko | 0:c3a652eff606 | 248 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; |
bonchenko | 0:c3a652eff606 | 249 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; |
bonchenko | 0:c3a652eff606 | 250 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; |
bonchenko | 0:c3a652eff606 | 251 | SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; |
bonchenko | 0:c3a652eff606 | 252 | |
bonchenko | 0:c3a652eff606 | 253 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; |
bonchenko | 0:c3a652eff606 | 254 | SPI_InitStructure.SPI_CRCPolynomial = 7; |
bonchenko | 0:c3a652eff606 | 255 | SPI_Init(SD_SPI, &SPI_InitStructure); |
bonchenko | 0:c3a652eff606 | 256 | |
bonchenko | 0:c3a652eff606 | 257 | SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */ |
bonchenko | 0:c3a652eff606 | 258 | } |
bonchenko | 0:c3a652eff606 | 259 | |
bonchenko | 0:c3a652eff606 | 260 | #ifdef USE_FULL_ASSERT |
bonchenko | 0:c3a652eff606 | 261 | |
bonchenko | 0:c3a652eff606 | 262 | /** |
bonchenko | 0:c3a652eff606 | 263 | * @brief Reports the name of the source file and the source line number |
bonchenko | 0:c3a652eff606 | 264 | * where the assert_param error has occurred. |
bonchenko | 0:c3a652eff606 | 265 | * @param file: pointer to the source file name |
bonchenko | 0:c3a652eff606 | 266 | * @param line: assert_param error line source number |
bonchenko | 0:c3a652eff606 | 267 | * @retval None |
bonchenko | 0:c3a652eff606 | 268 | */ |
bonchenko | 0:c3a652eff606 | 269 | void assert_failed(uint8_t* file, uint32_t line) |
bonchenko | 0:c3a652eff606 | 270 | { |
bonchenko | 0:c3a652eff606 | 271 | /* User can add his own implementation to report the file name and line number, |
bonchenko | 0:c3a652eff606 | 272 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
bonchenko | 0:c3a652eff606 | 273 | |
bonchenko | 0:c3a652eff606 | 274 | /* Infinite loop */ |
bonchenko | 0:c3a652eff606 | 275 | while (1) |
bonchenko | 0:c3a652eff606 | 276 | { |
bonchenko | 0:c3a652eff606 | 277 | } |
bonchenko | 0:c3a652eff606 | 278 | } |
bonchenko | 0:c3a652eff606 | 279 | #endif |
bonchenko | 0:c3a652eff606 | 280 | |
bonchenko | 0:c3a652eff606 | 281 | /* |
bonchenko | 0:c3a652eff606 | 282 | * Minimal __assert_func used by the assert() macro |
bonchenko | 0:c3a652eff606 | 283 | * */ |
bonchenko | 0:c3a652eff606 | 284 | void __assert_func(const char *file, int line, const char *func, const char *failedexpr) |
bonchenko | 0:c3a652eff606 | 285 | { |
bonchenko | 0:c3a652eff606 | 286 | while(1) |
bonchenko | 0:c3a652eff606 | 287 | {} |
bonchenko | 0:c3a652eff606 | 288 | } |
bonchenko | 0:c3a652eff606 | 289 | |
bonchenko | 0:c3a652eff606 | 290 | /* |
bonchenko | 0:c3a652eff606 | 291 | * Minimal __assert() uses __assert__func() |
bonchenko | 0:c3a652eff606 | 292 | * */ |
bonchenko | 0:c3a652eff606 | 293 | void __assert(const char *file, int line, const char *failedexpr) |
bonchenko | 0:c3a652eff606 | 294 | { |
bonchenko | 0:c3a652eff606 | 295 | __assert_func (file, line, NULL, failedexpr); |
bonchenko | 0:c3a652eff606 | 296 | } |
bonchenko | 0:c3a652eff606 | 297 | |
bonchenko | 0:c3a652eff606 | 298 | #ifdef USE_SEE |
bonchenko | 0:c3a652eff606 | 299 | #ifndef USE_DEFAULT_TIMEOUT_CALLBACK |
bonchenko | 0:c3a652eff606 | 300 | /** |
bonchenko | 0:c3a652eff606 | 301 | * @brief Basic management of the timeout situation. |
bonchenko | 0:c3a652eff606 | 302 | * @param None. |
bonchenko | 0:c3a652eff606 | 303 | * @retval sEE_FAIL. |
bonchenko | 0:c3a652eff606 | 304 | */ |
bonchenko | 0:c3a652eff606 | 305 | uint32_t sEE_TIMEOUT_UserCallback(void) |
bonchenko | 0:c3a652eff606 | 306 | { |
bonchenko | 0:c3a652eff606 | 307 | /* Return with error code */ |
bonchenko | 0:c3a652eff606 | 308 | return sEE_FAIL; |
bonchenko | 0:c3a652eff606 | 309 | } |
bonchenko | 0:c3a652eff606 | 310 | #endif |
bonchenko | 0:c3a652eff606 | 311 | #endif /* USE_SEE */ |