I'm new to ARM development and trying to do some fundamental beginner stuff with STM32. I have a VL Discovery board, and I'm just trying to send serial data. I set up the port, relying largely on sample code (though at this point I think I mostly understand what it's trying to do), and it definitely sends something, but it comes out as garbage on the other end. This happens for a variety of different baud rates, even 4800 baud. So I figure the baud rate is inaccurate for some reason (but I'm unsure how -- I call a function in the ST library and hand it a baud rate, it does the calculations).
So I try to measure the system clock. I try to set up the MCO on A8 so I can put a scope on it, and I end up getting a very faint signal, +/-40mV, that looks like a very messy clock, with waves that aren't very square. Most importantly, the period is not consistent. Many of the waves are sort of the same length, but frequently there are really short ones, and much longer ones. I couldn't even get a viewable image on my old analog scope; I had to use a DSO to capture a screenful so I could look at it.
So then I try to just toggle a GPIO pin to see how consistent that is, flipping it back and forth with the BSRR and BRR registers in a while(1) loop, mostly following example code to do so. And I'm getting no output at all.
So, I'm really confused at this point.
Simplest question first -- should the above be adequate for setting up the GPIO pin B1 for output? Is there anything else I need to do? I've looked at several examples online and in the ST library example code, and I can't see that they're doing anything else.
To toggle the bit, I'm just doing this:
I put a scope on the pin, and see nothing. I've tried several different pins on different ports, no difference.
FWIW, regarding the clock stuff, the chip is using an 8Mhz crystal with a PLL set for 24Mhz.
Edit -- I should probably add that I'm using KEIL for development, but I'm trying to stay away from KEIL-related code, eg. STM32_Init, etc. I'm using the ST library v3.5.0. I've deleted KEIL's ancient ST library to prevent it from using that, as most people seem to recommend.
So I try to measure the system clock. I try to set up the MCO on A8 so I can put a scope on it, and I end up getting a very faint signal, +/-40mV, that looks like a very messy clock, with waves that aren't very square. Most importantly, the period is not consistent. Many of the waves are sort of the same length, but frequently there are really short ones, and much longer ones. I couldn't even get a viewable image on my old analog scope; I had to use a DSO to capture a screenful so I could look at it.
So then I try to just toggle a GPIO pin to see how consistent that is, flipping it back and forth with the BSRR and BRR registers in a while(1) loop, mostly following example code to do so. And I'm getting no output at all.
So, I'm really confused at this point.
Code:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
Simplest question first -- should the above be adequate for setting up the GPIO pin B1 for output? Is there anything else I need to do? I've looked at several examples online and in the ST library example code, and I can't see that they're doing anything else.
To toggle the bit, I'm just doing this:
Code:
while (1) {
bit = !bit;
if (bit) GPIOB->BSRR = 1; else GPIOB->BRR = 1;
}
I put a scope on the pin, and see nothing. I've tried several different pins on different ports, no difference.
FWIW, regarding the clock stuff, the chip is using an 8Mhz crystal with a PLL set for 24Mhz.
Edit -- I should probably add that I'm using KEIL for development, but I'm trying to stay away from KEIL-related code, eg. STM32_Init, etc. I'm using the ST library v3.5.0. I've deleted KEIL's ancient ST library to prevent it from using that, as most people seem to recommend.
Last edited: