Skip to content

Commit

Permalink
fix: Fix stm32 qemu afio map use in PICSimLab !minor
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Jan 20, 2023
1 parent 9bdfaa7 commit 165abf3
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/boards/board_Arduino_Mega.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
########################################################################
Copyright (c) : 2015-2022 Luis Claudio Gambôa Lopes
Copyright (c) : 2015-2023 Luis Claudio Gambôa Lopes
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -65,6 +65,6 @@ void cboard_Arduino_Mega::ReadPreferences(char* name, char* value) {
}
}

// TODO cboard_Arduino_Mega: add suport to anaolog inputs A6 and A7
// TODO cboard_Arduino_Mega: add suport to analog inputs A6 and A7

board_init(BOARD_Arduino_Mega_Name, cboard_Arduino_Mega);
4 changes: 2 additions & 2 deletions src/boards/board_Arduino_Nano.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
########################################################################
Copyright (c) : 2015-2022 Luis Claudio Gambôa Lopes
Copyright (c) : 2015-2023 Luis Claudio Gambôa Lopes
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -66,6 +66,6 @@ void cboard_Arduino_Nano::ReadPreferences(char* name, char* value) {
}
}

// TODO cboard_Arduino_Nano: add suport to anaolog inputs A6 and A7
// TODO cboard_Arduino_Nano: add suport to analog inputs A6 and A7

