Ignore:
Timestamp:
Oct 15, 2026, 2:21:26 PM (3 weeks ago)
Author:
Zed
Message:

This is a commit where debugging of the main App is possible and RTT also works (BOOT0 = Low, BOOT1 = LOW and then attach the SES Debugger).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/firmware/App/SES/Core/Tasks/Src/sdmmcTask.cpp

    r33 r34  
    1212#endif
    1313
     14enum class SdCardState
     15{
     16    NotPresent,
     17    Inserted,
     18    Initialized,
     19    Deinitialized,
     20    Error
     21};
     22
     23constexpr unsigned SD_PRESENCE_SCAN_RATE_ms = 50U;
    1424constexpr unsigned MEDIA_CLOSED = 1U;
    1525constexpr unsigned MEDIA_OPENED = 0U;
    … …  
    1929FX_MEDIA sdio_disk;                                                                                                                             // Define FileX global data structures
    2030static UINT media_status;
     31static SdCardState sdCurrentState = SdCardState::NotPresent;
     32static SdCardState sdLastState = SdCardState::NotPresent;
    2133
    2234
    2335void StartSDMMCTask(void* arg)
    2436{
    25         UINT sd_status = FX_SUCCESS;
     37        static int insertionDetectionCnt, extractionDetectionCnt;
     38
     39        while(1)
     40        {
     41                switch(sdCurrentState)
     42                {
     43                        case SdCardState::NotPresent:
     44                                if (HAL_GPIO_ReadPin(SD_PRESENCE_GPIO_Port, SD_PRESENCE_Pin) == SD_PRESENT)
     45                                {
     46                                        extractionDetectionCnt = 0;
     47                                        if (insertionDetectionCnt > (1000U / SD_PRESENCE_SCAN_RATE_ms))
     48                                        {       // Here we can be sure that SD-card is really present
     49                                                if (sdLastState == SdCardState::NotPresent)
     50                                                {
     51                                                        sdLastState = sdCurrentState = SdCardState::Inserted;
     52                                                        printf("SD-card was inserted\n");
     53                                                }
     54                                        }
     55                                        else
     56                                                ++insertionDetectionCnt;
     57                                }
     58                                else
     59                                {
     60                                        insertionDetectionCnt = 0;
     61                                        printf("SD-card extraction detected\n");
     62                                }
     63                                break;
     64
     65                        case SdCardState::Inserted:
     66                                if (HAL_GPIO_ReadPin(SD_PRESENCE_GPIO_Port, SD_PRESENCE_Pin) == SD_NOT_PRESENT)
     67                                {
     68                                        extractionDetectionCnt = 0;
     69                                        if (insertionDetectionCnt > (1000U / SD_PRESENCE_SCAN_RATE_ms))
     70                                        {       // Here we can be sure that SD-card is really present
     71                                                if (sdLastState == SdCardState::NotPresent)
     72                                                {
     73                                                        sdLastState = sdCurrentState = SdCardState::Inserted;
     74                                                        printf("SD-card was inserted\n");
     75                                                }
     76                                        }
     77                                        else
     78                                                ++insertionDetectionCnt;
     79                                }
     80                                else
     81                                {
     82                                        insertionDetectionCnt = 0;
     83                                        printf("SD-card extraction detected\n");
     84                                }
     85                                break;
     86
     87                        case SdCardState::Initialized:
     88                                break;
     89
     90                        case SdCardState::Deinitialized:
     91                                break;
     92
     93                        case SdCardState::Error:
     94                                break;
     95                }
     96                osDelay(SD_PRESENCE_SCAN_RATE_ms);
     97        }
     98
     99        /*UINT sd_status = FX_SUCCESS;
    26100        fx_system_initialize();                                                                                                         // Initialize FileX
    27101
    … …  
    36110        {
    37111                Error_Handler();
    38         }
     112        }*/
    39113
    40114
    41115        while(1)
    42116        {
    43                 HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);
    44117                osDelay(1000U);
    45                 printf("Programm is running at %u MHz\n", SystemCoreClock / 1000000U);
    46 
    47118        }
    48119}
Note: See TracChangeset for help on using the changeset viewer.