gl-sergei / u2f-token

u2f token firmware for stm32f103 and efm32hg boards
GNU General Public License v3.0
339 stars 56 forks source link

My led is PB12 #9

Closed assasinfil closed 5 years ago

assasinfil commented 5 years ago

How can I reassign LED pc13 to pb12 in the code?

gl-sergei commented 5 years ago

If you compiling with TARGET=BLUE_PILL, then try to change these two lines: https://github.com/gl-sergei/chopstx/blob/984116b3b64b93f5a9e315f8a805db74f22fb90b/board/board-blue-pill.h#L12

Ideally, you should prepare header file for your board and add makefile target.

BTW, which board are you trying to run it on?

assasinfil commented 5 years ago

I work witch stm32f103c6 and led pin is PB12. I for a long time could not understand why the standard example blink does not work and having looked closely to the board I saw that the LED is connected to the foot of pb12

assasinfil commented 5 years ago

The LED should do some kind of work?

gl-sergei commented 5 years ago

For PB12 it should look like

#define GPIO_LED_BASE   GPIOB_BASE
#define GPIO_LED_CLEAR_TO_EMIT          12

and probably this line needs to be changed to something like

#define VAL_GPIO_LED_CRH            0x88838888      /* PB15...PB8 */

LED will blink when you plug the board and it will blink each time board communicates via USB.

assasinfil commented 5 years ago

i changed, but led didn't work(( maybe need change all lines?

define VAL_GPIO_LED_ODR 0xFFFFFFFF

define VAL_GPIO_LED_CRL 0x88888888 / PC7...PC0 /

assasinfil commented 5 years ago

stm32f103_hcdvbd0033_pinout

gl-sergei commented 5 years ago

I happened to have this board. Just tested it, it works with these changes:

diff --git i/board/board-blue-pill.h w/board/board-blue-pill.h
index 68843d7..8fe4fe9 100644
--- i/board/board-blue-pill.h
+++ w/board/board-blue-pill.h
@@ -9,8 +9,8 @@
 #define STM32_PLLMUL_VALUE              9
 #define STM32_HSECLK                    8000000

-#define GPIO_LED_BASE   GPIOC_BASE
-#define GPIO_LED_CLEAR_TO_EMIT          13
+#define GPIO_LED_BASE   GPIOB_BASE
+#define GPIO_LED_CLEAR_TO_EMIT          12
 #define GPIO_USB_BASE   GPIOA_BASE
 #define GPIO_USB_SET_TO_ENABLE          12
 #undef  GPIO_OTHER_BASE
@@ -29,8 +29,8 @@
 #define VAL_GPIO_USB_CRH            0x88811888      /* PA15...PA8 */

 #define VAL_GPIO_LED_ODR            0xFFFFFFFF
-#define VAL_GPIO_LED_CRL            0x88888888      /*  PC7...PC0 */
-#define VAL_GPIO_LED_CRH            0x88388888      /* PC15...PC8 */
+#define VAL_GPIO_LED_CRL            0x88888888      /*  PB7...PB0 */
+#define VAL_GPIO_LED_CRH            0x88838888      /* PB15...PB8 */

-#define RCC_ENR_IOP_EN      (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN)
+#define RCC_ENR_IOP_EN      (RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN)
 #define RCC_RSTR_IOP_RST    (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPCRST)

Make sure to run

make clean distclean && make TARGET=BLUE_PILL

after applying the patch.

Please also note that since your board does not have a push button to check for user presence, firmware will allow register/authenticate only within 10 seconds after device has been plugged in. You'll probably need to unplug the device and plug it back (or press HW reset button) to authenticate.

assasinfil commented 5 years ago

Nice its work! pls add it to compiler (Target=DARK_PILL)

assasinfil commented 5 years ago

The last question: where do I connect the button for authorization?

gl-sergei commented 5 years ago

First, you will need to solder a push button. Then, you will need to modify pbt.c to read events on this button's GPIO PIN and probably board-blue-pill.h as well, to initialise that GPIO PIN.

For new makefile target I created https://github.com/gl-sergei/u2f-token/issues/10