1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
with HAL; use HAL;
with STM32.Device; use STM32.Device;
with STM32.GPIO; use STM32.GPIO;
with STM32.USARTs; use STM32.USARTs;
package body Logging is
TX_Pin : constant GPIO_Point := PB6;
RX_Pin : constant GPIO_Point := PB7;
procedure Init is
begin
Enable_Clock (USART_1);
Enable_Clock (RX_Pin & TX_Pin);
Configure_IO
(RX_Pin & TX_Pin,
(Mode => Mode_AF,
AF => GPIO_B_AF_USART1_0,
Resistors => Pull_Up,
AF_Speed => Speed_50MHz,
AF_Output_Type => Push_Pull));
Disable (USART_1);
Set_Oversampling_Mode (USART_1, Oversampling_By_16);
Set_Baud_Rate (USART_1, 115200);
Set_Mode (USART_1, Tx_Rx_Mode);
Set_Stop_Bits (USART_1, Stopbits_1);
Set_Word_Length (USART_1, Word_Length_8);
Set_Parity (USART_1, No_Parity);
Set_Flow_Control (USART_1, No_Flow_Control);
Enable (USART_1);
end Init;
procedure Await_Send_Ready (This : USART) is
begin
loop
exit when Tx_Ready (This);
end loop;
end Await_Send_Ready;
procedure Put_Blocking (This : in out USART; Data : UInt16) is
begin
Await_Send_Ready (This);
Transmit (This, UInt9 (Data));
end Put_Blocking;
procedure Log (S : String; L : Integer := 1; Deindent : Integer := 0) is
begin
for C of S loop
Put_Blocking (USART_1, Character'Pos (C));
end loop;
Put_Blocking (USART_1, UInt16 (13)); -- CR
Put_Blocking (USART_1, UInt16 (10)); -- LF
end Log;
end Logging;
|