簡體   English   中英

使用STM32處理器與SD卡通信 - SDIO協議

[英]Communication with SD Card with STM32 Processor - SDIO protocol

我正在使用基於微控制器STM32F401RET6的Nucleo F401Re板。 我連接到主板上的Micro SD插槽,並有興趣將數據寫入SD卡並從中讀取數據。 我使用軟件STM32CubeX生成代碼,特別是帶有內置函數的SD庫。 我試着編寫一個簡單的代碼,將一個數組寫入一個特定的數組,然后嘗試讀取相同的數據。 代碼如下:

  int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_SDIO_SD_Init();

  char buffer[14] = "Hello, world\n";
  uint32_t to_send[512] ; // Te
  uint32_t to_receive[512];
  uint64_t address = 150; 
  HAL_SD_WriteBlocks(&hsd, to_send, address, 512, 1);
  HAL_SD_ReadBlocks(&hsd, to_receive, address, 512, 1);


  while (1)
  {
      HAL_UART_Transmit(&huart2, (uint8_t *)buffer, 14, 1000);
      HAL_UART_Transmit(&huart2, (uint8_t *)to_receive, 512, 1000);

}

代碼在函數HAL_Init()的中間停止,我收到以下消息:

The stack pointer for stack 'CSTACK' (currently 0x1FFFFD30) is outside the stack range (0x20000008 to 0x20000408) 

當我不使用函數HAL_SD_WriteBlocks()或HAL_SD_ReadBlocks()時,不會出現此消息。 如果有人已經遇到這個問題而且知道如何修復它,那么一些幫助可以幫我省錢。 如果需要,我可以添加其余的代碼。

你使用了太多的堆棧空間。 您可以在鏈接描述文件中調整分配的堆棧空間,並在需要時增加它。

但是,您可以通過不同地編寫代碼來避免這種情況。 在上面的示例中,您將在堆棧上分配大緩沖區(4kB)。 除非絕對必要,否則不要這樣做。 我是指這個:

int main(void) {
  // ...
  uint32_t to_send[512];
  uint32_t to_receive[512];
  // ...
}

相反,像這樣分配你的緩沖區:

uint32_t to_send[512];
uint32_t to_receive[512];

int main(void) {
  // ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM