rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
hal_lld.c
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2014-2015 Fabio Utzig
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file KE1xF/hal_lld.c
19 * @brief HAL Driver subsystem low level driver source.
20 * @author andreika <prometheus.pcb@gmail.com>
21 *
22 * @addtogroup HAL
23 * @{
24 */
25
26#include <stdint.h>
27#include "hal.h"
28#include "clock_config.h"
29
30/*===========================================================================*/
31/* Driver local definitions. */
32/*===========================================================================*/
33
34/*===========================================================================*/
35/* Driver exported variables. */
36/*===========================================================================*/
37
38/*===========================================================================*/
39/* Driver local variables and types. */
40/*===========================================================================*/
41
42// Bootloader config peripheral enable flags
43// Bootloader on LPUART & LPSPI, not on CAN
44#ifndef BCA_PERIPH
45#define BCA_PERIPH ((1<<0) | (1<<2)) /* LPUART | LPSPI */
46#endif /* BCA_PERIPH */
47
48__attribute__ ((used,section(".bcaconfig")))
49const uint8_t _bca[0x40] = {
50 'k', 'c', 'f', 'g', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
51 BCA_PERIPH, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
52 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
53 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
54};
55
56__attribute__ ((used,section(".cfmconfig")))
57const uint8_t _cfm[0x10] = {
58 0xFF, /* NV_BACKKEY3: KEY=0xFF */
59 0xFF, /* NV_BACKKEY2: KEY=0xFF */
60 0xFF, /* NV_BACKKEY1: KEY=0xFF */
61 0xFF, /* NV_BACKKEY0: KEY=0xFF */
62 0xFF, /* NV_BACKKEY7: KEY=0xFF */
63 0xFF, /* NV_BACKKEY6: KEY=0xFF */
64 0xFF, /* NV_BACKKEY5: KEY=0xFF */
65 0xFF, /* NV_BACKKEY4: KEY=0xFF */
66 0xFF, /* NV_FPROT3: PROT=0xFF */
67 0xFF, /* NV_FPROT2: PROT=0xFF */
68 0xFF, /* NV_FPROT1: PROT=0xFF */
69 0xFF, /* NV_FPROT0: PROT=0xFF */
70 /* [andreika][rusefi]: Warning! These two bytes are extremely important! Don't change them until 100% sure! */
71 /* there is an opinion that wrong values would brick your Kinetis chip for good */
72 0x7E, /* NV_FSEC: KEYEN=1,MEEN=3,FSLACC=3,SEC=2 */
73 0xFB, /* NV_FOPT: BOOTSRC_SEL=1,res=111,RESET_PIN_CFG=1,NMI_DIS=0,BOOTPIN_OPT=1,LPBOOT=1 */
74
75 0xFF,
76 0xFF
77};
78
79/*===========================================================================*/
80/* Driver local functions. */
81/*===========================================================================*/
82
83/*===========================================================================*/
84/* Driver interrupt handlers. */
85/*===========================================================================*/
86
87/*===========================================================================*/
88/* Driver exported functions. */
89/*===========================================================================*/
90
91/**
92 * @brief Low level HAL driver initialization.
93 * @todo Use a macro to define the system clock frequency.
94 *
95 * @notapi
96 */
97void hal_lld_init(void) {
98 // Enable DMA
99 dmaInit();
100}
101
102/**
103 * @brief KE1xF initialization.
104 * @note All the involved constants come from the file @p board.h.
105 * @note This function is meant to be invoked early during the system
106 * initialization, it is usually invoked from the file
107 * @p board.c.
108 * @todo This function needs to be more generic.
109 *
110 * @special
111 */
112void ke1xf_init(void) {
113#if ((__FPU_PRESENT == 1) && (__FPU_USED == 1))
114 SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access */
115#endif /* ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) */
116
117 /* Disable Watchdog */
118 WDOG->CNT = WDOG_UPDATE_KEY;
119 WDOG->TOVAL = 0xFFFF;
120 WDOG->CS = (uint32_t) ((WDOG->CS) & ~WDOG_CS_EN_MASK) | WDOG_CS_UPDATE_MASK;
121
122 /* Initialize Cache */
123 /* Enable Code Bus Cache */
124 /* set command to invalidate all ways, enable write buffer and write GO bit to initiate command */
125 LMEM->PCCCR |= LMEM_PCCCR_INVW1_MASK | LMEM_PCCCR_INVW0_MASK;
126 LMEM->PCCCR |= LMEM_PCCCR_GO_MASK;
127 /* Wait until the command completes */
128 while (LMEM->PCCCR & LMEM_PCCCR_GO_MASK) {
129 }
130 /* Enable cache, enable write buffer */
131 LMEM->PCCCR |= (LMEM_PCCCR_ENWRBUF_MASK | LMEM_PCCCR_ENCACHE_MASK);
132 __ISB();
133}
134
135/** @} */
typedef __attribute__
Ignition Mode.
void hal_lld_init(void)
Low level HAL driver initialization.
Definition hal_lld.c:97
void ke1xf_init(void)
KE1xF initialization.
Definition hal_lld.c:112
void dmaInit(void)
Definition kinetis_dma.c:31