Updated question, How to set PA15 to GPIO Output, and PWM questions...

Post here all questions related to LibMaple core if you can't find a relevant section!
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Updated question, How to set PA15 to GPIO Output, and PWM questions...

Post by Mangy_Dog »

updated question heres there more detailed problem please reread...
Hi
I have 5 LEDs.
The leds are attached to
PA1 PA11 PA15 PB4 and PB5.

Ive picked these pins as
Image
says these pins are PWM driven.
I need pwm control on these leds as ground sinks...

PA15 and PB4 are normally reserved for JTAG. But im not using JTAG, however i am using SWD Stlink for programming.

Bellow Mr Burnette mentioned linked me to that forum post to use
disableDebugPorts();
enableDebugPorts();

But this doesnt work and kills SWD for programming. Ive had to hotwire a reset line to the reset pin (this isnt currently broken out on my PCB design) and erase the chip from stlink utility to get it back up and running.

But while this did free up those pins, they wouldnt function with PWM controls at all. Either with analogWrite or pwmWrite.

Now the diagram listed above says these are PWM pins.

So firstly how do i set the jtag pins to gpio without breaking SWD as the method already mentioned doesnt work. And 2 how do I get PWM working on those pins, assuming theres something else im missing?








Old question//////////////////////////////////////////////////////////////////////////////////////////////////////
Hi i slight oversight on my pcb design... I need to free up PA15, im using SWD to program but not jtag.

When ever i try to use PA15 the pin is stuck high. Found out its a Jtag reserved pin, but struggling to find how to disable the jtag to free up the io.

google suggests this but its not working for me...

RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // Enable A.F. clock
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;

RCC and AFIO not declared in this scope.

Anyone know how to disable this?
Last edited by Mangy_Dog on Tue Oct 13, 2020 9:41 pm, edited 1 time in total.
Just a dogs body developer, mostly making props and stuff...
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: How to disable Jtag freeing PA15

Post by mrburnette »

Somewhere early in the sketch use:
disableDebugPorts(); // disable all debug pins to be used for debug. All debug pins are free to be used as IO
enableDebugPorts(); // this enables the SWD interface only: PA13,14 reserved for SWD, PA15, PB3,4 can be used as IO
It has been discussed a few times, such as here:
viewtopic.php?t=292

To use Google to find such things, a compound site search can be concocted as:

Code: Select all

"PA15" SWD site:stm32duino.com
Were you wanting to search the "old forum", then the Googling would appear as:

Code: Select all

"PA15" SWD site:stm32duinoforum.com
Ray
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: How to disable Jtag freeing PA15

Post by Mangy_Dog »

Well that didnt work...

SWD is closed now and i cant upload any more to my board :/
Just a dogs body developer, mostly making props and stuff...
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: How to disable Jtag freeing PA15

Post by mrburnette »

Mangy_Dog wrote: Tue Oct 13, 2020 5:01 pm Well that didnt work...

SWD is closed now and i cant upload any more to my board :/
https://community.st.com/s/question/0D5 ... d-debuging

Built-in silicon serial should still work:
https://www.st.com/resource/en/applicat ... ronics.pdf
Image
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: How to disable Jtag freeing PA15

Post by Mangy_Dog »

I brought it back by hotwiring the reset pin on the mcu, managed hardware reset programming with stlink utility.
Oh and ive disabled the USB serial as well. The hardware serial pins are wired to other components on the PCB.

But I cant do that every time I upload a new sketch... I need to keep SWD working without the hardware reset pin.

Also even then the PWM pins dont appear to be PWMing afterwards.

so what other ways can i set the jtag pins to gpio mode without killing the SWD software reset uploading method?
Just a dogs body developer, mostly making props and stuff...
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Updated question, How to set PA15 to GPIO Output, and PWM questions...

Post by stevestrong »

You have to only use

Code: Select all

enableDebugPorts();
in beginning of setup in your sketch.
Or replace lines https://github.com/rogerclarkmelbourne/ ... pp#L48-L50 with the same line as above (only 1 line, delete the #define stuff), then no need to add anything in your sketch.
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Updated question, How to set PA15 to GPIO Output, and PWM questions...

Post by Mangy_Dog »

BTW i dont know if it makes any difference, im using the generic f103c8, on my custom board... Not maple mini , blue pill , rev3 or the like...
Just a dogs body developer, mostly making props and stuff...
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Updated question, How to set PA15 to GPIO Output, and PWM questions...

Post by Mangy_Dog »

stevestrong wrote: Wed Oct 14, 2020 8:59 am You have to only use

Code: Select all

enableDebugPorts();
in beginning of setup in your sketch.
Or replace lines https://github.com/rogerclarkmelbourne/ ... pp#L48-L50 with the same line as above (only 1 line, delete the #define stuff), then no need to add anything in your sketch.
Ohh that on its own did work and not kill the swd :D

Now i just got to figure out how to get pwm working on those pins too D:
So ive checked each pin of individually and when calling analogWrite or pwmWrite on PB4 PB5 and PA15 the program locks up.

I can only guess, while these re PWM compatible pins, they need configuring for it first..... Soooo any guides to do that?
Just a dogs body developer, mostly making props and stuff...
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Updated question, How to set PA15 to GPIO Output, and PWM questions...

Post by stevestrong »

The PWM (timer) pins defined per default in the core and in the MCU can be found here: https://github.com/rogerclarkmelbourne/ ... pp#L58-L94.
The PWM timer and channel number are in the second and fifth position of each row.
As you can see, pins PB4/5 and PA15 do not have assigned any timer nor channel, this is conform to the default HW configuration.

