Skip to content

Commit 86c42bc

Browse files
committed
[stm32f429i-discovery] Switched over to UART1.
UART1 is connected through two jumpers to the programmer chip on the board. Making the use of it very streight forward.
1 parent d6cb05d commit 86c42bc

File tree

6 files changed

+67
-64
lines changed

6 files changed

+67
-64
lines changed

examples/stm32/f4/stm32f4-disco/lcd-serial/console.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,10 @@ void console_setup(int baud) {
193193
/* MUST enable the GPIO clock in ADDITION to the USART clock */
194194
rcc_periph_clock_enable(RCC_GPIOA);
195195

196-
/* This example uses PD5 and PD6 for Tx and Rx respectively
196+
/* This example uses PA9 and PA10 for Tx and Rx respectively
197197
* but other pins are available for this role on USART1 (our chosen
198-
* USART) as well, such as PA2 and PA3. You can also split them
199-
* so PA2 for Tx, PD6 for Rx but you would have to enable both
200-
* the GPIOA and GPIOD clocks in that case
198+
* USART) as well. We decided on the ones above as they are connected
199+
* to the programming circuitry through jumpers.
201200
*/
202201
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO10);
203202

@@ -209,9 +208,11 @@ void console_setup(int baud) {
209208

210209

211210
/* This then enables the clock to the USART1 peripheral which is
212-
* attached inside the chip to the APB2 bus. Different peripherals
211+
* attached inside the chip to the APB1 bus. Different peripherals
213212
* attach to different buses, and even some UARTS are attached to
214213
* APB1 and some to APB2, again the data sheet is useful here.
214+
* We use the rcc_periph_clock_enable function that knows which
215+
* peripheral is on which bus and sets it up for us.
215216
*/
216217
rcc_periph_clock_enable(RCC_USART1);
217218

examples/stm32/f4/stm32f4-disco/sdram/console.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*/
4848

4949

50-
#define CONSOLE_UART USART2
50+
#define CONSOLE_UART USART1
5151

5252

5353
/* This is a ring buffer to holding characters as they are typed
@@ -62,7 +62,7 @@ volatile int recv_ndx_nxt; // Next place to store
6262
volatile int recv_ndx_cur; // Next place to read
6363

6464
/* For interrupt handling we add a new function which is called
65-
* when recieve interrupts happen. The name (usart2_isr) is created
65+
* when recieve interrupts happen. The name (usart1_isr) is created
6666
* by the irq.json file in libopencm3 calling this interrupt for
6767
* USART2 'usart2', adding the suffix '_isr', and then weakly binding
6868
* it to the 'do nothing' interrupt function in vec.c.
@@ -72,7 +72,7 @@ volatile int recv_ndx_cur; // Next place to read
7272
* right or it won't work. And you'll wonder where your interrupts
7373
* are going.
7474
*/
75-
void usart2_isr(void) {
75+
void usart1_isr(void) {
7676
uint32_t reg;
7777
int i;
7878

@@ -193,29 +193,30 @@ int console_gets(char *s, int len) {
193193
void console_setup(void) {
194194

195195
/* MUST enable the GPIO clock in ADDITION to the USART clock */
196-
rcc_periph_clock_enable(RCC_GPIOD);
196+
rcc_periph_clock_enable(RCC_GPIOA);
197197

198-
/* This example uses PD5 and PD6 for Tx and Rx respectively
199-
* but other pins are available for this role on USART2 (our chosen
200-
* USART) as well, such as PA2 and PA3. You can also split them
201-
* so PA2 for Tx, PD6 for Rx but you would have to enable both
202-
* the GPIOA and GPIOD clocks in that case
198+
/* This example uses PD9 and PD10 for Tx and Rx respectively
199+
* but other pins are available for this role on USART1 (our chosen
200+
* USART) as well, we are using them because they are connected over
201+
* jumpers to the programmer.
203202
*/
204-
gpio_mode_setup(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO5 | GPIO6);
203+
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO10);
205204

206205
/* Actual Alternate function number (in this case 7) is part
207206
* depenedent, check the data sheet for the right number to
208207
* use.
209208
*/
210-
gpio_set_af(GPIOD, GPIO_AF7, GPIO5 | GPIO6);
209+
gpio_set_af(GPIOA, GPIO_AF7, GPIO9 | GPIO10);
211210

212211

213-
/* This then enables the clock to the USART2 peripheral which is
214-
* attached inside the chip to the APB2 bus. Different peripherals
212+
/* This then enables the clock to the USART1 peripheral which is
213+
* attached inside the chip to the APB1 bus. Different peripherals
215214
* attach to different buses, and even some UARTS are attached to
216215
* APB1 and some to APB2, again the data sheet is useful here.
216+
* We are using the rcc_periph_clock_enable function that knows which
217+
* peripheral is on which clock bus and sets things up accordingly.
217218
*/
218-
rcc_periph_clock_enable(RCC_USART2);
219+
rcc_periph_clock_enable(RCC_USART1);
219220

220221
/* Set up USART/UART parameters using the libopencm3 helper functions */
221222
usart_set_baudrate(CONSOLE_UART, 115200);
@@ -227,7 +228,7 @@ void console_setup(void) {
227228
usart_enable(CONSOLE_UART);
228229

229230
/* Enable interrupts from the USART */
230-
nvic_enable_irq(NVIC_USART2_IRQ);
231+
nvic_enable_irq(NVIC_USART1_IRQ);
231232

232233
/* Specifically enable recieve interrupts */
233234
usart_enable_rx_interrupt(CONSOLE_UART);

examples/stm32/f4/stm32f4-disco/spi/console.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ volatile int recv_ndx_nxt; // Next place to store
4747
volatile int recv_ndx_cur; // Next place to read
4848

4949
/* For interrupt handling we add a new function which is called
50-
* when recieve interrupts happen. The name (usart2_isr) is created
50+
* when recieve interrupts happen. The name (usart1_isr) is created
5151
* by the irq.json file in libopencm3 calling this interrupt for
52-
* USART2 'usart2', adding the suffix '_isr', and then weakly binding
52+
* USART1 'usart1', adding the suffix '_isr', and then weakly binding
5353
* it to the 'do nothing' interrupt function in vec.c.
5454
*
5555
* By defining it in this file the linker will override that weak
5656
* binding and instead bind it here, but you have to get the name
5757
* right or it won't work. And you'll wonder where your interrupts
5858
* are going.
5959
*/
60-
void usart2_isr(void) {
60+
void usart1_isr(void) {
6161
uint32_t reg;
6262
int i;
6363

@@ -191,29 +191,30 @@ int console_gets(char *s, int len) {
191191
void console_setup(int baud) {
192192

193193
/* MUST enable the GPIO clock in ADDITION to the USART clock */
194-
rcc_periph_clock_enable(RCC_GPIOD);
194+
rcc_periph_clock_enable(RCC_GPIOA);
195195

196-
/* This example uses PD5 and PD6 for Tx and Rx respectively
197-
* but other pins are available for this role on USART2 (our chosen
198-
* USART) as well, such as PA2 and PA3. You can also split them
199-
* so PA2 for Tx, PD6 for Rx but you would have to enable both
200-
* the GPIOA and GPIOD clocks in that case
196+
/* This example uses PA9 and PA10 for Tx and Rx respectively
197+
* but other pins are available for this role on USART1 (our chosen
198+
* USART) as well, we are using these because they are connected to the
199+
* programmer through some jumpers.
201200
*/
202-
gpio_mode_setup(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO5 | GPIO6);
201+
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO10);
203202

204203
/* Actual Alternate function number (in this case 7) is part
205204
* depenedent, CHECK THE DATA SHEET for the right number to
206205
* use.
207206
*/
208-
gpio_set_af(GPIOD, GPIO_AF7, GPIO5 | GPIO6);
207+
gpio_set_af(GPIOA, GPIO_AF7, GPIO9 | GPIO10);
209208

210209

211-
/* This then enables the clock to the USART2 peripheral which is
212-
* attached inside the chip to the APB2 bus. Different peripherals
210+
/* This then enables the clock to the USART1 peripheral which is
211+
* attached inside the chip to the APB1 bus. Different peripherals
213212
* attach to different buses, and even some UARTS are attached to
214213
* APB1 and some to APB2, again the data sheet is useful here.
214+
* We are using rcc_periph_clock_enable that knows which peripheral is
215+
* on which clock bus and sets up everything accordingly.
215216
*/
216-
rcc_periph_clock_enable(RCC_USART2);
217+
rcc_periph_clock_enable(RCC_USART1);
217218

218219
/* Set up USART/UART parameters using the libopencm3 helper functions */
219220
usart_set_baudrate(CONSOLE_UART, baud);
@@ -225,7 +226,7 @@ void console_setup(int baud) {
225226
usart_enable(CONSOLE_UART);
226227

227228
/* Enable interrupts from the USART */
228-
nvic_enable_irq(NVIC_USART2_IRQ);
229+
nvic_enable_irq(NVIC_USART1_IRQ);
229230

230231
/* Specifically enable recieve interrupts */
231232
usart_enable_rx_interrupt(CONSOLE_UART);

examples/stm32/f4/stm32f429i-discovery/usart_console/usart_console.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* we can use on a serial port.
3636
*/
3737

38-
#define CONSOLE_UART USART2
38+
#define CONSOLE_UART USART1
3939

4040
void console_putc(char c);
4141
char console_getc(int wait);
@@ -134,28 +134,29 @@ int main(void) {
134134
clock_setup(); // initialize our clock
135135

136136
/* MUST enable the GPIO clock in ADDITION to the USART clock */
137-
rcc_periph_clock_enable(RCC_GPIOD);
137+
rcc_periph_clock_enable(RCC_GPIOA);
138138

139-
/* This example uses PD5 and PD6 for Tx and Rx respectively
140-
* but other pins are available for this role on USART2 (our chosen
141-
* USART) as well, such as PA2 and PA3. You can also split them
142-
* so PA2 for Tx, PD6 for Rx but you would have to enable both
143-
* the GPIOA and GPIOD clocks in that case
139+
/* This example uses PA9 and PA10 for Tx and Rx respectively
140+
* but other pins are available for this role on USART1 (our chosen
141+
* USART) as it is connected to the programmer interface through
142+
* jumpers.
144143
*/
145-
gpio_mode_setup(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO5 | GPIO6);
144+
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO10);
146145

147146
/* Actual Alternate function number (in this case 7) is part
148147
* depenedent, check the data sheet for the right number to
149148
* use.
150149
*/
151-
gpio_set_af(GPIOD, GPIO_AF7, GPIO5 | GPIO6);
150+
gpio_set_af(GPIOA, GPIO_AF7, GPIO9 | GPIO10);
152151

153-
/* This then enables the clock to the USART2 peripheral which is
154-
* attached inside the chip to the APB2 bus. Different peripherals
152+
/* This then enables the clock to the USART1 peripheral which is
153+
* attached inside the chip to the APB1 bus. Different peripherals
155154
* attach to different buses, and even some UARTS are attached to
156155
* APB1 and some to APB2, again the data sheet is useful here.
156+
* We use the rcc_periph_clock_enable function that knows on which bus
157+
* the peripheral is and sets things up accordingly.
157158
*/
158-
rcc_periph_clock_enable(RCC_USART2);
159+
rcc_periph_clock_enable(RCC_USART1);
159160

160161
/* Set up USART/UART parameters using the libopencm3 helper functions */
161162
usart_set_baudrate(CONSOLE_UART, 115200);

examples/stm32/f4/stm32f429i-discovery/usart_irq_console/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ BINARY = usart_irq_console
2222
# Example showing how to generate a map file.
2323
LDFLAGS += -Wl,--Map=$(BINARY).map
2424

25-
LDSCRIPT = ../stm32f4-disco.ld
25+
LDSCRIPT = ../stm32f429i-discovery.ld
2626

2727
include ../../Makefile.include
2828

examples/stm32/f4/stm32f429i-discovery/usart_irq_console/usart_irq_console.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
*/
5555

5656

57-
#define CONSOLE_UART USART2
57+
#define CONSOLE_UART USART1
5858

5959
void console_putc(char c);
6060
char console_getc(int wait);
@@ -97,17 +97,17 @@ volatile int recv_ndx_nxt; // Next place to store
9797
volatile int recv_ndx_cur; // Next place to read
9898

9999
/* For interrupt handling we add a new function which is called
100-
* when recieve interrupts happen. The name (usart2_isr) is created
100+
* when recieve interrupts happen. The name (usart1_isr) is created
101101
* by the irq.json file in libopencm3 calling this interrupt for
102-
* USART2 'usart2', adding the suffix '_isr', and then weakly binding
102+
* USART1 'usart1', adding the suffix '_isr', and then weakly binding
103103
* it to the 'do nothing' interrupt function in vec.c.
104104
*
105105
* By defining it in this file the linker will override that weak
106106
* binding and instead bind it here, but you have to get the name
107107
* right or it won't work. And you'll wonder where your interrupts
108108
* are going.
109109
*/
110-
void usart2_isr(void) {
110+
void usart1_isr(void) {
111111
uint32_t reg;
112112
int i;
113113

@@ -272,29 +272,28 @@ int main(void) {
272272
clock_setup(); // initialize our clock
273273

274274
/* MUST enable the GPIO clock in ADDITION to the USART clock */
275-
rcc_periph_clock_enable(RCC_GPIOD);
275+
rcc_periph_clock_enable(RCC_GPIOA);
276276

277-
/* This example uses PD5 and PD6 for Tx and Rx respectively
278-
* but other pins are available for this role on USART2 (our chosen
279-
* USART) as well, such as PA2 and PA3. You can also split them
280-
* so PA2 for Tx, PD6 for Rx but you would have to enable both
281-
* the GPIOA and GPIOD clocks in that case
277+
/* This example uses PA9 and PA10 for Tx and Rx respectively
278+
* but other pins are available for this role on USART1 (our chosen
279+
* USART) as well. We are using the ones mentioned above because they
280+
* are connected to the programmer on the board through some jumpers.
282281
*/
283-
gpio_mode_setup(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO5 | GPIO6);
282+
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO10);
284283

285284
/* Actual Alternate function number (in this case 7) is part
286285
* depenedent, CHECK THE DATA SHEET for the right number to
287286
* use.
288287
*/
289-
gpio_set_af(GPIOD, GPIO_AF7, GPIO5 | GPIO6);
288+
gpio_set_af(GPIOA, GPIO_AF7, GPIO9 | GPIO10);
290289

291290

292-
/* This then enables the clock to the USART2 peripheral which is
293-
* attached inside the chip to the APB2 bus. Different peripherals
291+
/* This then enables the clock to the USART1 peripheral which is
292+
* attached inside the chip to the APB1 bus. Different peripherals
294293
* attach to different buses, and even some UARTS are attached to
295294
* APB1 and some to APB2, again the data sheet is useful here.
296295
*/
297-
rcc_periph_clock_enable(RCC_USART2);
296+
rcc_periph_clock_enable(RCC_USART1);
298297

299298
/* Set up USART/UART parameters using the libopencm3 helper functions */
300299
usart_set_baudrate(CONSOLE_UART, 115200);
@@ -306,7 +305,7 @@ int main(void) {
306305
usart_enable(CONSOLE_UART);
307306

308307
/* Enable interrupts from the USART */
309-
nvic_enable_irq(NVIC_USART2_IRQ);
308+
nvic_enable_irq(NVIC_USART1_IRQ);
310309

311310
/* Specifically enable recieve interrupts */
312311
usart_enable_rx_interrupt(CONSOLE_UART);

0 commit comments

Comments
 (0)