Select one of the symbols to view example projects that use it.
 
Outline
...
...
#include "lx_stm32_nor_simulator_driver.h"
nor_sector_memory
words_per_block
is_erased
mem_set(void *, int, size_t)
lx_stm32_nor_simulator_initialize(LX_NOR_FLASH *)
lx_nor_simulator_read(ULONG *, ULONG *, ULONG)
lx_nor_simulator_write(ULONG *, ULONG *, ULONG)
lx_nor_simulator_block_erase(ULONG, ULONG)
lx_nor_simulator_block_erased_verify(ULONG)
Files
loading...
SourceVuSTM32 Libraries and Sampleslevelxcommon/drivers/lx_stm32_nor_simulator_driver.c
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ /* Include necessary files. */ #include "lx_stm32_nor_simulator_driver.h" static UINT lx_nor_simulator_read(ULONG *flash_address, ULONG *destination, ULONG words); static UINT lx_nor_simulator_write(ULONG *flash_address, ULONG *source, ULONG words); static UINT lx_nor_simulator_block_erase(ULONG block, ULONG erase_count); static UINT lx_nor_simulator_block_erased_verify(ULONG block); #ifndef LX_DIRECT_READ static ULONG nor_sector_memory[LX_NOR_SIMULATOR_SECTOR_SIZE]; #endif static ULONG words_per_block = (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK) / sizeof(ULONG); static UINT is_erased = 0; static void mem_set(void* s, int c, size_t sz) { UCHAR *p = (UCHAR*)s; UCHAR x = c & 0xff; while (sz--) *p++ = x; }{ ... } UINT lx_stm32_nor_simulator_initialize(LX_NOR_FLASH *nor_flash) { /* Setup the base address of the flash memory. */ nor_flash->lx_nor_flash_base_address = (ULONG *) LX_NOR_SIMULATOR_FLASH_BASE_ADDRESS; if (is_erased == 0) { mem_set(nor_flash->lx_nor_flash_base_address, 0xff, LX_NOR_SIMULATOR_FLASH_SIZE); is_erased = 1; }if (is_erased == 0) { ... } /* Setup geometry of the flash. */ nor_flash->lx_nor_flash_total_blocks = (LX_NOR_SIMULATOR_FLASH_SIZE / (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK)); nor_flash->lx_nor_flash_words_per_block = words_per_block; /* Setup function pointers for the NOR flash services. */ nor_flash->lx_nor_flash_driver_read = lx_nor_simulator_read; nor_flash->lx_nor_flash_driver_write = lx_nor_simulator_write; nor_flash->lx_nor_flash_driver_block_erase = lx_nor_simulator_block_erase; nor_flash->lx_nor_flash_driver_block_erased_verify = lx_nor_simulator_block_erased_verify; #ifndef LX_DIRECT_READ /* Setup local buffer for NOR flash operation. This buffer must be the sector size of the NOR flash memory. */ nor_flash->lx_nor_flash_sector_buffer = &nor_sector_memory[0];/* ... */ #endif /* Return success. */ return(LX_SUCCESS); }{ ... } static UINT lx_nor_simulator_read(ULONG *flash_address, ULONG *destination, ULONG words) { memcpy((VOID *)destination, (VOID *)flash_address, words * sizeof(ULONG)); return(LX_SUCCESS); }{ ... } static UINT lx_nor_simulator_write(ULONG *flash_address, ULONG *source, ULONG words) { memcpy((VOID *)flash_address, (VOID *)source, words * sizeof(ULONG)); return(LX_SUCCESS); }{ ... } static UINT lx_nor_simulator_block_erase(ULONG block, ULONG erase_count) { ULONG *pointer; LX_PARAMETER_NOT_USED(erase_count); /* Setup pointer. */ pointer = (ULONG *) (LX_NOR_SIMULATOR_FLASH_BASE_ADDRESS + block * (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK)); /* Loop to erase block. */ mem_set((VOID *) pointer, 0xff, words_per_block * sizeof(ULONG)); return(LX_SUCCESS); }{ ... } static UINT lx_nor_simulator_block_erased_verify(ULONG block) { ULONG *word_ptr; ULONG words; /* Determine if the block is completely erased. */ word_ptr = (ULONG *) (LX_NOR_SIMULATOR_FLASH_BASE_ADDRESS + block * (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK)); /* Calculate the number of words in a block. */ words = words_per_block; /* Loop to check if the block is erased. */ while (words--) { /* Is this word erased? */ if (*word_ptr++ != 0xFFFFFFFF) return(LX_ERROR); }while (words--) { ... } /* Return success. */ return(LX_SUCCESS); }{ ... }
Details