Grasshopper custom pin mapping

Hi everybody!

I’d like to make a custom pinmapping for my Grasshopper board. I’d like to remap the digital pins for my own design I’m working on. I’d like to use the grasshopper board in the Arduino IDE using my own CMWX module on a custom PCB. The grasshopper board has a VBUS pin which I’d like to use to control a sensor. PA8 is on the same pin, yet I can’t access it.

What I’ve tried is swapping VBUS/PA8 with D1/PA9:
Editing the variant.cpp and variant.h files.

// 0..13 - Digital pins
{ GPIOA, STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PA10), STM32L0_GPIO_PIN_PA10,           (PIN_ATTR_EXTI),                               PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ GPIOA, STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PA9),  STM32L0_GPIO_PIN_PA9,            (PIN_ATTR_EXTI),                               PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ GPIOB, STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PB5),  STM32L0_GPIO_PIN_PB5_TIM22_CH2,  (PIN_ATTR_EXTI),                               PWM_INSTANCE_TIM22, PWM_CHANNEL_2,    ADC_CHANNEL_NONE },
{ GPIOB, STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PB6),  STM32L0_GPIO_PIN_PB6,            (PIN_ATTR_EXTI),                               PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ GPIOB, STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PB7),  STM32L0_GPIO_PIN_PB7,            (PIN_ATTR_EXTI),                               PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ GPIOB, STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PB2),  STM32L0_GPIO_PIN_PB2,            (PIN_ATTR_EXTI),                               PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ NULL,  0,                                            STM32L0_GPIO_PIN_NONE,           0,                                             PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ NULL,  0,                                            STM32L0_GPIO_PIN_NONE,           0,                                             PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ GPIOA, STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PA13), STM32L0_GPIO_PIN_PA13,           (PIN_ATTR_SWD | PIN_ATTR_EXTI),                PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ GPIOA, STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PA14), STM32L0_GPIO_PIN_PA14,           (PIN_ATTR_SWD | PIN_ATTR_EXTI),                PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },

And…

// 22..25 - Special pins (USB_DM, USB_DP, USB_VBUS, SFLASH_CS)
{ NULL,  STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PA11), STM32L0_GPIO_PIN_PA11,           (PIN_ATTR_EXTI),                               PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ NULL,  STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PA12), STM32L0_GPIO_PIN_PA12,           (PIN_ATTR_EXTI),                               PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ NULL,  STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PA8),  STM32L0_GPIO_PIN_PA8,            (PIN_ATTR_EXTI),                               PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },
{ NULL,  STM32L0_GPIO_PIN_MASK(STM32L0_GPIO_PIN_PH0),  STM32L0_GPIO_PIN_PH0,            0,                                             PWM_INSTANCE_NONE,  PWM_CHANNEL_NONE, ADC_CHANNEL_NONE },

These blocks of code define the pin mapping to my knowledge. I have tried to swap PA8 and PA9, effectively swapping VBUS and D1, yet when I uploaded, everything was normal.
Do you know how I could edit this file @onehorse?

I also edited the following lines in the variants.h file:

#define STM32L0_CONFIG_PIN_VBUS           STM32L0_GPIO_PIN_PA8
#define PIN_USB_VBUS         (24ul)

Yet I’m not quite sure what to edit the 24ul to in order to map it to a different pin.

Please help!

" I’d like to use the grasshopper board in the Arduino IDE using my own CMWX module on a custom PCB."

I think this is fine, but if you want to use the Grasshopper board variant in the Arduino IDE you need to conform to the Grasshopper pin mapping.

If you deviate from the Grasshopper pin mapping, you can’t expect to use the Grasshopper board variant, and you will be responsible for modifying and maintaining the custom board variant yourself.

If you don’t know how to modify the board variant for your custom design, then I suggest that you keep the Grasshopper pin map.