76 HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
117 printf(
"\x1b[2J\x1b[H");
118 printf(
"Hello World!!!!!\r\n");
124#ifdef W25Q_VALIDATION_TEST_ENABLE
127 uint32_t jedecId = 0;
128 if (w25qReadJEDECID(&jedecId)) {
129 printf(
"W25Q flash detected, JEDEC ID: 0x%06lX\r\n", (
unsigned long)jedecId);
131 printf(
"W25Q flash SPI read failed after Init() succeeded -- check for a loose connection\r\n");
137 const uint32_t demoAddr = 0x000000;
138 const char demoMessage[] =
"Hello from the H753, stored in W25Q flash!";
140 if (!w25qEraseSector(demoAddr)) {
141 printf(
"Demo erase failed\r\n");
142 }
else if (!w25qWriteBuffer(demoAddr, (
const uint8_t *)demoMessage,
sizeof(demoMessage))) {
143 printf(
"Demo write failed\r\n");
145 uint8_t readBack[
sizeof(demoMessage)] = { 0 };
146 if (!w25qReadBuffer(demoAddr, readBack,
sizeof(readBack))) {
147 printf(
"Demo read failed\r\n");
149 printf(
"Wrote: \"%s\"\r\n", demoMessage);
150 printf(
"Read : \"%s\"\r\n", readBack);
151 if (memcmp(demoMessage, readBack,
sizeof(demoMessage)) == 0) {
152 printf(
"Read-back matches -- write/read round trip OK\r\n");
154 printf(
"Read-back MISMATCH\r\n");
160 printf(
"W25Q flash NOT detected -- check wiring\r\n");
182 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
183 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
187 HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
191 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
193 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
198 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
199 RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
200 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
201 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
202 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
203 RCC_OscInitStruct.PLL.PLLM = 4;
204 RCC_OscInitStruct.PLL.PLLN = 60;
205 RCC_OscInitStruct.PLL.PLLP = 2;
206 RCC_OscInitStruct.PLL.PLLQ = 5;
207 RCC_OscInitStruct.PLL.PLLR = 2;
208 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
209 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
210 RCC_OscInitStruct.PLL.PLLFRACN = 0;
211 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
218 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
219 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
220 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
221 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
222 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
223 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
224 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
225 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
226 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
227 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
229 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
251 hspi1.Instance = SPI1;
252 hspi1.Init.Mode = SPI_MODE_MASTER;
253 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
254 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
255 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
256 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
257 hspi1.Init.NSS = SPI_NSS_SOFT;
258 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
259 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
260 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
261 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
262 hspi1.Init.CRCPolynomial = 0x0;
263 hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
264 hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
265 hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
266 hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
267 hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
268 hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
269 hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
270 hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
271 hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
272 hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;
273 if (HAL_SPI_Init(&hspi1) != HAL_OK)
298 huart1.Instance = USART1;
299 huart1.Init.BaudRate = 19200;
300 huart1.Init.WordLength = UART_WORDLENGTH_8B;
301 huart1.Init.StopBits = UART_STOPBITS_1;
302 huart1.Init.Parity = UART_PARITY_NONE;
303 huart1.Init.Mode = UART_MODE_TX_RX;
304 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
305 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
306 huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
307 huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
308 huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
309 if (HAL_UART_Init(&huart1) != HAL_OK)
313 if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
317 if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
321 if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
338 GPIO_InitTypeDef GPIO_InitStruct = {0};
344 __HAL_RCC_GPIOC_CLK_ENABLE();
345 __HAL_RCC_GPIOH_CLK_ENABLE();
346 __HAL_RCC_GPIOA_CLK_ENABLE();
347 __HAL_RCC_GPIOB_CLK_ENABLE();
350 HAL_GPIO_WritePin(WQ25_CS_GPIO_Port, WQ25_CS_Pin, GPIO_PIN_RESET);
353 GPIO_InitStruct.Pin = WQ25_CS_Pin;
354 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
355 GPIO_InitStruct.Pull = GPIO_NOPULL;
356 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
357 HAL_GPIO_Init(WQ25_CS_GPIO_Port, &GPIO_InitStruct);
static void MX_SPI1_Init(void)
SPI1 Initialization Function.
static void MX_USART1_UART_Init(void)
USART1 Initialization Function.
void SystemClock_Config(void)
System Clock Configuration.
int main(void)
The application entry point.
void _Error_Handler(const char *file, int line)
This function is executed in case of error occurrence.
static void MX_GPIO_Init(void)
GPIO Initialization Function.
: Header for main.c file. This file contains the common defines of the application.