board_init(BOARD_Arduino_Nano_Name, cboard_Arduino_Nano);
142 changes: 124 additions & 18 deletions src/boards/board_Blue_Pill.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
########################################################################
Copyright (c) : 2015-2022 Luis Claudio Gambôa Lopes
Copyright (c) : 2015-2023 Luis Claudio Gambôa Lopes
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -80,16 +80,14 @@ cboard_Blue_Pill::cboard_Blue_Pill(void) {
Proc = "stm32f103c8t6"; // default microcontroller if none defined in preferences
ReadMaps(); // Read input and output board maps

// TODO read pin configuration from registers instead use fixed pins
master_i2c[0].scl_pin = 42; // pb6 or pb8
master_i2c[0].sda_pin = 43; // pb7 or pb9
master_i2c[1].scl_pin = 21; // pb10
master_i2c[1].sda_pin = 22; // pb11
master_i2c[0].scl_pin = 0;
master_i2c[0].sda_pin = 0;
master_i2c[1].scl_pin = 0;
master_i2c[1].sda_pin = 0;

// TODO read pin configuration from registers instead use fixed pins
master_spi[0].sck_pin = 15; // pa5
master_spi[0].copi_pin = 17; // pa7
master_spi[0].cipo_pin = 16; // pa6
master_spi[0].sck_pin = 0;
master_spi[0].copi_pin = 0;
master_spi[0].cipo_pin = 0;
master_spi[0].cs_pin[0] = 0;
master_spi[0].cs_pin[1] = 0;
master_spi[0].cs_pin[2] = 0;
Expand All @@ -101,13 +99,12 @@ cboard_Blue_Pill::cboard_Blue_Pill(void) {
master_spi[1].cs_pin[1] = 0;
master_spi[1].cs_pin[2] = 0;

// TODO read pin configuration from registers instead use fixed pins
master_uart[0].tx_pin = 30; // pa9
master_uart[0].rx_pin = 31; // pa10
master_uart[1].tx_pin = 12; // pa2
master_uart[1].rx_pin = 13; // pa3
master_uart[2].tx_pin = 21; // pb10
master_uart[2].rx_pin = 22; // pb11
master_uart[0].tx_pin = 0;
master_uart[0].rx_pin = 0;
master_uart[1].tx_pin = 0;
master_uart[1].rx_pin = 0;
master_uart[2].tx_pin = 0;
master_uart[2].rx_pin = 0;

// label1
label1 = new CLabel();
Expand Down Expand Up @@ -621,7 +618,116 @@ void cboard_Blue_Pill::MSetAPin(int pin, float value) {
}
}

void cboard_Blue_Pill::PinsExtraConfig(int cfg) {}
void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
if ((cfg & 0x8008) == 0x8008) { // Alternate function
int pin = (cfg & 0x7FF0) >> 4;
int port = cfg & 0x0003;
uint32_t* uart_afio;
// int cfg_ = (cfg & 0x000C) >> 2;
// printf("Extra CFG port(%i) pin[%02i]=0x%02X \n", port, pin, cfg_);

switch (port) {
case 0: // GPIOA
switch (pin) {
case 2: // uart2
uart_afio = qemu_picsimlab_get_internals(0x1000 | 15);
if (!(*uart_afio)) {
master_uart[1].ctrl_on = 1;
master_uart[1].tx_pin = 12; // pa2
master_uart[1].rx_pin = 13; // pa3
}
break;
case 5:
case 6:
case 7: // spi1
uart_afio = qemu_picsimlab_get_internals(0x1000 | 53);
if (!(*uart_afio)) {
master_spi[0].ctrl_on = 1;
master_spi[0].sck_pin = 15; // pa5
master_spi[0].copi_pin = 17; // pa7
master_spi[0].cipo_pin = 16; // pa6
}
break;
case 9: // uart1
uart_afio = qemu_picsimlab_get_internals(0x1000 | 14);
if (!(*uart_afio)) {
master_uart[0].ctrl_on = 1;
master_uart[0].tx_pin = 30; // pa9
master_uart[0].rx_pin = 31; // pa10
}
break;
}
break;
case 1: // GPIOB
switch (pin) {
case 3:
case 4:
case 5: // spi1 (alt)
uart_afio = qemu_picsimlab_get_internals(0x1000 | 53);
if (!(*uart_afio)) {
master_spi[0].ctrl_on = 1;
master_spi[0].sck_pin = 39; // pb3
master_spi[0].copi_pin = 41; // pb5
master_spi[0].cipo_pin = 40; // pb4
}
break;
case 6: // uart1 (alt) and i2c
uart_afio = qemu_picsimlab_get_internals(0x1000 | 14);
if ((*uart_afio)) {
master_uart[0].ctrl_on = 1;
master_uart[0].tx_pin = 42; // pb6
master_uart[0].rx_pin = 43; // pb7
}
// break;
case 7: // i2c0
uart_afio = qemu_picsimlab_get_internals(0x1000 | 42);
if (!(*uart_afio)) {
master_i2c[0].ctrl_on = 1;
master_i2c[0].scl_pin = 42; // pb6
master_i2c[0].sda_pin = 43; // pb7
}
break;
case 8:
case 9: // i2c0 (alt)
uart_afio = qemu_picsimlab_get_internals(0x1000 | 42);
if ((*uart_afio)) {
master_i2c[0].ctrl_on = 1;
master_i2c[0].scl_pin = 45; // pb8
master_i2c[0].sda_pin = 46; // pb9
}
break;
case 10: // uart3
/*
uart_afio = qemu_picsimlab_get_internals(0x1000 | 16);
if (!(*uart_afio)) {
master_uart[2].ctrl_on = 1;
master_uart[2].tx_pin = 21; // pb10
master_uart[2].rx_pin = 22; // pb11
}
*/
case 11: // i2c1
master_i2c[1].ctrl_on = 1;
master_i2c[1].scl_pin = 21; // pb10
master_i2c[1].sda_pin = 22; // pb11
break;

case 13:
case 14:
case 15: // spi2
master_spi[1].ctrl_on = 1;
master_spi[1].sck_pin = 26; // pb13
master_spi[1].copi_pin = 28; // pb15
master_spi[1].cipo_pin = 27; // pb14
break;
}
break;
case 2: // GPIOC
break;
case 3: // GPIOD
break;
}
}
}

// Register the board in PICSimLab
board_init(BOARD_Blue_Pill_Name, cboard_Blue_Pill);
Loading

0 comments on commit 165abf3

Please sign in to comment.