Skip to content

Commit 5d09958

Browse files
committed
Set pins to a predetermined value before exit
There are cases when some pins are not direct I/Os. They are used to activate certain HW modules and must be brought to a certain value before exit, otherwise functionality might be affected. An example is S32N79RDB board, where leaving EN_CNTL_I2C or EN_RCON_I2C lines active, puts the FTDI4232's I2C lines in parallel with the CPU's and creates interferences during debug time. Signed-off-by: Costin Constantin <costin.constantin@nxp.com>
1 parent f13d97f commit 5d09958

4 files changed

Lines changed: 67 additions & 3 deletions

File tree

bcu.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static void print_help(char* cmd)
231231

232232
static void lsgpio(struct options_setting* setting)
233233
{
234+
setting->no_release_pins = 1;
234235
struct board_info* board = get_board(setting->board);
235236
if (board == NULL)
236237
return;
@@ -248,6 +249,7 @@ static void lsgpio(struct options_setting* setting)
248249

249250
static void lsboard(struct options_setting* setting)
250251
{
252+
setting->no_release_pins = 1;
251253
printf("\nlist of supported board model:\n\n");
252254
for (int i = 0; i < num_of_boards; i++)
253255
{
@@ -375,6 +377,7 @@ void free_gpio(struct gpio_device* gpio)
375377

376378
static void ptc_set_target_temperature(struct options_setting *setting)
377379
{
380+
setting->no_release_pins = 1;
378381
struct board_info *board = get_board(setting->board);
379382
if (board == NULL)
380383
return;
@@ -451,6 +454,7 @@ static void ptc_set_target_temperature(struct options_setting *setting)
451454

452455
static void ptc_set_current_temperature(struct options_setting *setting)
453456
{
457+
setting->no_release_pins = 1;
454458
struct board_info *board = get_board(setting->board);
455459
if (board == NULL)
456460
return;
@@ -489,6 +493,7 @@ static void ptc_set_current_temperature(struct options_setting *setting)
489493

490494
static void ptc_get_temperature(struct options_setting *setting) //
491495
{
496+
setting->no_release_pins = 1;
492497
struct board_info *board = get_board(setting->board);
493498
if (board == NULL)
494499
return;
@@ -523,6 +528,7 @@ static void ptc_get_temperature(struct options_setting *setting) //
523528

524529
static void ptc_get_is_stable(struct options_setting *setting) //
525530
{
531+
setting->no_release_pins = 1;
526532
struct board_info *board = get_board(setting->board);
527533
if (board == NULL)
528534
return;
@@ -564,6 +570,7 @@ static void ptc_get_is_stable(struct options_setting *setting) //
564570

565571
static void ptc_get_is_enable(struct options_setting *setting) //
566572
{
573+
setting->no_release_pins = 1;
567574
struct board_info *board = get_board(setting->board);
568575
if (board == NULL)
569576
return;
@@ -605,6 +612,7 @@ static void ptc_get_is_enable(struct options_setting *setting) //
605612

606613
static void get_temp(struct options_setting* setting)//
607614
{
615+
setting->no_release_pins = 1;
608616
struct board_info* board = get_board(setting->board);
609617
if (board == NULL)
610618
return;
@@ -699,7 +707,7 @@ static void set_gpio(struct options_setting* setting)
699707
if (status)
700708
printf("set gpio failed, error = 0x%x\n", status);
701709
else
702-
printf("set gpio successfully\n");
710+
printf("%s gpio set to %d successfully\n", setting->gpio_name, setting->output_state);
703711

704712
//hold time
705713
msleep(setting->hold);
@@ -1620,6 +1628,7 @@ static int eeprom(struct options_setting* setting)
16201628
void* head = NULL;
16211629
void* end_point;
16221630
int j = 0;
1631+
setting->no_release_pins = 1;
16231632

16241633
struct board_info* board=get_board(setting->board);
16251634
if (board == NULL)
@@ -1790,6 +1799,7 @@ static char catch_input_char_block()
17901799
static void monitor(struct options_setting* setting)
17911800
{
17921801
signal(SIGINT, handle_sigint);
1802+
setting->no_release_pins = 1;
17931803
struct board_info* board = get_board(setting->board);
17941804
if (board == NULL) {
17951805
// printf("entered board model are not supported.\n");
@@ -3184,6 +3194,7 @@ char *iso8601(char *local_time)
31843194
static int server_monitor(struct options_setting* setting)
31853195
{
31863196
signal(SIGINT, handle_sigint);
3197+
setting->no_release_pins = 1;
31873198
struct board_info* board = get_board(setting->board);
31883199
if (board == NULL) {
31893200
// printf("entered board model are not supported.\n");
@@ -4049,6 +4060,7 @@ static int lsftdi(struct options_setting* setting)
40494060

40504061

40514062
int board_num = 0;
4063+
setting->no_release_pins = 1;
40524064
char location_id_str[MAX_NUMBER_OF_USB_DEVICES][MAX_LOCATION_ID_LENGTH];
40534065
if (!setting->auto_find_board)
40544066
ft_list_devices(location_id_str, &board_num, LIST_DEVICE_MODE_PRINT);
@@ -4168,6 +4180,36 @@ void terminateBCU(void)
41684180
ft4232h_i2c_remove_all(enable_exit_handler);
41694181
}
41704182

4183+
static int release_pins_before_exit(struct options_setting* setting)
4184+
{
4185+
4186+
if (setting->no_release_pins)
4187+
{
4188+
return 0;
4189+
}
4190+
4191+
struct board_info* board = get_board(setting->board);
4192+
if (board == NULL || !board->gpio_on_exit)
4193+
{
4194+
return 0;
4195+
}
4196+
4197+
int i = 0;
4198+
while (board->gpio_on_exit[i].name != NULL)
4199+
{
4200+
if (i == 0)
4201+
{
4202+
setting->hold = 0;
4203+
printf("\nReleasing pins before exit:\n");
4204+
}
4205+
strcpy(setting->gpio_name, board->gpio_on_exit[i].name);
4206+
setting->output_state = board->gpio_on_exit[i].value;
4207+
set_gpio(setting);
4208+
i++;
4209+
}
4210+
return 1;
4211+
}
4212+
41714213
int main(int argc, char** argv)
41724214
{
41734215
setbuf(stdin, NULL);
@@ -4534,9 +4576,16 @@ int main(int argc, char** argv)
45344576
else
45354577
{
45364578
printf("%s is a invalid command\n\n", cmd);
4579+
setting.no_release_pins = 1;
45374580
print_help(NULL);
45384581
}
45394582

4583+
// exit by setting required pins to a predefined state
4584+
if(!release_pins_before_exit(&setting) && !setting.no_release_pins)
4585+
{
4586+
printf("No pins release before exit required.\n");
4587+
}
4588+
45404589
printf("done\n");
45414590
return 0;
45424591
}

bcu_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct options_setting {
9090
int ptc_onoff;
9191
int ptc_sensor;
9292
int autoranging;
93+
int no_release_pins; // no need to release pins before exit
9394
};
9495

9596
struct group {

board.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,13 @@ struct boot_config s32n79_boot_config[] = {
25502550
{NULL, {0}}
25512551
};
25522552

2553+
// pins that must be set to a certain state. Without this some functionalities of S32N79RDB are affected
2554+
struct gpio_state_on_exit s32n79_pins_on_exit[] = {
2555+
{"EN_CNTL_I2C", 1},
2556+
{"EN_RCON_I2C", 1},
2557+
{NULL, 0}
2558+
};
2559+
25532560
struct board_info board_list[] =
25542561
{
25552562
{"imx8dxlevk", imx8xxl, imx8xxl_boot_modes, 0, NULL, imx8xxl_power_groups, imx8xxlevk_board_links, &imx8dxlevk_ftdi_eeprom_user_area_info, 500},
@@ -2594,7 +2601,7 @@ struct board_info board_list[] =
25942601
{"imx943evk19a0", imx943evk19a0_board, imx943_board_boot_modes, 0, NULL, imx943evk19_power_groups, null_board_links, &imx943evk19_ftdi_eeprom_user_area_info, 500},
25952602
{"imx943evk19b1", imx943evk19b1_board, imx943_board_boot_modes, 0, NULL, imx943evk19_power_groups, null_board_links, &imx943evk19b1_ftdi_eeprom_user_area_info, 500},
25962603
{"imx943obx", imx943obx_board, imx943_board_boot_modes, 0, NULL, imx943evk19_power_groups, null_board_links, &imx943obx_ftdi_eeprom_user_area_info, 500},
2597-
{"s32n79rdb", s32n79_mappings, s32n79_boot_modes, 0, s32n79_boot_config, NULL, null_board_links, &s32n79rdb_ftdi_eeprom_user_area_info, 500},
2604+
{"s32n79rdb", s32n79_mappings, s32n79_boot_modes, 0, s32n79_boot_config, NULL, null_board_links, &s32n79rdb_ftdi_eeprom_user_area_info, 500, s32n79_pins_on_exit},
25982605
{"val_board_7", val_board_7_board, imx943_board_boot_modes, 0, NULL, NULL, null_board_links, &val_board_7_ftdi_eeprom_user_area_info, 500},
25992606
{"val_board_9", val_board_9_board, null_boot_mode, 0, NULL, val_board_9_power_groups, null_board_links, &val_board_9_ftdi_eeprom_user_area_info, 500},
26002607
{"val_board_10", val_board_10_board, val_board_10_boot_modes, 0, NULL, val_board_10_power_groups, null_board_links, &val_board_10_ftdi_eeprom_user_area_info, 500},

board.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ struct boot_config {
7676
*/
7777
};
7878

79+
// there are cases when before exit certain pins used as enablers for hw functionalities must be brought to a known value
80+
struct gpio_state_on_exit {
81+
const char* name;
82+
int value;
83+
};
84+
7985
struct board_links {
8086
char* flashbin;
8187
char* sdcard;
@@ -96,6 +102,7 @@ struct board_info {
96102
struct board_links* links;
97103
struct ftdi_eeprom_user_area* eeprom_data;
98104
unsigned int reset_time_ms;
105+
struct gpio_state_on_exit* gpio_on_exit;
99106
};
100107

101108
/*find if there is the gpio_name on the board*/
@@ -121,4 +128,4 @@ char* get_boot_mode_name_from_hex(struct board_info* board, int boot_mode_hex);
121128
char* get_boot_config_name_from_hex(struct board_info* board, int *boot_config_hex, int boot_mode_hex);
122129
enum mapping_type get_mapping_type(char* mapping_name, struct board_info* board);
123130

124-
#endif //BOARD_H
131+
#endif //BOARD_H

0 commit comments

Comments
 (0)