| @@ -10,6 +10,7 @@ | |||||
| [env:genericSTM32F405RG] | [env:genericSTM32F405RG] | ||||
| platform = ststm32 | platform = ststm32 | ||||
| board = genericSTM32F405RG | |||||
| framework = stm32cube | framework = stm32cube | ||||
| build_flags = -DF4 | |||||
| board = genericSTM32F405RG | |||||
| build_flags = -DF4 | |||||
| test_transport = custom | |||||
| @@ -0,0 +1,55 @@ | |||||
| #include <main.h> | |||||
| #include <unity.h> | |||||
| void setUp(void) { | |||||
| HAL_Init(); | |||||
| LED_GPIO_CLK_ENABLE(); | |||||
| GPIO_InitTypeDef GPIO_InitStruct; | |||||
| GPIO_InitStruct.Pin = LED_PIN; | |||||
| GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |||||
| GPIO_InitStruct.Pull = GPIO_PULLUP; | |||||
| GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |||||
| HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct); | |||||
| } | |||||
| void tearDown(void) { | |||||
| HAL_GPIO_DeInit(LED_GPIO_PORT, LED_PIN); | |||||
| } | |||||
| void test_led_builtin_pin_number(void) { | |||||
| TEST_ASSERT_EQUAL(LED_PIN, GPIO_PIN_5); | |||||
| } | |||||
| void test_led_state_high(void) { | |||||
| HAL_GPIO_WritePin(LED_GPIO_PORT, LED_PIN, GPIO_PIN_SET); | |||||
| TEST_ASSERT_EQUAL(HAL_GPIO_ReadPin(LED_GPIO_PORT, LED_PIN), GPIO_PIN_SET); | |||||
| } | |||||
| void test_led_state_low(void) { | |||||
| HAL_GPIO_WritePin(LED_GPIO_PORT, LED_PIN, GPIO_PIN_RESET); | |||||
| TEST_ASSERT_EQUAL(HAL_GPIO_ReadPin(LED_GPIO_PORT, LED_PIN), GPIO_PIN_RESET); | |||||
| } | |||||
| int main() { | |||||
| UNITY_BEGIN(); | |||||
| RUN_TEST(test_led_builtin_pin_number); | |||||
| for (unsigned int i = 0; i < 5; i++) | |||||
| { | |||||
| RUN_TEST(test_led_state_high); | |||||
| HAL_Delay(500); | |||||
| RUN_TEST(test_led_state_low); | |||||
| HAL_Delay(500); | |||||
| } | |||||
| UNITY_END(); // Stop testing | |||||
| while (1) {} | |||||
| } | |||||
| void SysTick_Handler(void) { | |||||
| HAL_IncTick(); | |||||
| } | |||||
| @@ -0,0 +1,72 @@ | |||||
| #include "unittest_transport.h" | |||||
| #include <main.h> | |||||
| #define USARTx USART2 | |||||
| #define USARTx_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE() | |||||
| #define USARTx_CLK_DISABLE() __HAL_RCC_USART2_CLK_DISABLE() | |||||
| #define USARTx_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |||||
| #define USARTx_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |||||
| #define USARTx_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() | |||||
| #define USARTx_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() | |||||
| #define USARTx_FORCE_RESET() __HAL_RCC_USART2_FORCE_RESET() | |||||
| #define USARTx_RELEASE_RESET() __HAL_RCC_USART2_RELEASE_RESET() | |||||
| #define USARTx_TX_PIN GPIO_PIN_2 | |||||
| #define USARTx_TX_GPIO_PORT GPIOA | |||||
| #define USARTx_TX_AF GPIO_AF7_USART2 | |||||
| #define USARTx_RX_PIN GPIO_PIN_3 | |||||
| #define USARTx_RX_GPIO_PORT GPIOA | |||||
| #define USARTx_RX_AF GPIO_AF7_USART2 | |||||
| static UART_HandleTypeDef UartHandle; | |||||
| void unittest_uart_begin() | |||||
| { | |||||
| GPIO_InitTypeDef GPIO_InitStruct; | |||||
| USARTx_TX_GPIO_CLK_ENABLE(); | |||||
| USARTx_RX_GPIO_CLK_ENABLE(); | |||||
| USARTx_CLK_ENABLE(); | |||||
| GPIO_InitStruct.Pin = USARTx_TX_PIN; | |||||
| GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | |||||
| GPIO_InitStruct.Pull = GPIO_PULLUP; | |||||
| GPIO_InitStruct.Speed = GPIO_SPEED_FAST; | |||||
| GPIO_InitStruct.Alternate = USARTx_TX_AF; | |||||
| HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct); | |||||
| GPIO_InitStruct.Pin = USARTx_RX_PIN; | |||||
| GPIO_InitStruct.Alternate = USARTx_RX_AF; | |||||
| HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct); | |||||
| UartHandle.Instance = USARTx; | |||||
| UartHandle.Init.BaudRate = 115200; // Or 9600 | |||||
| UartHandle.Init.WordLength = UART_WORDLENGTH_8B; | |||||
| UartHandle.Init.StopBits = UART_STOPBITS_1; | |||||
| UartHandle.Init.Parity = UART_PARITY_NONE; | |||||
| UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |||||
| UartHandle.Init.Mode = UART_MODE_TX_RX; | |||||
| UartHandle.Init.OverSampling = UART_OVERSAMPLING_16; | |||||
| if (HAL_UART_Init(&UartHandle) != HAL_OK) { | |||||
| while (1) {} | |||||
| } | |||||
| } | |||||
| void unittest_uart_putchar(char c) | |||||
| { | |||||
| HAL_UART_Transmit(&UartHandle, (uint8_t*)(&c), 1, 1000); | |||||
| } | |||||
| void unittest_uart_flush() {} | |||||
| void unittest_uart_end() { | |||||
| USARTx_CLK_DISABLE(); | |||||
| USARTx_RX_GPIO_CLK_DISABLE(); | |||||
| USARTx_TX_GPIO_CLK_DISABLE(); | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| #ifndef UNITEST_TRANSPORT_H | |||||
| #define UNITEST_TRANSPORT_H | |||||
| #ifdef __cplusplus | |||||
| extern "C" { | |||||
| #endif | |||||
| void unittest_uart_begin(); | |||||
| void unittest_uart_putchar(char c); | |||||
| void unittest_uart_flush(); | |||||
| void unittest_uart_end(); | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif | |||||
| #endif // UNITEST_TRANSPORT_H | |||||
| @@ -0,0 +1,15 @@ | |||||
| Test Case: Command_Ctrl | |||||
| Description: Assure that commands given are carried out with response. | |||||
| 1. Open a TTY connection with 115200 8N1. | |||||
| 2. Connect a USB host to the DUT with a 3.1 cable. | |||||
| 3A. Enter a test command opcode terminated with a CR/LF. | |||||
| 3B. Compare with the well known response text. | |||||
| Command Opcode : Response | |||||
| -------------- -------- | |||||
| ASDFUIOP : Command unknown | |||||
| HELP : Enter a command | |||||
| MENU : HELP | |||||
| MENU | |||||
| DUMP | |||||
| @@ -0,0 +1,6 @@ | |||||
| Test Case: USB_Data | |||||
| Description: Assure that the USB circuit exchanges data properly. | |||||
| 1. Open a TTY connection with 115200 8N1. | |||||
| 2. Connect a USB host to the DUT with a 3.1 cable. | |||||
| 3. Observe boot sequence log traffic over USB using screen(1). | |||||
| @@ -0,0 +1,7 @@ | |||||
| Test Case: De_Activate | |||||
| Description: Assure that RF activation and deactivate is possible. | |||||
| 1. Bridge the RF disable jumper. | |||||
| 2. Sample the relevant frequencies. | |||||
| 3. Apply power. | |||||
| 4. Observe RF activity. | |||||
| @@ -0,0 +1,7 @@ | |||||
| Test Case: First_Contact | |||||
| Description: Assure that the test rig properly makes contact. | |||||
| 1. Mount the DUT in the test rig. | |||||
| 2. Lower the pogopin contact assembly. | |||||
| 3. Observe the test rig display output. | |||||
| 4. Listen to the test rig audio output. | |||||
| @@ -0,0 +1,7 @@ | |||||
| Test Case: Power_On | |||||
| Description: Assure that application of power causes proper operation. | |||||
| 1. Place finger on regulator circuits to feel warmth. | |||||
| 2. Connect a USB cable from a 5V powered host to the DUT. | |||||
| 3. Measure voltage (assert 5V) between test points with a multimeter. | |||||
| 4. Observe power LED on the DUT board top. | |||||
| @@ -0,0 +1,6 @@ | |||||
| Test Case: Radio_On | |||||
| Description: Assure that the radio tranceiver works properly. | |||||
| 1. Sample 868 MHz and 915 MHz frequencies with a RF spectrum analyser. | |||||
| 2. Apply power to the DUT and observe boot sequence. | |||||
| 3. Compare RF boot signature with reference samples. | |||||
| @@ -0,0 +1,5 @@ | |||||
| Test Case: Optical | |||||
| Description: Assure the absence of solder bridges and other problems. | |||||
| 1. Inspect under 10X magnification assembled parts on the board top. | |||||
| 2. Inspect under 10X magnification assembled parts on the board bottom. | |||||