If you want to use those pins for PWM you have to manually add the info for each pin into the table:
PB4: TIM3 CH1 (like PA6)
PB5: TIM3 CH2 (like PA7)
PA15: TIM2 CH1 (like PA0)
and then remap the timer pins in setup:

Code: Select all

afio_remap(AFIO_REMAP_TIM3_PARTIAL);
afio_remap(AFIO_REMAP_TIM2_PARTIAL_1);
Last edited by stevestrong on Wed Oct 14, 2020 12:15 pm, edited 1 time in total.
User avatar
Mangy_Dog
Posts: 92
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Updated question, How to set PA15 to GPIO Output, and PWM questions...

Post by Mangy_Dog »

Code: Select all

#include "Arduino.h"
//The setup function is called once at startup of the sketch

#define scan1 PB4
#define scan2 PB5
#define scan3 PA1

#define scanRED1 PA11
#define scanRED2 PA15

#define buzzer PB0

void setup ()
{

	enableDebugPorts ();
	afio_remap (AFIO_REMAP_TIM3_PARTIAL);
	afio_remap (AFIO_REMAP_TIM2_PARTIAL_1);

	//*(volatile uint32_t*)0x40010004 = (2 << 24) | (1 << 8);;

	pinMode (PB1, OUTPUT);
	pinMode (buzzer, OUTPUT);

	pinMode (scan1, OUTPUT);
	pinMode (scan2, OUTPUT);
	pinMode (scan3, OUTPUT);

	pinMode (scanRED1, OUTPUT);
	pinMode (scanRED2, OUTPUT);
	pinMode (PA12, OUTPUT);

// Add your initialization code here
}
uint16_t testpwm = 0;
// The loop function is called in an endless loop
void loop ()
{
	testpwm++;
	analogWrite (PB1, testpwm);
//	analogWrite(scan1,testpwm); // locks up PB4
//	analogWrite(scan2,testpwm); //locks up PB5
//	analogWrite(scan3,testpwm);
////  analogWrite(PA12,testpwm);
//	analogWrite(scanRED1,testpwm);
	analogWrite (scanRED2, testpwm); //locks up PA15
	delay (10);

//Add your repeated code here
}

and edited board.cpp

Code: Select all

extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS] = {


    {&gpioa, &timer2, &adc1,  0, 1,    0}, /* PA0 */
    {&gpioa, &timer2, &adc1,  1, 2,    1}, /* PA1 */
    {&gpioa, &timer2, &adc1,  2, 3,    2}, /* PA2 */	
    {&gpioa, &timer2, &adc1,  3, 4,    3}, /* PA3 */
    {&gpioa,   NULL, &adc1,  4, 0,    4}, /* PA4 */
    {&gpioa,   NULL, &adc1,  5, 0,    5}, /* PA5 */
    {&gpioa, &timer3, &adc1,  6, 1,    6}, /* PA6 */
    {&gpioa, &timer3, &adc1,  7, 2,    7}, /* PA7 */
    {&gpioa, &timer1, NULL,  8, 1, ADCx}, /* PA8 */	
    {&gpioa, &timer1, NULL,  9, 2, ADCx}, /* PA9 */	
    {&gpioa, &timer1, NULL, 10, 3, ADCx}, /* PA10 */
    {&gpioa, &timer1, NULL, 11, 4, ADCx}, /* PA11 */
    {&gpioa,   NULL, NULL, 12, 0, ADCx}, /* PA12 */	
    {&gpioa,   NULL, NULL, 13, 0, ADCx}, /* PA13 */	
    {&gpioa,   NULL, NULL, 14, 0, ADCx}, /* PA14 */
    {&gpioa, &timer2, &adc1, 15, 0, ADCx}, /* PA15 */
	
    {&gpiob, &timer3, &adc1,  0, 3,    8}, /* PB0 */	
    {&gpiob, &timer3, &adc1,  1, 4,    9}, /* PB1 */
    {&gpiob,   NULL, NULL,  2, 0, ADCx}, /* PB2 */
    {&gpiob,   NULL, NULL,  3, 0, ADCx}, /* PB3 */
    {&gpiob, &timer3, &adc1,  4, 0, ADCx}, /* PB4 */
    {&gpiob, &timer3, &adc2,  5, 0, ADCx}, /* PB5 */
    {&gpiob, &timer4, NULL,  6, 1, ADCx}, /* PB6 */
    {&gpiob, &timer4, NULL,  7, 2, ADCx}, /* PB7 */	
    {&gpiob, &timer4, NULL,  8, 3, ADCx}, /* PB8 */	
    {&gpiob, &timer4, NULL,  9, 4, ADCx}, /* PB9 */	
    {&gpiob,   NULL, NULL, 10, 0, ADCx}, /* PB10 */	
    {&gpiob,   NULL, NULL, 11, 0, ADCx}, /* PB11 */
    {&gpiob,   NULL, NULL, 12, 0, ADCx}, /* PB12 */
    {&gpiob,   NULL, NULL, 13, 0, ADCx}, /* PB13 */
    {&gpiob,   NULL, NULL, 14, 0, ADCx}, /* PB14 */
    {&gpiob,   NULL, NULL, 15, 0, ADCx}, /* PB15 */

    {&gpioc,   NULL, NULL, 13, 0, ADCx}, /* PC13 */	
    {&gpioc,   NULL, NULL, 14, 0, ADCx}, /* PC14 */
    {&gpioc,   NULL, NULL, 15, 0, ADCx}, /* PC15 */



};
still hanging, do I need to NULL out the original pin maps? IE the ones i copied from? This assuming the same mappings cant be used on multiple pins?
Just a dogs body developer, mostly making props and stuff...
Post Reply

Return to “General discussion”