Mercurial > public > ostc4
comparison BootLoader/Src/tComm_mini.c @ 1044:9d9d506a82d3 BootloaderOstc5
Bugfix BT init sequence:
Some older steps which were related to OSTC were deactivated (to be removed) and a command for the second echo step was missing. in addition two stps for switching the power of the modul before the sequence starts have been added to have a defined starting point.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 02 Nov 2025 19:30:58 +0100 |
| parents | 0dd92e9b70a2 |
| children | 493a5903ec20 |
comparison
equal
deleted
inserted
replaced
| 1016:0dd92e9b70a2 | 1044:9d9d506a82d3 |
|---|---|
| 72 #include "ostc.h" | 72 #include "ostc.h" |
| 73 | 73 |
| 74 #include "base_bootloader.h" | 74 #include "base_bootloader.h" |
| 75 #include "firmwareEraseProgram.h" | 75 #include "firmwareEraseProgram.h" |
| 76 #include "text_multilanguage.h" | 76 #include "text_multilanguage.h" |
| 77 #include "tInfoBootloader.h" | |
| 77 | 78 |
| 78 #ifdef SPECIALPROGRAMM | 79 #ifdef SPECIALPROGRAMM |
| 79 # include "firmwareEraseProgram.h" | 80 # include "firmwareEraseProgram.h" |
| 80 #endif | 81 #endif |
| 81 #include <stdlib.h> | 82 #include <stdlib.h> |
| 558 count += 64; | 559 count += 64; |
| 559 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | 560 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
| 560 break; | 561 break; |
| 561 | 562 |
| 562 case 0x73: | 563 case 0x73: |
| 563 answer = receive_update_flex(0); | 564 answer = receive_update_flex(1); |
| 564 if(answer == 0) | 565 if(answer == 0) |
| 565 return 0; | 566 return 0; |
| 566 else if(answer == 2) // 2 = RTE without bootToBootloader | 567 else if(answer == 2) // 2 = RTE without bootToBootloader |
| 567 { | 568 { |
| 568 aTxBuffer[0] = 0xFF; | 569 aTxBuffer[0] = 0xFF; |
| 1675 } | 1676 } |
| 1676 | 1677 |
| 1677 | 1678 |
| 1678 void tComm_StartBlueModBaseInit() | 1679 void tComm_StartBlueModBaseInit() |
| 1679 { | 1680 { |
| 1680 BmTmpConfig = BM_INIT_TRIGGER_ON; | 1681 BmTmpConfig = BM_INIT_POWEROFF; |
| 1681 } | 1682 } |
| 1682 | 1683 |
| 1683 | 1684 |
| 1684 uint8_t tComm_GetBTCmdStr(BTCmd cmdId, char* pCmdStr) | 1685 uint8_t tComm_GetBTCmdStr(BTCmd cmdId, char* pCmdStr) |
| 1685 { | 1686 { |
| 1744 return ret; | 1745 return ret; |
| 1745 } | 1746 } |
| 1746 | 1747 |
| 1747 void tComm_StartBlueModConfig() | 1748 void tComm_StartBlueModConfig() |
| 1748 { | 1749 { |
| 1750 #ifdef OSTC4_HW | |
| 1749 uint8_t answer = HAL_OK; | 1751 uint8_t answer = HAL_OK; |
| 1750 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; | 1752 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; |
| 1751 uint8_t index = 0; | 1753 uint8_t index = 0; |
| 1754 | |
| 1752 | 1755 |
| 1753 BmTmpConfig = BM_CONFIG_ECHO; | 1756 BmTmpConfig = BM_CONFIG_ECHO; |
| 1754 do /* flush RX buffer */ | 1757 do /* flush RX buffer */ |
| 1755 { | 1758 { |
| 1756 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&RxBuffer[index], 1, 10); | 1759 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&RxBuffer[index], 1, 10); |
| 1757 if(index < UART_CMD_BUF_SIZE) index++; | 1760 if(index < UART_CMD_BUF_SIZE) index++; |
| 1758 }while(answer == HAL_OK); | 1761 }while(answer == HAL_OK); |
| 1762 #else | |
| 1763 BmTmpConfig = BM_CONFIG_DONE; | |
| 1764 #endif | |
| 1759 } | 1765 } |
| 1760 | 1766 |
| 1761 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) | 1767 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) |
| 1762 { | 1768 { |
| 1763 if(ticksstart <= ticksnow) | 1769 if(ticksstart <= ticksnow) |
| 1766 return 0xFFFFFFFF - ticksstart + ticksnow; | 1772 return 0xFFFFFFFF - ticksstart + ticksnow; |
| 1767 } | 1773 } |
| 1768 | 1774 |
| 1769 uint8_t tComm_HandleBlueModConfig() | 1775 uint8_t tComm_HandleBlueModConfig() |
| 1770 { | 1776 { |
| 1777 #ifdef OSTC4_HW | |
| 1771 static uint8_t RestartModule = 1; /* used to do power off / on cycle */ | 1778 static uint8_t RestartModule = 1; /* used to do power off / on cycle */ |
| 1779 #endif | |
| 1772 static uint8_t ConfigRetryCnt = 0; /* Retry count without power cycle */ | 1780 static uint8_t ConfigRetryCnt = 0; /* Retry count without power cycle */ |
| 1773 static uint8_t lastConfigStep = BM_CONFIG_OFF; | 1781 static uint8_t lastConfigStep = BM_CONFIG_OFF; |
| 1774 static uint32_t cmdStartTick = 0; | 1782 static uint32_t cmdStartTick = 0; |
| 1775 | 1783 |
| 1776 char TxBuffer[UART_CMD_BUF_SIZE]; | 1784 char TxBuffer[UART_CMD_BUF_SIZE]; |
| 1786 lastConfigStep = BmTmpConfig; | 1794 lastConfigStep = BmTmpConfig; |
| 1787 } | 1795 } |
| 1788 | 1796 |
| 1789 if(time_elapsed_ms(cmdStartTick, HAL_GetTick()) > 100) | 1797 if(time_elapsed_ms(cmdStartTick, HAL_GetTick()) > 100) |
| 1790 { | 1798 { |
| 1799 cmdStartTick = HAL_GetTick(); | |
| 1791 switch (BmTmpConfig) | 1800 switch (BmTmpConfig) |
| 1792 { | 1801 { |
| 1793 case BM_CONFIG_ECHO: tComm_GetBTCmdStr (BT_CMD_ECHO, TxBuffer); | 1802 case BM_CONFIG_ECHO: tComm_GetBTCmdStr (BT_CMD_ECHO, TxBuffer); |
| 1794 break; | 1803 break; |
| 1795 case BM_CONFIG_SILENCE: tComm_GetBTCmdStr (BT_CMD_SILENCE, TxBuffer); | 1804 case BM_CONFIG_SILENCE: tComm_GetBTCmdStr (BT_CMD_SILENCE, TxBuffer); |
| 1814 } | 1823 } |
| 1815 break; | 1824 break; |
| 1816 case BM_CONFIG_DONE: | 1825 case BM_CONFIG_DONE: |
| 1817 case BM_CONFIG_OFF: | 1826 case BM_CONFIG_OFF: |
| 1818 ConfigRetryCnt = 0; | 1827 ConfigRetryCnt = 0; |
| 1828 #ifdef OSTC4_HW | |
| 1819 RestartModule = 1; | 1829 RestartModule = 1; |
| 1830 #endif | |
| 1820 break; | 1831 break; |
| 1821 | 1832 |
| 1822 | 1833 |
| 1823 #ifndef OSTC4_HW | 1834 #ifndef OSTC4_HW |
| 1824 /* the procedure below is just needed for the initial bluetooth module initialization */ | 1835 /* the procedure below is just needed for the initial bluetooth module initialization */ |
| 1836 case BM_INIT_POWEROFF: MX_Bluetooth_PowerOff(); | |
| 1837 HAL_Delay(1000); | |
| 1838 BmTmpConfig++; | |
| 1839 break; | |
| 1840 case BM_INIT_POWERON: MX_Bluetooth_PowerOn(); | |
| 1841 BmTmpConfig++; | |
| 1842 break; | |
| 1825 case BM_INIT_TRIGGER_ON: HAL_Delay(2000); | 1843 case BM_INIT_TRIGGER_ON: HAL_Delay(2000); |
| 1826 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); | 1844 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); |
| 1827 BmTmpConfig++; | 1845 BmTmpConfig++; |
| 1828 break; | 1846 break; |
| 1829 case BM_INIT_TRIGGER_OFF: HAL_Delay(1); | 1847 case BM_INIT_TRIGGER_OFF: HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_SET); |
| 1830 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_SET); | |
| 1831 HAL_Delay(2000); | 1848 HAL_Delay(2000); |
| 1832 BmTmpConfig++; | 1849 BmTmpConfig++; |
| 1833 break; | 1850 break; |
| 1834 case BM_INIT_ECHO: sprintf(TxBuffer,"ATE0\r"); | 1851 case BM_INIT_ECHO: |
| 1852 case BM_INIT_ECHO2: sprintf(TxBuffer,"ATE0\r"); | |
| 1835 break; | 1853 break; |
| 1836 case BM_INIT_FACTORY: sprintf(TxBuffer,"AT+UFACTORY\r"); /*Set to factory defined configuration */ | 1854 case BM_INIT_FACTORY: sprintf(TxBuffer,"AT+UFACTORY\r"); /*Set to factory defined configuration */ |
| 1837 break; | 1855 break; |
| 1838 case BM_INIT_MODE: sprintf(TxBuffer,"AT+UMSM=1\r"); /* start in Data mode */ | 1856 case BM_INIT_MODE: sprintf(TxBuffer,"AT+UMSM=1\r"); /* start in Data mode */ |
| 1839 break; | 1857 break; |
| 1856 break; | 1874 break; |
| 1857 case BM_INIT_STORE: sprintf(TxBuffer,"AT&W0\r"); /* write settings into eeprom */ | 1875 case BM_INIT_STORE: sprintf(TxBuffer,"AT&W0\r"); /* write settings into eeprom */ |
| 1858 break; | 1876 break; |
| 1859 case BM_INIT_RESTART: sprintf(TxBuffer,"AT+CPWROFF\r"); /* reboot module */ | 1877 case BM_INIT_RESTART: sprintf(TxBuffer,"AT+CPWROFF\r"); /* reboot module */ |
| 1860 break; | 1878 break; |
| 1861 case BM_INIT_DONE: BmTmpConfig = BM_CONFIG_ECHO; | 1879 case BM_INIT_DONE: tInfo_write("Done"); |
| 1880 BmTmpConfig = BM_CONFIG_DONE; | |
| 1862 break; | 1881 break; |
| 1863 default: | 1882 default: |
| 1864 break; | 1883 break; |
| 1865 } | 1884 } |
| 1866 #else | 1885 #else |
| 1907 #endif | 1926 #endif |
| 1908 | 1927 |
| 1909 if(TxBuffer[0] != 0) /* forward command to module */ | 1928 if(TxBuffer[0] != 0) /* forward command to module */ |
| 1910 { | 1929 { |
| 1911 CmdSize = strlen(TxBuffer); | 1930 CmdSize = strlen(TxBuffer); |
| 1912 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000) == HAL_OK) | 1931 result = HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 500); |
| 1932 if(result == HAL_OK) | |
| 1913 { | 1933 { |
| 1914 result = tComm_CheckAnswerOK(); | 1934 result = tComm_CheckAnswerOK(); |
| 1915 | 1935 #ifdef OSTC4_HW |
| 1916 if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate != 460800)) /* is com already switched to fast speed? */ | 1936 if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate != 460800)) /* is com already switched to fast speed? */ |
| 1917 { | 1937 { |
| 1918 HAL_UART_DeInit(&UartHandle); | 1938 HAL_UART_DeInit(&UartHandle); |
| 1919 HAL_Delay(1); | 1939 HAL_Delay(1); |
| 1920 UartHandle.Init.BaudRate = 460800; | 1940 UartHandle.Init.BaudRate = 460800; |
| 1932 HAL_UART_Init(&UartHandle); | 1952 HAL_UART_Init(&UartHandle); |
| 1933 sprintf(TxBuffer,"AT&W\r"); /* write configuration */ | 1953 sprintf(TxBuffer,"AT&W\r"); /* write configuration */ |
| 1934 CmdSize = strlen(TxBuffer); | 1954 CmdSize = strlen(TxBuffer); |
| 1935 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | 1955 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); |
| 1936 } | 1956 } |
| 1957 #endif | |
| 1937 if(result == HAL_OK) | 1958 if(result == HAL_OK) |
| 1938 { | 1959 { |
| 1960 ConfigRetryCnt = 0; | |
| 1939 BmTmpConfig++; | 1961 BmTmpConfig++; |
| 1940 cmdStartTick = HAL_GetTick(); | |
| 1941 if(BmTmpConfig == BM_CONFIG_RETRY) | 1962 if(BmTmpConfig == BM_CONFIG_RETRY) |
| 1942 { | 1963 { |
| 1943 BmTmpConfig = BM_CONFIG_DONE; | 1964 BmTmpConfig = BM_CONFIG_DONE; |
| 1944 } | 1965 } |
| 1945 } | 1966 } |
| 1967 #ifdef OSTC4_HW | |
| 1946 if(BmTmpConfig == BM_CONFIG_ECHO) | 1968 if(BmTmpConfig == BM_CONFIG_ECHO) |
| 1947 { | 1969 { |
| 1948 BmTmpConfig = BM_CONFIG_DONE; | 1970 BmTmpConfig = BM_CONFIG_DONE; |
| 1949 ConfigRetryCnt = 0; | 1971 ConfigRetryCnt = 0; |
| 1950 RestartModule = 1; | 1972 RestartModule = 1; |
| 1951 } | 1973 } |
| 1974 #endif | |
| 1952 } | 1975 } |
| 1953 } | 1976 } |
| 1954 else /* no command for the configuration step found => skip step */ | 1977 else /* no command for the configuration step found => skip step */ |
| 1955 { | 1978 { |
| 1956 if((BmTmpConfig > BM_CONFIG_OFF) && (BmTmpConfig < BM_CONFIG_DONE)) | 1979 if((BmTmpConfig > BM_CONFIG_OFF) && (BmTmpConfig < BM_CONFIG_DONE)) |
| 1962 { | 1985 { |
| 1963 ConfigRetryCnt++; | 1986 ConfigRetryCnt++; |
| 1964 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ | 1987 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ |
| 1965 { | 1988 { |
| 1966 MX_Bluetooth_PowerOff(); | 1989 MX_Bluetooth_PowerOff(); |
| 1990 tInfo_write("Failed"); | |
| 1991 BmTmpConfig = BM_CONFIG_OFF; | |
| 1992 | |
| 1993 #ifdef OSTC4_HW | |
| 1967 if(RestartModule) | 1994 if(RestartModule) |
| 1968 { | 1995 { |
| 1969 RestartModule = 0; /* only one try */ | 1996 RestartModule = 0; /* only one try */ |
| 1970 ConfigRetryCnt = 200; /* used for delay to startup module again */ | 1997 ConfigRetryCnt = 200; /* used for delay to startup module again */ |
| 1971 | 1998 |
| 1981 else /* even restarting module failed => switch bluetooth off */ | 2008 else /* even restarting module failed => switch bluetooth off */ |
| 1982 { | 2009 { |
| 1983 ConfigRetryCnt = 0; | 2010 ConfigRetryCnt = 0; |
| 1984 BmTmpConfig = BM_CONFIG_OFF; | 2011 BmTmpConfig = BM_CONFIG_OFF; |
| 1985 } | 2012 } |
| 2013 #endif | |
| 1986 } | 2014 } |
| 1987 } | 2015 } |
| 1988 } | 2016 } |
| 1989 return result; | 2017 return result; |
| 1990 } | 2018 } |
