mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-03 21:32:33 +00:00
feat(core/prodtest): Add ble-radio-test command into prodtest
This commit is contained in:
parent
04611d25ca
commit
f2048ad9b5
@ -20,8 +20,10 @@
|
|||||||
#ifdef USE_BLE
|
#ifdef USE_BLE
|
||||||
|
|
||||||
#include <trezor_rtl.h>
|
#include <trezor_rtl.h>
|
||||||
|
#include <trezor_bsp.h>
|
||||||
|
|
||||||
#include <io/ble.h>
|
#include <io/ble.h>
|
||||||
|
#include <io/usb.h>
|
||||||
#include <rtl/cli.h>
|
#include <rtl/cli.h>
|
||||||
#include <sys/systick.h>
|
#include <sys/systick.h>
|
||||||
#include <sys/systimer.h>
|
#include <sys/systimer.h>
|
||||||
@ -225,6 +227,133 @@ static void prodtest_ble_erase_bonds_cmd(cli_t* cli) {
|
|||||||
cli_ok(cli, "");
|
cli_ok(cli, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prodtest_ble_radio_test_cmd(cli_t* cli){
|
||||||
|
|
||||||
|
if (cli_arg_count(cli) > 0) {
|
||||||
|
cli_error_arg_count(cli);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
|
||||||
|
// UART3 settings
|
||||||
|
// UART connected to NRF via unmeasurable wires, TX line for some reason do not work
|
||||||
|
// RAD TX (PB10 - P0.09)
|
||||||
|
// RAD RX (PA5 - P0.06)
|
||||||
|
|
||||||
|
/* Enable clock for USART1 */
|
||||||
|
__HAL_RCC_USART3_FORCE_RESET();
|
||||||
|
__HAL_RCC_USART3_RELEASE_RESET();
|
||||||
|
__HAL_RCC_USART3_CLK_ENABLE();
|
||||||
|
|
||||||
|
/* Enable clock for GPIO port */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
|
|
||||||
|
// RAD_RX PA5 USART3_RX AF7
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
// RAD TX PB10 USART3_TX AF7
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
|
||||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
|
||||||
|
// UART3 settings
|
||||||
|
// UART connected to NRF via QI I2C line reconfigured to UART
|
||||||
|
// This line requires physical connection between TP3-TP37 and TP4-TP36
|
||||||
|
// RAD TX (PF0 - P0.16)
|
||||||
|
// RAD RX (PF1 - P0.15)
|
||||||
|
|
||||||
|
/* Enable clock for USART1 */
|
||||||
|
__HAL_RCC_USART6_FORCE_RESET();
|
||||||
|
__HAL_RCC_USART6_RELEASE_RESET();
|
||||||
|
__HAL_RCC_USART6_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||||
|
|
||||||
|
// USART6_RX AF7
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_1;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART6;
|
||||||
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
// USART6 TX AF7
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART6;
|
||||||
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
|
||||||
|
// NRF Reset pin
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
UART_HandleTypeDef huart = {0};
|
||||||
|
|
||||||
|
/* Configure the UART peripheral */
|
||||||
|
huart.Instance = USART6; // USART3
|
||||||
|
huart.Init.BaudRate = 115200;
|
||||||
|
huart.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
huart.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
huart.Init.Parity = UART_PARITY_NONE;
|
||||||
|
huart.Init.Mode = UART_MODE_TX_RX;
|
||||||
|
huart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
huart.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
|
huart.Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
||||||
|
huart.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||||
|
|
||||||
|
uint8_t cmd_line_byte;
|
||||||
|
uint8_t nrf_byte;
|
||||||
|
|
||||||
|
// Initialize UART
|
||||||
|
if (HAL_UART_Init(&huart) != HAL_OK)
|
||||||
|
{
|
||||||
|
cli_error(cli, CLI_ERROR, "Could not initialize UART.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset NRF
|
||||||
|
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_0, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
|
||||||
|
if(cli_aborted(cli)){
|
||||||
|
cli_trace(cli, "Aborted.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read byte from the command line and pass it to NRF UART;
|
||||||
|
if( usb_vcp_read(0, &cmd_line_byte, 1) > 0){
|
||||||
|
HAL_UART_Transmit(&huart, &cmd_line_byte, 1, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read byte from the NRF UART and pass it to command line;
|
||||||
|
if(HAL_UART_Receive(&huart, &nrf_byte, 1, 10) == HAL_OK){
|
||||||
|
cli->write(cli, (const char *) &nrf_byte, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
cli_ok(cli, "");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
PRODTEST_CLI_CMD(
|
PRODTEST_CLI_CMD(
|
||||||
@ -255,4 +384,11 @@ PRODTEST_CLI_CMD(
|
|||||||
.args = ""
|
.args = ""
|
||||||
);
|
);
|
||||||
|
|
||||||
|
PRODTEST_CLI_CMD(
|
||||||
|
.name = "ble-radio-test",
|
||||||
|
.func = prodtest_ble_radio_test_cmd,
|
||||||
|
.info = "Connect to Radio test CLI",
|
||||||
|
.args = ""
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
2234
nordic/radio_test/nrf52832_xxaa_rx16_tx15_v2.hex
Normal file
2234
nordic/radio_test/nrf52832_xxaa_rx16_tx15_v2.hex
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user