|
|
@@ -1,20 +1,20 @@
|
|
|
/* USER CODE BEGIN Header */
|
|
|
/**
|
|
|
- ******************************************************************************
|
|
|
- * @file : main.c
|
|
|
- * @brief : Main program body
|
|
|
- ******************************************************************************
|
|
|
- * @attention
|
|
|
- *
|
|
|
- * Copyright (c) 2025 STMicroelectronics.
|
|
|
- * All rights reserved.
|
|
|
- *
|
|
|
- * This software is licensed under terms that can be found in the LICENSE file
|
|
|
- * in the root directory of this software component.
|
|
|
- * If no LICENSE file comes with this software, it is provided AS-IS.
|
|
|
- *
|
|
|
- ******************************************************************************
|
|
|
- */
|
|
|
+ ******************************************************************************
|
|
|
+ * @file : main.c
|
|
|
+ * @brief : Main program body
|
|
|
+ ******************************************************************************
|
|
|
+ * @attention
|
|
|
+ *
|
|
|
+ * Copyright (c) 2025 STMicroelectronics.
|
|
|
+ * All rights reserved.
|
|
|
+ *
|
|
|
+ * This software is licensed under terms that can be found in the LICENSE file
|
|
|
+ * in the root directory of this software component.
|
|
|
+ * If no LICENSE file comes with this software, it is provided AS-IS.
|
|
|
+ *
|
|
|
+ ******************************************************************************
|
|
|
+ */
|
|
|
/* USER CODE END Header */
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
#include "main.h"
|
|
|
@@ -68,102 +68,41 @@ static void MX_TIM1_Init(void);
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
|
|
#include "at45db041.h"
|
|
|
-
|
|
|
+#include <stdint.h>
|
|
|
#include <stdio.h>
|
|
|
+#include <string.h>
|
|
|
|
|
|
-typedef struct {
|
|
|
- uint8_t counter;
|
|
|
- uint8_t is_test;
|
|
|
-} TestData;
|
|
|
+extern UART_HandleTypeDef huart2;
|
|
|
|
|
|
int _write(int file, char *ptr, int len) {
|
|
|
- HAL_UART_Transmit(&huart2, (uint8_t*)ptr, len, HAL_MAX_DELAY);
|
|
|
- return len;
|
|
|
+ HAL_UART_Transmit(&huart2, (uint8_t *)ptr, len, HAL_MAX_DELAY);
|
|
|
+ return len;
|
|
|
}
|
|
|
|
|
|
-// ---
|
|
|
-#define PAGE_SIZE 256
|
|
|
-#define RX_BUF_SIZE 1
|
|
|
+#define RX_DATA_SIZE 4096
|
|
|
+#define RC_DATA_SIZE 256
|
|
|
|
|
|
-uint8_t rx_buf[RX_BUF_SIZE];
|
|
|
-uint8_t file_data[256];
|
|
|
-uint32_t file_len = 0;
|
|
|
+typedef struct Packet {
|
|
|
+ uint8_t header[2];
|
|
|
+ uint8_t data[RC_DATA_SIZE];
|
|
|
+} Packet;
|
|
|
|
|
|
-void start_uart_rx(void)
|
|
|
-{
|
|
|
- HAL_UARTEx_ReceiveToIdle_DMA(&huart2, rx_buf, RX_BUF_SIZE);
|
|
|
-}
|
|
|
+static uint8_t rx_buffer[258];
|
|
|
+static uint8_t rx_buffer_idx;
|
|
|
|
|
|
-/* Этот колб�?к вызывает�?�? при IDLE */
|
|
|
-void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
|
|
-{
|
|
|
- if (huart->Instance == USART2)
|
|
|
- {
|
|
|
- // Копируем данные в общий буфер
|
|
|
- memcpy(&file_data[file_len], rx_buf, Size);
|
|
|
- file_len += Size;
|
|
|
+static uint8_t tmp_buffer[258];
|
|
|
|
|
|
- printf("Received chunk: %u bytes (total: %lu)\r\n", Size, file_len);
|
|
|
+void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) {
|
|
|
+ // memcpy(rx_buffer + (RC_DATA_SIZE * rc_idx), rc_buffer, RC_DATA_SIZE);
|
|
|
|
|
|
- start_uart_rx();
|
|
|
- }
|
|
|
-}
|
|
|
+ // rc_idx += 1;
|
|
|
+ // if (rc_idx >= RX_DATA_SIZE) {
|
|
|
+ // rc_idx = 0;
|
|
|
+ // }
|
|
|
|
|
|
-void uart_receive_audio(void)
|
|
|
-{
|
|
|
- printf("=== UART Flash Loader Ready ===\r\n");
|
|
|
- printf("Send your audio file now...\r\n");
|
|
|
-
|
|
|
- start_uart_rx();
|
|
|
-
|
|
|
- while (1)
|
|
|
- {
|
|
|
-// buffer[total_bytes] = tmp_byte;
|
|
|
-// total_bytes += 1;
|
|
|
-// if (total_bytes >= 256) {
|
|
|
-// total_bytes = 0;
|
|
|
-// for (int i = 0; i < total_bytes; i += 1) {
|
|
|
-// printf("%u", buffer[i]);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// if (HAL_UART_Receive(&huart2, &byte, 1, 10) == HAL_OK)
|
|
|
-// {
|
|
|
-//
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// // е�?ли 2 �?екунды тишины — значит передача закончила�?ь
|
|
|
-// if (HAL_GetTick() - last_rx_time > 2000)
|
|
|
-// {
|
|
|
-// if (index > 0)
|
|
|
-// {
|
|
|
-// // запи�?ываем неполную �?траницу
|
|
|
-//// at45db_write(page, page_buffer, index);
|
|
|
-//// at45db_wait_ready();
|
|
|
-// total_bytes += index;
|
|
|
-// }
|
|
|
-//
|
|
|
-// printf("Upload complete. Total %lu bytes written.\r\n", total_bytes);
|
|
|
-//
|
|
|
-// {
|
|
|
-// printf("Data read:\r\n");
|
|
|
-// for (int i = 0; i < page_buffer / 256; i++)
|
|
|
-// {
|
|
|
-// printf("%02X ", page_buffer[i]);
|
|
|
-// }
|
|
|
-// printf("\r\n");
|
|
|
-// }
|
|
|
-//
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
- }
|
|
|
+ HAL_UART_Receive_DMA(&huart2, rx_buffer, sizeof(rx_buffer));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/* USER CODE END 0 */
|
|
|
|
|
|
/**
|
|
|
@@ -200,82 +139,17 @@ int main(void)
|
|
|
MX_TIM1_Init();
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
|
|
- at45db_init();
|
|
|
-
|
|
|
-// {
|
|
|
-// uint8_t buffer[1024] = {0};
|
|
|
-//
|
|
|
-// printf("Data read:\r\n");
|
|
|
-// for (int i = 0; i < sizeof(buffer); i++)
|
|
|
-// {
|
|
|
-// at45db_read(i, buffer, sizeof(buffer));
|
|
|
-// at45db_wait_ready();
|
|
|
-// printf("%02X ", buffer[i]);
|
|
|
-// }
|
|
|
-// printf("\r\n");
|
|
|
-// }
|
|
|
-
|
|
|
- uart_receive_audio();
|
|
|
-
|
|
|
-// // подождём, пока чип готов
|
|
|
-// at45db_wait_ready();
|
|
|
-//
|
|
|
-// // �?тираем �?траницу (необ�?зательно, е�?ли 0xFF)
|
|
|
-//// at45db_page_erase(0);
|
|
|
-// at45db_wait_ready();
|
|
|
-//
|
|
|
-// TestData test_data = {
|
|
|
-// .counter = 4,
|
|
|
-// .is_test = 5,
|
|
|
-// };
|
|
|
-//
|
|
|
-// at45db_write(0, (uint8_t*)&test_data, sizeof(test_data));
|
|
|
-// at45db_wait_ready();
|
|
|
-//
|
|
|
-// at45db_read(0, (uint8_t*)&test_data, sizeof(test_data));
|
|
|
-// printf("Read back: %d, %d\r\n", test_data.counter, test_data.is_test);
|
|
|
-// at45db_wait_ready();
|
|
|
-//
|
|
|
-// // читаем первые 16 байт дл�? контрол�?
|
|
|
-// uint8_t buffer[16] = {0};
|
|
|
-// at45db_read(0, buffer, sizeof(buffer));
|
|
|
-// printf("Data read:\r\n");
|
|
|
-// for (int i = 0; i < sizeof(buffer); i++)
|
|
|
-// printf("%02X ", buffer[i]);
|
|
|
-// printf("\r\n");
|
|
|
+ HAL_UART_Receive_DMA(&huart2, rx_buffer, sizeof(rx_buffer));
|
|
|
|
|
|
+// at45db_init();
|
|
|
+// uart_receive_loop();
|
|
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
/* Infinite loop */
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
- while (1)
|
|
|
- {
|
|
|
-// printf("=== AT45DB041E Test ===\r\n");
|
|
|
-//
|
|
|
-// uint8_t is_ready = at45db_is_ready();
|
|
|
-//
|
|
|
-// if (is_ready)
|
|
|
-// {
|
|
|
-// printf("Device READY\r\n");
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// printf("Device BUSY\r\n");
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-//
|
|
|
-// dev_id_t id = at45db_read_man_id();
|
|
|
-// if (id == DEV_ID_OK)
|
|
|
-// printf("Manufacturer ID OK\r\n");
|
|
|
-// else
|
|
|
-// printf("Manufacturer ID ERROR\r\n");
|
|
|
-//
|
|
|
-// uint8_t status = at45db_get_status();
|
|
|
-// printf("Status: 0x%02X\r\n", status);
|
|
|
-// printf("Page size: %u bytes\r\n", at45db_get_page_size());
|
|
|
-
|
|
|
- HAL_Delay(1);
|
|
|
+ while (1) {
|
|
|
+ HAL_Delay(10);
|
|
|
|
|
|
/* USER CODE END WHILE */
|
|
|
|
|
|
@@ -550,8 +424,7 @@ void Error_Handler(void)
|
|
|
/* USER CODE BEGIN Error_Handler_Debug */
|
|
|
/* User can add his own implementation to report the HAL error return state */
|
|
|
__disable_irq();
|
|
|
- while (1)
|
|
|
- {
|
|
|
+ while (1) {
|
|
|
}
|
|
|
/* USER CODE END Error_Handler_Debug */
|
|
|
}
|
|
|
@@ -567,8 +440,9 @@ void Error_Handler(void)
|
|
|
void assert_failed(uint8_t *file, uint32_t line)
|
|
|
{
|
|
|
/* USER CODE BEGIN 6 */
|
|
|
- /* User can add his own implementation to report the file name and line number,
|
|
|
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
|
+ /* User can add his own implementation to report the file name and line
|
|
|
+ number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file,
|
|
|
+ line) */
|
|
|
/* USER CODE END 6 */
|
|
|
}
|
|
|
#endif /* USE_FULL_ASSERT */
|