annotate Discovery/Src/externCPU2bootloader.c @ 834:2a8af51ab04d Evo_2_23

Added event based display changes for big font view: It is now possible to activate "Autofocus" option in custom view dialog. This enables automatic switching of the current view depending on current dive situation. Because T7 view already displays a lot of information this feature targets the T3 view.
author Ideenmodellierer
date Sun, 17 Dec 2023 21:14:17 +0100
parents 01f40cb1057e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file externCPU2bootloader.c Template
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 23-Oct-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @since 23-Oct-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * @brief Main Template to communicate with the second CPU in bootloader mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * bootloader ROM build by ST and defined in AN4286
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 * <h2><center>&copy; COPYRIGHT(c) 2016 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 #include "stdio.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 #include "ostc.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 #include "settings.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 #include "externCPU2bootloader.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 #include "externLogbookFlash.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 #include "tComm.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 /* Exported variables --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 /* Private types -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
43 static uint8_t boot_sync_frame(void);
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
44 static uint8_t boot_ack(void);
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
45 static uint8_t boot_get_id(uint8_t *RxBuffer);
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
46 static uint8_t boot_get_version(uint8_t *RxBuffer);
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
47 static uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data);
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
48 static uint8_t boot_erase_memory(void);
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
49 static void Bootloader_send_command(uint8_t command);
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
50 static void Bootloader_spi_single(uint8_t TxByte);
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
51 static void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer);
699
01f40cb1057e Cleanup warnings:
Ideenmodellierer
parents: 300
diff changeset
52 //static void Bootloader_Error_Handler(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 uint8_t extCPU2bootloader_start(uint8_t *version, uint16_t *chipID)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 uint8_t aRxBuffer[256] = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 boot_sync_frame();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 boot_get_version(aRxBuffer);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 *version = aRxBuffer[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 HAL_Delay(10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 boot_get_id(aRxBuffer);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 *chipID = ((uint16_t)aRxBuffer[2]) << 8;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 *chipID += (uint16_t)aRxBuffer[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 HAL_Delay(10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 if((*chipID == 0x431) && (*version > 10) && (*version < 32))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
53
f64cf099a7f5 Allow RTE binaries > 64k size
Ideenmodellierer
parents: 38
diff changeset
77 uint8_t extCPU2bootloader_internal(uint8_t* buffer, uint32_t length, char* display_text)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 uint8_t version = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 uint16_t chipID = 0;
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
81
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 if(!extCPU2bootloader_start(&version,&chipID))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 if(!boot_erase_memory())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 HAL_Delay(100);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 uint16_t i=0;
53
f64cf099a7f5 Allow RTE binaries > 64k size
Ideenmodellierer
parents: 38
diff changeset
88 uint32_t lengthsave = length;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 uint8_t percent = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 while(length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 percent = (100 * (i * 256)) /lengthsave;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 tComm_verlauf(percent);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 if(length > 256)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 if( !boot_write_memory(0x08000000 + (i * 256), 255, &buffer[i * 256]) )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 return 0;;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 length -= 256;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 if(!boot_write_memory(0x08000000 + (i * 256), length - 1, &buffer[i * 256]))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 length = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 i++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 return 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
53
f64cf099a7f5 Allow RTE binaries > 64k size
Ideenmodellierer
parents: 38
diff changeset
115 uint8_t extCPU2bootloader(uint8_t* buffer, uint32_t length, char* display_text)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 uint8_t result = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 MX_SmallCPU_Reset_To_Boot();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 result = extCPU2bootloader_internal(buffer,length,display_text);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 MX_SmallCPU_Reset_To_Standard();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 return result;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 /* Private functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
127 static uint8_t boot_sync_frame(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 Bootloader_spi_single(0x5a);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 return boot_ack();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
133 static uint8_t boot_get_version(uint8_t *RxBuffer)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 Bootloader_spi_single(0x5a);
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
136 Bootloader_send_command(0x01);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 if(!boot_ack())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 Bootloader_spi(3, NULL, RxBuffer);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 return boot_ack();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
144 static uint8_t boot_get_id(uint8_t *RxBuffer)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 Bootloader_spi_single(0x5a);
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
147 Bootloader_send_command(0x02);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 if(!boot_ack())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 Bootloader_spi(5, NULL, RxBuffer);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 return boot_ack();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 uint8_t addressNew[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 uint8_t checksum = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 uint16_t length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 Bootloader_spi_single(0x5a);
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
162 Bootloader_send_command(0x31);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 if(!boot_ack())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 HAL_Delay(5);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 addressNew[0] = (uint8_t)((address >> 24) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 addressNew[1] = (uint8_t)((address >> 16) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 addressNew[2] = (uint8_t)((address >> 8) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 addressNew[3] = (uint8_t)((address >> 0) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 Bootloader_spi(4, addressNew, NULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 checksum = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 checksum ^= addressNew[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 checksum ^= addressNew[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 checksum ^= addressNew[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 checksum ^= addressNew[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 Bootloader_spi_single(checksum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 if(!boot_ack())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 HAL_Delay(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 Bootloader_spi_single(length_minus_1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 length = ((uint16_t)length_minus_1) + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 Bootloader_spi(length, data, NULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 HAL_Delay(26);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 checksum = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 checksum ^= length_minus_1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 for(int i=0;i<length;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 checksum ^= data[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 Bootloader_spi_single(checksum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 if(!boot_ack())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 HAL_Delay(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
196 static uint8_t boot_erase_memory(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 uint8_t special_erase_with_checksum[3] = {0xFF, 0xFF, 0x00};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 Bootloader_spi_single(0x5a);
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
201 Bootloader_send_command(0x44);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 if(!boot_ack())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 Bootloader_spi(3, special_erase_with_checksum, NULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 HAL_Delay(11000); /* 5.5 to 11 seconds */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 if(!boot_ack())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 /* write unprotect does reset the system !! */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 uint8_t boot_write_unprotect(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 Bootloader_spi_single(0x5a);
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
215 Bootloader_send_command(0x73);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 if(!boot_ack())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 return boot_ack();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
221 static uint8_t boot_ack(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 uint8_t answer = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 Bootloader_spi_single(0x00);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 for(int i=0; i< 1000; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 Bootloader_spi(1, NULL, &answer);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 if((answer == 0x79) || (answer == 0x1F))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 Bootloader_spi_single(0x79);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 HAL_Delay(10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 if(answer == 0x79)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
242 static void Bootloader_send_command(uint8_t command)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 uint8_t send[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 uint8_t receive[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 send[0] = command;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 send[1] = 0xFF ^ command;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 Bootloader_spi(2, send, receive);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
252 static void Bootloader_spi_single(uint8_t TxByte)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 Bootloader_spi(1,&TxByte, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
258 static void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 uint8_t dummy[256] = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 uint8_t *tx_data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 uint8_t *rx_data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 tx_data = aTxBuffer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 rx_data = aRxBuffer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 if(aTxBuffer == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 tx_data = dummy;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 if(aRxBuffer == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 rx_data = dummy;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 //HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_RESET); // only for testing with Oscilloscope
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 HAL_SPI_TransmitReceive(&cpu2DmaSpi, (uint8_t *)tx_data, (uint8_t *)rx_data, (uint16_t)lengthData,1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 if(HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)tx_data, (uint8_t *)rx_data, (uint16_t)lengthData) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 if(HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)tx_data, (uint8_t *)rx_data, (uint16_t)lengthData) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 Bootloader_Error_Handler();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 while (HAL_SPI_GetState(&cpu2DmaSpi) != HAL_SPI_STATE_READY)// only for testing with Oscilloscope
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET); // only for testing with Oscilloscope
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288
699
01f40cb1057e Cleanup warnings:
Ideenmodellierer
parents: 300
diff changeset
289 /*
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 53
diff changeset
290 static void Bootloader_Error_Handler(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 while(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 }
699
01f40cb1057e Cleanup warnings:
Ideenmodellierer
parents: 300
diff changeset
294 */