Firmware to run on a Nucleo board to interact with an IRDA bootloader. Used with a bootloader running on a STM32F042 (MP for more information)

Dependencies:   mbed

Committer:
garivetm
Date:
Tue Sep 03 08:25:33 2019 +0000
Revision:
0:f600cde37499
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
garivetm 0:f600cde37499 1 #include "mbed.h"
garivetm 0:f600cde37499 2
garivetm 0:f600cde37499 3 //------------------------------------
garivetm 0:f600cde37499 4 // Recopie de Serial pc vers Serial IRDA
garivetm 0:f600cde37499 5 //------------------------------------
garivetm 0:f600cde37499 6 IRDA_HandleTypeDef hirda1;
garivetm 0:f600cde37499 7 Serial pc(SERIAL_TX, SERIAL_RX);
garivetm 0:f600cde37499 8 Serial irda(PA_9, PA_10);
garivetm 0:f600cde37499 9 uint8_t c;
garivetm 0:f600cde37499 10 char echo = 0;
garivetm 0:f600cde37499 11 #define RX_BUFFER_SIZE 50
garivetm 0:f600cde37499 12 uint8_t rxbuffer[RX_BUFFER_SIZE] = {0};
garivetm 0:f600cde37499 13 char rxi = 0;
garivetm 0:f600cde37499 14 #define TX_BUFFER_SIZE 50
garivetm 0:f600cde37499 15 uint8_t txbuffer[TX_BUFFER_SIZE] = {0};
garivetm 0:f600cde37499 16 char txi = 0;
garivetm 0:f600cde37499 17
garivetm 0:f600cde37499 18 #define HELLO 0x68
garivetm 0:f600cde37499 19
garivetm 0:f600cde37499 20 void Irda1_init(void);
garivetm 0:f600cde37499 21 void IRDA_RxCpltCallback(void);
garivetm 0:f600cde37499 22 void PC_RxCpltCallback(void);
garivetm 0:f600cde37499 23
garivetm 0:f600cde37499 24 unsigned long* USART_CR3 = (unsigned long*)0x40013808; // offset 0x08
garivetm 0:f600cde37499 25 unsigned long* USART_CR2 = (unsigned long*)0x40013804; // offset 0x04
garivetm 0:f600cde37499 26 unsigned long* USART_CR1 = (unsigned long*)0x40013800; // offset 0x00
garivetm 0:f600cde37499 27 unsigned long* USART_GTPR = (unsigned long*)0x40013810; // offset 0x10
garivetm 0:f600cde37499 28 unsigned long* USART_BRR = (unsigned long*)0x4001380C; // offset 0x0C
garivetm 0:f600cde37499 29
garivetm 0:f600cde37499 30 void Irda1_init(void)
garivetm 0:f600cde37499 31 {
garivetm 0:f600cde37499 32 hirda1.Instance = USART1;
garivetm 0:f600cde37499 33 hirda1.Init.BaudRate = 9600;
garivetm 0:f600cde37499 34 hirda1.Init.WordLength = IRDA_WORDLENGTH_8B;
garivetm 0:f600cde37499 35 hirda1.Init.Parity = IRDA_PARITY_NONE;
garivetm 0:f600cde37499 36 hirda1.Init.Prescaler = 1;
garivetm 0:f600cde37499 37 hirda1.Init.PowerMode = IRDA_POWERMODE_NORMAL;
garivetm 0:f600cde37499 38 hirda1.Init.Mode = IRDA_MODE_TX_RX;
garivetm 0:f600cde37499 39 HAL_IRDA_Init(&hirda1);
garivetm 0:f600cde37499 40 }
garivetm 0:f600cde37499 41
garivetm 0:f600cde37499 42 int main() {
garivetm 0:f600cde37499 43 pc.baud(9600);
garivetm 0:f600cde37499 44 pc.printf("IRDA BOOTLOADER.\r\n");
garivetm 0:f600cde37499 45
garivetm 0:f600cde37499 46 Irda1_init();
garivetm 0:f600cde37499 47
garivetm 0:f600cde37499 48 c = HELLO;
garivetm 0:f600cde37499 49 irda.putc(c);
garivetm 0:f600cde37499 50
garivetm 0:f600cde37499 51 while(1) {
garivetm 0:f600cde37499 52 if(irda.readable()){
garivetm 0:f600cde37499 53 c = irda.getc();
garivetm 0:f600cde37499 54 while(!pc.writeable());
garivetm 0:f600cde37499 55 pc.putc(c);
garivetm 0:f600cde37499 56 }
garivetm 0:f600cde37499 57
garivetm 0:f600cde37499 58 if(pc.readable()){
garivetm 0:f600cde37499 59 c = pc.getc();
garivetm 0:f600cde37499 60 while(!irda.writeable());
garivetm 0:f600cde37499 61 irda.putc(c);
garivetm 0:f600cde37499 62 }
garivetm 0:f600cde37499 63 }
garivetm 0:f600cde37499 64 }
garivetm 0:f600cde37499 65