Skip to content

Commit 600b49a

Browse files
committed
bootmode: initial commit
Let the user (and another use case the failsafe mode) configure the bootmode. Signed-off-by: Michael Walle <[email protected]>
1 parent 0ffcf28 commit 600b49a

File tree

5 files changed

+119
-1
lines changed

5 files changed

+119
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LIBS += -lgcc
3030

3131
OBJECTS = startup.o main.o miniprintf.o uart.o systick.o adc.o vref.o misc.o
3232
OBJECTS += iomux.o sysctl.o gpio.o cp.o i2c.o nvic.o nvm.o config.o wdt.o led.o
33-
OBJECTS += ticks.o sl28wdt.o
33+
OBJECTS += ticks.o sl28wdt.o bootmode.o
3434

3535
DEPS := $(shell find -name '*.d')
3636

bootmode.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: BSD-2-Clause
2+
/*
3+
* Copyright (c) 2025 Kontron Europe GmbH
4+
*/
5+
6+
#include "bootmode.h"
7+
#include "config.h"
8+
#include "gpio.h"
9+
#include "misc.h"
10+
11+
#define BOOTMODE_PIN_FAILSAFE 0x0000000c
12+
#define BOOTMODE_PIN_MASK 0x00c007fc
13+
14+
static unsigned short bootmode;
15+
16+
void bootmode_enable(unsigned short mode)
17+
{
18+
unsigned int mask;
19+
20+
printf("%s mode=%04x\n", __func__, mode);
21+
22+
gpio_mask_clr(BOOTMODE_PIN_MASK);
23+
/* PA8 .. PA2 */
24+
mask = ((unsigned int)mode >> 1) & 0x000001fc;
25+
/* PA23 */
26+
mask |= ((unsigned int)mode << 13) & 0x00800000;
27+
/* PA22 */
28+
mask |= ((unsigned int)mode << 11) & 0x00400000;
29+
/* PA10 .. PA9 */
30+
mask |= ((unsigned int)mode >> 3) & 0x00000600;
31+
gpio_mask_set(mask);
32+
gpio_out_mask(BOOTMODE_PIN_MASK);
33+
}
34+
35+
void bootmode_write(unsigned char offset, unsigned char value)
36+
{
37+
switch (offset) {
38+
case 0:
39+
bootmode = (bootmode & 0x00ff) | (value << 8);
40+
break;
41+
case 1:
42+
bootmode = (bootmode & 0xff00) | value;
43+
bootmode_enable(bootmode);
44+
break;
45+
}
46+
}
47+
48+
unsigned char bootmode_read(unsigned char offset)
49+
{
50+
switch (offset) {
51+
case 0:
52+
return bootmode & 0xff;
53+
case 1:
54+
return bootmode >> 8;
55+
default:
56+
return 0xff;
57+
}
58+
}
59+
60+
void bootmode_disable(void)
61+
{
62+
gpio_in_mask(BOOTMODE_PIN_MASK);
63+
}
64+
65+
void bootmode_init(void)
66+
{
67+
if (config->flags & CFG_F_DRIVE_BOOTMODE)
68+
bootmode_enable(config->bootmode);
69+
else
70+
bootmode_disable();
71+
}

bootmode.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: BSD-2-Clause
2+
/*
3+
* Copyright (c) 2025 Kontron Europe GmbH
4+
*/
5+
6+
#ifndef __BOOTMODE_H
7+
#define __BOOTMODE_H
8+
9+
#define BOOTMODE_FAILSAFE 0x00000018
10+
11+
void bootmode_write(unsigned char offset, unsigned char value);
12+
unsigned char bootmode_read(unsigned char offset);
13+
14+
void bootmode_enable(unsigned short mode);
15+
void bootmode_write(unsigned char offset, unsigned char value);
16+
unsigned char bootmode_read(unsigned char offset);
17+
void bootmode_disable(void);
18+
void bootmode_init(void);
19+
20+
#endif /* __BOOTMODE_H */

i2c.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "bootmode.h"
78
#include "config.h"
89
#include "gpio.h"
910
#include "i2c.h"
@@ -325,6 +326,8 @@ static void i2c_rxdata(unsigned char offset, unsigned char value)
325326
return config_write(offset - 0, value);
326327
case 4 ... 7:
327328
return sl28wdt_write(offset - 4, value);
329+
case 16 ... 17:
330+
return bootmode_write(offset - 16, value);
328331
}
329332
}
330333

main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdbool.h>
77
#include <stddef.h>
88
#include "adc.h"
9+
#include "bootmode.h"
910
#include "config.h"
1011
#include "cp.h"
1112
#include "gpio.h"
@@ -49,6 +50,28 @@ const struct iomux_config iomux_default_config[] = {
4950
{ 17, PINCM_PC | PINCM17_PF_TIMG0_C0 },
5051
/* PA18 (healthy LED) */
5152
{ 19, PINCM_PC | PINCM19_PF_TIMG4_C1 },
53+
/* PA2 (BOOTMODE03) */
54+
{ 3, PINCM_PC | PINCM_PF_GPIO },
55+
/* PA3 (BOOTMODE04) */
56+
{ 4, PINCM_PC | PINCM_PF_GPIO },
57+
/* PA4 (BOOTMODE05) */
58+
{ 5, PINCM_PC | PINCM_PF_GPIO },
59+
/* PA5 (BOOTMODE06) */
60+
{ 6, PINCM_PC | PINCM_PF_GPIO },
61+
/* PA6 (BOOTMODE07) */
62+
{ 7, PINCM_PC | PINCM_PF_GPIO },
63+
/* PA7 (BOOTMODE08) */
64+
{ 8, PINCM_PC | PINCM_PF_GPIO },
65+
/* PA8 (BOOTMODE09) */
66+
{ 9, PINCM_PC | PINCM_PF_GPIO },
67+
/* PA23 (BOOTMODE10) */
68+
{ 24, PINCM_PC | PINCM_PF_GPIO },
69+
/* PA22 (BOOTMODE11) */
70+
{ 23, PINCM_PC | PINCM_PF_GPIO },
71+
/* PA9 (BOOTMODE12) */
72+
{ 10, PINCM_PC | PINCM_PF_GPIO },
73+
/* PA10 (BOOTMODE13) */
74+
{ 11, PINCM_PC | PINCM_PF_GPIO },
5275
{ 0 }
5376
};
5477

@@ -91,6 +114,7 @@ int main(void)
91114
i2c_init();
92115
wdt_init();
93116
led_init();
117+
bootmode_init();
94118

95119
i2c_bus_reset();
96120

0 commit comments

Comments
 (0)